home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3108 < prev    next >
Encoding:
Internet Message Format  |  1991-03-22  |  24.6 KB

  1. From: timcc@csv.viccol.edu.au (Tim Cook)
  2. Newsgroups: alt.sources
  3. Subject: dls/describe part 2 of 2
  4. Message-ID: <1991Mar22.181801.6621@csv.viccol.edu.au>
  5. Date: 22 Mar 91 23:18:00 GMT
  6.  
  7. #!/bin/sh
  8. # this is dls.02 (part 2 of a multipart archive)
  9. # do not concatenate these parts, unpack them in order with /bin/sh
  10. # file describe.c continued
  11. #
  12. if test ! -r _shar_seq_.tmp; then
  13.     echo 'Please unpack part 1 first!'
  14.     exit 1
  15. fi
  16. (read Scheck
  17.  if test "$Scheck" != 2; then
  18.     echo Please unpack part "$Scheck" next!
  19.     exit 1
  20.  else
  21.     exit 0
  22.  fi
  23. ) < _shar_seq_.tmp || exit 1
  24. if test ! -f _shar_wnt_.tmp; then
  25.     echo 'x - still skipping describe.c'
  26. else
  27. echo 'x - continuing file describe.c'
  28. sed 's/^X//' << 'SHAR_EOF' >> 'describe.c' &&
  29. X     perror2 (program_name, file) ;
  30. X     exit (2) ; } }
  31. X   if (chdir (directory) == -1) {
  32. X      perror2 (program_name, directory) ;
  33. X      exit (2) ; }
  34. X   while (! feof (descriptions)) {
  35. X      if (fgets (buffer, sizeof (buffer), descriptions) != NULL_CP) {
  36. X     n = sscanf (buffer, "\"%[^\"]\" %[^\n]\n", file_name, description) ;
  37. X     if (n < 2)
  38. X        n = sscanf (buffer, "%s %[^\n]\n", file_name, description) ;
  39. X     if (n == 2 && file_name[0] != '#') {
  40. X        if (stat (file_name, &status) == -1) {
  41. X           perror2 (program_name, file_name) ; }
  42. X        else {
  43. X           set_description (file_name, status.st_ino, description) ; } } }
  44. X      }
  45. X   fclose (descriptions) ;
  46. X   }
  47. X
  48. X
  49. #define uninitialised    0
  50. #define not_found    1
  51. #define initialised    2
  52. X
  53. static int desc_state = uninitialised ;
  54. X
  55. static
  56. int init_desc_file (file_name, read_only)
  57. X   char *file_name ;
  58. X   int read_only ;
  59. {
  60. X   static char desc_file[MAXNAMLEN+1] ;
  61. X   char new_desc_file[MAXNAMLEN+1] ;
  62. X   char name[MAXNAMLEN+1] ;
  63. X   char *p ;
  64. #ifdef NDBM
  65. X   int open_flags ;
  66. #else
  67. X   struct stat status ;
  68. X   int fd ;
  69. #endif
  70. X
  71. X   strcpy (new_desc_file, file_name) ;
  72. X   if (desc_state == uninitialised || strcmp (desc_file, new_desc_file) != 0) {
  73. X
  74. X      /* Changing desc_file */
  75. X
  76. X      strcpy (desc_file, new_desc_file) ;
  77. X      if (*new_desc_file != EOS)
  78. X     strcat (new_desc_file, "/") ;
  79. X      strcat (new_desc_file, ".desc.pag") ;
  80. X      p = strrchr (new_desc_file, '.') ;
  81. X
  82. #ifdef NDBM
  83. X
  84. X      /* By crikey, it's easier this way! */
  85. X
  86. X      *p = EOS ;
  87. X
  88. X      if (read_only)
  89. X     open_flags = O_RDONLY ;
  90. X      else
  91. X     open_flags = O_RDWR | O_CREAT ;
  92. X      if ((desc_database = dbm_open (new_desc_file, open_flags, 0666))
  93. X               == (DBM *) NULL) {
  94. X     desc_state = not_found ;
  95. X     return FALSE && (! read_only) ; }
  96. X      desc_state = initialised ;
  97. X
  98. #else    /* DBM */
  99. X
  100. X      if (stat (new_desc_file, &status) != -1) {    /* File exists */
  101. X     *p = EOS ;
  102. X     if (dbminit (new_desc_file) < 0) {
  103. X        desc_state = not_found ;
  104. X        return FALSE ; }
  105. X     else
  106. X        desc_state = initialised ; }
  107. X      else {
  108. X     if (read_only) {
  109. X        desc_state = not_found ;
  110. X        return FALSE ; }        /* Signal that there isn't one */
  111. X     else {
  112. X        /* Create .desc.(pag|dir) files */
  113. X        if ((fd = open (new_desc_file, O_CREAT | O_EXCL | O_RDWR, 0666))
  114. X        < 0) {
  115. X           perror2 (program_name, new_desc_file) ;
  116. X           exit (2) ; }
  117. X        close (fd) ;
  118. X        strcpy (p, ".dir") ;
  119. X        if ((fd = open (new_desc_file, O_CREAT | O_EXCL | O_RDWR, 0666))
  120. X        < 0) {
  121. X           perror2 (program_name, new_desc_file) ;
  122. X           exit (2) ; }
  123. X        close (fd) ;
  124. X        *p = EOS ;
  125. X
  126. X        /* Start up DBM */
  127. X        if (dbminit (new_desc_file) < 0)
  128. X           desc_state = not_found ;
  129. X        else
  130. X           desc_state = initialised ; } }
  131. #endif    /* NDBM */
  132. X      }
  133. X   return TRUE ;
  134. X   }
  135. X
  136. X
  137. static
  138. void set_description (file_name, inode, description)
  139. X   char *file_name ;
  140. X   ino_t inode ;
  141. X   char *description ;
  142. {
  143. X   datum key, content ;
  144. X
  145. X   /* Store the description, indexed by the file name */
  146. X   key.dptr = file_name ;
  147. X   key.dsize = strlen (file_name) ;
  148. X   if (key.dsize == sizeof (ino_t))
  149. X      key.dsize++ ;
  150. X   content.dptr = description ;
  151. X   content.dsize = strlen (description) + 1 ;
  152. #ifdef NDBM
  153. X   if (dbm_store (desc_database, key, content, DBM_REPLACE) < 0)
  154. #else
  155. X   if (store (key, content) < 0)
  156. #endif
  157. X   {
  158. X      perror2 (program_name, file_name) ;
  159. X      exit (2) ; }
  160. X
  161. X   /* Store the file name, indexed by the inode number */
  162. X   key.dptr = (char *) &inode ;
  163. X   key.dsize = sizeof (ino_t) ;
  164. X   content.dptr = file_name ;
  165. X   content.dsize = strlen (file_name) ;
  166. #ifdef NDBM
  167. X   if (dbm_store (desc_database, key, content, DBM_REPLACE) < 0)
  168. #else
  169. X   if (store (key, content) < 0)
  170. #endif
  171. X   {
  172. X      perror2 (program_name, file_name) ;
  173. X      exit (2) ; }
  174. X   }
  175. X
  176. X
  177. static
  178. void delete_description (file_name, inode)
  179. X   char *file_name ;
  180. X   ino_t inode ;
  181. {
  182. X   datum key ;
  183. X
  184. X   key.dptr = (char *) &inode ;
  185. X   key.dsize = sizeof (ino_t) ;
  186. #ifdef NDBM
  187. X   dbm_delete (desc_database, key) ;
  188. #else
  189. X   delete (key) ;
  190. #endif
  191. X   key.dptr = file_name ;
  192. X   key.dsize = strlen (file_name) ;
  193. X   if (key.dsize == sizeof (ino_t))
  194. X      key.dsize++ ;
  195. #ifdef NDBM
  196. X   dbm_delete (desc_database, key) ;
  197. #else
  198. X   delete (key) ;
  199. #endif
  200. X   }
  201. X
  202. X
  203. static
  204. void list_descriptions ()
  205. {
  206. X   datum key, last_key, content ;
  207. X   char file_name[MAXNAMLEN+1] ;
  208. X   int file_name_length ;
  209. X   int gap ;
  210. X
  211. #ifdef NDBM
  212. X   for (key = dbm_firstkey (desc_database) ; key.dptr != NULL_CP ;
  213. X     key = dbm_nextkey (desc_database))
  214. #else
  215. X   for (key = firstkey () ; key.dptr != NULL_CP ; key = nextkey (last_key))
  216. #endif
  217. X   {
  218. X      last_key = key ;
  219. X      if (key.dsize != sizeof (ino_t)) {
  220. #ifdef NDBM
  221. X     content = dbm_fetch (desc_database, key) ;
  222. #else
  223. X     content = fetch (key) ;
  224. #endif
  225. X     file_name_length = key.dsize ;
  226. X     if (file_name_length == sizeof (ino_t) + 1
  227. X         && key.dptr[sizeof(ino_t)] == EOS)
  228. X        file_name_length-- ;
  229. X     strncpy (file_name, key.dptr, file_name_length) ;
  230. X     file_name[file_name_length] = EOS ;
  231. X     if (strpbrk (file_name, " \t") != NULL_CP) {
  232. X        printc ('"') ;
  233. X        print (file_name) ;
  234. X        printc ('"') ;
  235. X        gap = 18 - file_name_length ; }
  236. X     else {
  237. X        print (file_name) ;
  238. X        gap = 20 - file_name_length ; }
  239. X     printc (' ') ;        /* We need at least one space */
  240. X     while (gap-- > 0)
  241. X        printc (' ') ;
  242. X     print (content.dptr) ;
  243. X         printc ('\n') ; } }
  244. X   }
  245. SHAR_EOF
  246. echo 'File describe.c is complete' &&
  247. chmod 0640 describe.c ||
  248. echo 'restore of describe.c failed'
  249. Wc_c="`wc -c < 'describe.c'`"
  250. test 8873 -eq "$Wc_c" ||
  251.     echo 'describe.c: original size 8873, current size' "$Wc_c"
  252. rm -f _shar_wnt_.tmp
  253. fi
  254. # ============= list.c ==============
  255. if test -f 'list.c' -a X"$1" != X"-c"; then
  256.     echo 'x - skipping list.c (File already exists)'
  257.     rm -f _shar_wnt_.tmp
  258. else
  259. > _shar_wnt_.tmp
  260. echo 'x - extracting list.c (Text)'
  261. sed 's/^X//' << 'SHAR_EOF' > 'list.c' &&
  262. /* list.c -    List manipulation routines
  263. X *
  264. X * SYNOPSIS
  265. X *    void list_init (struct list *list) ;
  266. X *
  267. X *        Initializes the list.  This is actually only a macro,
  268. X *        and it does not free any storage that may have been
  269. X *        allocated to the list.
  270. X *
  271. X *    void list_free (struct list *list) ;
  272. X *
  273. X *        Deallocates and initializes the list.
  274. X *
  275. X *    void list_push (struct list *list, void *element) ;
  276. X *
  277. X *        Adds the element to the end of the list.
  278. X *
  279. X *    void *list_pop (struct list *list) ;
  280. X *
  281. X *        Returns the last element in the list and removes it.
  282. X *        The list is automatically deallocated using list_free
  283. X *        when the last element has been popped.
  284. X *
  285. X *    void *list_shift (struct list *list) ;
  286. X *
  287. X *        Returns the first element in the list and removes it
  288. X *        The list is automatically deallocated using list_free
  289. X *        when the last element has been shifted.
  290. X *
  291. X *    void list_sort (struct list *list, int (*compare) ()) ;
  292. X *
  293. X *        Sorts the list using compare() (like qsort(3))
  294. X *
  295. X * Copyright (c) 1991 Tim Cook.
  296. X * Non-profit distribution allowed.  See README for details.
  297. X */
  298. X
  299. static char rcsid[] = "$Header: list.c 1.0 91/03/22 $" ;
  300. X
  301. #define _LIST_C
  302. X
  303. #include <list.h>
  304. X
  305. #define NULL    0
  306. X
  307. extern void *malloc () ;
  308. extern void *realloc () ;
  309. extern int free () ;
  310. X
  311. #define INITIAL_ENTRIES    512
  312. X
  313. X
  314. void list_free (list)
  315. X   struct list *list ;
  316. {
  317. X   free (list->s_start) ;
  318. X   list->s_start = (void **) NULL ;
  319. X   }
  320. X
  321. X
  322. void list_push (list, element)
  323. X   struct list *list ;
  324. X   void *element ;
  325. {
  326. X   register unsigned int x, y, z ;
  327. X
  328. X   if (list->start == (void **) NULL) {
  329. X      x = sizeof (void *) * INITIAL_ENTRIES ;
  330. X      list->s_start = (void **) malloc (x) ;
  331. X      list->s_end = list->s_start + INITIAL_ENTRIES ;
  332. X      list->start = list->s_start ;
  333. X      list->end = list->start ;
  334. X      *list->end = element ; }
  335. X   else {
  336. X      if (list->end >= list->s_end) {
  337. X     x = (unsigned int) list->s_end - (unsigned int) list->s_start ;
  338. X     y = (unsigned int) list->start - (unsigned int) list->s_start ;
  339. X     z = (unsigned int) list->end - (unsigned int) list->s_start ;
  340. X     x = x << 1 ;
  341. X     list->s_start = (void **) realloc (list->s_start, x) ;
  342. X     list->s_end = (void **) ((unsigned int) list->s_start + x) ;
  343. X     list->start = (void **) ((unsigned int) list->s_start + y) ;
  344. X     list->end = (void **) ((unsigned int) list->s_start + z) ; }
  345. X      list->end++ ;
  346. X      *list->end = element ; } }
  347. X
  348. X
  349. void *list_shift (list)
  350. X   struct list *list ;
  351. {
  352. X   if (list->start > list->end) {
  353. X      list_free (list) ;
  354. X      return (void *) NULL ; }
  355. X   else
  356. X      return *list->start++ ;
  357. X   }
  358. X
  359. X
  360. void *list_pop (list)
  361. X   struct list *list ;
  362. {
  363. X   if (list->start == (void **) NULL)
  364. X      return (void *) NULL ;
  365. X   else {
  366. X      if (list->end == list->start) {
  367. X     list_free (list) ;
  368. X     return *list->end ; }
  369. X      else
  370. X    return *list->end-- ; }
  371. X   }
  372. X
  373. X
  374. void list_sort (list, compare)
  375. X   struct list *list ;
  376. X   int (*compare) () ;
  377. {
  378. X   register unsigned int x ;
  379. X
  380. X   x = (unsigned int) list->end - (unsigned int) list->start ;
  381. X   x = x / sizeof (void *)  + 1 ;
  382. X   qsort (list->start, x, sizeof (void *), compare) ;
  383. X   }
  384. SHAR_EOF
  385. chmod 0640 list.c ||
  386. echo 'restore of list.c failed'
  387. Wc_c="`wc -c < 'list.c'`"
  388. test 3043 -eq "$Wc_c" ||
  389.     echo 'list.c: original size 3043, current size' "$Wc_c"
  390. rm -f _shar_wnt_.tmp
  391. fi
  392. # ============= list.h ==============
  393. if test -f 'list.h' -a X"$1" != X"-c"; then
  394.     echo 'x - skipping list.h (File already exists)'
  395.     rm -f _shar_wnt_.tmp
  396. else
  397. > _shar_wnt_.tmp
  398. echo 'x - extracting list.h (Text)'
  399. sed 's/^X//' << 'SHAR_EOF' > 'list.h' &&
  400. /* list.h -    Definitions for list manipulation
  401. X *
  402. X * Copyright (c) 1991 Tim Cook.
  403. X * Non-profit distribution allowed.  See README for details.
  404. X *
  405. X * $Header: list.h 1.0 91/03/22 $
  406. X */
  407. X
  408. #ifndef _LIST_H
  409. #define _LIST_H
  410. X
  411. struct list {
  412. X   void **start ;    /* First element (NULL if empty) */
  413. X   void **end ;        /* Last element */
  414. X   void **s_start ;    /* Beginning of storage */
  415. X   void **s_end ;    /* Just past end of storage */
  416. X   } ;
  417. X
  418. #ifndef _LIST_C
  419. #define list_init(l)    ((l)->start = (void **) 0)
  420. extern void list_push () ;
  421. extern void *list_pop () ;
  422. extern void *list_shift () ;
  423. extern void list_sort () ;
  424. extern void list_free () ;
  425. #endif    /* _LIST_C */
  426. X
  427. #endif    /* _LIST_H */
  428. SHAR_EOF
  429. chmod 0640 list.h ||
  430. echo 'restore of list.h failed'
  431. Wc_c="`wc -c < 'list.h'`"
  432. test 669 -eq "$Wc_c" ||
  433.     echo 'list.h: original size 669, current size' "$Wc_c"
  434. rm -f _shar_wnt_.tmp
  435. fi
  436. # ============= smalloc.c ==============
  437. if test -f 'smalloc.c' -a X"$1" != X"-c"; then
  438.     echo 'x - skipping smalloc.c (File already exists)'
  439.     rm -f _shar_wnt_.tmp
  440. else
  441. > _shar_wnt_.tmp
  442. echo 'x - extracting smalloc.c (Text)'
  443. sed 's/^X//' << 'SHAR_EOF' > 'smalloc.c' &&
  444. /* smalloc.c -    Allocate a small chunk of memory that will not be freed
  445. X *
  446. X * SYNOPSIS
  447. X *    void *smalloc (size_t length)
  448. X *
  449. X * DESCRIPTION
  450. X *    smalloc allocates large chunks of memory from malloc(3), and
  451. X *    parcels it out in much smaller chunks.  It does not waste
  452. X *    time recording where these chunks are, as it knows the memory
  453. X *    will only be released when the calling process terminates.
  454. X *
  455. X * Copyright (c) 1991 Tim Cook.
  456. X * Non-profit distribution allowed.  See README for details.
  457. X */
  458. X
  459. static char rcsid[] = "$Header: smalloc.c 1.0 91/03/22 $" ;
  460. X
  461. #include <sys/types.h>
  462. X
  463. #define NULL    ((void *) 0)
  464. X
  465. extern void *malloc () ;
  466. X
  467. #define MALLOC_CHUNK_SIZE    16384
  468. X
  469. #ifdef DEBUG
  470. int _smalloc_chunks = 0 ;
  471. int _smalloc_areas = 0 ;
  472. #endif
  473. X
  474. X
  475. void *smalloc (length)
  476. X   size_t length ;
  477. {
  478. X   static void *virgin = NULL ;        /* Points to next available byte */
  479. X   static void *end = NULL ;        /* Points just past end of storage */
  480. X   void *p ;
  481. X
  482. X   if (length > (size_t) MALLOC_CHUNK_SIZE)
  483. X      return NULL ;
  484. X   if (virgin == NULL || ((u_long) virgin + (u_long) length) > (u_long) end) {
  485. X      virgin = malloc (MALLOC_CHUNK_SIZE) ;
  486. X      if (virgin == NULL)
  487. X     return NULL ;
  488. #ifdef DEBUG
  489. X      _smalloc_areas++ ;
  490. #endif
  491. X      end = (void *) ((u_long) virgin + (u_long) MALLOC_CHUNK_SIZE) ; }
  492. X   p = virgin ;
  493. X   virgin = (void *) ((u_long) virgin + (u_long) length) ;
  494. #ifdef DEBUG
  495. X   _smalloc_chunks++ ;
  496. #endif
  497. X   return p ;
  498. X   }
  499. SHAR_EOF
  500. chmod 0640 smalloc.c ||
  501. echo 'restore of smalloc.c failed'
  502. Wc_c="`wc -c < 'smalloc.c'`"
  503. test 1412 -eq "$Wc_c" ||
  504.     echo 'smalloc.c: original size 1412, current size' "$Wc_c"
  505. rm -f _shar_wnt_.tmp
  506. fi
  507. # ============= vclib.h ==============
  508. if test -f 'vclib.h' -a X"$1" != X"-c"; then
  509.     echo 'x - skipping vclib.h (File already exists)'
  510.     rm -f _shar_wnt_.tmp
  511. else
  512. > _shar_wnt_.tmp
  513. echo 'x - extracting vclib.h (Text)'
  514. sed 's/^X//' << 'SHAR_EOF' > 'vclib.h' &&
  515. /*    vclib.h - VClib definitions file (trimmed for release with dls)
  516. X *
  517. X * Copyright (c) 1991 Tim Cook.
  518. X * Non-profit distribution allowed.  See README for details.
  519. X *
  520. X * $Header: vclib.h 1.0 91/03/22 $
  521. X */
  522. X
  523. #ifndef   VClib
  524. #define   VClib        1
  525. X
  526. /***    M a c r o   C o n s t a n t   D e f i n i t i o n s    ***/
  527. X
  528. /* To enable the use of Boolean variables and constants */
  529. X
  530. typedef   unsigned int    bool ;
  531. X
  532. #ifndef    TRUE
  533. X
  534. #define   TRUE        1
  535. #define   FALSE        0
  536. X
  537. #endif    /* defined (TRUE) */
  538. X
  539. /***    M a c r o   T y p e   D e f i n i t i o n s    ***/
  540. X
  541. /***    t y p e d e f   T y p e   D e f i n i t i o n s    ***/
  542. X
  543. /***    S t r u c t u r e   a n d   U n i o n   D e f i n i t i o n s    ***/
  544. X
  545. #ifdef    sequent    /* If a sequent, shorts are 16 bits */
  546. X
  547. typedef char        byte ;
  548. typedef unsigned char    ubyte ;
  549. typedef    short        word ;
  550. typedef    unsigned short    uword ;
  551. typedef int        longword ;
  552. typedef unsigned int    ulongword ;
  553. X
  554. #endif    /* sequent */
  555. X
  556. /***    M a c r o   F u n c t i o n   D e f i n i t i o n s    ***/
  557. X
  558. /*   To provide a consistent interface to stdio routines */
  559. X
  560. #define    print(s)    fputs(s,stdout)
  561. #define    fprint(f,s)    fputs(s,f)
  562. #define printc(c)    fputc(c,stdout)
  563. #define fprintc(f,c)    fputc(c,f)
  564. X
  565. /***    M i s c e l l a n e o u s   M a c r o   D e f i n i t i o n s    ***/
  566. X
  567. /***    V C l i b   R o u t i n e   D e f i n i t i o n s    ***/
  568. X
  569. #endif    /* ! defined (VClib) */
  570. SHAR_EOF
  571. chmod 0640 vclib.h ||
  572. echo 'restore of vclib.h failed'
  573. Wc_c="`wc -c < 'vclib.h'`"
  574. test 1344 -eq "$Wc_c" ||
  575.     echo 'vclib.h: original size 1344, current size' "$Wc_c"
  576. rm -f _shar_wnt_.tmp
  577. fi
  578. # ============= split_pathname.c ==============
  579. if test -f 'split_pathname.c' -a X"$1" != X"-c"; then
  580.     echo 'x - skipping split_pathname.c (File already exists)'
  581.     rm -f _shar_wnt_.tmp
  582. else
  583. > _shar_wnt_.tmp
  584. echo 'x - extracting split_pathname.c (Text)'
  585. sed 's/^X//' << 'SHAR_EOF' > 'split_pathname.c' &&
  586. /* split_pathname.c -    Split path into directory and name
  587. X *
  588. X * SYNOPSIS
  589. X *    char *split_pathname (const char *pathname, char *directory,
  590. X *              char *name)
  591. X *
  592. X * DESCRIPTION
  593. X *    Extracts the directory part and the name part of a Unix pathname.
  594. X *    Returns a pointer to the name part.
  595. X *
  596. X * Copyright (c) 1991 Tim Cook.
  597. X * Non-profit distribution allowed.  See README for details.
  598. X */
  599. X
  600. static char rcsid[] = "$Header: split_pathname.c 1.0 91/03/22 $" ;
  601. X
  602. #include <string.h>
  603. #define NULL_CP        ((char *) 0)
  604. #define EOS        '\0'
  605. X
  606. X
  607. char *split_pathname (pathname, directory, name)
  608. X   char *pathname, *directory, *name ;
  609. {
  610. X   char *p ;
  611. X
  612. X   strcpy (directory, pathname) ;
  613. X   while ((p = strrchr (directory, '/')) != NULL_CP && p[1] == EOS) *p = EOS ;
  614. X   if (p == NULL_CP) {
  615. X      strcpy (name, pathname) ;
  616. X      directory[0] = EOS ; }
  617. X   else {
  618. X      strcpy (name, p + 1) ;
  619. X      if (p == directory) {    /* The slash is at the start of pathname */
  620. X     directory[1] = EOS ; }
  621. X      else {
  622. X     *p = EOS ; } }
  623. X   return name ; }
  624. X
  625. X
  626. #ifdef TEST
  627. #include <stdio.h>
  628. X
  629. int main (argc, argv)
  630. X   int argc ;
  631. X   char **argv ;
  632. {
  633. X   char directory[256] ;
  634. X   char name[256] ;
  635. X
  636. X   if (split_pathname (argv[1], directory, name) == NULL_CP) {
  637. X      fprintf (stderr, "%s: couldn't parse \"%s\"\n", argv[0], argv[1]) ; }
  638. X   else {
  639. X      printf ("pathname:  \"%s\"\ndirectory: \"%s\"\nname:     \"%s\"\n",
  640. X     argv[1], directory, name) ; }
  641. X   }
  642. #endif
  643. SHAR_EOF
  644. chmod 0640 split_pathname.c ||
  645. echo 'restore of split_pathname.c failed'
  646. Wc_c="`wc -c < 'split_pathname.c'`"
  647. test 1417 -eq "$Wc_c" ||
  648.     echo 'split_pathname.c: original size 1417, current size' "$Wc_c"
  649. rm -f _shar_wnt_.tmp
  650. fi
  651. # ============= dls.man ==============
  652. if test -f 'dls.man' -a X"$1" != X"-c"; then
  653.     echo 'x - skipping dls.man (File already exists)'
  654.     rm -f _shar_wnt_.tmp
  655. else
  656. > _shar_wnt_.tmp
  657. echo 'x - extracting dls.man (Text)'
  658. sed 's/^X//' << 'SHAR_EOF' > 'dls.man' &&
  659. .\" dls.man -    Man page for descriptive ls
  660. .\"
  661. .\" Copyright (c) 1991 Tim Cook.
  662. .\" Non-profit distribution allowed.  See README for details.
  663. .\"
  664. .\" $Header: dls.man 1.0 91/03/22 $
  665. .\"
  666. .TH DLS 1 "20 March, 1991"
  667. .UC 4
  668. .SH NAME
  669. dls \- Descriptive ls
  670. .SH SYNOPSIS
  671. .B dls
  672. [
  673. flags
  674. ] [
  675. file ...
  676. ]
  677. .SH DESCRIPTION
  678. .I Dls
  679. lists files and directories in the manner of ls(1), but includes a
  680. descriptive comment for each file that has a description set.
  681. By default,
  682. .I dls
  683. lists the file name, size of the file in bytes and the description.
  684. If the file is a directory, a hyphen (-) is shown instead of the size,
  685. and if the file is a directory that contains other directories, an equals
  686. sign (=) is shown.
  687. .PP
  688. Descriptions are set by
  689. .I describe
  690. and are stored in a hidden file in the same directory as the files for
  691. which descriptions are held.
  692. .\" The descriptions are matched to files by name
  693. .\" and inode-number, so renaming or editing the file in the same directory
  694. .\" will not cause the loss of its description.
  695. .PP
  696. Options:
  697. .TP 1i
  698. .B \-d
  699. List the date and time of each file.  The last modification date and time
  700. are listed after the file size, in the same format used by ls(1).
  701. .TP 1i
  702. .B \-e
  703. List everything, even inaccessible files.
  704. By default, files that cannot be read or executed are ignored.
  705. .TP 1i
  706. .B \-t
  707. Sort by last modification time.  Most recently modified files come first.
  708. .TP 1i
  709. .BI \-f width
  710. Use a maximum of
  711. .I width
  712. columns to display the file name.
  713. If a file name is longer than
  714. .I width,
  715. it may expand into the area used to show the size.
  716. If this overflows, the size and other information will be listed on a
  717. separate line.
  718. .SH FILES
  719. For each directory, a .desc.pag and .desc.dir (DBM files) are used to
  720. store descriptions.
  721. .SH SEE\ ALSO
  722. ls(1), describe(1).
  723. SHAR_EOF
  724. chmod 0640 dls.man ||
  725. echo 'restore of dls.man failed'
  726. Wc_c="`wc -c < 'dls.man'`"
  727. test 1774 -eq "$Wc_c" ||
  728.     echo 'dls.man: original size 1774, current size' "$Wc_c"
  729. rm -f _shar_wnt_.tmp
  730. fi
  731. # ============= describe.man ==============
  732. if test -f 'describe.man' -a X"$1" != X"-c"; then
  733.     echo 'x - skipping describe.man (File already exists)'
  734.     rm -f _shar_wnt_.tmp
  735. else
  736. > _shar_wnt_.tmp
  737. echo 'x - extracting describe.man (Text)'
  738. sed 's/^X//' << 'SHAR_EOF' > 'describe.man' &&
  739. .\" describe.man -    Man page for describe
  740. .\"
  741. .\" Copyright (c) 1991 Tim Cook.
  742. .\" Non-profit distribution allowed.  See README for details.
  743. .\"
  744. .\" $Header: describe.man 1.0 91/03/22 $
  745. .\"
  746. .TH DESCRIBE 1 "20 March, 1991"
  747. .UC 4
  748. .SH NAME
  749. describe - Set or list a descriptive comment for a file
  750. .SH SYNOPSIS
  751. .B describe file description
  752. .PP
  753. .B describe -s descriptions-file
  754. [
  755. directory
  756. ]
  757. .PP
  758. .B describe -d file ...
  759. .PP
  760. .B describe -l
  761. [
  762. directory
  763. ]
  764. .SH DESCRIPTION
  765. .I Describe
  766. sets, deletes or lists file descriptions, as used by the
  767. .I dls
  768. utility.
  769. To set the description on one file, use the first form shown above.
  770. To set descriptions on a number of files, put the descriptions into a file,
  771. then use the -s option as shown above
  772. (leaving off
  773. .I directory
  774. implies the current directory).  If you use a hyphen (-) as the name of the
  775. descriptions file,
  776. .I describe
  777. will read standard input for the list of descriptions.
  778. To delete the description for one or more files, use the -d option as shown
  779. above.
  780. To list all the descriptions set for files in a directory, use the -l option
  781. (again, leaving off
  782. .I directory
  783. means the current directory).
  784. .PP
  785. A description-file is a simple text file.
  786. Each line should list the file name (quoted with double quotes if it
  787. contains white-space), followed by white-space, followed by the
  788. description.
  789. The description itself may contain white-space, and is only terminated
  790. by an end-of-line.
  791. Comments may appear in a description file, as a line that starts with a
  792. hash (#) character.
  793. .PP
  794. Descriptions are stored in DBM files.
  795. Each description is keyed by the file name, and the file name is also
  796. keyed by the file's inode-number.
  797. This means that renaming or editing the file in the same directory will
  798. not mean the loss of its description.
  799. If you wish to ``optimize'' the description database of a directory,
  800. you can do so in the following manner:
  801. .PP
  802. .nf
  803. X    % describe -l > /tmp/descriptions
  804. X    % rm .desc.*
  805. X    % describe -s /tmp/descriptions
  806. .fi
  807. .SH FILES
  808. For each directory, a .desc.pag and .desc.dir (DBM files) are used to
  809. store descriptions.
  810. .SH SEE\ ALSO
  811. dls(1).
  812. SHAR_EOF
  813. chmod 0640 describe.man ||
  814. echo 'restore of describe.man failed'
  815. Wc_c="`wc -c < 'describe.man'`"
  816. test 2094 -eq "$Wc_c" ||
  817.     echo 'describe.man: original size 2094, current size' "$Wc_c"
  818. rm -f _shar_wnt_.tmp
  819. fi
  820. # ============= strpbrk.c ==============
  821. if test -f 'strpbrk.c' -a X"$1" != X"-c"; then
  822.     echo 'x - skipping strpbrk.c (File already exists)'
  823.     rm -f _shar_wnt_.tmp
  824. else
  825. > _shar_wnt_.tmp
  826. echo 'x - extracting strpbrk.c (Text)'
  827. sed 's/^X//' << 'SHAR_EOF' > 'strpbrk.c' &&
  828. /*
  829. X * Copyright (c) 1985 Regents of the University of California.
  830. X * All rights reserved.
  831. X *
  832. X * Redistribution and use in source and binary forms are permitted
  833. X * provided that the above copyright notice and this paragraph are
  834. X * duplicated in all such forms and that any documentation,
  835. X * advertising materials, and other materials related to such
  836. X * distribution and use acknowledge that the software was developed
  837. X * by the University of California, Berkeley.  The name of the
  838. X * University may not be used to endorse or promote products derived
  839. X * from this software without specific prior written permission.
  840. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  841. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  842. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  843. X */
  844. X
  845. #if defined(LIBC_SCCS) && !defined(lint)
  846. static char sccsid[] = "@(#)strpbrk.c    5.5 (Berkeley) 5/10/89";
  847. #endif /* LIBC_SCCS and not lint */
  848. X
  849. char *
  850. strpbrk(s1, s2)
  851. X    register char *s1, *s2;
  852. {
  853. X    register int c, sc;
  854. X    register char *scanp;
  855. X
  856. X    for (; c = *s1; ++s1)
  857. X        for (scanp = s2; sc = *scanp++;)
  858. X            if (sc == c)
  859. X                return(s1);
  860. X    return(0);
  861. }
  862. SHAR_EOF
  863. chmod 0640 strpbrk.c ||
  864. echo 'restore of strpbrk.c failed'
  865. Wc_c="`wc -c < 'strpbrk.c'`"
  866. test 1162 -eq "$Wc_c" ||
  867.     echo 'strpbrk.c: original size 1162, current size' "$Wc_c"
  868. rm -f _shar_wnt_.tmp
  869. fi
  870. # ============= perror2.c ==============
  871. if test -f 'perror2.c' -a X"$1" != X"-c"; then
  872.     echo 'x - skipping perror2.c (File already exists)'
  873.     rm -f _shar_wnt_.tmp
  874. else
  875. > _shar_wnt_.tmp
  876. echo 'x - extracting perror2.c (Text)'
  877. sed 's/^X//' << 'SHAR_EOF' > 'perror2.c' &&
  878. /* perror2 -    Like perror(3), but with two string prefixes
  879. X *
  880. X * SYNOPSIS
  881. X *    void perror2 (const char *str1, const char *str2) ;
  882. X *
  883. X * DESCRIPTION
  884. X *    Prints str1, then a colon and a space, then str2, then a colon and
  885. X *    a space, then the error message corresponding to the contents of
  886. X *    errno, then a newline on stderr.
  887. X */
  888. X
  889. static char rcsid[] = "$Header: perror2.c 1.1 91/03/22 $" ;
  890. X
  891. extern int strlen () ;
  892. X
  893. X
  894. void perror2 (str1, str2)
  895. X   char *str1, *str2 ;
  896. {
  897. X   extern int errno ;
  898. X   extern char *sys_errlist[] ;
  899. X   extern int sys_nerr ;
  900. X   register int save_errno = errno ;
  901. X   static char unknown_error[] = "Unknown error" ;
  902. X   static char colon_space[2] = {':', ' '} ;
  903. X   static char newline = '\n' ;
  904. X   char *p ;
  905. X
  906. X   if (save_errno < 0 || save_errno >= sys_nerr)
  907. X      p = unknown_error ;
  908. X   else
  909. X      p = sys_errlist[save_errno] ;
  910. X   write (2, str1, strlen (str1)) ;
  911. X   write (2, colon_space, sizeof (colon_space)) ;
  912. X   write (2, str2, strlen (str2)) ;
  913. X   write (2, colon_space, sizeof (colon_space)) ;
  914. X   write (2, p, strlen (p)) ;
  915. X   write (2, &newline, 1) ;
  916. X   }
  917. X
  918. X
  919. #ifdef TEST
  920. X
  921. int main (argc, argv)
  922. X   int argc ;
  923. X   char **argv ;
  924. {
  925. X   extern int errno ;
  926. X
  927. X   errno = atoi (argv[1]) ;
  928. X   perror2 (argv[2], argv[3]) ;
  929. X   exit (1) ;
  930. X   }
  931. X
  932. #endif    /* TEST */
  933. SHAR_EOF
  934. chmod 0640 perror2.c ||
  935. echo 'restore of perror2.c failed'
  936. Wc_c="`wc -c < 'perror2.c'`"
  937. test 1265 -eq "$Wc_c" ||
  938.     echo 'perror2.c: original size 1265, current size' "$Wc_c"
  939. rm -f _shar_wnt_.tmp
  940. fi
  941. rm -f _shar_seq_.tmp
  942. echo You have unpacked the last part
  943. exit 0
  944.