home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1976 / cookhash.c next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  943 b   |  53 lines

  1. /* cookhash - read a sayings file and generate an index file
  2.  * by Karl Lehenbauer (karl@sugar.uu.net, uunet!sugar!karl)
  3.  *  cookhash.c  1.1  1/12/89
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. #define YES 1
  9. #define NO 0
  10. #define METACHAR '%'
  11.  
  12. main(argc,argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.     int c, sawmeta;
  17.     long charpos = 0;
  18.  
  19.     if (argc != 1)
  20.     {
  21.         fprintf(stderr,"usage: cookhash <cookiefile >hashfile\n");
  22.         exit(1);
  23.     }
  24.  
  25.     /* write out the "address" of the first cookie */
  26.     puts("000000");
  27.  
  28.     /* read the cookie until the end,
  29.      *   whenever the end-of-cookie ("%%") sequence is found,
  30.      *   the "address" (file position) of the first byte following
  31.      *   it (start of next cookie) is written to the index (hash) file
  32.      */
  33.     while ((c = getchar()) != EOF)
  34.     {
  35.         if (c == METACHAR)
  36.         {
  37.             if (sawmeta)
  38.             {
  39.                 printf("%06lx\n",charpos+2);
  40.                 sawmeta = NO;
  41.             }
  42.             else
  43.                 sawmeta = YES;
  44.         }
  45.         else
  46.             sawmeta = NO;
  47.         charpos++;
  48.     }
  49.     exit(0);
  50. }
  51.  
  52. /* end of cookhash.c */
  53.