home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3932 < prev    next >
Encoding:
Text File  |  1991-08-29  |  22.0 KB  |  870 lines

  1. Path: wupost!uunet!munnari.oz.au!murtoa.cs.mu.oz.au!csv.viccol.edu.au!timcc
  2. From: timcc@csv.viccol.edu.au (Tim Cook)
  3. Newsgroups: alt.sources
  4. Subject: dl v1.6, part 3 of 3
  5. Message-ID: <1991Aug21.174037.6833@csv.viccol.edu.au>
  6. Date: 21 Aug 91 22:40:37 GMT
  7. Organization: Computer Services, Victoria College, Melbourne
  8. Lines: 860
  9.  
  10. #!/bin/sh
  11. # This is part 03 of a multipart archive
  12. # ============= allocate.c ==============
  13. if test -f 'allocate.c' -a X"$1" != X"-c"; then
  14.     echo 'x - skipping allocate.c (File already exists)'
  15. else
  16. echo 'x - extracting allocate.c (Text)'
  17. sed 's/^X//' << 'SHAR_EOF' > 'allocate.c' &&
  18. /* allocate.c -    Interface to malloc/realloc
  19. X *
  20. X * DESCRIPTION
  21. X *    These routines, allocate and re_allocate call malloc(3) and
  22. X *    realloc(3) respectively.  If malloc or realloc returns NULL,
  23. X *    an error message is printed and execution is terminated,
  24. X *    otherwise, the value returned by malloc/realloc is returned.
  25. X *
  26. X * Copyright (c) 1991 Tim Cook.
  27. X * Non-profit distribution allowed.  See README for details.
  28. X */
  29. X
  30. static char rcsid[] = "$Header: allocate.c 1.0 91/08/19 $" ;
  31. X
  32. #include "config.h"
  33. X
  34. extern VOID_PTR malloc () ;
  35. extern VOID_PTR realloc () ;
  36. X
  37. X
  38. VOID_PTR allocate (length)
  39. X   size_t length ;
  40. {
  41. X   VOID_PTR tmp ;
  42. X
  43. X   if ((tmp = malloc (length)) == (VOID_PTR) NULL) {
  44. X      perror ("malloc") ;
  45. X      exit (1) ; }
  46. X   else
  47. X      return tmp ;
  48. X   }
  49. X
  50. X
  51. VOID_PTR re_allocate (p, length)
  52. X   VOID_PTR p ;
  53. X   size_t length ;
  54. {
  55. X   VOID_PTR tmp ;
  56. X
  57. X   if ((tmp = realloc (p, length)) == (VOID_PTR) NULL) {
  58. X      perror ("realloc") ;
  59. X      exit (1) ; }
  60. X   else
  61. X      return tmp ;
  62. X   }
  63. SHAR_EOF
  64. chmod 0640 allocate.c ||
  65. echo 'restore of allocate.c failed'
  66. fi
  67. # ============= pathname.c ==============
  68. if test -f 'pathname.c' -a X"$1" != X"-c"; then
  69.     echo 'x - skipping pathname.c (File already exists)'
  70. else
  71. echo 'x - extracting pathname.c (Text)'
  72. sed 's/^X//' << 'SHAR_EOF' > 'pathname.c' &&
  73. /* pathname.c -    Construct a pathname from a directory and basename
  74. X *
  75. X * SYNOPSIS
  76. X *    char *pathname (char *directory, char *name)
  77. X *
  78. X * RETURNS
  79. X *    Returns "directory" + "/" + "name" (copied into static
  80. X *    storage), or a pointer to "name" if "directory" is null.
  81. X *
  82. X * Copyright (c) 1991 Tim Cook.
  83. X * Non-profit distribution allowed.  See README for details.
  84. X */
  85. X
  86. static char rcsid[] = "$Header: pathname.c 1.0 91/08/21 $" ;
  87. X
  88. #include "config.h"
  89. #include <sys/param.h>
  90. X
  91. #ifndef MAXPATHLEN
  92. #define MAXPATHLEN    1024
  93. #endif
  94. X
  95. X
  96. char *pathname (directory, name)
  97. X   char *directory, *name ;
  98. {
  99. X   static char return_value[MAXPATHLEN+1] ;
  100. X
  101. X   if (directory && *directory != EOS) {
  102. X      strcpy (return_value, directory) ;
  103. X      strcat (return_value, "/") ;
  104. X      strcat (return_value, name) ;
  105. X      return return_value ; }
  106. X   else
  107. X      return name ;
  108. X   }
  109. SHAR_EOF
  110. chmod 0640 pathname.c ||
  111. echo 'restore of pathname.c failed'
  112. fi
  113. # ============= split_pathname.c ==============
  114. if test -f 'split_pathname.c' -a X"$1" != X"-c"; then
  115.     echo 'x - skipping split_pathname.c (File already exists)'
  116. else
  117. echo 'x - extracting split_pathname.c (Text)'
  118. sed 's/^X//' << 'SHAR_EOF' > 'split_pathname.c' &&
  119. /* split_pathname.c -    Split path into directory and name
  120. X *
  121. X * SYNOPSIS
  122. X *    char *split_pathname (const char *pathname, char *directory,
  123. X *              char *name)
  124. X *
  125. X * DESCRIPTION
  126. X *    Extracts the directory part and the name part of a Unix pathname.
  127. X *    Returns a pointer to the name part.
  128. X *
  129. X * Copyright (c) 1991 Tim Cook.
  130. X * Non-profit distribution allowed.  See README for details.
  131. X */
  132. X
  133. static char rcsid[] = "$Header: split_pathname.c 1.1 91/08/06 $" ;
  134. X
  135. #include "config.h"
  136. X
  137. #define NULL_CP        ((char *) 0)
  138. #define EOS        '\0'
  139. X
  140. X
  141. char *split_pathname (pathname, directory, name)
  142. X   char *pathname, *directory, *name ;
  143. {
  144. X   char *p ;
  145. X
  146. X   strcpy (directory, pathname) ;
  147. X   while ((p = strrchr (directory, '/')) != NULL_CP && p[1] == EOS) *p = EOS ;
  148. X   if (p == NULL_CP) {
  149. X      strcpy (name, pathname) ;
  150. X      directory[0] = EOS ; }
  151. X   else {
  152. X      strcpy (name, p + 1) ;
  153. X      if (p == directory) {    /* The slash is at the start of pathname */
  154. X     directory[1] = EOS ; }
  155. X      else {
  156. X     *p = EOS ; } }
  157. X   return name ; }
  158. X
  159. X
  160. #ifdef TEST
  161. #include <stdio.h>
  162. X
  163. int main (argc, argv)
  164. X   int argc ;
  165. X   char **argv ;
  166. {
  167. X   char directory[256] ;
  168. X   char name[256] ;
  169. X
  170. X   if (split_pathname (argv[1], directory, name) == NULL_CP) {
  171. X      fprintf (stderr, "%s: couldn't parse \"%s\"\n", argv[0], argv[1]) ; }
  172. X   else {
  173. X      printf ("pathname:  \"%s\"\ndirectory: \"%s\"\nname:     \"%s\"\n",
  174. X     argv[1], directory, name) ; }
  175. X   }
  176. #endif
  177. SHAR_EOF
  178. chmod 0640 split_pathname.c ||
  179. echo 'restore of split_pathname.c failed'
  180. fi
  181. # ============= getdesc.c ==============
  182. if test -f 'getdesc.c' -a X"$1" != X"-c"; then
  183.     echo 'x - skipping getdesc.c (File already exists)'
  184. else
  185. echo 'x - extracting getdesc.c (Text)'
  186. sed 's/^X//' << 'SHAR_EOF' > 'getdesc.c' &&
  187. /* getdesc.c -    Get file description
  188. X *
  189. X * Copyright (c) 1991 Tim Cook.
  190. X * Non-profit distribution allowed.  See README for details.
  191. X */
  192. X
  193. static char rcsid[] = "$Header: getdesc.c 1.0 91/08/21 $" ;
  194. X
  195. #include "config.h"
  196. #include <fcntl.h>
  197. X
  198. extern int _initdesc () ;
  199. #ifdef NDBM
  200. extern DBM *_desc_database ;
  201. #endif
  202. X
  203. X
  204. char *getdesc (directory, name, inode)
  205. X   char *directory ;
  206. X   char *name ;
  207. X   ino_t inode ;
  208. {
  209. X   static datum key, value ;
  210. X
  211. X   if (name == NULL_CP && inode == 0) {
  212. X      return NULL_CP ; }
  213. X
  214. X   if (_initdesc (directory, O_RDONLY)) {
  215. X
  216. X      /* We have a description database */
  217. X
  218. X      int found = FALSE ;
  219. X
  220. X      if (name) {
  221. X
  222. X     /* Check for it by name */
  223. X
  224. X     key.dptr = name ;
  225. X     key.dsize = strlen (name) ;
  226. X     if (key.dsize == sizeof (ino_t))
  227. X        key.dsize++ ;
  228. X     value = DBM_fetch (_desc_database, key) ;
  229. X     found = value.dptr != NULL_CP ; }
  230. X
  231. X      if (! found && inode) {
  232. X
  233. X     /* Check for it by inode */
  234. X
  235. X     key.dptr = (char *) &inode ;
  236. X     key.dsize = sizeof (ino_t) ;
  237. X     value = DBM_fetch (_desc_database, key) ;
  238. X     if (value.dptr != NULL_CP) {
  239. X        char temp[sizeof (ino_t) + 1] ;
  240. X
  241. X        /* Now use the name we got using the inode */
  242. X
  243. X        if (value.dsize == sizeof (ino_t)) {
  244. X           strncpy (temp, value.dptr, sizeof (ino_t)) ;
  245. X           temp[sizeof (ino_t) + 1] = EOS ;
  246. X           key.dptr = temp ;
  247. X           key.dsize = sizeof (temp) ; }
  248. X        else {
  249. X           key.dptr = value.dptr ;
  250. X           key.dsize = value.dsize ; }
  251. X        value = DBM_fetch (_desc_database, key) ;
  252. X        found = value.dptr != NULL_CP ; } }
  253. X
  254. X      if (found)
  255. X     return value.dptr ;
  256. X      }
  257. X   return NULL_CP ;
  258. X   }
  259. SHAR_EOF
  260. chmod 0640 getdesc.c ||
  261. echo 'restore of getdesc.c failed'
  262. fi
  263. # ============= setdesc.c ==============
  264. if test -f 'setdesc.c' -a X"$1" != X"-c"; then
  265.     echo 'x - skipping setdesc.c (File already exists)'
  266. else
  267. echo 'x - extracting setdesc.c (Text)'
  268. sed 's/^X//' << 'SHAR_EOF' > 'setdesc.c' &&
  269. /* setdesc.c -    Set a file description
  270. X *
  271. X * Copyright (c) 1991 Tim Cook.
  272. X * Non-profit distribution allowed.  See README for details.
  273. X */
  274. X
  275. static char rcsid[] = "$Header: setdesc.c 1.0 91/08/21 $" ;
  276. X
  277. #include "config.h"
  278. #include <fcntl.h>
  279. #include <sys/stat.h>
  280. #include <sys/errno.h>
  281. X
  282. extern int errno ;
  283. extern char *pathname () ;
  284. extern int _initdesc () ;
  285. #ifdef NDBM
  286. extern DBM *_desc_database ;
  287. #endif
  288. X
  289. X
  290. int setdesc (directory, name, inode, description)
  291. X   char *directory ;
  292. X   char *name ;
  293. X   ino_t inode ;
  294. X   char *description ;
  295. {
  296. X   datum key, content ;
  297. X
  298. X   if (! name) {
  299. X      errno = EINVAL ;
  300. X      return FALSE ; }
  301. X
  302. X   if (! inode) {
  303. X      struct stat file_status ;
  304. X
  305. X      if (stat (pathname (directory, name), &file_status) == 0)
  306. X     inode = file_status.st_ino ; }
  307. X
  308. X   if (description == NULL_CP || *description == EOS) {
  309. X      /* Set the description to null?  This means delete */
  310. X
  311. X      if (! _initdesc (directory, O_RDWR))
  312. X     return FALSE ;
  313. X
  314. X      if (inode) {
  315. X     key.dptr = (char *) &inode ;
  316. X     key.dsize = sizeof (ino_t) ;
  317. X     DBM_delete (_desc_database, key) ; }
  318. X      key.dptr = name ;
  319. X      key.dsize = strlen (name) ;
  320. X      if (key.dsize == sizeof (ino_t))
  321. X     key.dsize++ ;
  322. X      DBM_delete (_desc_database, key) ;
  323. X      return TRUE ; }
  324. X
  325. X   if (! _initdesc (directory, O_RDWR | O_CREAT))
  326. X      return FALSE ;
  327. X
  328. X   /* Store the description, indexed by the file name */
  329. X
  330. X   key.dptr = name ;
  331. X   key.dsize = strlen (name) ;
  332. X
  333. X   /*
  334. X    * Name and inode keys are distinguished by the key length.  Inode
  335. X    * keys are all "sizeof (ino_t)" long, while all other keys are
  336. X    * name keys.
  337. X    */
  338. X
  339. X   if (key.dsize == sizeof (ino_t))
  340. X      /*
  341. X       * To distinguish this from an inode key, we'll store the
  342. X       * terminating null byte as well
  343. X       */
  344. X      key.dsize++ ;
  345. X
  346. X   content.dptr = description ;
  347. X   content.dsize = strlen (description) + 1 ;
  348. X   if (DBM_store (_desc_database, key, content) < 0)
  349. X      return FALSE ;
  350. X
  351. X   if (inode) {
  352. X
  353. X      /* Store the file name, indexed by the inode number */
  354. X
  355. X      key.dptr = (char *) &inode ;
  356. X      key.dsize = sizeof (ino_t) ;
  357. X      content.dptr = name ;
  358. X      content.dsize = strlen (name) ;
  359. X      if (DBM_store (_desc_database, key, content) < 0)
  360. X     return FALSE ;
  361. X      }
  362. X   return TRUE ;
  363. X   }
  364. SHAR_EOF
  365. chmod 0640 setdesc.c ||
  366. echo 'restore of setdesc.c failed'
  367. fi
  368. # ============= enddesc.c ==============
  369. if test -f 'enddesc.c' -a X"$1" != X"-c"; then
  370.     echo 'x - skipping enddesc.c (File already exists)'
  371. else
  372. echo 'x - extracting enddesc.c (Text)'
  373. sed 's/^X//' << 'SHAR_EOF' > 'enddesc.c' &&
  374. /* enddesc.c -    Initialise/deallocate description database
  375. X *
  376. X * Copyright (c) 1991 Tim Cook.
  377. X * Non-profit distribution allowed.  See README for details.
  378. X */
  379. X
  380. static char rcsid[] = "$Header: enddesc.c 1.0 91/08/21 $" ;
  381. X
  382. #include <sys/param.h>
  383. #include <sys/errno.h>
  384. #include "config.h"
  385. X
  386. extern int errno ;
  387. #ifdef NDBM
  388. DBM *_desc_database = (DBM *) NULL ;
  389. #define DB_OPEN        (_desc_database != (DBM *) NULL)
  390. #else
  391. static int _db_open = FALSE ;
  392. #define DB_OPEN        _db_open
  393. #endif
  394. X
  395. X
  396. VOID enddesc ()
  397. {
  398. #ifdef NDBM
  399. X   if (_desc_database)
  400. X      dbm_close (_desc_database) ;
  401. #else
  402. X   dbmclose () ;
  403. #endif
  404. X   }
  405. X
  406. X
  407. /*
  408. X * This is support routine for getdesc() and setdesc(), and should not
  409. X * normally be called by the programmer. 
  410. X */
  411. X
  412. int _initdesc (directory, open_flags)
  413. X   char *directory ;
  414. X   int open_flags ;
  415. {
  416. X   static char desc_file[MAXPATHLEN+1] = "" ;
  417. X   static int db_flags ;
  418. X
  419. X   if (! directory || *directory == EOS)
  420. X      directory = "." ;
  421. X
  422. X   if (open_flags == db_flags && strcmp (directory, desc_file) == 0)
  423. X      return DB_OPEN ;        /* Tell 'em what we said before */
  424. X
  425. X   /* Otherwise, we need to try to open a database */
  426. X   {
  427. X      char *p ;
  428. #ifndef NDBM
  429. X      char *q ;
  430. X      struct stat status ;
  431. #endif
  432. X
  433. X      DBM_close (_desc_database) ;
  434. X
  435. X      strcpy (desc_file, directory) ;
  436. X      db_flags = open_flags ;
  437. X
  438. X      /* Find end of "desc_file" */
  439. X      for (p = desc_file ; *p != EOS ; p++) ;
  440. X
  441. #ifdef NDBM
  442. X
  443. X      /* By crikey, it's easier this way! */
  444. X
  445. X      strcpy (p, "/.desc") ;
  446. X
  447. #ifdef TEST
  448. X      printf ("Opening new database\n") ;
  449. #endif
  450. X      if ((_desc_database = dbm_open (desc_file, db_flags, 0666))
  451. X               == (DBM *) NULL) {
  452. X     return FALSE ; }
  453. X
  454. #else    /* DBM */
  455. X
  456. X      _db_open = FALSE ;    /* We just closed it above */
  457. X
  458. X      strcpy (p, "/.desc.pag") ;
  459. X      q = strrchr (p, '.') ;
  460. X
  461. X      if (stat (desc_file, &status) != -1) {
  462. X
  463. X     /* Database exists */
  464. X
  465. X     *q = EOS ;        /* Hide ".pag" */
  466. X     if (dbminit (desc_file) < 0) {
  467. X        return FALSE ; }
  468. X     else
  469. X        _db_open = TRUE ; }
  470. X      else {
  471. X
  472. X     /* No database */
  473. X
  474. X     if (db_flags & O_RDWR) {
  475. X        int fd ;
  476. X
  477. X        /* Create .desc.(pag|dir) files */
  478. X        if ((fd = open (desc_file, db_flags | O_EXCL, 0666))
  479. X          < 0)
  480. X           return FALSE ;
  481. X        close (fd) ;
  482. X        strcpy (q, ".dir") ;
  483. X        if ((fd = open (desc_file, db_flags | O_EXCL, 0666))
  484. X          < 0)
  485. X           return FALSE ;
  486. X        close (fd) ;
  487. X
  488. X        /* Start up DBM */
  489. X        *q = EOS ;        /* Hide ".dir" */
  490. X        if (dbminit (desc_file) == 0)
  491. X           _db_open = TRUE ; }
  492. X     else {
  493. X        errno = ENOENT ;
  494. X        return FALSE ; } }
  495. #endif    /* NDBM */
  496. X
  497. X      /* Return "desc_file" to just a directory name */
  498. X      *p = EOS ;
  499. X      }
  500. X   return TRUE ;
  501. X   }
  502. SHAR_EOF
  503. chmod 0640 enddesc.c ||
  504. echo 'restore of enddesc.c failed'
  505. fi
  506. # ============= dl.1 ==============
  507. if test -f 'dl.1' -a X"$1" != X"-c"; then
  508.     echo 'x - skipping dl.1 (File already exists)'
  509. else
  510. echo 'x - extracting dl.1 (Text)'
  511. sed 's/^X//' << 'SHAR_EOF' > 'dl.1' &&
  512. ..\" dl.1 -    Man page for descriptive ls
  513. ..\"
  514. ..\" Copyright (c) 1991 Tim Cook.
  515. ..\" Non-profit distribution allowed.  See README for details.
  516. ..\"
  517. ..\" $Header: dl.1 1.2 91/08/07 $
  518. ..\"
  519. ..TH DL 1 "20 March, 1991"
  520. ..UC 4
  521. ..SH NAME
  522. dl \- Descriptive ls
  523. ..SH SYNOPSIS
  524. ..B dl
  525. [
  526. flags
  527. ] [
  528. file ...
  529. ]
  530. ..SH DESCRIPTION
  531. ..I Dl
  532. lists files and directories in the manner of ls(1), but includes a
  533. descriptive comment for each file that has a description set.
  534. By default,
  535. ..I dl
  536. lists the file name, size of the file in bytes and the description.
  537. If the file is a directory, a hyphen (-) is shown instead of the size,
  538. and if the file is a directory that contains other directories, an equals
  539. sign (=) is shown.
  540. ..PP
  541. Descriptions are set by describe(1) and are stored in a hidden file in
  542. the same directory as the files for which descriptions are held.
  543. ..\" The descriptions are matched to files by name
  544. ..\" and inode-number, so renaming or editing the file in the same directory
  545. ..\" will not cause the loss of its description.
  546. ..PP
  547. Options:
  548. ..TP 1i
  549. ..B \-d
  550. List the date and time of each file.  The last modification date and time
  551. are listed after the file size, in the same format used by ls(1).
  552. ..TP 1i
  553. ..B \-e
  554. List everything, even inaccessible files.
  555. By default, files that cannot be read or executed are ignored.
  556. ..TP 1i
  557. ..B \-t
  558. Sort by last modification time.  Most recently modified files come first.
  559. ..TP 1i
  560. ..BI \-f width
  561. Use a maximum of
  562. ..I width
  563. columns to display the file name.
  564. If a file name is longer than
  565. ..I width,
  566. it may expand into the area used to show the size.
  567. If this overflows, the size and other information will be listed on a
  568. separate line.
  569. ..TP 1i
  570. ..B \-R
  571. Recursively list any subdirectories encountered, just like ls(1).
  572. ..SH FILES
  573. For each directory, a .desc.pag and .desc.dir (DBM files) are used to
  574. store descriptions.
  575. ..SH SEE\ ALSO
  576. ls(1), describe(1).
  577. SHAR_EOF
  578. chmod 0640 dl.1 ||
  579. echo 'restore of dl.1 failed'
  580. fi
  581. # ============= describe.1 ==============
  582. if test -f 'describe.1' -a X"$1" != X"-c"; then
  583.     echo 'x - skipping describe.1 (File already exists)'
  584. else
  585. echo 'x - extracting describe.1 (Text)'
  586. sed 's/^X//' << 'SHAR_EOF' > 'describe.1' &&
  587. ..\" describe.1 -    Man page for describe
  588. ..\"
  589. ..\" Copyright (c) 1991 Tim Cook.
  590. ..\" Non-profit distribution allowed.  See README for details.
  591. ..\"
  592. ..\" $Header: describe.1 1.1 91/08/07 $
  593. ..\"
  594. ..TH DESCRIBE 1 "20 March, 1991"
  595. ..UC 4
  596. ..SH NAME
  597. describe - Set or list a descriptive comment for a file
  598. ..SH SYNOPSIS
  599. ..B describe file description
  600. ..PP
  601. ..B describe -s descriptions-file
  602. [
  603. directory
  604. ]
  605. ..PP
  606. ..B describe -d file ...
  607. ..PP
  608. ..B describe -l
  609. [
  610. directory
  611. ]
  612. ..SH DESCRIPTION
  613. ..I Describe
  614. sets, deletes or lists file descriptions, as used by dl(1).
  615. To set the description on one file, use the first form shown above.
  616. To set descriptions on a number of files, put the descriptions into a file,
  617. then use the -s option as shown above
  618. (leaving off
  619. ..I directory
  620. implies the current directory).  If you use a hyphen (-) as the name of the
  621. descriptions file,
  622. ..I describe
  623. will read standard input for the list of descriptions.
  624. To delete the description for one or more files, use the -d option as shown
  625. above.
  626. To list all the descriptions set for files in a directory, use the -l option
  627. (again, leaving off
  628. ..I directory
  629. means the current directory).
  630. ..PP
  631. A description-file is a simple text file.
  632. Each line should list the file name (quoted with double quotes if it
  633. contains white-space), followed by white-space, followed by the
  634. description.
  635. The description itself may contain white-space, and is only terminated
  636. by an end-of-line.
  637. Comments may appear in a description file, as a line that starts with a
  638. hash (#) character.
  639. ..PP
  640. If you set a description to null,
  641. ..I describe
  642. will attempt to delete any
  643. existing description, which will achieve the same result.
  644. ..PP
  645. Descriptions are stored in DBM files.
  646. Each description is keyed by the file name, and the file name is also
  647. keyed by the file's inode-number.
  648. This means that renaming or editing the file in the same directory will
  649. not mean the loss of its description.
  650. If you wish to ``optimize'' the description database of a directory,
  651. you can do so in the following manner:
  652. ..PP
  653. ..nf
  654. X    % describe -l > /tmp/descriptions
  655. X    % rm .desc.*
  656. X    % describe -s /tmp/descriptions
  657. ..fi
  658. ..PP
  659. NOTE:  Old descriptions can be passed on to irrelevant files if you
  660. create a new file that uses the same inode that the originally
  661. described file used.  This can be avoided by either deleting the
  662. description when the original file is deleted, or making sure you set
  663. a new description when you create new files, even if you set it to
  664. null.
  665. ..SH FILES
  666. For each directory, a .desc.pag and .desc.dir (DBM files) are used to
  667. store descriptions.
  668. ..SH SEE\ ALSO
  669. dl(1).
  670. SHAR_EOF
  671. chmod 0640 describe.1 ||
  672. echo 'restore of describe.1 failed'
  673. fi
  674. # ============= getdesc.3 ==============
  675. if test -f 'getdesc.3' -a X"$1" != X"-c"; then
  676.     echo 'x - skipping getdesc.3 (File already exists)'
  677. else
  678. echo 'x - extracting getdesc.3 (Text)'
  679. sed 's/^X//' << 'SHAR_EOF' > 'getdesc.3' &&
  680. ..\" getdesc.3 -    Man page for getdesc(), setdesc() and enddesc()
  681. ..\"
  682. ..\" Copyright (c) 1991 Tim Cook.
  683. ..\" Non-profit distribution allowed.  See README for details.
  684. ..\"
  685. ..\" $Header: getdesc.3 1.0 91/08/21 $
  686. ..\"
  687. ..TH GETDESC 3 "20 March, 1991"
  688. ..UC 4
  689. ..SH NAME
  690. getdesc, setdesc, enddesc - File description routines
  691. ..SH SYNOPSIS
  692. ..nf
  693. ..ft B
  694. #include <sys/types.h>
  695. ..sp
  696. char *getdesc (char *dir, char *name, ino_t inode)
  697. ..sp
  698. int setdesc (char *dir, char *name, ino_t inode, char *desc)
  699. ..sp
  700. void enddesc ()
  701. ..ft R
  702. ..fi
  703. ..SH DESCRIPTION
  704. ..I Getdesc
  705. returns a description for a file located in directory
  706. ..I dir
  707. with either a basename of
  708. ..I name
  709. or an inode number of
  710. ..I inode.
  711. If
  712. ..I name
  713. is null or
  714. ..I inode
  715. is zero, their values will not be used to locate the description.
  716. ..PP
  717. ..I Setdesc
  718. sets a description for a file, specified as specified to
  719. ..I getdesc.
  720. The
  721. ..I name
  722. parameter to
  723. ..I setdesc
  724. can not be null, and if the
  725. ..I inode
  726. parameter is zero,
  727. ..I setdesc
  728. will attempt to look up the file's inode number.
  729. Any null-terminated string can be used as a description, although it is
  730. advised that a file description be human-readable.
  731. If
  732. ..I desc
  733. is null,
  734. ..I setdesc
  735. will attempt to delete any existing description for the file.
  736. If a description database does not exist, it will be created.
  737. ..PP
  738. ..I Enddesc
  739. deallocates any resources that may have been allocated by
  740. ..I getdesc
  741. or
  742. ..I setdesc.
  743. ..SH RETURN VALUE
  744. ..I Getdesc
  745. returns null if no description was found, with errno set as possible
  746. explanation.
  747. ..PP
  748. ..I Setdesc
  749. returns 0 (FALSE) if it was unable to set a description, with errno
  750. set as possible explanation.  It returns non-zero (TRUE) if successful.
  751. ..SH FILES
  752. For each directory, a .desc.pag and .desc.dir (DBM files) are used to
  753. store descriptions.
  754. ..SH SEE\ ALSO
  755. dl(1), describe(1).
  756. SHAR_EOF
  757. chmod 0640 getdesc.3 ||
  758. echo 'restore of getdesc.3 failed'
  759. fi
  760. # ============= strpbrk.c ==============
  761. if test -f 'strpbrk.c' -a X"$1" != X"-c"; then
  762.     echo 'x - skipping strpbrk.c (File already exists)'
  763. else
  764. echo 'x - extracting strpbrk.c (Text)'
  765. sed 's/^X//' << 'SHAR_EOF' > 'strpbrk.c' &&
  766. /*
  767. X * Copyright (c) 1985 Regents of the University of California.
  768. X * All rights reserved.
  769. X *
  770. X * Redistribution and use in source and binary forms are permitted
  771. X * provided that the above copyright notice and this paragraph are
  772. X * duplicated in all such forms and that any documentation,
  773. X * advertising materials, and other materials related to such
  774. X * distribution and use acknowledge that the software was developed
  775. X * by the University of California, Berkeley.  The name of the
  776. X * University may not be used to endorse or promote products derived
  777. X * from this software without specific prior written permission.
  778. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  779. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  780. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  781. X */
  782. X
  783. #if defined(LIBC_SCCS) && !defined(lint)
  784. static char sccsid[] = "@(#)strpbrk.c    5.5 (Berkeley) 5/10/89";
  785. #endif /* LIBC_SCCS and not lint */
  786. X
  787. char *
  788. strpbrk(s1, s2)
  789. X    register char *s1, *s2;
  790. {
  791. X    register int c, sc;
  792. X    register char *scanp;
  793. X
  794. X    for (; c = *s1; ++s1)
  795. X        for (scanp = s2; sc = *scanp++;)
  796. X            if (sc == c)
  797. X                return(s1);
  798. X    return(0);
  799. }
  800. SHAR_EOF
  801. chmod 0640 strpbrk.c ||
  802. echo 'restore of strpbrk.c failed'
  803. fi
  804. # ============= perror2.c ==============
  805. if test -f 'perror2.c' -a X"$1" != X"-c"; then
  806.     echo 'x - skipping perror2.c (File already exists)'
  807. else
  808. echo 'x - extracting perror2.c (Text)'
  809. sed 's/^X//' << 'SHAR_EOF' > 'perror2.c' &&
  810. /* perror2 -    Like perror(3), but with two string prefixes
  811. X *
  812. X * SYNOPSIS
  813. X *    void perror2 (const char *str1, const char *str2) ;
  814. X *
  815. X * DESCRIPTION
  816. X *    Prints str1, then a colon and a space, then str2, then a colon and
  817. X *    a space, then the error message corresponding to the contents of
  818. X *    errno, then a newline on stderr.
  819. X */
  820. X
  821. static char rcsid[] = "$Header: perror2.c 1.1 91/03/22 $" ;
  822. X
  823. extern int strlen () ;
  824. X
  825. X
  826. void perror2 (str1, str2)
  827. X   char *str1, *str2 ;
  828. {
  829. X   extern int errno ;
  830. X   extern char *sys_errlist[] ;
  831. X   extern int sys_nerr ;
  832. X   register int save_errno = errno ;
  833. X   static char unknown_error[] = "Unknown error" ;
  834. X   static char colon_space[2] = {':', ' '} ;
  835. X   static char newline = '\n' ;
  836. X   char *p ;
  837. X
  838. X   if (save_errno < 0 || save_errno >= sys_nerr)
  839. X      p = unknown_error ;
  840. X   else
  841. X      p = sys_errlist[save_errno] ;
  842. X   write (2, str1, strlen (str1)) ;
  843. X   write (2, colon_space, sizeof (colon_space)) ;
  844. X   write (2, str2, strlen (str2)) ;
  845. X   write (2, colon_space, sizeof (colon_space)) ;
  846. X   write (2, p, strlen (p)) ;
  847. X   write (2, &newline, 1) ;
  848. X   }
  849. X
  850. X
  851. #ifdef TEST
  852. X
  853. int main (argc, argv)
  854. X   int argc ;
  855. X   char **argv ;
  856. {
  857. X   extern int errno ;
  858. X
  859. X   errno = atoi (argv[1]) ;
  860. X   perror2 (argv[2], argv[3]) ;
  861. X   exit (1) ;
  862. X   }
  863. X
  864. #endif    /* TEST */
  865. SHAR_EOF
  866. chmod 0640 perror2.c ||
  867. echo 'restore of perror2.c failed'
  868. fi
  869. exit 0
  870.