Annotation of coherent/d/bin/spell/spell.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Version of spell that uses compressed
                      3:  * dictionary but exhaustive dictionary read.
                      4:  * This version will work in any address space
                      5:  * but is perhaps marginally slower (on short
                      6:  * documents than the hashed version). It has the
                      7:  * virtue that it is guaranteed accurate (no misses).
                      8:  */
                      9: 
                     10: #include <stdio.h>
                     11: #include <ctype.h>
                     12: 
                     13: #define        NWORD   50
                     14: 
                     15: char   inword[NWORD];
                     16: char   lowword[NWORD];
                     17: 
                     18: char   *wget();
                     19: char   *getword();
                     20: 
                     21: main(argc, argv)
                     22: char *argv[];
                     23: {
                     24:        FILE *dfp;
                     25:        FILE *hfp = NULL;
                     26: 
                     27:        if (argc == 3) {
                     28:                argc--;
                     29:                hfp = fopen(argv[2], "a");
                     30:        }
                     31:        if (argc != 2)
                     32:                usage();
                     33:        if ((dfp = fopen(argv[1], "r")) == NULL)
                     34:                cerr("cannot open compressed dictionary `%s'", argv[1]);
                     35:        exit(spell(stdin, dfp, hfp));
                     36: }
                     37: 
                     38: /*
                     39:  * Called with the input words (sorted)
                     40:  * the the dictionary file pointer.
                     41:  * Returns non-zero if there are any spelling errors.
                     42:  */
                     43: spell(inf, dfp, hfp)
                     44: FILE *inf;
                     45: FILE *dfp;
                     46: FILE *hfp;
                     47: {
                     48:        register char *wp = "";
                     49:        register int s;
                     50:        register int stat = 0;
                     51: 
                     52:        for (;;) {
                     53:                if (wget(inword, lowword, inf) == NULL)
                     54:                        return (stat);
                     55:                while ((s = strcmp(wp, lowword)) < 0)
                     56:                        if ((wp = getword(dfp)) == NULL)
                     57:                                return (stat);
                     58:                if (s != 0) {
                     59:                        stat = 1;
                     60:                        printf("%s\n", inword);
                     61:                        if (hfp != NULL)
                     62:                                fprintf(hfp, "%s\n", inword);
                     63:                }
                     64:        }
                     65: }
                     66: 
                     67: char *
                     68: wget(b1, b2, io)
                     69: char *b1, *b2;
                     70: FILE *io;
                     71: {
                     72:        register int c;
                     73:        register int lim;
                     74:        register char *s1;
                     75:        register char *s2;
                     76: 
                     77: again:
                     78:        s1 = b1;
                     79:        s2 = b2;
                     80:        lim = NWORD;
                     81:        while (--lim>0 && (c = getc(io))!=EOF) {
                     82:                if (c == '\n')
                     83:                        break;
                     84:                *s1++ = c;
                     85:                *s2++ = isalpha(c) ? tolower(c) : c;
                     86:        }
                     87:        *s1 = '\0';
                     88:        *s2 = '\0';
                     89:        if (c == EOF)
                     90:                return (NULL);
                     91:        while (c != '\n')
                     92:                c = getc(io);
                     93:        if (s2 == b2)
                     94:                goto again;
                     95:        return (b1);
                     96: }
                     97: 
                     98: usage()
                     99: {
                    100:        fprintf(stderr, "Usage: spell dict [history]\n");
                    101:        exit(1);
                    102: }
                    103: 
                    104: /* VARARGS */
                    105: cerr(x)
                    106: {
                    107:        fprintf(stderr, "spell: %r\n", &x);
                    108:        exit(1);
                    109: }

unix.superglobalmegacorp.com

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