Annotation of researchv10no/cmd/dict/wdefine.c, revision 1.1

1.1     ! root        1: # include <stdio.h>
        !             2: # include <ctype.h>
        !             3: # include <assert.h>
        !             4: char *dictdir = "/usr/dict/w7full";
        !             5: extern char *ggets(), *fgets(), *strchr(), *getenv();
        !             6: int debug=0;
        !             7: 
        !             8: main(argc,argv)
        !             9: char *argv[];
        !            10: {
        !            11:        char ln[100];
        !            12:        char *dict = getenv("W7DIR");
        !            13:        if(dict==0)
        !            14:                dict = dictdir;
        !            15:        assert( chdir(dict) == NULL);
        !            16:        argc--; argv++;
        !            17:        while (argc>0 && argv[0][0]=='-') {
        !            18:                switch (argv[0][1])
        !            19:                        {
        !            20:                        case 'd': debug++; break;
        !            21:                        }
        !            22:                argc--; argv++;
        !            23:        }
        !            24:        if (argc<=0) {
        !            25:                while (ggets(ln,sizeof ln,stdin))
        !            26:                        lookup(ln);
        !            27:        }
        !            28:        while (argc-- >0)
        !            29:                lookup(*argv++);
        !            30: }
        !            31: 
        !            32: lcase (s)
        !            33: char *s;
        !            34: {
        !            35:        for (; *s; s++)
        !            36:                if (isupper(*s))
        !            37:                        *s = tolower(*s);
        !            38: }
        !            39: 
        !            40: FILE *desc[26];
        !            41: 
        !            42: lookup (wd)
        !            43: char *wd;
        !            44: {
        !            45:        int ilet, yet, ks;
        !            46:        char fn[10], dbuff[300], wdb[50], xbuff[300];
        !            47:        FILE *fd;
        !            48:        while(*wd && isascii(*wd) && isspace(*wd))
        !            49:                wd++;
        !            50:        if(*wd == 0)
        !            51:                return;
        !            52:        scnobl(wdb, wd); wd=wdb;
        !            53:        lcase(wd);
        !            54:        ccut(wd);
        !            55:        ilet = *wd;
        !            56:        assert (ilet>='a' && ilet <= 'z');
        !            57:        sprintf(fn, "D%c", ilet);
        !            58:        if (desc[ilet-'a']==0)
        !            59:                desc[ilet-'a'] = fd = fopen(fn, "r");
        !            60:        else
        !            61:                fd = desc[ilet-'a'];
        !            62:        if (fd==NULL) {
        !            63:                fprintf(stderr, "Too many files open: %s\n", wd);
        !            64:                return;
        !            65:        }
        !            66:        binpos (fd, wd);
        !            67:        yet=0;
        !            68:        while (fgets(dbuff, 300, fd)) {
        !            69:                if (dbuff[0]=='F' && dbuff[1]==';') {
        !            70:                        scnobl(xbuff, dbuff+2);
        !            71:                        lcase(xbuff);
        !            72:                        ccut(xbuff);
        !            73:                        ks = scomp(xbuff, wd);
        !            74:                        if(debug)fprintf(stderr, "xbuff %s wd %s ks %d\n",xbuff,wd,ks);
        !            75:                        if (ks>0)
        !            76:                                break;
        !            77:                        if (ks==0) yet=1;
        !            78:                }
        !            79:                if (yet>0) dump(dbuff);
        !            80:        }
        !            81: }
        !            82: 
        !            83: dump(s)
        !            84: char *s;
        !            85: {
        !            86:        char *p;
        !            87:        if (isupper(s[0]) && s[1]==';')
        !            88:                s++;
        !            89:        for(p=s; *p; p++)
        !            90:                if (*p==';')
        !            91:                        *p=' ';
        !            92:        fputs(s,stdout);
        !            93: }
        !            94: 
        !            95: scomp( dl, wd)
        !            96: char *dl, *wd;
        !            97: {
        !            98:        int n, k;
        !            99:        char t1[100], t2[100];
        !           100:        scnobl(t1, dl);
        !           101:        dl=t1;
        !           102:        scnobl(t2, wd);
        !           103:        wd=t2;
        !           104:        n = strlen(wd);
        !           105:        k = strncmp(dl, wd,n);
        !           106:        if (k==0 && (dl[n]==0 || dl[n]==';'))
        !           107:                return(0);
        !           108:        return(k==0? 1: k);
        !           109: }
        !           110: 
        !           111: scnobl(s, t)
        !           112: char *s, *t;
        !           113: {
        !           114:        while (*t) {
        !           115:                if (*t!=' ')
        !           116:                        *s++ = *t;
        !           117:                t++;
        !           118:        }
        !           119:        *s=0;
        !           120: }
        !           121: 
        !           122: binpos(f, word)
        !           123: char *word;
        !           124: FILE *f;
        !           125: {
        !           126:        long top, bot, mid;
        !           127:        int k, c, oc, ooc;
        !           128:        char line[100];
        !           129:        bot=0;
        !           130:        fseek(f, 0L, 2);
        !           131:        top = ftell(f);
        !           132:        for (;;) {
        !           133:                mid = (top+bot)/2;
        !           134:                fseek(f, mid, 0);
        !           135:                oc=getc(f);
        !           136:                c=getc(f);
        !           137:                mid+=2;
        !           138:                do {
        !           139:                        ooc=oc;
        !           140:                        oc=c;
        !           141:                        c = getc(f);
        !           142:                        mid++;
        !           143:                } while (c!=EOF && ( c!='F' || oc!='\n' || ooc=='#'));
        !           144:                if (fgets(line, 50, f)==NULL)
        !           145:                        break;
        !           146:                lcase(line);
        !           147:                if (debug) fprintf(stderr, " bot %ld mid %ld top %ld line %s", bot,mid,top,line);
        !           148:                ccut(line+1);
        !           149:                k = scomp(word, line+1);
        !           150:                if(debug) fprintf(stderr, "  k %d\n",k);
        !           151:                if (k<=0) {
        !           152:                        if (top<=mid)
        !           153:                                break;
        !           154:                        top = mid;
        !           155:                        continue;
        !           156:                } else {
        !           157:                        bot= mid;
        !           158:                        continue;
        !           159:                }
        !           160:        }
        !           161:        fseek(f, bot, 0);
        !           162:        if (bot!=0)
        !           163:        while ( (c=getc(f)) != '\n' && c!= EOF);
        !           164: }
        !           165: 
        !           166: ccut(s)
        !           167: char *s;
        !           168: {
        !           169:        char x[100], *p, *y;
        !           170:        y=s;
        !           171:        for(p=x; *s &&  *s!=';'; s++)
        !           172:                if (!strchr("-'^`{}:,.~", *s))
        !           173:                        *p++ = *s;
        !           174:        *p=0;
        !           175:        strcpy(y, x);
        !           176: }
        !           177: 
        !           178: char *
        !           179: ggets(s,n,f)
        !           180: char *s;
        !           181: FILE *f;
        !           182: {
        !           183:        char *p = fgets(s,n,f);
        !           184:        char *q;
        !           185:        if(p && (q=strchr(s,'\n')))
        !           186:                *q = 0;
        !           187:        return p;
        !           188: }

unix.superglobalmegacorp.com

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