Annotation of researchv10no/cmd/refer/mkey2.c, revision 1.1.1.1

1.1       root        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:        extern int minlen, keycount, labels, wholefile;
                      9:        extern char *iglist;
                     10: 
                     11: dofile(f, name)
                     12:        FILE *f;
                     13:        char *name;
                     14: {
                     15: 
                     16: /* read file f & spit out keys & ptrs */
                     17: # define MAXLINE 500
                     18: char line[MAXLINE], *s;
                     19: int c;
                     20: long grec();
                     21: alph=used=prevc=eof=0;
                     22: 
                     23: lp=0;
                     24: if (wholefile==0)
                     25: while (lim = grec(line,f))
                     26:        {
                     27: # if D1
                     28: fprintf(stderr, "line: /%s",line);
                     29: # endif
                     30:        used=alph=0;
                     31:        p = key;
                     32:        for(s=line; (c= *s) && (used<keycount); s++)
                     33:                chkey(c, name);
                     34:        lp += lim;
                     35:        if (used) putchar('\n');
                     36:        }
                     37: else
                     38:        {
                     39:        p=key;
                     40:        used=alph=0;
                     41:        while ( (c=getc(f)) != EOF && used<keycount)
                     42:                chkey (c, name);
                     43:        if (used) putchar('\n');
                     44:        }
                     45: fclose(f);
                     46: }
                     47: 
                     48: outkey( ky, lead, trail)
                     49:        char *ky;
                     50: {
                     51:        int n;
                     52: n = strlen(ky);
                     53: if (n<minlen) return (0);
                     54: if (n<3)
                     55:        {
                     56:        if (trail == '.') return(0);
                     57:        if (mindex(".%,!#$%&'();+:*", lead)!=0) return(0);
                     58:        }
                     59: if (isdigit(ky[0]))
                     60:        if (ky[0] != '1' || (ky[1] != '9' && ky[1]!='8') || n!= 4) return(0);
                     61: if (common(ky))
                     62:        return(0);
                     63: return(1);
                     64: }
                     65: long grec (s, f)
                     66:        char *s;
                     67:        FILE *f;
                     68: {
                     69:        char tm[200];
                     70:        int curtype= 0;
                     71:        long len= 0L, tlen= 0L;
                     72:        extern int wholefile;
                     73:        if (eof) return(0);
                     74:        *s = 0;
                     75:        while (fgets(tm, 200, f))
                     76:                {
                     77:                tlen += strlen(tm);
                     78:                if (tm[0] == '%' || tm[0] == '.')
                     79:                        curtype = tm[1];
                     80:                if (tlen < MAXLINE && mindex(iglist,curtype)==0)
                     81:                                strcat(s, tm);
                     82:                len = tlen;
                     83:                if (wholefile==0 && tm[0] == '\n' && len>0)
                     84:                        return(len);
                     85:                if (wholefile>0 && len >= MAXLINE)
                     86:                        {
                     87:                        fseek (f, 0L, 2);
                     88:                        return(ftell(f));
                     89:                        }
                     90:                }
                     91:        eof=1;
                     92:        return(s[0] ? len : 0L);
                     93: }
                     94: char *
                     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)) && prevc != '\\')
                    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:        }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.