home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 310.lha / DevKit_v1.2 / Sources / GetAutoDoc.c < prev    next >
C/C++ Source or Header  |  1980-12-03  |  6KB  |  176 lines

  1. /**************************************************************
  2.  *
  3.  *      GetAutoDoc.c - Gets an autodoc given the function name
  4.  *
  5.  *      Copyright (c) 1989, Peter Cherna
  6.  *
  7.  *      Created:  March 26, 1989
  8.  *      Modified: August 23, 1989       Release 1.2:  August 29, 1989
  9.  *
  10.  *      Auto: cc -q -o RAM:<file>.o <path><file>
  11.  *      Auto: ln RAM:<file>.o -lc -o <path><file>
  12.  *
  13.  **************************************************************/
  14.  
  15. #include <functions.h>
  16. #include <stdio.h>
  17. #include <ctype.h>
  18. #ifndef EXEC_MEMORY_H
  19. #include <exec/memory.h>
  20. #endif
  21.  
  22. extern char *index();
  23.  
  24. #define BUFFERSIZE 200
  25. #define NAMESIZE 60
  26. #define FORMFEED 12
  27.  
  28. main(argc,argv)
  29.  
  30.     int argc;
  31.     char *argv[];
  32.  
  33.     {
  34.     FILE *file;
  35.     char *buffer, *filename, *ch1, *ch2;
  36.     LONG offset;
  37.     int error;
  38.     int done;
  39.  
  40.     error = 0;
  41.  
  42.     if (argc < 2)
  43.         {
  44.         /* insufficient parameters */
  45.         puts("- GetAutoDoc Copyright (c) 1989, Peter Cherna");
  46.         fputs("    Usage:  ",stdout);
  47.         fputs(argv[0],stdout);
  48.         puts(" function");
  49.         puts("Displays the AutoDoc for the requested function.");
  50.         error = 1;
  51.         }
  52.     else
  53.         {
  54.         filename = AllocMem((LONG) NAMESIZE, MEMF_CLEAR);
  55.         buffer = AllocMem((LONG) BUFFERSIZE, MEMF_CLEAR);
  56.         if ((!filename) || (!buffer))
  57.             {
  58.             fputs("- ",stdout);
  59.             fputs(argv[0],stdout);
  60.             puts(":  Unable to allocate buffer.");
  61.             error = 20;
  62.             }
  63.         else
  64.             {
  65.             sprintf(filename,"AutoDocs:Index/Index%c",toupper(*argv[1]));
  66.             file = fopen(filename,"r");
  67.             if (!file)
  68.                 {
  69.                 /*  If none of the AutoDocs are on line, this could
  70.                     be a serious error.  However, we have to assume that
  71.                     there are no autodocs for this particular letter,
  72.                     (for example, as of 1.2, there is no IndexZ).  Thus
  73.                     the message returned is "<function> not found." */
  74.                 fputs("- ",stdout);
  75.                 fputs(argv[1],stdout);
  76.                 puts(" not found.");
  77.                 error = 5;
  78.                 }
  79.             else
  80.                 {
  81.                 done = 0;
  82.                 while ((!feof(file)) && (!done))
  83.                     {
  84.                     if (!fgets(buffer,BUFFERSIZE,file))
  85.                         {
  86.                         if (!feof(file))
  87.                             {
  88.                             fputs("- ",stdout);
  89.                             fputs(argv[0],stdout);
  90.                             puts(":  Error reading index file.");
  91.                             done = TRUE;
  92.                             error = 20;
  93.                             }
  94.                         }
  95.                     else
  96.                         {
  97.                         ch1 = buffer;
  98.                         ch2 = argv[1];
  99.                         while ((*ch1 != ';') && (toupper(*ch1) == toupper(*ch2)))
  100.                             {
  101.                             ch1++;
  102.                             ch2++;
  103.                             }
  104.                         if ((*ch1 == ';') && (*ch2 == '\0'))
  105.                             done = TRUE;
  106.                         }                       
  107.                     }
  108.                 if (!done)
  109.                     {
  110.                     fputs("- ",stdout);
  111.                     fputs(argv[1],stdout);
  112.                     puts(" not found.");
  113.                     error = 5;
  114.                     }
  115.                 fclose(file);
  116.                 if (!error)
  117.                     {
  118.                     /*  Skip function name: */
  119.                     ch1 = index(buffer,';');
  120.                     ch1++;
  121.                     /*  Skip additional info (not used): */
  122.                     ch1 = index(ch1,';');
  123.                     ch1++;
  124.                     ch1++;
  125.  
  126.                     ch2 = filename;
  127.                     while ((*ch2 = *ch1) != ' ')
  128.                         {
  129.                         ch1++;
  130.                         ch2++;
  131.                         }
  132.  
  133.                     /*  Terminate the file name: */
  134.                     *ch2++ = '\0';
  135.                     ch1++;
  136.  
  137.                     file = fopen(filename,"r");
  138.                     if (!file)
  139.                         {
  140.                         fputs("- ",stdout);
  141.                         fputs(argv[0],stdout);
  142.                         puts(":  AutoDoc file not found.");
  143.                         error = 20;
  144.                         }
  145.                     else
  146.                         {
  147.                         offset = 0;
  148.                         while ((*ch1 >= '0') && (*ch1 <= '9'))
  149.                             offset = 10 * offset + *ch1++ - '0';
  150.                         fseek(file,offset,0);
  151.  
  152.                         while ((!feof(file)) && (*buffer != FORMFEED) && (!error))
  153.                             {
  154.                             if ((!fgets(buffer,BUFFERSIZE,file)) && (!feof(file)))
  155.                                 {
  156.                                 fputs("- ",stdout);
  157.                                 fputs(argv[0],stdout);
  158.                                 puts(":  Error reading AutoDoc file.");
  159.                                 error = 20;
  160.                                 }
  161.                             else if (*buffer != FORMFEED)
  162.                                 fputs(buffer,stdout);
  163.                             }
  164.                         fclose(file);
  165.                         }
  166.                     }
  167.                 }
  168.             if (buffer)
  169.                 FreeMem(buffer, (LONG) BUFFERSIZE);
  170.             if (filename)
  171.                 FreeMem(filename, (LONG) NAMESIZE);
  172.             }
  173.         }
  174.     exit(error);
  175.     }
  176.