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

  1. /* Make a list of all autodocs in short format */
  2.  
  3. #include <exec/memory.h>
  4.  
  5. #include "global.h"
  6. #include "misc.h"
  7. #include "adfile.h"
  8. #include "shortad.h"
  9.  
  10. /***********************************************/
  11.  
  12. struct ShortAutodocEntry *ShortAutodocArray;
  13.  
  14. /***********************************************/
  15.  
  16. static int InternalSearchShortAutodoc(char *Name)
  17.  
  18. {
  19.    int Index;
  20.  
  21.    for (Index=1; Index<=(int)ShortAutodocArray[Index].Name; Index++)
  22.       {
  23.          if (!strcmp(ShortAutodocArray[Index].Name,Name))
  24.             {
  25.                return(Index);
  26.             }
  27.       }
  28.    return(0);
  29. }
  30.  
  31. /***********************************************/
  32.  
  33. static int GetResidentIndex(struct AutodocNode *AutodocNode)
  34.  
  35. {
  36.    static struct
  37.       {
  38.          char *Name;
  39.          int Length;
  40.       } ResidentTypes[]=
  41.       {
  42.          "library",7,   /* 0 */
  43.          "device",6,    /* 1 */
  44.          "datatype",8,  /* 2 */
  45.          "lib",3,       /* 3 */
  46.          "resource",8   /* 4 */
  47.       };
  48.  
  49.    int Index;
  50.    char *ResidentTypeEnd;
  51.    int Length;
  52.  
  53.    if (AutodocNode)
  54.       {
  55.          ResidentTypeEnd=FindSlash(AutodocNode->Node.Name);
  56.          Length=ResidentTypeEnd-AutodocNode->Node.Name;
  57.          for (Index=0; Index<5; Index++)
  58.             {
  59.                if (ResidentTypes[Index].Length<=Length)
  60.                   {
  61.                      if (!__builtin_memcmp(ResidentTypeEnd-ResidentTypes[Index].Length,ResidentTypes[Index].Name,ResidentTypes[Index].Length))
  62.                         {
  63.                            return(Index);
  64.                         }
  65.                   }
  66.             }
  67.       }
  68.    return(5);
  69. }
  70.  
  71. /***********************************************/
  72.  
  73. BOOL MakeShortAutodocs(void)
  74.  
  75. {
  76.    struct AutodocNode *TempNode, *PrevNode;
  77.    int Index;
  78.    int CurrentNode;
  79.    int ExistingNode;
  80.  
  81.    if (ShortAutodocArray=AllocVec((((int)AutodocArray[0])+1)*sizeof(struct ShortAutodocEntry),MEMF_CLEAR))
  82.       {
  83.          for (CurrentNode=1; CurrentNode<=(int)AutodocArray[0]; CurrentNode++)
  84.             {
  85.                if (Break()) return(FALSE);
  86.                if ((int)ShortAutodocArray[0].Name && (ExistingNode=InternalSearchShortAutodoc(FindSlash(AutodocArray[CurrentNode]->Node.Name)+1)))
  87.                   {
  88.                      Index=GetResidentIndex(AutodocArray[CurrentNode]);
  89.                      TempNode=ShortAutodocArray[ExistingNode].AutodocNode;
  90.                      PrevNode=NULL;
  91.                      while (Index>GetResidentIndex(TempNode))
  92.                         {
  93.                            PrevNode=TempNode;
  94.                            TempNode=TempNode->ShortLink;
  95.                         }
  96.                      AutodocArray[CurrentNode]->ShortLink=TempNode;
  97.                      if (PrevNode)
  98.                         {
  99.                            PrevNode->ShortLink=AutodocArray[CurrentNode];
  100.                         }
  101.                      else
  102.                         {
  103.                            ShortAutodocArray[ExistingNode].AutodocNode=AutodocArray[CurrentNode];
  104.                         }
  105.                   }
  106.                else
  107.                   {
  108.                      (int)(ShortAutodocArray[0].Name)++;
  109.                      ShortAutodocArray[(int)ShortAutodocArray[0].Name].Name=FindSlash(AutodocArray[CurrentNode]->Node.Name)+1;
  110.                      ShortAutodocArray[(int)ShortAutodocArray[0].Name].AutodocNode=AutodocArray[CurrentNode];
  111.                   }
  112.             }
  113.          for (CurrentNode=1; CurrentNode<(int)(ShortAutodocArray[0].Name); CurrentNode++)
  114.             {
  115.                if (Break()) return(FALSE);
  116.                for (Index=CurrentNode+1; Index<=(int)(ShortAutodocArray[0].Name); Index++)
  117.                   {
  118.                      if (strcmp(ShortAutodocArray[Index].Name,ShortAutodocArray[CurrentNode].Name)<0)
  119.                         {
  120.                            TempNode=ShortAutodocArray[Index].AutodocNode;
  121.                            ShortAutodocArray[Index].AutodocNode=ShortAutodocArray[CurrentNode].AutodocNode;
  122.                            ShortAutodocArray[CurrentNode].AutodocNode=TempNode;
  123.                            TempNode=(struct AutodocNode *)ShortAutodocArray[Index].Name;
  124.                            ShortAutodocArray[Index].Name=ShortAutodocArray[CurrentNode].Name;
  125.                            ShortAutodocArray[CurrentNode].Name=(char *)TempNode;
  126.                         }
  127.                   }
  128.             }
  129.          return(TRUE);
  130.       }
  131.    PrintFault(ERROR_NO_FREE_STORE,NULL);
  132.    return(FALSE);
  133. }
  134.  
  135. /***********************************************/
  136.  
  137. struct AutodocNode *SearchShortAutodoc(char *Name)
  138.  
  139. {
  140.    int OldIndex;
  141.    int Upper, Lower;
  142.    int Index;
  143.    int Result;
  144.    struct AutodocNode *AutodocNode;
  145.  
  146.    Lower=1;
  147.    Upper=(int)(ShortAutodocArray[0].Name)+1;
  148.    Index=0;
  149.    do
  150.       {
  151.          OldIndex=Index;
  152.          Index=(Upper+Lower)/2;
  153.          if (!(Result=strcmp(ShortAutodocArray[Index].Name,Name)))
  154.             {
  155.                Upper=strlen(CurrentUnit);
  156.                AutodocNode=ShortAutodocArray[Index].AutodocNode;
  157.                while (AutodocNode)
  158.                   {
  159.                      if (!__builtin_memcmp(CurrentUnit,AutodocNode->Node.Name,Upper))
  160.                         {
  161.                            if (AutodocNode->Node.Name[Upper]=='/')
  162.                               {
  163.                                  return(AutodocNode);
  164.                               }
  165.                         }
  166.                      AutodocNode=AutodocNode->ShortLink;
  167.                   }
  168.                AutodocNode=ShortAutodocArray[Index].AutodocNode;
  169.                if (AutodocNode==CurrentAutodocNode)
  170.                   {
  171.                      AutodocNode=AutodocNode->ShortLink;
  172.                   }
  173.                return(AutodocNode);
  174.             }
  175.          if (Result<0)
  176.             {
  177.                Lower=Index;
  178.             }
  179.          else
  180.             {
  181.                Upper=Index;
  182.             }
  183.       }
  184.    while (Index!=OldIndex);
  185.    return(NULL);
  186. }
  187.  
  188. /***********************************************/
  189.  
  190. BOOL PrintShortAutodocList(void)
  191.  
  192. {
  193.    int Index;
  194.  
  195.    if (FPrintf(XRefFile,"\n/* Functions and Commands, without subsystem */\n")==-1)
  196.       {
  197.          PrintFault(IoErr(),Arguments.XRefFile);
  198.          return(FALSE);
  199.       }
  200.    for (Index=1; Index<=(int)ShortAutodocArray[0].Name; Index++)
  201.       {
  202.          if (FPrintf(XRefFile,"\x22%s\x22 \x22%s\x22 0 %ld /* %s */\n",ShortAutodocArray[Index].Name,ShortAutodocArray[Index].AutodocNode->File,ShortAutodocArray[Index].AutodocNode->Type,ShortAutodocArray[Index].AutodocNode->Node.Name)==-1)
  203.             {
  204.                PrintFault(IoErr(),Arguments.XRefFile);
  205.                return(FALSE);
  206.             }
  207.       }
  208.    return(TRUE);
  209. }
  210.