home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / elvis / Source / c / ref < prev    next >
Encoding:
Text File  |  1990-03-28  |  2.7 KB  |  130 lines

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