Subversion Repositories pentevo

Rev

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

  1. /* entryaddress.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Portierung                                                             */
  6. /*                                                                           */
  7. /* Maintain entry addresses                                                  */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include "stdinc.h"
  12.  
  13. #include "strutil.h"
  14.  
  15. #include "entryaddress.h"
  16.  
  17. typedef struct sEntryAddress
  18. {
  19.   struct sEntryAddress *pNext;
  20.   LargeWord Address;
  21. } tEntryAddress;
  22.  
  23. static tEntryAddress *pFirstEntryAddress;
  24.  
  25. Boolean EntryAddressAvail(void)
  26. {
  27.   return pFirstEntryAddress != NULL;
  28. }
  29.  
  30. void AddEntryAddress(LargeWord Address)
  31. {
  32.   tEntryAddress *pRun, *pPrev, *pNew;
  33.  
  34.   for (pPrev = NULL, pRun = pFirstEntryAddress; pRun; pPrev = pRun, pRun = pRun->pNext)
  35.   {
  36.     if (pRun->Address == Address)
  37.       return;
  38.     if (pRun->Address > Address)
  39.       break;
  40.   }
  41.  
  42.   pNew = (tEntryAddress*)malloc(sizeof(*pNew));
  43.   pNew->Address = Address;
  44.  
  45.   pNew->pNext = pRun;
  46.   if (pPrev)
  47.     pPrev->pNext = pNew;
  48.   else
  49.     pFirstEntryAddress = pNew;
  50. }
  51.  
  52. LargeWord GetEntryAddress(Boolean UsePreferredAddress, LargeWord PreferredAddress)
  53. {
  54.   tEntryAddress *pOld = NULL, *pPrev = NULL;
  55.   LargeWord Result;
  56.  
  57.   if (!pFirstEntryAddress)
  58.   {
  59.     fprintf(stderr, "internal error: entry address list is empty\n");
  60.     exit(255);
  61.   }
  62.  
  63.   if (UsePreferredAddress)
  64.   {
  65.     for (pPrev = NULL, pOld = pFirstEntryAddress; pOld; pPrev = pOld, pOld = pOld->pNext)
  66.       if (pOld->Address >= PreferredAddress)
  67.       {
  68.         if (pOld->Address > PreferredAddress)
  69.           pOld = NULL;
  70.         break;
  71.       }
  72.   }
  73.   if (!pOld)
  74.   {
  75.     pOld = pFirstEntryAddress;
  76.     pPrev = NULL;
  77.   }
  78.  
  79.   if (pPrev)
  80.     pPrev->pNext = pOld->pNext;
  81.   else
  82.     pFirstEntryAddress = pOld->pNext;
  83.  
  84.   Result = pOld->Address;
  85.   free(pOld);
  86.   return Result;
  87. }
  88.  
  89. void PrintEntryAddress(FILE *pFile)
  90. {
  91.   tEntryAddress *pRun;
  92.   String Str;
  93.  
  94.   fprintf(pFile, "(");
  95.   for (pRun = pFirstEntryAddress; pRun; pRun = pRun->pNext)
  96.   {
  97.     as_snprintf(Str, sizeof Str, " %lllx", pRun->Address);
  98.     fprintf(pFile, "%s\n", Str);
  99.   }
  100.   fprintf(pFile, ")\n");
  101. }
  102.  
  103. void entryaddress_init()
  104. {
  105.   pFirstEntryAddress = NULL;
  106. }
  107.