home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / refer / mkey2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  2.1 KB  |  137 lines

  1. # include "stdio.h"
  2. # include "ctype.h"
  3.  
  4.     static int eof 0;
  5.     static long lp, lim;
  6.     static int alph, used, prevc;
  7.     static char *p, key[20];
  8.  
  9. dofile(f, name)
  10.     FILE *f;
  11.     char *name;
  12. {
  13.  
  14. /* read file f & spit out keys & ptrs */
  15. # define MAXLINE 500
  16. char line[MAXLINE], *s;
  17. extern int minlen, keycount, labels;
  18. int c;
  19. long grec();
  20. extern int wholefile;
  21. extern char *iglist;
  22. alph=used=prevc=eof=0;
  23.  
  24. lp=0;
  25. if (wholefile==0)
  26. while (lim = grec(line,f))
  27.     {
  28. # if D1
  29. fprintf(stderr, "line: /%s",line);
  30. # endif
  31.     used=alph=0;
  32.     p = key;
  33.     for(s=line; (c= *s) && (used<keycount); s++)
  34.         chkey(c, name);
  35.     lp += lim;
  36.     if (used) putchar('\n');
  37.     }
  38. else
  39.     {
  40.     p=key;
  41.     used=alph=0;
  42.     while ( (c=getc(f)) != EOF && used<keycount)
  43.         chkey (c, name);
  44.     if (used) putchar('\n');
  45.     }
  46. fclose(f);
  47. }
  48.  
  49. outkey( ky, lead, trail)
  50.     char *ky;
  51. {
  52.     int n;
  53. n = strlen(ky);
  54. if (n<minlen) return (0);
  55. if (n<3)
  56.     {
  57.     if (trail == '.') return(0);
  58.     if (mindex(".%,!#$%&'();+:*", lead)!=0) return(0);
  59.     }
  60. if (isdigit(ky[0]))
  61.     if (ky[0] != '1' || ky[1] != '9' || n!= 4) return(0);
  62. if (common(ky))
  63.     return(0);
  64. return(1);
  65. }
  66. long grec (s, f)
  67.     char *s;
  68.     FILE *f;
  69. {
  70.     char tm[200];
  71.     int curtype 0;
  72.     long len 0L, tlen 0L;
  73.     extern int wholefile;
  74.     if (eof) return(0);
  75.     *s = 0;
  76.     while (fgets(tm, 200, f))
  77.         {
  78.         tlen += strlen(tm);
  79.         if (tm[0] == '%' || tm[0] == '.')
  80.             curtype = tm[1];
  81.         if (tlen < MAXLINE && mindex(iglist,curtype)==0)
  82.                 strcat(s, tm);
  83.         len = tlen;
  84.         if (wholefile==0 && tm[0] == '\n')
  85.             return(len);
  86.         if (wholefile>0 && len >= MAXLINE)
  87.             {
  88.             fseek (f, 0L, 2);
  89.             return(ftell(f));
  90.             }
  91.         }
  92.     eof=1;
  93.     return(s[0] ? len : 0L);
  94. }
  95. trimnl(ln)
  96.     char *ln;
  97. {
  98. register char *p ln;
  99. while (*p) p++;
  100. p--;
  101. if (*p == '\n') *p=0;
  102. return(ln);
  103. }
  104. chkey (c, name)
  105.     {
  106.     if (isalpha(c) || isdigit(c))
  107.         {
  108.         if (alph++ < 6)
  109.             *p++ = c;
  110.         }
  111.     else
  112.         {
  113.         *p = 0;
  114.         for(p=key; *p; p++)
  115.             *p |= 040;
  116.         if (outkey(p=key,prevc,c))
  117.             {
  118.             if (used==0)
  119.                 {
  120.                 if (labels)
  121.                 {
  122.                 if (wholefile==0)
  123.                     printf("%s:%ld,%ld\t", name, lp, lim);
  124.                 else
  125.                     printf("%s\t", name);
  126.                 }
  127.                 }
  128.             else
  129.                 putchar(' ');
  130.             fputs(key, stdout);
  131.             used++;
  132.             }
  133.         prevc=c;
  134.         alph=0;
  135.         }
  136.     }
  137.