home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / utilities / hypertext / adtoht / source / adfile.c next >
Encoding:
C/C++ Source or Header  |  1994-06-22  |  5.2 KB  |  186 lines

  1. /* Make a table of contents from all autodoc files */
  2.  
  3. #include "global.h"
  4. #include "misc.h"
  5. #include "adfile.h"
  6. #include "readdir.h"
  7.  
  8. /***********************************************/
  9.  
  10. struct AutodocNode **AutodocArray;
  11. struct AutodocNode *AutodocList;
  12. struct AutodocFileNode *AutodocFileList;
  13.  
  14. /***********************************************/
  15.  
  16. BOOL AddAutodoc(char *Name, char *File, long Type)
  17.  
  18. {
  19.    struct AutodocNode *NewNode;
  20.    int Length;
  21.    char *Temp;
  22.  
  23.    NewNode=AutodocList;
  24.    while (NewNode && strcmp(NewNode->Node.Name,Name))
  25.       {
  26.          NewNode=(struct AutodocNode *)(NewNode->Node.Next);
  27.       }
  28.    if (NewNode)
  29.       {
  30.          printf("Error: AutoDoc %s already defined in %s\n",Name,NewNode->File);
  31.          return(FALSE);
  32.       }
  33.    Length=0;
  34.    for (Temp=File+strlen(File); *Temp!='.'; Temp--) Length++;
  35.    if (NewNode=AllocVec(sizeof(struct AutodocNode)+strlen(Name)+strlen(File)+strlen(Arguments.Extension)-Length+2,0))
  36.       {
  37.          NewNode->ShortLink=NULL;
  38.          NewNode->Node.Name=(char *)(NewNode+1);
  39.          NewNode->File=stpcpy(NewNode->Node.Name,Name)+1;
  40.          stpcpy(stpcpy(NewNode->File,File)-Length,Arguments.Extension);
  41.          Name=FindSlash(Name);
  42.          if (!*(Name++))
  43.             {
  44.                WriteError("Warning: Improper autodoc entry.\n"
  45.                           "         Expected format: xxx/yyy  (e.g. exec.library/AllocMem)\n"
  46.                           "         Ignoring entry.\n");
  47.                FreeVec(NewNode);
  48.                return(TRUE);
  49.             }
  50.          if (Type==-1)
  51.             {
  52.                if (*Name=='-')
  53.                   {
  54.                      NewNode->Type=0;
  55.                   }
  56.                else
  57.                   {
  58.                      Length=strlen(Name);
  59.                      if (Length>=9 && !Stricmp(&Name[Length-9],".datatype"))
  60.                         {
  61.                            NewNode->Type=0;
  62.                         }
  63.                      else
  64.                         {
  65.                            NewNode->Type=2;
  66.                            while (*Name)
  67.                               {
  68.                                  if (*Name!=ToUpper(*Name))
  69.                                     {
  70.                                        NewNode->Type=1;
  71.                                        break;
  72.                                     }
  73.                                  Name++;
  74.                               }
  75.                         }
  76.                   }
  77.             }
  78.          else
  79.             {
  80.                NewNode->Type=Type;
  81.             }
  82.          NewNode->Node.Next=AutodocList;
  83.          AutodocList=NewNode;
  84.          return(TRUE);
  85.       }
  86.    else
  87.       {
  88.          PrintFault(ERROR_NO_FREE_STORE,NULL);
  89.          return(FALSE);
  90.       }
  91. }
  92.  
  93. /***********************************************/
  94.  
  95. static BOOL AddAutodocContents(char *File)
  96.  
  97. {
  98.    BOOL Success;
  99.  
  100.    CurrentSource=FileList->Node.Name;
  101.    printf("      Reading %s\n",CurrentSource);
  102.    Success=FALSE;
  103.    if (CurrentFile=Open(File,MODE_OLDFILE))
  104.       {
  105.          do
  106.             {
  107.                Success=ReadLine(FALSE,FALSE);
  108.             }
  109.          while (!Buffer[0] && Success);
  110.          if (Success)
  111.             {
  112.                if (!Stricmp(Buffer,"TABLE OF CONTENTS"))
  113.                   {
  114.                      do
  115.                         {
  116.                            if (Success=ReadLine(FALSE,FALSE))
  117.                               {
  118.                                  if (Buffer[0]!='\x0c' && Buffer[0])
  119.                                     {
  120.                                        Success=AddAutodoc(Buffer,CurrentSource,-1);
  121.                                     }
  122.                               }
  123.                         }
  124.                      while (Success && Buffer[0]!='\x0c');
  125.                   }
  126.                else
  127.                   {
  128.                      WriteError("Error: First line in autodoc file must read\n"
  129.                                 "       \x22TABLE OF CONTENTS\x22\n"
  130.                                 "       File: %s\n"
  131.                                 "       Operation aborted.\n",CurrentSource);
  132.                   }
  133.             }
  134.          Close(CurrentFile);
  135.       }
  136.    else
  137.       {
  138.          PrintFault(IoErr(),CurrentSource);
  139.       }
  140.    return(Success);
  141. }
  142.  
  143. /***********************************************/
  144.  
  145. BOOL ReadAutodocs(void)
  146.  
  147. {
  148.    FileList=NULL;
  149.    if (ReadDir(AutodocDir,"",".doc",AddAutodocContents))
  150.       {
  151.          AutodocFileList=FileList;
  152.          FileList=NULL;
  153.          if (AutodocArray=(struct AutodocNode **)ListToArray(AutodocList))
  154.             {
  155.                return(TRUE);
  156.             }
  157.       }
  158.    return(FALSE);
  159. }
  160.  
  161. /***********************************************/
  162.  
  163. #if 0
  164. BOOL PrintAutodocList(void)
  165.  
  166. {
  167.    int Index;
  168.  
  169.    printf("      %ld autodoc entries found\n",(int)AutodocArray[0]);
  170.    if (FPrintf(XRefFile,"\n/* Functions and Commands */\n")==-1)
  171.       {
  172.          PrintFault(IoErr(),Arguments.XRefFile);
  173.          return(FALSE);
  174.       }
  175.    for (Index=1; Index<=(int)AutodocArray[0]; Index++)
  176.       {
  177.          if (FPrintf(XRefFile,"\x22%s\x22 \x22%s\x22 0 %ld\n",AutodocArray[Index]->Node.Name,AutodocArray[Index]->File,AutodocArray[Index]->Type)==-1)
  178.             {
  179.                PrintFault(IoErr(),Arguments.XRefFile);
  180.                return(FALSE);
  181.             }
  182.       }
  183.    return(TRUE);
  184. }
  185. #endif
  186.