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:     n = strlen(ky);
  58:     if (n<minlen) return (0);
  59:     if (n<3)
  60:     {
  61:         if (trail == '.') return(0);
  62:         if (mindex(".%,!#$%&'();+:*", lead)!=0) return(0);
  63:     }
  64:     if (isdigit(ky[0]))
  65:         if (ky[0] != '1' || ky[1] != '9' || n!= 4) return(0);
  66:     if (common(ky))
  67:         return(0);
  68:     return(1);
  69: }
  70: 
  71: long
  72: grec (s, f)
  73: char *s;
  74: FILE *f;
  75: {
  76:     char tm[200];
  77:     int curtype = 0;
  78:     long len = 0L, tlen = 0L;
  79:     extern int wholefile;
  80:     if (eof) return(0);
  81:     *s = 0;
  82:     while (fgets(tm, 200, f))
  83:     {
  84:         tlen += strlen(tm);
  85:         if (tm[0] == '%' || tm[0] == '.')
  86:             curtype = tm[1];
  87:         if (tlen < MAXLINE && mindex(iglist,curtype)==0)
  88:             strcat(s, tm);
  89:         len = tlen;
  90:         if (wholefile==0 && tm[0] == '\n')
  91:             return(len);
  92:         if (wholefile>0 && len >= MAXLINE)
  93:         {
  94:             fseek (f, 0L, 2);
  95:             return(ftell(f));
  96:         }
  97:     }
  98:     eof=1;
  99:     return(s[0] ? len : 0L);
 100: }
 101: 
 102: char *
 103: trimnl(ln)
 104: char *ln;
 105: {
 106:     register char *p = ln;
 107:     while (*p) p++;
 108:     p--;
 109:     if (*p == '\n') *p=0;
 110:     return(ln);
 111: }
 112: 
 113: chkey (c, name)
 114: {
 115:     if (isalpha(c) || isdigit(c))
 116:     {
 117:         if (alph++ < 6)
 118:             *p++ = c;
 119:     }
 120:     else
 121:     {
 122:         *p = 0;
 123:         for(p=key; *p; p++)
 124:             *p |= 040;
 125:         if (outkey(p=key,prevc,c))
 126:         {
 127:             if (used==0)
 128:             {
 129:                 if (labels)
 130:                 {
 131:                     if (wholefile==0)
 132:                         printf("%s:%ld,%ld\t", name, lp, lim);
 133:                     else
 134:                         printf("%s\t", name);
 135:                 }
 136:             }
 137:             else
 138:                 putchar(' ');
 139:             fputs(key, stdout);
 140:             used++;
 141:         }
 142:         prevc=c;
 143:         alph=0;
 144:     }
 145: }

Defined functions

chkey defined in line 113; used 2 times
dofile defined in line 14; used 3 times
grec defined in line 71; used 2 times
outkey defined in line 53; used 1 times
trimnl defined in line 102; 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: 1983-05-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1173
Valid CSS Valid XHTML 1.0 Strict