Annotation of researchv10no/cmd/ap/apnews/mkey2.c, revision 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' || 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: trimnl(ln)
        !            95:        char *ln;
        !            96: {
        !            97: register char *p ln;
        !            98: while (*p) p++;
        !            99: p--;
        !           100: if (*p == '\n') *p=0;
        !           101: return(ln);
        !           102: }
        !           103: chkey (c, name)
        !           104:        {
        !           105:        if ((isalpha(c) || isdigit(c)) && prevc != '\\')
        !           106:                {
        !           107:                if (alph++ < 6)
        !           108:                        *p++ = c;
        !           109:                }
        !           110:        else
        !           111:                {
        !           112:                *p = 0;
        !           113:                for(p=key; *p; p++)
        !           114:                        *p |= 040;
        !           115:                if (outkey(p=key,prevc,c))
        !           116:                        {
        !           117:                        if (used==0)
        !           118:                            {
        !           119:                            if (labels)
        !           120:                                {
        !           121:                                if (wholefile==0)
        !           122:                                        printf("%s:%ld,%ld\t", name, lp, lim);
        !           123:                                else
        !           124:                                        printf("%s\t", name);
        !           125:                            }
        !           126:                                }
        !           127:                        else
        !           128:                                putchar(' ');
        !           129:                        fputs(key, stdout);
        !           130:                        used++;
        !           131:                        }
        !           132:                prevc=c;
        !           133:                alph=0;
        !           134:                }
        !           135:        }

unix.superglobalmegacorp.com

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