home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / yp-quote / quotedb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-07  |  878 b   |  51 lines

  1. #include <stdio.h>
  2.  
  3. #define MAXLEN 450
  4.  
  5. char quotebuf[MAXLEN];
  6. char line[MAXLEN];
  7. int numq = 0;
  8.  
  9. char *strcat();
  10. char *strcpy();
  11.  
  12. main()
  13. {
  14.  
  15.     char *c, *index();
  16.     int endit = 0;
  17.  
  18.     while (gets(line)) {
  19.     if (line[0] == '%' && (line[1] == '%' || line[1] == '-')) {
  20.  
  21.         if (strlen(quotebuf)) {
  22.         numq++;
  23.  
  24.         /*
  25.          * mark all newlines and tabs with special character flags so
  26.          * you don't confuse makedbm
  27.          */
  28.  
  29.         while ((c = index(quotebuf, '\n')))
  30.             *c = '\001';
  31.  
  32.         while ((c = index(quotebuf, '\t')))
  33.             *c = '\002';
  34.  
  35.         printf("%d\t%s\n", numq, quotebuf);
  36.         strcpy(quotebuf, "");
  37.         }
  38.     } else {
  39.  
  40.         if ((strlen(line) + strlen(quotebuf)) > MAXLEN) {
  41. /*        fprintf(stderr, "\nLong quote:\n%s\n", quotebuf); */
  42.         strcpy(quotebuf, "");
  43.         } else {
  44.         strcat(quotebuf, line);
  45.         strcat(quotebuf, "\001");
  46.         }
  47.     }
  48.     }
  49.     printf("MAX\t%d\n", numq);
  50. }
  51.