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

  1. #include <proto/exec.h>
  2. #include <proto/dos.h>
  3. #include <proto/utility.h>
  4.  
  5. #include <MyStartup.h>
  6. #include <MyLib.h>
  7.  
  8. #define extern
  9. #include "global.h"
  10. #undef extern
  11.  
  12. #include "misc.h"
  13. #include "readdir.h"
  14. #include "adfile.h"
  15. #include "shortad.h"
  16. #include "incfile.h"
  17. #include "convertad.h"
  18. #include "readxref.h"
  19.  
  20. /***********************************************/
  21.  
  22. char VersionString[]="$VER: ADtoHT 1.3 (12.08.93)";
  23.  
  24. /***********************************************/
  25.  
  26. void CloseAll(void)
  27.  
  28. {
  29.    FreeArgs(RDArgs);
  30.    if (IncludeDir) UnLock(IncludeDir);
  31.    if (AutodocDir) UnLock(AutodocDir);
  32.    if (XRefFile) Close(XRefFile);
  33.    if (HypertextDir) UnLock(HypertextDir);
  34.    if (ErrorFile) Close(ErrorFile);
  35.    FreeList(FileList);
  36.    FreeList(IncludeFileList);
  37.    FreeList(StructList);
  38.    FreeList(TypedefList);
  39.    FreeList(AutodocList);
  40.    FreeList(AutodocFileList);
  41.    FreeList(TypedefTempList);
  42.    FreeVec(IncludeFileArray);
  43.    FreeVec(StructArray);
  44.    FreeVec(AutodocArray);
  45.    FreeVec(TypedefArray);
  46.    FreeVec(ShortAutodocArray);
  47.    CloseLibrary(UtilityBase);
  48. }
  49.  
  50. /***********************************************/
  51.  
  52. void main(void)
  53.  
  54. {
  55.    if (CommandLineLength)
  56.       {
  57.          if (UtilityBase=OpenLibrary("utility.library",37))
  58.             {
  59.                Arguments.XRefFile="autodoc.xref";
  60.                Arguments.Extension=".guide";
  61.                Arguments.ErrorFile="NIL:";
  62.                if (RDArgs=ReadArgs("AUTODOCS/A,INCLUDES/A,HYPERTEXT/A,XREFOUT/K,XREFIN/K,ERROR/K,EXTENSION/K,NOEXPAND/S,TYPES/S,CED/S,SHORTTOC/S",(long *)&Arguments,NULL))
  63.                   {
  64.                      if (ErrorFile=Open(Arguments.ErrorFile,MODE_NEWFILE))
  65.                         {
  66.                            if (AutodocDir=Lock(Arguments.AutodocDir,ACCESS_READ))
  67.                               {
  68.                                  if (IncludeDir=Lock(Arguments.IncludeDir,ACCESS_READ))
  69.                                     {
  70.                                        if (HypertextDir=Lock(Arguments.HypertextDir,ACCESS_READ))
  71.                                           {
  72.                                              if (!ReadXRef())
  73.                                                 {
  74.                                                    CloseAll();
  75.                                                    exit(RETURN_ERROR);
  76.                                                 }
  77.                                              if (XRefFile=Open(Arguments.XRefFile,MODE_NEWFILE))
  78.                                                 {
  79.                                                    if (FPrintf(XRefFile,"/* This file was created by ADtoHT V1.3 */\n"
  80.                                                                         "/* Do not edit.                                            */\n\n"
  81.                                                                         "XREF:\n")==-1)
  82.                                                       {
  83.                                                          DosError(Arguments.XRefFile);
  84.                                                       }
  85.                                                    printf("*** Reading includes ***\n");
  86.                                                    if (!ProcessIncludes(IncludeDir,""))
  87.                                                       {
  88.                                                          CloseAll();
  89.                                                          exit(RETURN_ERROR);
  90.                                                       }
  91.                                                    if (!(IncludeFileArray=(struct FileNode **)ListToArray(FileList)))
  92.                                                       {
  93.                                                          CloseAll();
  94.                                                          exit(RETURN_ERROR);
  95.                                                       }
  96.                                                    FileList=NULL;
  97.                                                    if (!(StructArray=(struct StructNode **)ListToArray(StructList)))
  98.                                                       {
  99.                                                          CloseAll();
  100.                                                          exit(RETURN_ERROR);
  101.                                                       }
  102.                                                    if (!(TypedefArray=(struct StructNode **)ListToArray(TypedefList)))
  103.                                                       {
  104.                                                          CloseAll();
  105.                                                          exit(RETURN_ERROR);
  106.                                                       }
  107.                                                    if (!PrintIncludeFileList())
  108.                                                       {
  109.                                                          CloseAll();
  110.                                                          exit(RETURN_ERROR);
  111.                                                       }
  112.                                                    if (!PrintStructList())
  113.                                                       {
  114.                                                          CloseAll();
  115.                                                          exit(RETURN_ERROR);
  116.                                                       }
  117.                                                    if (!PrintTypedefs())
  118.                                                       {
  119.                                                          CloseAll();
  120.                                                          exit(RETURN_ERROR);
  121.                                                       }
  122.                                                    printf("*** Collecting autodoc contents ***\n");
  123.                                                    if (!ReadAutodocs())
  124.                                                       {
  125.                                                          CloseAll();
  126.                                                          exit(RETURN_ERROR);
  127.                                                       }
  128.                                                    if (!MakeShortAutodocs())
  129.                                                       {
  130.                                                          CloseAll();
  131.                                                          exit(RETURN_ERROR);
  132.                                                       }
  133.                                                    if (!PrintShortAutodocList())
  134.                                                       {
  135.                                                          CloseAll();
  136.                                                          exit(RETURN_ERROR);
  137.                                                       }
  138.                                                    if (FPrintf(XRefFile,"\n#\n")==-1)
  139.                                                       {
  140.                                                          DosError(Arguments.XRefFile);
  141.                                                       }
  142.                                                    printf("*** Converting autodocs to hypertext ***\n");
  143.                                                    if (!ConvertAutodocs())
  144.                                                       {
  145.                                                          CloseAll();
  146.                                                          exit(RETURN_ERROR);
  147.                                                       }
  148.                                                 }
  149.                                              else
  150.                                                 {
  151.                                                    DosError(Arguments.XRefFile);
  152.                                                 }
  153.                                           }
  154.                                        else
  155.                                           {
  156.                                              DosError(Arguments.HypertextDir);
  157.                                           }
  158.                                     }
  159.                                  else
  160.                                     {
  161.                                        DosError(Arguments.IncludeDir);
  162.                                     }
  163.                               }
  164.                            else
  165.                               {
  166.                                  DosError(Arguments.AutodocDir);
  167.                               }
  168.                         }
  169.                      else
  170.                         {
  171.                            DosError(Arguments.ErrorFile);
  172.                         }
  173.                   }
  174.                else
  175.                   {
  176.                      DosError(NULL);
  177.                   }
  178.                CloseAll();
  179.             }
  180.          else
  181.             {
  182.                Write(Output(),"ADtoHT requires Kickstart V37 or later.\n",71-32);
  183.                exit(RETURN_ERROR);
  184.             }
  185.       }
  186. }
  187.