forked from Macroassembler-AS/asl-releases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asmfnums.c
170 lines (143 loc) · 3.26 KB
/
asmfnums.c
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* asmfnums.c */
/*****************************************************************************/
/* AS-Portierung */
/* */
/* Verwaltung von Datei-Nummern */
/* */
/* Historie: 15. 5.1996 Grundsteinlegung */
/* 25. 7.1998 GetFileName jetzt mit int statt Byte */
/* Verwaltung Adressbereiche */
/* Caching FileCount */
/* 16. 8.1998 Ruecksetzen Adressbereiche */
/* */
/*****************************************************************************/
#include "stdinc.h"
#include <string.h>
#include "strutil.h"
#include "chunks.h"
#include "asmdef.h"
#include "asmsub.h"
#include "intconsts.h"
#include "asmfnums.h"
#ifdef HAS64
#define ADRMAX INTCONST_9223372036854775807
#else
#define ADRMAX INTCONST_4294967295
#endif
typedef struct sToken
{
struct sToken *Next;
LargeWord FirstAddr, LastAddr;
char *Name;
} TToken, *PToken;
static PToken FirstFile;
static int FileCount;
void InitFileList(void)
{
FirstFile = NULL;
FileCount = 0;
}
void ClearFileList(void)
{
PToken F;
while (FirstFile)
{
F = FirstFile->Next;
free(FirstFile->Name);
free(FirstFile);
FirstFile = F;
}
FileCount = 0;
}
static PToken SearchToken(int Num)
{
PToken Lauf = FirstFile;
while (Num > 0)
{
if (!Lauf)
return NULL;
Num--;
Lauf = Lauf->Next;
}
return Lauf;
}
void AddFile(char *FName)
{
PToken Lauf, Neu;
if (GetFileNum(FName) != -1)
return;
Neu = (PToken) malloc(sizeof(TToken));
Neu->Next = NULL;
Neu->Name = as_strdup(FName);
Neu->FirstAddr = ADRMAX;
Neu->LastAddr = 0;
if (!FirstFile)
FirstFile = Neu;
else
{
Lauf = FirstFile;
while (Lauf->Next)
Lauf = Lauf->Next;
Lauf->Next = Neu;
}
FileCount++;
}
Integer GetFileNum(char *Name)
{
PToken FLauf = FirstFile;
int Cnt = 0;
while ((FLauf) && (strcmp(FLauf->Name,Name)))
{
Cnt++;
FLauf = FLauf->Next;
}
return FLauf ? Cnt : -1;
}
char *GetFileName(int Num)
{
PToken Lauf = SearchToken(Num);
static char *Dummy = "";
return Lauf ? Lauf->Name : Dummy;
}
Integer GetFileCount(void)
{
return FileCount;
}
void AddAddressRange(int File, LargeWord Start, LargeWord Len)
{
PToken Lauf = SearchToken(File);
if (!Lauf)
return;
if (Start < Lauf->FirstAddr)
Lauf->FirstAddr = Start;
if ((Len += Start - 1) > Lauf->LastAddr)
Lauf->LastAddr = Len;
}
void GetAddressRange(int File, LargeWord *Start, LargeWord *End)
{
PToken Lauf = SearchToken(File);
if (!Lauf)
{
*Start = ADRMAX;
*End = 0;
}
else
{
*Start = Lauf->FirstAddr;
*End = Lauf->LastAddr;
}
}
void ResetAddressRanges(void)
{
PToken Run;
for (Run = FirstFile; Run; Run = Run->Next)
{
Run->FirstAddr = ADRMAX;
Run->LastAddr = 0;
}
}
void asmfnums_init(void)
{
FirstFile = NULL;
FileCount = 0;
}