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

Defined functions

chkey defined in line 115; used 2 times
dofile defined in line 14; used 3 times
grec defined in line 72; used 2 times
outkey defined in line 53; used 1 times
trimnl defined in line 104; never used

Defined variables

alph defined in line 11; used 5 times
eof defined in line 9; used 3 times
key defined in line 12; used 5 times
lim defined in line 10; used 3 times
lp defined in line 10; used 3 times
p defined in line 12; used 15 times
prevc defined in line 11; used 3 times
sccsid defined in line 2; never used
used defined in line 11; used 9 times

Defined macros

MAXLINE defined in line 7; used 3 times
Last modified: 1987-03-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2565
Valid CSS Valid XHTML 1.0 Strict