2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
#ifndef PD_CHUNKS_INCLUDED
|
|
|
32 |
#define PD_CHUNKS_INCLUDED
|
|
|
33 |
|
|
|
34 |
#define DATA_SIZE 256
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
typedef int Bool;
|
|
|
38 |
|
|
|
39 |
typedef struct chunk_struct
|
|
|
40 |
{ struct chunk_struct *next;
|
|
|
41 |
short int usage;
|
|
|
42 |
unsigned char offst; unsigned char aligned;
|
|
|
43 |
unsigned char data[DATA_SIZE];
|
|
|
44 |
} Chunk;
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
typedef struct { Chunk * first; Chunk * last;
|
|
|
48 |
unsigned int no; unsigned int sort;} TDF;
|
|
|
49 |
|
|
|
50 |
extern TDF * current_TDF; /* the current output stream */
|
|
|
51 |
|
|
|
52 |
extern Chunk * create_chunk PROTO_S((void));
|
|
|
53 |
extern void out_basic_int PROTO_S((unsigned long num, unsigned int bts));
|
|
|
54 |
extern void append_TDF PROTO_S((TDF * tdf, Bool free_it));
|
|
|
55 |
extern unsigned long bits_in_TDF PROTO_S((TDF *tdf));
|
|
|
56 |
extern void out_extendable_int PROTO_S((unsigned long num, unsigned int bts));
|
|
|
57 |
extern void out_tdfint32 PROTO_S((unsigned long n));
|
|
|
58 |
extern void out_tdfbool PROTO_S((Bool b));
|
|
|
59 |
extern void out_tdfstring_bytes PROTO_S((char * s, unsigned int k,
|
|
|
60 |
unsigned int n));
|
|
|
61 |
extern void out_tdfident_bytes PROTO_S((char *s));
|
|
|
62 |
extern void append_bytestream PROTO_S((TDF *tdf, Bool free_it));
|
|
|
63 |
extern void byte_align PROTO_S((void));
|
|
|
64 |
|
|
|
65 |
#include "errors.h"
|
|
|
66 |
|
|
|
67 |
/* NEW_STREAM creates a new output stream in ptrtoTDF (ie a non-void TDF *)
|
|
|
68 |
for the extent of make_stream, re-instating the original stream after
|
|
|
69 |
make_stream.
|
|
|
70 |
*/
|
|
|
71 |
|
|
|
72 |
#if FS_TENDRA
|
|
|
73 |
#pragma TenDRA begin
|
|
|
74 |
#pragma TenDRA variable hiding analysis off
|
|
|
75 |
#endif
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
#define NEW_STREAM(ptrtoTDF, make_stream)\
|
|
|
79 |
{ TDF * new_hold_;\
|
|
|
80 |
new_hold_ = current_TDF;\
|
|
|
81 |
current_TDF = ptrtoTDF;\
|
|
|
82 |
current_TDF->first = current_TDF->last = create_chunk();\
|
|
|
83 |
make_stream;\
|
|
|
84 |
current_TDF = new_hold_;\
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
/* CONT_STREAM changes the output stream to an existing stream, ptrtoTDF, for
|
|
|
89 |
the extent of make_stream, re-instating the original stream after
|
|
|
90 |
make_stream.
|
|
|
91 |
*/
|
|
|
92 |
|
|
|
93 |
#define CONT_STREAM(ptrtoTDF, make_stream)\
|
|
|
94 |
{ TDF * cont_hold_ = current_TDF;\
|
|
|
95 |
current_TDF = ptrtoTDF;\
|
|
|
96 |
make_stream;\
|
|
|
97 |
current_TDF = cont_hold_;\
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
#define TDF_COND(code_, sort_, exp_, arg1, arg2)\
|
|
|
102 |
{ TDF new_;\
|
|
|
103 |
code_; exp_; ASSERT_SORT(s_exp);\
|
|
|
104 |
NEW_STREAM(&new_, arg1; ASSERT_SORT(sort_);)\
|
|
|
105 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
106 |
append_TDF(&new_,1);\
|
|
|
107 |
NEW_STREAM(&new_, arg2; ASSERT_SORT(sort_);)\
|
|
|
108 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
109 |
append_TDF(&new_,1);\
|
|
|
110 |
SET_RSORT(sort_);\
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
#define TDF_LIST(x, sort_)\
|
|
|
114 |
{ TDF * list_hold_ = current_TDF;\
|
|
|
115 |
TDF temp_;\
|
|
|
116 |
temp_.last = temp_.first = create_chunk();\
|
|
|
117 |
temp_.no = 0;\
|
|
|
118 |
current_TDF = &temp_;\
|
|
|
119 |
current_TDF->sort = sort_;\
|
|
|
120 |
x; ASSERT_SORT_OR_EMPTY(sort_);\
|
|
|
121 |
current_TDF = list_hold_;\
|
|
|
122 |
out_basic_int(UL(0),UI(1));\
|
|
|
123 |
out_tdfint32(UL(temp_.no));\
|
|
|
124 |
append_TDF(&temp_, 1);\
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
#define TDF_SLIST(x, sort_)\
|
|
|
128 |
{ TDF * slist_hold_ = current_TDF;\
|
|
|
129 |
TDF temp_;\
|
|
|
130 |
temp_.last = temp_.first = create_chunk();\
|
|
|
131 |
temp_.no = 0;\
|
|
|
132 |
current_TDF = &temp_;\
|
|
|
133 |
current_TDF->sort = sort_;\
|
|
|
134 |
x; ASSERT_SORT_OR_EMPTY(sort_);\
|
|
|
135 |
current_TDF = slist_hold_;\
|
|
|
136 |
out_tdfint32(UL(temp_.no));\
|
|
|
137 |
append_TDF(&temp_, 1);\
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
#define LIST_ELEM(x)\
|
|
|
141 |
{ unsigned int sort_ = current_TDF->sort;\
|
|
|
142 |
x; ASSERT_SORT(sort_);\
|
|
|
143 |
current_TDF->no ++;\
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
#define TDF_OPTION(x, sort_)\
|
|
|
147 |
{ TDF * opt_hold_ = current_TDF;\
|
|
|
148 |
TDF temp_;\
|
|
|
149 |
temp_.last = temp_.first = create_chunk();\
|
|
|
150 |
temp_.no = 0;\
|
|
|
151 |
current_TDF = &temp_;\
|
|
|
152 |
x; ASSERT_SORT_OR_EMPTY(sort_);\
|
|
|
153 |
current_TDF = opt_hold_;\
|
|
|
154 |
Assert(temp_.no<=1);\
|
|
|
155 |
out_basic_int(UL(temp_.no),UI(1));\
|
|
|
156 |
if (temp_.no != 0 ) append_TDF(&temp_,1);\
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
#define OPTION(x)\
|
|
|
161 |
{ x; Assert(current_TDF->no==0); current_TDF->no = 1; }
|
|
|
162 |
|
|
|
163 |
#define TOK_APP(num_, sort_, tok_, pars_)\
|
|
|
164 |
{ TDF new_;\
|
|
|
165 |
num_; tok_; ASSERT_SORT(s_token);\
|
|
|
166 |
NEW_STREAM(&new_, pars_)\
|
|
|
167 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
168 |
append_TDF(&new_,1);\
|
|
|
169 |
SET_RSORT(sort_);\
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
#define o_token_def(p_result_sort, p_tok_params, p_body)\
|
|
|
173 |
{ TDF new_;\
|
|
|
174 |
NEW_STREAM( & new_,\
|
|
|
175 |
{ out_basic_int(UL(1),UI(1));\
|
|
|
176 |
p_result_sort; ASSERT_SORT(s_sortname);\
|
|
|
177 |
TDF_LIST(p_tok_params, s_tokformals);\
|
|
|
178 |
p_body;\
|
|
|
179 |
}\
|
|
|
180 |
)\
|
|
|
181 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
182 |
append_TDF(&new_,1);\
|
|
|
183 |
SET_RSORT(s_bitstream);\
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
#if FS_TENDRA
|
|
|
187 |
#pragma TenDRA end
|
|
|
188 |
#endif
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
#endif
|