home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / misc / cookie.lha / cookhash.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  953b  |  52 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. #include <stdlib.h>
  8.  
  9. #define YES 1
  10. #define NO 0
  11. #define METACHAR '%'
  12.  
  13. main(int argc,char *argv[])
  14. {
  15.     int c, sawmeta=0;
  16.     long charpos = 0;
  17.  
  18.     if (argc != 1)
  19.     {
  20.         fprintf(stderr,"usage: cookhash <cookiefile >hashfile\n");
  21.         exit(1);
  22.     }
  23.  
  24.     /* write out the "address" of the first cookie */
  25.     puts("000000");
  26.  
  27.     /* read the cookie until the end,
  28.      *   whenever the end-of-cookie ("%%") sequence is found,
  29.      *   the "address" (file position) of the first byte following
  30.      *   it (start of next cookie) is written to the index (hash) file
  31.      */
  32.     while ((c = getchar()) != EOF)
  33.     {
  34.         if (c == METACHAR)
  35.         {
  36.             if (sawmeta)
  37.             {
  38.                 printf("%06lx\n",charpos+2);
  39.                 sawmeta = NO;
  40.             }
  41.             else
  42.                 sawmeta = YES;
  43.         }
  44.         else
  45.             sawmeta = NO;
  46.         charpos++;
  47.     }
  48.     exit(0);
  49. }
  50.  
  51. /* end of cookhash.c */
  52.