aboutsummaryrefslogtreecommitdiffstats
path: root/asmrelocs.c
blob: bb24e22aab0f607355fc9c64f15079b649206135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* asmrelocs.c */
/*****************************************************************************/
/* AS-Portierung                                                             */
/*                                                                           */
/* Verwaltung von Relokationslisten                                          */
/*                                                                           */
/* Historie: 25. 7.1999 Grundsteinlegung                                     */
/*            1. 8.1999 Merge-Funktion implementiert                         */
/*            8. 8.1999 Reloc-Liste gespeichert                              */
/*           15. 9.1999 fehlende Includes                                    */
/*                      Add in Merge                                         */
/*****************************************************************************/

#include "stdinc.h"
#include <string.h>
#include "strutil.h"
#include "asmdef.h"
#include "asmsub.h"
#include "asmrelocs.h"

/*---------------------------------------------------------------------------*/

PRelocEntry LastRelocs = Nil;

/*---------------------------------------------------------------------------*/

	PRelocEntry MergeRelocs(PRelocEntry *list1, PRelocEntry *list2,
                                Boolean Add)
BEGIN
   PRelocEntry PRun1, PRun2, PPrev, PNext, PLast, PRes;

   PRun1 = *list1; PLast = PRes = Nil;

   /* ueber alle in Liste 1 */

   while (PRun1 != Nil)
    BEGIN
     /* Uebereinstimmung suchen, die sich aufhebt */

     PNext = PRun1->Next;
     PRun2 = *list2; PPrev = Nil;
     while (PRun2 != Nil)
      if ((strcasecmp(PRun1->Ref, PRun2->Ref) == 0) AND ((PRun1->Add != PRun2->Add) != Add))
       BEGIN
        /* gefunden -> beide weg */

        free(PRun1->Ref); free(PRun2->Ref);
        if (PPrev == Nil) *list2 = PRun2->Next;
        else PPrev->Next = PRun2->Next;
        free(PRun2); free(PRun1); PRun1 = Nil;
        break;
       END
      else
       BEGIN
        PPrev = PRun2; PRun2 = PRun2->Next;
       END

     /* ansonsten an Ergebnisliste anhaengen */

     if (PRun1 != Nil)
      if (PLast == Nil) PRes = PLast = PRun1;
      else 
       BEGIN
        PLast->Next = PRun1; PLast = PRun1;
       END
     PRun1 = PNext;
    END

   /* Reste aus Liste 2 nicht vergessen */

   if (PLast == Nil) PRes = *list2;
   else PLast->Next = *list2;

   /* Quellisten jetzt leer */

   *list1 = *list2 = Nil;

   /* fertich */

   return PRes;
END

	void InvertRelocs(PRelocEntry *erg, PRelocEntry *src)
BEGIN
   PRelocEntry SRun;

   for (SRun = *src; SRun != Nil; SRun = SRun->Next)
    SRun->Add = NOT (SRun->Add);

   *erg = *src;
END

	void FreeRelocs(PRelocEntry *list)
BEGIN
   PRelocEntry Run;

   while (*list != Nil)
    BEGIN
     Run = *list;
     *list = (*list)->Next;
     free(Run->Ref);
     free(Run);
    END
END

	 PRelocEntry DupRelocs(PRelocEntry src)
BEGIN
   PRelocEntry First, Run, SRun, Neu;

   First = Run = Nil;
   for (SRun = src; SRun != Nil; SRun = SRun->Next)
    BEGIN
     Neu = (PRelocEntry) malloc(sizeof(TRelocEntry));
     Neu->Next = Nil;
     Neu->Ref = strdup(SRun->Ref);
     Neu->Add = SRun->Add;
     if (First == Nil) First = Neu;
     else Run->Next = Neu;
     Run = Neu;
    END

   return First;
END

	void SetRelocs(PRelocEntry List)
BEGIN
   if (LastRelocs != Nil)
    BEGIN
     WrError(1155);
     FreeRelocs(&LastRelocs);
    END
   LastRelocs = List;
END