Annotation of coherent/b/bin/apropos.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * apropos.c
                      3:  *
                      4:  * implement a simple version of the Berkeley command "apropos".  This
                      5:  * command searches the file /usr/man/man.index for a word that the
                      6:  * user enters on the command line, and prints every index entry in which
                      7:  * that token appears.
                      8:  *
                      9:  * Usage:  apropos token
                     10:  *
                     11:  * 3/17/1993 (aye and begorah!), fwb, first draft
                     12:  * 9/1/1993, fwb, changed behavior to continue when it reads a "bad" line
                     13:  */
                     14: #ifdef TEST
                     15: #      define INDEXFILE "/v/fwb/doc/coherent/man.index"
                     16: #else
                     17: #      define INDEXFILE "/usr/man/man.index"
                     18: #endif
                     19: 
                     20: #define BUFFERSIZE 200
                     21: 
                     22: #include <ctype.h>
                     23: #include <stdio.h>
                     24: #include <string.h>
                     25: #include <stdlib.h>
                     26: 
                     27: main(argc, argv)
                     28: int argc; char **argv;
                     29: {
                     30:        char inb[BUFFERSIZE], testb[BUFFERSIZE], *inbp;
                     31:        int i, j, lowerflag;
                     32:        FILE *fp;
                     33: 
                     34:        if (argc < 2) {
                     35:                fprintf(stderr, "Usage: apropos word\n");
                     36:                exit(EXIT_FAILURE);
                     37:        }
                     38: 
                     39:        if ((fp = fopen(INDEXFILE, "r")) == NULL) {
                     40:                fprintf(stderr, "apropos: Cannot open index file %s\n",
                     41:                        INDEXFILE);
                     42:                exit(EXIT_FAILURE);
                     43:        }
                     44: 
                     45:        /* if first character of user's word is upper-cased, then assume
                     46:         * the user wants an exact match, and therefore do not
                     47:         * shift the description into lower case.
                     48:         */
                     49: 
                     50:        if (isupper(argv[1][0]))
                     51:                lowerflag = 0;
                     52:        else
                     53:                lowerflag = 1;
                     54: 
                     55:        for (i = 1; fgets(inb, BUFFERSIZE-1, fp) != NULL; i++) {
                     56:                if ((inbp = strchr(inb, '\t')) == NULL)
                     57:                        continue;
                     58: 
                     59:                inbp++;
                     60:                strcpy (testb, inbp);
                     61: 
                     62:                if (lowerflag)
                     63:                        for (j = 0; j < strlen (testb); j++)
                     64:                                if (isupper(testb[j]))
                     65:                                        testb[j] = tolower(testb[j]);
                     66: 
                     67:                if (strstr(testb, argv[1]) != NULL)
                     68:                        printf("%s", inbp);
                     69:        }
                     70:        fclose(fp);
                     71:        exit(EXIT_SUCCESS);
                     72: }

unix.superglobalmegacorp.com

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