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 |
#ifndef PD_CHUNKS_INCLUDED
|
|
|
62 |
#define PD_CHUNKS_INCLUDED
|
|
|
63 |
|
|
|
64 |
#define DATA_SIZE 256
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
typedef int Bool;
|
|
|
68 |
|
|
|
69 |
typedef struct chunk_struct
|
|
|
70 |
{ struct chunk_struct *next;
|
|
|
71 |
short int usage;
|
|
|
72 |
unsigned char offst;
|
|
|
73 |
unsigned char aligned;
|
|
|
74 |
unsigned char data[DATA_SIZE];
|
|
|
75 |
} Chunk;
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
typedef struct {
|
|
|
79 |
Chunk *first;
|
|
|
80 |
Chunk *last;
|
|
|
81 |
unsigned int no;
|
|
|
82 |
unsigned int sort;
|
|
|
83 |
} TDF;
|
|
|
84 |
|
|
|
85 |
extern TDF *current_TDF; /* the current output stream */
|
|
|
86 |
|
|
|
87 |
extern Chunk *create_chunk(void);
|
|
|
88 |
extern void out_basic_int(unsigned long num, unsigned int bts);
|
|
|
89 |
extern void append_TDF(TDF *tdf, Bool free_it);
|
|
|
90 |
extern unsigned long bits_in_TDF(TDF *tdf);
|
|
|
91 |
extern void out_extendable_int(unsigned long num, unsigned int bts);
|
|
|
92 |
extern void out_tdfint32(unsigned long n);
|
|
|
93 |
extern void out_tdfbool(Bool b);
|
|
|
94 |
extern void out_tdfstring_bytes(char *s, unsigned int k, unsigned int n);
|
|
|
95 |
extern void out_tdfident_bytes(char *s);
|
|
|
96 |
extern void append_bytestream(TDF *tdf, Bool free_it);
|
|
|
97 |
extern void byte_align(void);
|
|
|
98 |
|
|
|
99 |
#include "errors.h"
|
|
|
100 |
|
|
|
101 |
/* NEW_STREAM creates a new output stream in ptrtoTDF (ie a non-void TDF *)
|
|
|
102 |
for the extent of make_stream, re-instating the original stream after
|
|
|
103 |
make_stream.
|
|
|
104 |
*/
|
|
|
105 |
|
|
|
106 |
#if FS_TENDRA
|
|
|
107 |
#pragma TenDRA begin
|
|
|
108 |
#pragma TenDRA variable hiding analysis off
|
|
|
109 |
#endif
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
#define NEW_STREAM(ptrtoTDF, make_stream)\
|
|
|
113 |
{ TDF *new_hold_;\
|
|
|
114 |
new_hold_ = current_TDF;\
|
|
|
115 |
current_TDF = ptrtoTDF;\
|
|
|
116 |
current_TDF->first = current_TDF->last = create_chunk();\
|
|
|
117 |
make_stream;\
|
|
|
118 |
current_TDF = new_hold_;\
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
/* CONT_STREAM changes the output stream to an existing stream, ptrtoTDF, for
|
|
|
123 |
the extent of make_stream, re-instating the original stream after
|
|
|
124 |
make_stream.
|
|
|
125 |
*/
|
|
|
126 |
|
|
|
127 |
#define CONT_STREAM(ptrtoTDF, make_stream)\
|
|
|
128 |
{ TDF *cont_hold_ = current_TDF;\
|
|
|
129 |
current_TDF = ptrtoTDF;\
|
|
|
130 |
make_stream;\
|
|
|
131 |
current_TDF = cont_hold_;\
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
#define TDF_COND(code_, sort_, exp_, arg1, arg2)\
|
|
|
136 |
{ TDF new_;\
|
|
|
137 |
code_; exp_; ASSERT_SORT(s_exp);\
|
|
|
138 |
NEW_STREAM(&new_, arg1; ASSERT_SORT(sort_);)\
|
|
|
139 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
140 |
append_TDF(&new_,1);\
|
|
|
141 |
NEW_STREAM(&new_, arg2; ASSERT_SORT(sort_);)\
|
|
|
142 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
143 |
append_TDF(&new_,1);\
|
|
|
144 |
SET_RSORT(sort_);\
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
#define TDF_LIST(x, sort_)\
|
|
|
148 |
{ TDF *list_hold_ = current_TDF;\
|
|
|
149 |
TDF temp_;\
|
|
|
150 |
temp_.last = temp_.first = create_chunk();\
|
|
|
151 |
temp_.no = 0;\
|
|
|
152 |
current_TDF = &temp_;\
|
|
|
153 |
current_TDF->sort = sort_;\
|
|
|
154 |
x; ASSERT_SORT_OR_EMPTY(sort_);\
|
|
|
155 |
current_TDF = list_hold_;\
|
|
|
156 |
out_basic_int(UL(0), UI(1));\
|
|
|
157 |
out_tdfint32(UL(temp_.no));\
|
|
|
158 |
append_TDF(&temp_, 1);\
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
#define TDF_SLIST(x, sort_)\
|
|
|
162 |
{ TDF *slist_hold_ = current_TDF;\
|
|
|
163 |
TDF temp_;\
|
|
|
164 |
temp_.last = temp_.first = create_chunk();\
|
|
|
165 |
temp_.no = 0;\
|
|
|
166 |
current_TDF = &temp_;\
|
|
|
167 |
current_TDF->sort = sort_;\
|
|
|
168 |
x; ASSERT_SORT_OR_EMPTY(sort_);\
|
|
|
169 |
current_TDF = slist_hold_;\
|
|
|
170 |
out_tdfint32(UL(temp_.no));\
|
|
|
171 |
append_TDF(&temp_, 1);\
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
#define LIST_ELEM(x)\
|
|
|
175 |
{ unsigned int sort_ = current_TDF->sort;\
|
|
|
176 |
x; ASSERT_SORT(sort_);\
|
|
|
177 |
current_TDF->no++;\
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
#define TDF_OPTION(x, sort_)\
|
|
|
181 |
{ TDF *opt_hold_ = current_TDF;\
|
|
|
182 |
TDF temp_;\
|
|
|
183 |
temp_.last = temp_.first = create_chunk();\
|
|
|
184 |
temp_.no = 0;\
|
|
|
185 |
current_TDF = &temp_;\
|
|
|
186 |
x; ASSERT_SORT_OR_EMPTY(sort_);\
|
|
|
187 |
current_TDF = opt_hold_;\
|
|
|
188 |
Assert(temp_.no <= 1);\
|
|
|
189 |
out_basic_int(UL(temp_.no), UI(1));\
|
|
|
190 |
if (temp_.no != 0) append_TDF(&temp_, 1);\
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
#define OPTION(x)\
|
|
|
195 |
{ x; Assert(current_TDF->no == 0); current_TDF->no = 1; }
|
|
|
196 |
|
|
|
197 |
#define TOK_APP(num_, sort_, tok_, pars_)\
|
|
|
198 |
{ TDF new_;\
|
|
|
199 |
num_; tok_; ASSERT_SORT(s_token);\
|
|
|
200 |
NEW_STREAM(&new_, pars_)\
|
|
|
201 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
202 |
append_TDF(&new_, 1);\
|
|
|
203 |
SET_RSORT(sort_);\
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
#define o_token_def(p_result_sort, p_tok_params, p_body)\
|
|
|
207 |
{ TDF new_;\
|
|
|
208 |
NEW_STREAM(& new_,\
|
|
|
209 |
{ out_basic_int(UL(1), UI(1));\
|
|
|
210 |
p_result_sort; ASSERT_SORT(s_sortname);\
|
|
|
211 |
TDF_LIST(p_tok_params, s_tokformals);\
|
|
|
212 |
p_body;\
|
|
|
213 |
}\
|
|
|
214 |
)\
|
|
|
215 |
out_tdfint32(bits_in_TDF(&new_));\
|
|
|
216 |
append_TDF(&new_, 1);\
|
|
|
217 |
SET_RSORT(s_bitstream);\
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
#if FS_TENDRA
|
|
|
221 |
#pragma TenDRA end
|
|
|
222 |
#endif
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
#endif
|