Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. /* asminclist.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Portierung                                                             */
  6. /*                                                                           */
  7. /* Verwaltung der Include-Verschachtelungsliste                              */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include "stdinc.h"
  12. #include <string.h>
  13.  
  14. #include "strutil.h"
  15. #include "chunks.h"
  16. #include "nls.h"
  17. #include "nlmessages.h"
  18. #include "as.rsc"
  19. #include "asmfnums.h"
  20. #include "asmdef.h"
  21. #include "asmsub.h"
  22.  
  23. #include "asminclist.h"
  24.  
  25.  
  26. typedef struct sFileNode
  27. {
  28.   Integer Name;
  29.   Integer Len;
  30.   struct sFileNode *Parent;
  31.   struct sFileNode **Subs;
  32. } TFileNode, *PFileNode;
  33. typedef struct sFileNode **PFileArray;
  34.  
  35. static PFileNode Root,Curr;
  36.  
  37.  
  38. void PushInclude(char *S)
  39. {
  40.   PFileNode Neu;
  41.  
  42.   Neu = (PFileNode) malloc(sizeof(TFileNode));
  43.   Neu->Name = GetFileNum(S);
  44.   Neu->Len = 0;
  45.   Neu->Subs = NULL;
  46.   Neu->Parent = Curr;
  47.   if (!Root)
  48.     Root = Neu;
  49.   if (!Curr)
  50.     Curr = Neu;
  51.   else
  52.   {
  53.     if (Curr->Len == 0)
  54.       Curr->Subs = (PFileArray) malloc(sizeof(void *));
  55.     else
  56.       Curr->Subs = (PFileArray) realloc(Curr->Subs, sizeof(void *) * (Curr->Len + 1));
  57.     Curr->Subs[Curr->Len++] = Neu;
  58.     Curr = Neu;
  59.   }
  60. }
  61.  
  62. void PopInclude(void)
  63. {
  64.   if (Curr)
  65.     Curr = Curr->Parent;
  66. }
  67.  
  68. static void PrintIncludeList_PrintNode(PFileNode Node, int Indent)
  69. {
  70.   int z;
  71.   String h;
  72.  
  73.   ChkStack();
  74.  
  75.   if (Node)
  76.   {
  77.     strmaxcpy(h, Blanks(Indent), STRINGSIZE);
  78.     strmaxcat(h,GetFileName(Node->Name), STRINGSIZE);
  79.     WrLstLine(h);
  80.     for (z = 0; z < Node->Len; z++)
  81.       PrintIncludeList_PrintNode(Node->Subs[z], Indent + 5);
  82.   }
  83. }
  84.  
  85. void PrintIncludeList(void)
  86. {
  87.   NewPage(ChapDepth, True);
  88.   WrLstLine(getmessage(Num_ListIncludeListHead1));
  89.   WrLstLine(getmessage(Num_ListIncludeListHead2));
  90.   WrLstLine("");
  91.   PrintIncludeList_PrintNode(Root, 0);
  92. }
  93.  
  94. static void ClearIncludeList_ClearNode(PFileNode Node)
  95. {
  96.   int z;
  97.  
  98.   ChkStack();
  99.  
  100.   if (Node)
  101.   {
  102.     for (z = 0; z < Node->Len; ClearIncludeList_ClearNode(Node->Subs[z++]));
  103.     if (Node->Len > 0)
  104.       free(Node->Subs);
  105.     free(Node);
  106.   }
  107. }
  108.  
  109. void ClearIncludeList(void)
  110. {
  111.   ClearIncludeList_ClearNode(Root);
  112.   Curr = NULL;
  113.   Root = NULL;
  114. }
  115.  
  116. void asminclist_init(void)
  117. {
  118.   Root = NULL;
  119.   Curr = NULL;
  120. }
  121.