home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_03 / 9n03116b < prev    next >
Text File  |  1991-01-16  |  966b  |  54 lines

  1.  
  2. /*
  3.  * xr.c - a cross-reference generator
  4.  */
  5. #include <assert.h>
  6. #include <ctype.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include "xrt.h"
  12.  
  13. int getword(char *word, size_t lim)
  14.     {
  15.     int c;
  16.     char *w = word;
  17.  
  18.     assert(lim > 2);
  19.     while (isspace(c = fgetc(stdin)) && c != '\n')
  20.         ;
  21.     if (c != EOF)
  22.         *w++ = c;
  23.     if (!isalpha(c))
  24.         {
  25.         *w = '\0';
  26.         return c;
  27.         }
  28.     for ( ; lim-- > 0; ++w)
  29.         if (!isalnum(*w = fgetc(stdin)))
  30.             {
  31.             ungetc(*w, stdin);
  32.             break;
  33.             }
  34.     *w = '\0';
  35.     return *word;
  36.     }
  37.  
  38. #define MAXWORD 100
  39.  
  40. int main(void)
  41.     {
  42.     char word[MAXWORD];
  43.     unsigned lineno = 1;
  44.  
  45.     while (getword(word, MAXWORD) != EOF)
  46.         if (isalpha(word[0]))
  47.             xrt_add(word, lineno);
  48.         else if (word[0] == '\n')
  49.             ++lineno;
  50.     xrt_print();
  51.     return 0;
  52.     }
  53.  
  54.