forked from ogdenpm/aedit-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
218 lines (152 loc) · 5.13 KB
/
util.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// #SMALL
// #title('UTIL UTILITY ROUTINES')
/*********************************************************************
* INTEL CORPORATION PROPRIETARY INFORMATION *
* This software is supplied under the terms of a license agreement *
* or nondisclosure agreement with Intel Corporation and may not be *
* copied or disclosed except in accordance with the terms of that *
* agreement. *
*********************************************************************/
#include <stdbool.h>
#include <string.h>
#include <memory.h>
#include "lit.h"
#include "type.h"
#include "data.h"
#include "proc.h"
// Min & Max replaced by macros to support different number types
word Size_of_text_in_memory() {
return (word)(oa.high_e - oa.high_s + oa.low_e - oa.low_s);
} /* size_of_text_in_memory */
/*
MOVE A NAME
*/
void Move_name(pointer fromp, pointer top) {
#pragma warning(suppress:26451)
memcpy(top, fromp, *fromp + 1);
} /* move_name */
/*
COMPARE TWO STRINGS
*/
byte Cmp_name(pointer fromp, pointer top) {
#pragma warning(suppress:26451)
return memcmp(fromp, top, *fromp + 1) == 0 ? _TRUE : _FALSE;
} /* cmp_name */
byte outfield[34];
/***************************************************************************
Prints a 32 bit number. BASE is the required base. B$WIDTH is the
printing width. If the number is greater than 07FFF$FFFFH, then only
the bases 2,8,16 are allowed (due to PLM/VAX malfunction).
If b$width is negative, the number is left justified; otherwise -
right justified. If base is negative, the filling chars are zeroes,
otherwise spaces.
Returns pointer to the buffer in which the number is expanded.
***************************************************************************/
pointer Print_number(dword d_number, byte b_width, byte base) {
static byte hexdigits[16] = "0123456789ABCDEF";
byte field[34]; /* FIELD[0] IS UNUSED */
byte fill_char;
short i, places, width;
// Fill_chars expanded in line
outfield[0] = 0;
width = (signed char)b_width;
fill_char = ' '; /* initial fill char to blank */
if (base > 127) { /* test for 0 fill char */
base = -base;
fill_char = '0';
}
if (base > 16) /* make sure base is */
base = 16; /* in range */
else if (base < 2) {
base = 10;
}
memset(field, fill_char, sizeof(field)); /* initialize field */
i = sizeof(field);
while (d_number != 0) { // note original did not check for decimal numbers with top bit set so this doesn't
field[--i] = hexdigits[d_number % base];
d_number /= base;
}
if (i == sizeof(field))
field[--i] = '0';
places = sizeof(field) - i;
for (i = places + 1; i <= width; i++) /* print out leading fill chars */
outfield[++outfield[0]] = fill_char;
for (i = sizeof(field) - places; i < sizeof(field); i++) { /* print out number */
outfield[++outfield[0]] = field[i];
}
if (width < 0) { /* print out post fill chars */
width = -width;
for (i = places + 1; i <= width; i++) /* print out leading fill chars */
outfield[++outfield[0]] = fill_char;
}
return outfield;
} /* print_number */
pointer string_p;
int max_string_length;
void Init_str(pointer str_p, int len) {
string_p = str_p;
max_string_length = len - 1; /* Substract leading byte. */
string_p[0] = 0;
} /* init_str */
void Reuse_str(pointer str_p, int len) {
/* Initialize, but do not cancel current contents. */
string_p = str_p;
max_string_length = len - 1; /* Substract leading byte. */
} /* reuse_str */
void Add_str_char(byte ch) {
if (string_p[0] >= max_string_length)
return;
string_p[++string_p[0]] = ch;
} /* add_str_char */
void Add_str(char *s) {
while (*s)
Add_str_char(*s++);
}
void Add_str_str(pointer str_p) {
for (byte i = str_p[0]; i > 0; i--)
Add_str_char(*++str_p);
} /* add_str_str */
void Add_str_num(dword num, byte base) {
Add_str_str(Print_number(num, 0, base));
} /* add_str_num */
/********************************************************
Utilities for input-line scanning.
********************************************************/
pointer scan_p;
void Init_scan(pointer str_p) {
scan_p = str_p;
} /* init_scan */
void Swb() {
while (*scan_p == ' ' || *scan_p == TAB)
scan_p++;
} /* swb */
boolean Skip_char(byte ch) {
Swb();
if (*scan_p != ch)
return _FALSE;
scan_p++;
return _TRUE;
} /* skip_char */
word Num_in(boolean *err_p) {
byte ch;
dword num;
*err_p = _FALSE;
Swb();
if (*scan_p < '0' || *scan_p > '9') {
*err_p = _TRUE;
return 0;
}
num = 0;
for (;;) {
ch = *scan_p - '0';
if (ch < 0 || ch > 9)
return num;
num = num * 10 + ch;
if ((num >> 16) != 0) {
*err_p = _TRUE;
return 0;
}
scan_p++;
}
} /* num_in */
/********************************************************/