home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff297.lzh / DevKit / Sources / MakeHeaderIndex.c < prev    next >
C/C++ Source or Header  |  1989-12-29  |  6KB  |  177 lines

  1. /**************************************************************
  2.  *
  3.  *      MakeHeaderIndex.c - Makes an index from header (.h) files.
  4.  *
  5.  *      Copyright (c) 1989, Peter Cherna
  6.  *
  7.  *      Created:  March 21, 1989
  8.  *      Modified: August 28, 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.  
  19. #ifndef EXEC_MEMORY_H
  20. #include <exec/memory.h>
  21. #endif
  22.  
  23. extern char *scdir();
  24.  
  25. #define DIRCOUNT 8      /*  Number of directories that have include files */
  26.  
  27. char *includedir[] =
  28.     {
  29.     "ch:devices/*",
  30.     "ch:exec/*",
  31.     "ch:graphics/*",
  32.     "ch:hardware/*",
  33.     "ch:intuition/*",
  34.     "ch:libraries/*",
  35.     "ch:resources/*",
  36.     "ch:workbench/*",
  37.     };
  38.  
  39. #define BUFFERSIZE 200
  40. #define FORMFEED 12
  41.  
  42. struct Library *DosBase;
  43. main(argc,argv)
  44.  
  45.     int argc;
  46.     char *argv[];
  47.  
  48.     {
  49.     FILE *source, *dest;
  50.     char *buffer, *start, *end, *pat, *docfile, *destname;
  51.     char subindex, ch;
  52.     LONG offset;
  53.     int p;
  54.  
  55.     DosBase = OpenLibrary("dos.library",0L);
  56.     dest = fopen("ch:TempIndex","w");
  57.     buffer = AllocMem((LONG) BUFFERSIZE,MEMF_CLEAR);
  58.     destname = AllocMem((LONG) BUFFERSIZE,MEMF_CLEAR);
  59.     if (!dest)
  60.         {
  61.         printf("Could not open ch:TempIndex for writing.\n");
  62.         }
  63.     else if (!buffer || !destname)
  64.         {
  65.         printf("Could not allocate buffer.\n");
  66.         }
  67.     else
  68.         {
  69.         for (p = 0; p < DIRCOUNT; p++)
  70.             {
  71.             pat = includedir[p];
  72.  
  73.             while (docfile = scdir(pat))
  74.                 {
  75.                 printf("Scanning file %s ...\n",docfile);
  76.                 source = fopen(docfile,"r");
  77.                 offset = 0;
  78.                 while (!feof(source))
  79.                     {
  80.                     offset++;
  81.                     if (!fgets(buffer,BUFFERSIZE,source))
  82.                         {
  83.                         if (ferror(source))
  84.                             printf("Error %d\n",ferror(source));
  85.                         }
  86.                     else if (!strncmp(buffer,"#define",7))
  87.                         {
  88.                         start = buffer+7;
  89.                         /* skip any blanks after the '#define': */
  90.                         while ((*start == ' ') || (*start == '\t'))
  91.                             start++;
  92.                         end = start;
  93.                         /*  skip until the first blank after the label: */
  94.                         while ((*end != ' ') && (*end != '\n') && (*end != '\t'))
  95.                             end++;
  96.                         *end = '\0';
  97.                         fprintf(dest,"%s; %s; %ld\n",start,docfile,offset);
  98.                         }
  99.                     else if (!strncmp(buffer,"struct",6))
  100.                         {
  101.                         start = buffer+7;
  102.                         /* skip any blanks after the 'struct ': */
  103.                         while ((*start == ' ') || (*start == '\t'))
  104.                             start++;
  105.                         end = start;
  106.                         while ((*end != ' ') && (*end != '\n') && (*end != '\t'))
  107.                             end++;
  108.                         *end = '\0';
  109.                         fprintf(dest,"%s; %s; %ld\n",start,docfile,offset);
  110.                         }
  111.                     }
  112.                 if (source)
  113.                     fclose(source);
  114.                 }
  115.             }
  116.         fclose(dest);
  117.  
  118.         subindex = ' ';
  119.         dest = NULL;
  120.  
  121.         printf("Sorting index...\n");
  122.         if (!Execute("sort >nil: from ch:TempIndex to ch:SortedIndex",
  123.             NULL,NULL))
  124.             printf("Sort failed.  Make sure the 'sort' command is available.\n");
  125.         else
  126.             {
  127.             source = fopen("ch:SortedIndex","r");
  128.             if (!source)
  129.                 printf("Sort failed - could not find resulting file.\n");
  130.             else
  131.                 {
  132.                 printf("Sorted.\n");
  133.                 DeleteFile("ch:TempIndex");
  134.  
  135.                 /*  Make an Index directory.  Ignore return code (probably
  136.                     directory already exists)  Error will be caught when
  137.                     we try to write the first index file. */
  138.                 Execute("makedir ch:Index", NULL, NULL);
  139.                 while (!feof(source))
  140.                     {
  141.                     if (!fgets(buffer,BUFFERSIZE,source))
  142.                         {
  143.                         if (ferror(source))
  144.                             printf("Error %d\n",ferror(source));
  145.                         else if (!feof(source))
  146.                             printf("Unknown problem.\n");
  147.                         }
  148.                     else
  149.                         {
  150.                         ch = toupper(*buffer);
  151.                         if (ch != subindex)
  152.                             {
  153.                             if (dest)
  154.                                 fclose(dest);
  155.                             sprintf(destname,"ch:Index/Index%c",ch);
  156.                             dest = fopen(destname,"w");
  157.                             subindex = ch;
  158.                             printf("Building subindex %c ...\n",ch);
  159.                             }
  160.                         fprintf(dest,"%s",buffer);
  161.                         }
  162.                     }
  163.                 fclose(dest);
  164.                 fclose(source);
  165.                 DeleteFile("ch:SortedIndex");
  166.                 }
  167.             }
  168.         }
  169.     if (destname)
  170.         FreeMem(destname,(LONG) BUFFERSIZE);
  171.     if (buffer)
  172.         FreeMem(buffer,(LONG) BUFFERSIZE);
  173.     printf("Done.\n");
  174.     if (DosBase)
  175.         CloseLibrary(DosBase);
  176.     }
  177.