comparison src/gpf3/ccd/t30_ident.c @ 2:c41a534f33c6

src/gpf3: preened GPF goo from TCS3.2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Sep 2016 23:52:50 +0000
parents
children
comparison
equal deleted inserted replaced
1:864b8cc0cf63 2:c41a534f33c6
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : t30_ident.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : Definition of encoding and decoding functions for T30_IDENT elements
18 +-----------------------------------------------------------------------------
19 */
20
21
22 /*
23 * standard definitions like GLOBAL, UCHAR, ERROR etc.
24 */
25 #include "typedefs.h"
26 #include "header.h"
27
28 /*
29 * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only
30 * look at ccdapi.h
31 */
32 #undef USE_DRIVER
33 #include "ccdapi.h"
34
35 /*
36 * Types and functions for bit access and manipulation
37 */
38 #include "ccd_globs.h"
39 #include "bitfun.h"
40
41 /*
42 * Prototypes of ccd internal functions
43 */
44 #include "ccd.h"
45
46 /*
47 * Declaration of coder/decoder tables
48 */
49 #include "ccdtable.h"
50 #include "ccddata.h"
51
52 #ifndef RUN_INT_RAM
53 /*
54 +--------------------------------------------------------------------+
55 | PROJECT : CCD (6144) MODULE : CCD |
56 | STATE : code ROUTINE : cdc_t30_ident_decode |
57 +--------------------------------------------------------------------+
58
59 PURPOSE :
60
61 */
62
63 SHORT cdc_t30_ident_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
64 {
65 ULONG max_rep;
66 BOOL is_variable;
67 UBYTE digBuffer[30], bit, digT30, digASCII;
68 UBYTE *addr_c_xxx;
69 int i, repeat;
70 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
71 register UBYTE *ident;
72
73 #ifdef DEBUG_CCD
74 #ifndef CCD_SYMBOLS
75 TRACE_CCD (globs, "cdc_t30_ident_decode()");
76 #else
77 TRACE_CCD (globs, "cdc_t30_ident_decode() %s", ccddata_get_alias((USHORT) e_ref, 1));
78 #endif
79 #endif
80
81 cix_ref = melem[e_ref].calcIdxRef;
82 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
83 prolog_step_ref = calcidx[cix_ref].prologStepRef;
84
85 /*
86 * if this element is conditional, check the condition
87 */
88 if (calcidx[cix_ref].numCondCalcs NEQ 0
89 AND ! ccd_conditionOK (e_ref, globs))
90 return 1;
91
92 /*
93 * if this element have a defined Prolog
94 * we have to process it before decoding the bitstream
95 */
96 if (num_prolog_steps)
97 {
98 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
99 }
100
101 /*
102 * if this element is repeatable, and the number of
103 * repeats depends on another element, calculate the repeater
104 */
105
106 if (melem[e_ref].repType NEQ ' ')
107 {
108 ULONG rep;
109 is_variable = ccd_calculateRep (e_ref, &rep, &max_rep, globs);
110 repeat = rep;
111 }
112 else
113 {
114 repeat = 1;
115 is_variable = FALSE;
116 }
117
118 /*
119 * setup the offset into the C-structure for this element
120 */
121 globs->pstructOffs = melem[e_ref].structOffs;
122
123 if (melem[e_ref].optional)
124 {
125 /*
126 * for optional elements set the valid-flag
127 */
128 globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE;
129 }
130
131
132 if (is_variable)
133 {
134 /*
135 * for variable sized elements store the min-value
136 * as counter into the C-Structure (c_xxx).
137 */
138 addr_c_xxx = (UBYTE *) (globs->pstruct + globs->pstructOffs++);
139 if (max_rep > 255)
140 globs->pstructOffs++;
141 }
142 else
143 addr_c_xxx = NULL;
144
145 /*
146 * calculate the address of the Most Significant Digit
147 * of the T30_IDENT element in the C-struct
148 */
149 ident = (UBYTE *) (globs->pstruct + globs->pstructOffs);
150
151
152 /*
153 * now read 'repeat' T30_IDENT digits and convert them
154 * into ASCII.
155 */
156 i=0;
157
158 while (!bf_endOfBitstream(globs) AND i<repeat)
159 {
160 digT30 = bf_decodeByteNumber (8, globs);
161 #ifdef DEBUG_CCD
162 TRACE_CCD (globs, "T30 digit (%X) read", digT30);
163 #endif
164 /*
165 * conversion T30->ASCII
166 * reverse the bitorder of each byte
167 */
168 digASCII = 0;
169
170 for (bit = 0; bit < 8; bit++)
171 {
172 digASCII <<= 1;
173 digASCII |= (digT30 & 0x01);
174 digT30 >>= 1;
175 }
176
177 digBuffer[i] = digASCII;
178 #ifdef DEBUG_CCD
179 TRACE_CCD (globs, " converted to %X = %c", digBuffer[i], digBuffer[i]);
180 #endif
181 i++;
182 }
183
184 /*
185 * eleminate leading spaces
186 */
187 while (i > 0 AND digBuffer[i-1] EQ ' ')
188 {
189 #ifdef DEBUG_CCD
190 TRACE_CCD (globs, "eliminating leading space");
191 #endif
192 i--;
193 }
194
195 repeat = i;
196
197
198 if (addr_c_xxx NEQ NULL)
199 {
200 /*
201 * store the number of digits into the
202 * c_xxx variable if there is one.
203 */
204 if (max_rep > 65535)
205 {
206 ULONG *addr_c_xxx_u32;
207 addr_c_xxx_u32 = (ULONG *)addr_c_xxx;
208 *addr_c_xxx_u32 = (ULONG) repeat;
209 #ifdef DEBUG_CCD
210 TRACE_CCD (globs, "storing %d into counter var at (%lx)",
211 repeat, addr_c_xxx_u32);
212 #endif
213 }
214 else if (max_rep > 255)
215 {
216 USHORT *addr_c_xxx_u16;
217 addr_c_xxx_u16 = (USHORT *)addr_c_xxx;
218 *addr_c_xxx_u16 = (USHORT) repeat;
219 #ifdef DEBUG_CCD
220 TRACE_CCD (globs, "storing %d into counter var at (%lx)",
221 repeat, addr_c_xxx_u16);
222 #endif
223 }
224 else
225 {
226 *addr_c_xxx = (UBYTE) repeat;
227 #ifdef DEBUG_CCD
228 TRACE_CCD (globs, "storing %d into counter var at (%lx)",
229 repeat,
230 addr_c_xxx);
231 #endif
232 }
233 }
234
235 /*
236 * store the digits in reverse order
237 * into the C-Structure variable
238 */
239 #ifdef DEBUG_CCD
240 TRACE_CCD (globs, "storing %d digits into cstruct at (%lx)",
241 repeat,
242 ident);
243 #endif
244
245 for (i=0; i<repeat; i++)
246 ident[i] = digBuffer[(repeat-1)-i];
247
248 return 1;
249 }
250 #endif /* !RUN_INT_RAM */
251
252 #ifndef RUN_INT_RAM
253 /*
254 +--------------------------------------------------------------------+
255 | PROJECT : CCD (6144) MODULE : CCD |
256 | STATE : code ROUTINE : cdc_t30_ident_encode |
257 +--------------------------------------------------------------------+
258
259 PURPOSE :
260
261 */
262
263
264 SHORT cdc_t30_ident_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
265 {
266 ULONG repeat, max_rep;
267 UBYTE digBuffer[30], bit, digT30, digASCII;
268 ULONG i;
269 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
270 register UBYTE *ident;
271
272 #ifdef DEBUG_CCD
273 #ifndef CCD_SYMBOLS
274 TRACE_CCD (globs, "cdc_t30_ident_encode()");
275 #else
276 TRACE_CCD (globs, "cdc_t30_ident_encode() %s", ccddata_get_alias((USHORT) e_ref, 1));
277 #endif
278 #endif
279
280 cix_ref = melem[e_ref].calcIdxRef;
281 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
282 prolog_step_ref = calcidx[cix_ref].prologStepRef;
283
284 /*
285 * if this element is conditional, check the condition
286 */
287 if (calcidx[cix_ref].numCondCalcs NEQ 0
288 AND ! ccd_conditionOK (e_ref, globs))
289 return 1;
290
291 /*
292 * if this element have a defined Prolog
293 * we have to process it before encoding
294 */
295 if (num_prolog_steps)
296 {
297 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
298 }
299
300 /*
301 * setup the offset into the C-structure for this element
302 */
303 globs->pstructOffs = melem[e_ref].structOffs;
304
305 if (melem[e_ref].optional)
306 {
307 /*
308 * for optional elements check the valid-flag
309 */
310 if (globs->pstruct[globs->pstructOffs++] == FALSE)
311 {
312 return 1;
313 }
314 #ifdef DEBUG_CCD
315 else if (globs->pstruct [melem[e_ref].structOffs] != TRUE)
316 {
317 TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d",
318 e_ref);
319 }
320 #endif
321 }
322
323 /*
324 * if this element is repeatable, and the number of
325 * repeats depends on another element, calculate the repeater
326 */
327 if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i')
328 {
329 /*
330 * for variable sized elements read the amount
331 * of repeats out of the C-Structure (c_xxx).
332 * If the number of repeats given by the C-Structure
333 * exceeds the allowed value (maxRepeat) CCD gives a warning!
334 */
335 if (melem[e_ref].maxRepeat > 255)
336 {
337 ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++));
338 repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat);
339 if (repeat < count)
340 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
341 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
342 }
343 else
344 {
345 repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs],
346 melem[e_ref].maxRepeat);
347 if ( repeat < (ULONG) (globs->pstruct[globs->pstructOffs]) )
348 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
349 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
350 }
351 globs->pstructOffs++;
352 max_rep = (ULONG) melem[e_ref].maxRepeat;
353 }
354 else
355 if (melem[e_ref].repType EQ 'c')
356 {
357 repeat = (ULONG) melem[e_ref].maxRepeat;
358 max_rep = (ULONG) melem[e_ref].maxRepeat;
359 }
360 else
361 {
362 repeat = 1;
363 max_rep = 1;
364 }
365
366 /*
367 * setup the read pointer to the byte array that contain
368 * the ident number.
369 */
370 ident = (UBYTE *) (globs->pstruct + globs->pstructOffs);
371
372 /*
373 * read the digits in reverse order out of the C-Structure variable.
374 * (filled up with blanks to the maxRepeat)
375 */
376
377 i=0;
378
379 while (i < max_rep)
380 {
381 if (i < repeat)
382 digBuffer[i] = ident[(repeat-1)-i];
383 else
384 {
385 #ifdef DEBUG_CCD
386 TRACE_CCD (globs, "appending space char");
387 #endif
388 digBuffer[i] = ' ';
389 }
390 i++;
391 }
392
393 /*
394 * now read 'repeat' T30_IDENT digits and convert them
395 * into ASCII.
396 */
397 i=0;
398
399 while (i < max_rep)
400 {
401 digASCII = digBuffer[i];
402
403 #ifdef DEBUG_CCD
404 TRACE_CCD (globs, "ASCII digit (%X) = %c ", (USHORT) digASCII, digASCII);
405 #endif
406 /*
407 * conversion ASCII->T30
408 * reverse the bitorder of each byte
409 */
410 digT30 = 0;
411
412 for (bit = 0; bit < 8; bit++)
413 {
414 digT30 <<= 1;
415 digT30 |= (digASCII & 0x01);
416 digASCII >>= 1;
417 }
418
419 #ifdef DEBUG_CCD
420 TRACE_CCD (globs, " converted to %X", (USHORT) digT30);
421 #endif
422 bf_codeByteNumber (8, digT30, globs);
423
424 i++;
425 }
426
427 return 1;
428 }
429 #endif /* !RUN_INT_RAM */