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 / MakeAutoDocIndex.c < prev    next >
C/C++ Source or Header  |  1989-12-29  |  6KB  |  173 lines

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