6 |
7u83 |
1 |
/*
|
|
|
2 |
* Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
*
|
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
|
6 |
* modification, are permitted provided that the following conditions are met:
|
|
|
7 |
*
|
|
|
8 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
9 |
* this list of conditions and the following disclaimer.
|
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
11 |
* this list of conditions and the following disclaimer in the documentation
|
|
|
12 |
* and/or other materials provided with the distribution.
|
|
|
13 |
* 3. Neither the name of The TenDRA Project nor the names of its contributors
|
|
|
14 |
* may be used to endorse or promote products derived from this software
|
|
|
15 |
* without specific, prior written permission.
|
|
|
16 |
*
|
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
|
|
18 |
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
19 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
|
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
22 |
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
28 |
*
|
|
|
29 |
* $Id$
|
|
|
30 |
*/
|
|
|
31 |
/*
|
|
|
32 |
Crown Copyright (c) 1997
|
|
|
33 |
|
|
|
34 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
35 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
36 |
acting through the Defence Evaluation and Research Agency
|
|
|
37 |
(DERA). It is made available to Recipients with a
|
|
|
38 |
royalty-free licence for its use, reproduction, transfer
|
|
|
39 |
to other parties and amendment for any purpose not excluding
|
|
|
40 |
product development provided that any such use et cetera
|
|
|
41 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
42 |
|
|
|
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
|
|
45 |
|
|
|
46 |
(2) Any amended version of it shall be clearly marked to
|
|
|
47 |
show both the nature of and the organisation responsible
|
|
|
48 |
for the relevant amendment or amendments;
|
|
|
49 |
|
|
|
50 |
(3) Its onward transfer from a recipient to another
|
|
|
51 |
party shall be deemed to be that party's acceptance of
|
|
|
52 |
these conditions;
|
|
|
53 |
|
|
|
54 |
(4) DERA gives no warranty or assurance as to its
|
|
|
55 |
quality or suitability for any purpose and DERA accepts
|
|
|
56 |
no liability whatsoever in relation to any use to which
|
|
|
57 |
it may be put.
|
|
|
58 |
*/
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/**********************************************************************
|
|
|
62 |
$Author: release $
|
|
|
63 |
$Date: 1998/01/17 15:57:25 $
|
|
|
64 |
$Revision: 1.1.1.1 $
|
|
|
65 |
$Log: standardsh.c,v $
|
|
|
66 |
* Revision 1.1.1.1 1998/01/17 15:57:25 release
|
|
|
67 |
* First version to be checked into rolling release.
|
|
|
68 |
*
|
|
|
69 |
* Revision 1.3 1995/08/21 16:00:58 currie
|
|
|
70 |
* put <stdlib> at top of headers
|
|
|
71 |
*
|
|
|
72 |
* Revision 1.2 1995/06/08 09:13:54 currie
|
|
|
73 |
* Added sigs to tokdecs/defs
|
|
|
74 |
*
|
|
|
75 |
* Revision 1.1 1995/04/07 14:29:07 currie
|
|
|
76 |
* Initial revision
|
|
|
77 |
*
|
|
|
78 |
* Revision 1.1 1995/04/07 14:29:07 currie
|
|
|
79 |
* Initial revision
|
|
|
80 |
*
|
|
|
81 |
* Revision 1.2 1994/07/21 10:36:36 currie
|
|
|
82 |
* Added banner
|
|
|
83 |
*
|
|
|
84 |
***********************************************************************/
|
|
|
85 |
#include "config.h"
|
|
|
86 |
#include "util.h"
|
|
|
87 |
#include "streams.h"
|
|
|
88 |
#include "units.h"
|
|
|
89 |
#include "encodings.h"
|
|
|
90 |
#include "enc_nos.h"
|
|
|
91 |
#include "defs.h"
|
|
|
92 |
#include "errors.h"
|
|
|
93 |
#include "standardsh.h"
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
static Name *intshtok = (Name *)0;
|
|
|
97 |
static Name *longshtok = (Name *)0;
|
|
|
98 |
static Name *shortshtok = (Name *)0;
|
|
|
99 |
static Name *charshtok = (Name *)0;
|
|
|
100 |
static Name *uintshtok = (Name *)0;
|
|
|
101 |
static Name *ulongshtok = (Name *)0;
|
|
|
102 |
static Name *ushortshtok = (Name *)0;
|
|
|
103 |
static Name *ucharshtok = (Name *)0;
|
|
|
104 |
static Name *floatshtok = (Name *)0;
|
|
|
105 |
static Name *doubleshtok = (Name *)0;
|
|
|
106 |
|
|
|
107 |
static TDFlist *extra_toks = (TDFlist *)0;
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
void
|
|
|
111 |
select_tokdef_unit(void)
|
|
|
112 |
{
|
|
|
113 |
/* can define a token while in a token definition in shapes */
|
|
|
114 |
if (current_Unit != tokdef_unit) {
|
|
|
115 |
SELECT_UNIT(tokdef_unit);
|
|
|
116 |
} else {
|
|
|
117 |
TDFlist *tl = MALLOC(TDFlist);
|
|
|
118 |
tl->next = extra_toks;
|
|
|
119 |
extra_toks = tl;
|
|
|
120 |
current_TDF = &tl->t;
|
|
|
121 |
INIT_TDF(current_TDF);
|
|
|
122 |
current_Unit = tokdef_unit;
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
void
|
|
|
128 |
add_extra_toks(void)
|
|
|
129 |
{
|
|
|
130 |
SELECT_UNIT(tokdef_unit);
|
|
|
131 |
while (extra_toks != (TDFlist *)0) {
|
|
|
132 |
append_TDF(&extra_toks->t, 1);
|
|
|
133 |
INC_LIST;
|
|
|
134 |
extra_toks = extra_toks->next;
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
static void
|
|
|
140 |
make_intsh(Bool issigned)
|
|
|
141 |
{
|
|
|
142 |
o_integer(o_var_limits(
|
|
|
143 |
o_make_signed_nat(out_tdfbool(issigned),
|
|
|
144 |
out_tdfint32(UL((issigned) ? MINSI : 0))),
|
|
|
145 |
o_make_signed_nat(out_tdfbool(0),
|
|
|
146 |
out_tdfint32(UL((issigned) ? MAXSI : MAXUSI)))));
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
static void
|
|
|
151 |
make_longsh(Bool issigned)
|
|
|
152 |
{
|
|
|
153 |
o_integer(o_var_limits(
|
|
|
154 |
o_make_signed_nat(out_tdfbool(issigned),
|
|
|
155 |
out_tdfint32(UL((issigned) ? MINSL : 0))),
|
|
|
156 |
o_make_signed_nat(out_tdfbool(0),
|
|
|
157 |
out_tdfint32(UL((issigned) ? MAXSL : MAXUSL)))));
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
static void
|
|
|
162 |
make_shortsh(Bool issigned)
|
|
|
163 |
{
|
|
|
164 |
o_integer(o_var_limits(
|
|
|
165 |
o_make_signed_nat(out_tdfbool(issigned),
|
|
|
166 |
out_tdfint32(UL((issigned) ? MINSS : 0))),
|
|
|
167 |
o_make_signed_nat(out_tdfbool(0),
|
|
|
168 |
out_tdfint32(UL((issigned) ? MAXSS : MAXUSS)))));
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
static void
|
|
|
173 |
make_charsh(Bool issigned)
|
|
|
174 |
{
|
|
|
175 |
o_integer(o_var_limits(
|
|
|
176 |
o_make_signed_nat(out_tdfbool(issigned),
|
|
|
177 |
out_tdfint32(UL((issigned) ? MINSC : 0))),
|
|
|
178 |
o_make_signed_nat(out_tdfbool(0),
|
|
|
179 |
out_tdfint32(UL((issigned) ? MAXSC : MAXUSC)))));
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
static void
|
|
|
184 |
make_floatsh(void)
|
|
|
185 |
{
|
|
|
186 |
o_floating(o_flvar_parms(
|
|
|
187 |
o_make_nat(out_tdfint32(UL(2))),
|
|
|
188 |
o_make_nat(out_tdfint32(UL(MANT_FLOAT))),
|
|
|
189 |
o_make_nat(out_tdfint32(UL(MINEXP_FLOAT))),
|
|
|
190 |
o_make_nat(out_tdfint32(UL(MAXEXP_FLOAT)))
|
|
|
191 |
)
|
|
|
192 |
)
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
static void
|
|
|
197 |
make_doublesh(void)
|
|
|
198 |
{
|
|
|
199 |
o_floating(o_flvar_parms(
|
|
|
200 |
o_make_nat(out_tdfint32(UL(2))),
|
|
|
201 |
o_make_nat(out_tdfint32(UL(MANT_DOUBLE))),
|
|
|
202 |
o_make_nat(out_tdfint32(UL(MINEXP_DOUBLE))),
|
|
|
203 |
o_make_nat(out_tdfint32(UL(MAXEXP_DOUBLE)))
|
|
|
204 |
)
|
|
|
205 |
)
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
Name *
|
|
|
210 |
tokforintsh(Bool issigned)
|
|
|
211 |
{
|
|
|
212 |
TDF *place = current_TDF;
|
|
|
213 |
int cu = current_Unit;
|
|
|
214 |
Name **t = (issigned) ? &intshtok : &uintshtok;
|
|
|
215 |
if ((*t) != (Name *)0) {
|
|
|
216 |
return(*t);
|
|
|
217 |
}
|
|
|
218 |
(*t) = MALLOC(Name);
|
|
|
219 |
select_tokdef_unit();
|
|
|
220 |
*(*t) = next_name(tok_ent);
|
|
|
221 |
o_make_tokdef(out_tdfint32(UL((*t)->unit_name)), {},
|
|
|
222 |
o_token_def(o_shape, {;}, make_intsh(issigned))
|
|
|
223 |
);
|
|
|
224 |
INC_LIST;
|
|
|
225 |
current_Unit = cu;
|
|
|
226 |
RESET_TDF(place);
|
|
|
227 |
return(*t);
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
Name *
|
|
|
232 |
tokforlongsh(Bool issigned)
|
|
|
233 |
{
|
|
|
234 |
TDF *place = current_TDF;
|
|
|
235 |
int cu = current_Unit;
|
|
|
236 |
Name **t = (issigned) ? &longshtok : &ulongshtok;
|
|
|
237 |
if ((*t) != (Name *)0) {
|
|
|
238 |
return(*t);
|
|
|
239 |
}
|
|
|
240 |
(*t) = MALLOC(Name);
|
|
|
241 |
select_tokdef_unit();
|
|
|
242 |
*(*t) = next_name(tok_ent);
|
|
|
243 |
o_make_tokdef(out_tdfint32(UL((*t)->unit_name)), {},
|
|
|
244 |
o_token_def(o_shape, {;}, make_longsh(issigned))
|
|
|
245 |
);
|
|
|
246 |
INC_LIST;
|
|
|
247 |
current_Unit = cu;
|
|
|
248 |
RESET_TDF(place);
|
|
|
249 |
return(*t);
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
Name *
|
|
|
254 |
tokforshortsh(Bool issigned)
|
|
|
255 |
{
|
|
|
256 |
TDF *place = current_TDF;
|
|
|
257 |
int cu = current_Unit;
|
|
|
258 |
Name **t = (issigned) ? &shortshtok : &ushortshtok;
|
|
|
259 |
if ((*t) != (Name *)0) {
|
|
|
260 |
return(*t);
|
|
|
261 |
}
|
|
|
262 |
(*t) = MALLOC(Name);
|
|
|
263 |
select_tokdef_unit();
|
|
|
264 |
*(*t) = next_name(tok_ent);
|
|
|
265 |
o_make_tokdef(out_tdfint32(UL((*t)->unit_name)), {},
|
|
|
266 |
o_token_def(o_shape, {;}, make_shortsh(issigned))
|
|
|
267 |
);
|
|
|
268 |
INC_LIST;
|
|
|
269 |
current_Unit = cu;
|
|
|
270 |
RESET_TDF(place);
|
|
|
271 |
return(*t);
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
Name *
|
|
|
276 |
tokforcharsh(Bool issigned)
|
|
|
277 |
{
|
|
|
278 |
TDF *place = current_TDF;
|
|
|
279 |
int cu = current_Unit;
|
|
|
280 |
Name **t = (issigned) ? &charshtok : &ucharshtok;
|
|
|
281 |
if ((*t) != (Name *)0) {
|
|
|
282 |
return(*t);
|
|
|
283 |
}
|
|
|
284 |
(*t) = MALLOC(Name);
|
|
|
285 |
select_tokdef_unit();
|
|
|
286 |
*(*t) = next_name(tok_ent);
|
|
|
287 |
o_make_tokdef(out_tdfint32(UL((*t)->unit_name)), {},
|
|
|
288 |
o_token_def(o_shape, {;}, make_charsh(issigned))
|
|
|
289 |
);
|
|
|
290 |
INC_LIST;
|
|
|
291 |
current_Unit = cu;
|
|
|
292 |
RESET_TDF(place);
|
|
|
293 |
return(*t);
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
Name *
|
|
|
298 |
tokforfloatsh(void)
|
|
|
299 |
{
|
|
|
300 |
TDF *place = current_TDF;
|
|
|
301 |
int cu = current_Unit;
|
|
|
302 |
Name ** t = &floatshtok;
|
|
|
303 |
if ((*t) != (Name *)0) {
|
|
|
304 |
return(*t);
|
|
|
305 |
}
|
|
|
306 |
(*t) = MALLOC(Name);
|
|
|
307 |
select_tokdef_unit();
|
|
|
308 |
*(*t) = next_name(tok_ent);
|
|
|
309 |
o_make_tokdef(out_tdfint32(UL((*t)->unit_name)), {},
|
|
|
310 |
o_token_def(o_shape, {;}, make_floatsh())
|
|
|
311 |
);
|
|
|
312 |
INC_LIST;
|
|
|
313 |
current_Unit = cu;
|
|
|
314 |
RESET_TDF(place);
|
|
|
315 |
return(*t);
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
Name *
|
|
|
320 |
tokfordoublesh(void)
|
|
|
321 |
{
|
|
|
322 |
TDF *place = current_TDF;
|
|
|
323 |
int cu = current_Unit;
|
|
|
324 |
Name **t = &doubleshtok;
|
|
|
325 |
if ((*t) != (Name *)0) {
|
|
|
326 |
return(*t);
|
|
|
327 |
}
|
|
|
328 |
(*t) = MALLOC(Name);
|
|
|
329 |
select_tokdef_unit();
|
|
|
330 |
*(*t) = next_name(tok_ent);
|
|
|
331 |
o_make_tokdef(out_tdfint32(UL((*t)->unit_name)), {},
|
|
|
332 |
o_token_def(o_shape, {;}, make_doublesh())
|
|
|
333 |
);
|
|
|
334 |
INC_LIST;
|
|
|
335 |
current_Unit = cu;
|
|
|
336 |
RESET_TDF(place);
|
|
|
337 |
return(*t);
|
|
|
338 |
}
|