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

unix.superglobalmegacorp.com

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