Annotation of researchv10no/cmd/ap/apkeys/keys.c, revision 1.1.1.1

1.1       root        1: # include "stdio.h"
                      2: # include "assert.h"
                      3: # include "ctype.h"
                      4: 
                      5:        static long lp, lim;
                      6:        static int alph, prevc;
                      7:        static char *p, key[20];
                      8:        extern char *iglist, *svc();
                      9:        void addkey(), searchkey();
                     10:        void (*what)();
                     11: # define NK 300
                     12:        struct keyst {
                     13:                char *keytxt;
                     14:                int keywt;
                     15:                int keyocc;
                     16:                } keys[NK];
                     17:        struct keyst *keyp;
                     18: 
                     19: resetkey()
                     20: {
                     21: keyp=keys;
                     22: }
                     23: 
                     24: dofile (name)
                     25:        char *name;
                     26: {
                     27: 
                     28: # define MAXLINE 500
                     29: struct keyst *ks;
                     30: int c;
                     31: FILE *f;
                     32: f = fopen(name, "r");
                     33: if (f==NULL) return;
                     34: alph=lp=prevc=0;
                     35: p=key;
                     36: while ( (c=getc(f)) != EOF )
                     37:        chkey (c);
                     38: fclose(f);
                     39: }
                     40: 
                     41: outkey( ky, lead, trail)
                     42:        char *ky;
                     43: {
                     44:        int n;
                     45: n = strlen(ky);
                     46: if (n<2) return(0);
                     47: if (n<3)
                     48:        {
                     49:        if (trail == '.') return(0);
                     50:        if (strchr(".%,!#$%&'();+:*", lead)) return(0);
                     51:        }
                     52: if (isdigit(ky[0]))
                     53:        if (ky[0] != '1' || ky[1] != '9' || n!= 4) return(0);
                     54: if (common(ky))
                     55:        return(0);
                     56: return(1);
                     57: }
                     58: chkey (c)
                     59:        {
                     60:        if ((isalpha(c) || isdigit(c)) && prevc != '\\')
                     61:                {
                     62:                if (alph++ < 6)
                     63:                        *p++ = c;
                     64:                }
                     65:        else
                     66:                {
                     67:                *p = 0;
                     68:                for(p=key; *p; p++)
                     69:                        *p |= 040;
                     70:                if (outkey(p=key,prevc,c))
                     71:                        (*what)(key);
                     72:                prevc=c;
                     73:                alph=0;
                     74:                }
                     75:        }
                     76: void
                     77: addkey(key)
                     78:        char *key;
                     79: {
                     80: struct keyst *ks;
                     81:        for(ks=keys; ks<keyp; ks++)
                     82:                if (strcmp(ks->keytxt, key)==0)
                     83:                        break;
                     84:        if (ks<keyp)
                     85:                ks->keywt++;
                     86:        else
                     87:                {
                     88:                keyp->keytxt = svc(key);
                     89:                keyp->keywt=1;
                     90:                assert(++keyp-keys <NK);
                     91:                }
                     92:        }
                     93: void
                     94: searchkey(s)
                     95:        char *s;
                     96: {
                     97: struct keyst *ks;
                     98: for(ks=keys; ks<keyp; ks++)
                     99:        {
                    100:        if (strcmp(ks->keytxt, s)==0)
                    101:                break;
                    102:        }
                    103: if (ks<keyp)
                    104:        ks->keyocc++;
                    105: }
                    106: zerokey()
                    107: {
                    108: struct keyst *ks;
                    109: for(ks=keys; ks<keyp; ks++)
                    110:        ks->keyocc=0;
                    111: }
                    112: scorekey()
                    113: {
                    114: struct keyst *ks;
                    115: int sc=0;
                    116: for(ks=keys; ks<keyp; ks++)
                    117:        sc += min(ks->keyocc, ks->keywt);
                    118: return(sc);
                    119: }
                    120: min(a,b)
                    121: {
                    122: return(a<b ? a : b);
                    123: }
                    124: mkkey(s)
                    125:        char *s;
                    126: {
                    127: int i, na; char *sa[20];
                    128: na = getargs(s, sa);
                    129: for(i=0; i<na; i++)
                    130:        {
                    131:        if (isdigit(sa[i][0]))
                    132:                keyp->keywt = atoi(sa[i]);
                    133:        else
                    134:                {
                    135:                if (strlen(sa[i]) > 6)
                    136:                        sa[i][6]=0;
                    137:                keyp->keytxt = svc(sa[i]);
                    138:                keyp->keywt = 1;
                    139:                keyp++;
                    140:                }
                    141:        }
                    142: }

unix.superglobalmegacorp.com

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