Annotation of coherent/d/usr/bin/elvis/ref.c, revision 1.1

1.1     ! root        1: /* ref.c */
        !             2: 
        !             3: /* Author:
        !             4:  *     Steve Kirkendall
        !             5:  *     16820 SW Tallac Way
        !             6:  *     Beaverton, OR 97006
        !             7:  *     [email protected], or ...uunet!tektronix!psueea!jove!kirkenda
        !             8:  */
        !             9: 
        !            10: 
        !            11: /* This program looks up the declarations of library functions. */
        !            12: 
        !            13: #include <stdio.h>
        !            14: 
        !            15: /* This is the list of files that are searched. */
        !            16: #ifdef OSK
        !            17: char *refslist[] = {
        !            18:        "refs",
        !            19:        "/dd/usr/src/lib/refs",
        !            20:        "../lib/refs",
        !            21:        "/dd/usr/local/lib/refs",
        !            22: };
        !            23: #else
        !            24: char *refslist[] = {
        !            25:        "refs",
        !            26:        "/usr/src/lib/refs",
        !            27:        "../lib/refs",
        !            28:        "/usr/local/lib/refs",
        !            29: };
        !            30: #endif
        !            31: #define NREFS  (sizeof refslist / sizeof(char *))
        !            32: 
        !            33: main(argc, argv)
        !            34:        int     argc;
        !            35:        char    **argv;
        !            36: {
        !            37:        int     i;      /* used to step through the refslist */
        !            38: 
        !            39:        /* make sure our arguments are OK */
        !            40:        if (argc != 2)
        !            41:        {
        !            42:                fprintf(stderr, "usage: %s function_name\n", *argv);
        !            43:                exit(2);
        !            44:        }
        !            45: 
        !            46:        /* check for the function in each database */
        !            47:        for (i = 0; i < NREFS; i++)
        !            48:        {
        !            49:                if (lookinfor(refslist[i], argv[1]))
        !            50:                {
        !            51:                        exit(0);
        !            52:                }
        !            53:        }
        !            54: 
        !            55:        fprintf(stderr, "%s: don't know about %s\n", argv[0], argv[1]);
        !            56:        exit(2);
        !            57: }
        !            58: 
        !            59: 
        !            60: /* This function checks a single file for the function.  Returns 1 if found */
        !            61: int lookinfor(filename, func)
        !            62:        char    *filename;      /* name of file to look in */
        !            63:        char    *func;          /* name of function to look for */
        !            64: {
        !            65:        FILE    *fp;    /* stream used to access the database */
        !            66:        char    linebuf[300];
        !            67:                /* NOTE: in actual use, the first character of linebuf is */
        !            68:                /* set to ' ' and then we use all EXCEPT the 1st character */
        !            69:                /* everywhere in this function.  This is because the func */
        !            70:                /* which examines the linebuf could, in some circumstances */
        !            71:                /* examine the character before the used part of linebuf; */
        !            72:                /* we need to control what happens then.                   */
        !            73: 
        !            74: 
        !            75:        /* open the database file */
        !            76:        fp = fopen(filename, "r");
        !            77:        if (!fp)
        !            78:        {
        !            79:                return 0;
        !            80:        }
        !            81: 
        !            82:        /* find the desired entry */
        !            83:        *linebuf = ' ';
        !            84:        do
        !            85:        {
        !            86:                if (!fgets(linebuf + 1, (sizeof linebuf) - 1, fp))
        !            87:                {
        !            88:                        fclose(fp);
        !            89:                        return 0;
        !            90:                }
        !            91:        } while (!desired(linebuf + 1, func));
        !            92: 
        !            93:        /* print it */
        !            94:        do
        !            95:        {
        !            96:                fputs(linebuf + 1, stdout);
        !            97:        } while (fgets(linebuf + 1, sizeof linebuf, fp) && linebuf[1] == '\t');
        !            98: 
        !            99:        /* cleanup & exit */
        !           100:        fclose(fp);
        !           101:        return 1;
        !           102: }
        !           103: 
        !           104: 
        !           105: /* This function checks to see if a given line is the first line of the */
        !           106: /* entry the user wants to see.  If it is, return non-0 else return 0   */
        !           107: desired(line, word)
        !           108:        char    *line;  /* the line buffer */
        !           109:        char    *word;  /* the string it should contain */
        !           110: {
        !           111:        static  wlen = -1;/* length of the "word" variable's value */
        !           112:        register char *scan;
        !           113: 
        !           114:        /* if this line starts with a tab, it couldn't be desired */
        !           115:        if (*line == '\t')
        !           116:        {
        !           117:                return 0;
        !           118:        }
        !           119: 
        !           120:        /* if we haven't found word's length yet, do so */
        !           121:        if (wlen < 0)
        !           122:        {
        !           123:                wlen = strlen(word);
        !           124:        }
        !           125: 
        !           126:        /* search for the word in the line */
        !           127:        for (scan = line; *scan != '('; scan++)
        !           128:        {
        !           129:        }
        !           130:        while (*--scan == ' ')
        !           131:        {
        !           132:        }
        !           133:        scan -= wlen;
        !           134:        if (scan < line - 1 || *scan != ' ' && *scan != '\t' && *scan != '*')
        !           135:        {
        !           136:                return 0;
        !           137:        }
        !           138:        scan++;
        !           139:        return !strncmp(scan, word, wlen);
        !           140: }

unix.superglobalmegacorp.com

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