Commit | Line | Data |
---|---|---|
459ebbd7 C |
1 | /* ptabs.c */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/pepsy/RCS/ptabs.c,v 7.8 91/02/22 09:49:58 mrose Interim $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/pepsy/RCS/ptabs.c,v 7.8 91/02/22 09:49:58 mrose Interim $ | |
9 | * | |
10 | * | |
11 | * $Log: ptabs.c,v $ | |
12 | * Revision 7.8 91/02/22 09:49:58 mrose | |
13 | * Interim 6.8 | |
14 | * | |
15 | * Revision 7.7 91/01/08 12:50:56 mrose | |
16 | * update | |
17 | * | |
18 | * Revision 7.6 90/12/23 17:25:26 mrose | |
19 | * patches | |
20 | * | |
21 | * Revision 7.5 90/12/11 10:41:09 mrose | |
22 | * sync | |
23 | * | |
24 | * Revision 7.4 90/11/11 10:54:20 mrose | |
25 | * update | |
26 | * | |
27 | * Revision 7.3 90/11/04 19:21:09 mrose | |
28 | * update | |
29 | * | |
30 | * Revision 7.2 90/07/27 08:49:29 mrose | |
31 | * update | |
32 | * | |
33 | * Revision 7.1 90/07/09 14:53:16 mrose | |
34 | * sync | |
35 | * | |
36 | */ | |
37 | ||
38 | /* | |
39 | * NOTICE | |
40 | * | |
41 | * Acquisition, use, and distribution of this module and related | |
42 | * materials are subject to the restrictions of a license agreement. | |
43 | * Consult the Preface in the User's Manual for the full terms of | |
44 | * this agreement. | |
45 | * | |
46 | */ | |
47 | ||
48 | ||
49 | #include <stdio.h> | |
50 | #include "pepsydefs.h" | |
51 | #include "pass2.h" | |
52 | #include "mine.h" | |
53 | ||
54 | extern FILE *fp; | |
55 | extern char *c_tag(), *c_class(); | |
56 | extern char *ec_tag(), *ec_class(), *pec_class(); | |
57 | extern char *strip_last(); | |
58 | extern char *str_yp_code[]; | |
59 | extern char *get_val(), *get_comp(), *strp2name(); | |
60 | extern s_table *lookup_list(), *get_offset(); | |
61 | extern YP tprnt_loop(); | |
62 | extern int gen_pentry(); | |
63 | ||
64 | extern char *concat(); | |
65 | extern char *my_strcat(); | |
66 | extern char *rm_indirect(); | |
67 | extern char *getfield(); | |
68 | extern char *setfield(); | |
69 | ||
70 | /* | |
71 | extern int explicit; | |
72 | */ | |
73 | ||
74 | static int cons_type = 0; | |
75 | ||
76 | s_table *ptr; | |
77 | s_table *save_ptr; | |
78 | ||
79 | #define WORDSIZE 20 | |
80 | ||
81 | /* | |
82 | * Marshall's three extra conditions for changing the printing output | |
83 | */ | |
84 | static int mrose1; /* if NamedType */ | |
85 | static int mrose2; /* !mrose1 && -h && DefinedType */ | |
86 | static int mrose3; /* (mrose1 || !mrose2) && TAG && (OPTIONAL|DEFAULT) */ | |
87 | ||
88 | /* | |
89 | * table printe a type. generate tables for the printing of a type | |
90 | */ | |
91 | tprnt_typ(fp, yp, id, type) | |
92 | FILE *fp; | |
93 | YP yp; | |
94 | char *id; | |
95 | char *type; | |
96 | { | |
97 | char *t, *f; | |
98 | char *p1; | |
99 | char *s1, *s2, *s3; | |
100 | char *s; | |
101 | s_table *ptr1, *ptr2; | |
102 | YP y; | |
103 | int flag; | |
104 | int ptr_tblidx = -1; | |
105 | ||
106 | if (yp->yp_code < 0 || yp->yp_code > YP_REAL) | |
107 | ferrd(1, "tdec_typ: unimplemented type %d\n", yp->yp_code); | |
108 | ||
109 | if (yp == NULL) { | |
110 | ferr(0, "tprnt_typ:NULL arguement\n"); | |
111 | return; | |
112 | } | |
113 | ||
114 | if (yp->yp_bef_alist && yp->yp_bef_alist->yal_prn) | |
115 | gen_act(fp, yp->yp_bef_alist->yal_prn); | |
116 | ||
117 | if (yp->yp_flags & YP_ID) | |
118 | mrose1 = 1; | |
119 | else | |
120 | mrose1 = 0; | |
121 | ||
122 | if (!mrose1 && hflag && yp->yp_code == YP_IDEFINED) | |
123 | mrose2 = 1; | |
124 | else | |
125 | mrose2 = 0; | |
126 | ||
127 | if ((mrose1 || !mrose2) && yp->yp_flags & YP_TAG | |
128 | && yp->yp_flags & (YP_OPTIONAL|YP_DEFAULT)) | |
129 | mrose3 = 1; | |
130 | else | |
131 | mrose3 = 0; | |
132 | ||
133 | if (type) | |
134 | t = type; | |
135 | else if (yp->yp_param_type) { | |
136 | char *t1; | |
137 | /* we have a [[ P type ]] specification */ | |
138 | if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) { | |
139 | fprintf(stderr, | |
140 | "\ntenc_typ:SETLIST can't extract direct type from %s\n", | |
141 | yp->yp_param_type); | |
142 | exit(1); | |
143 | } | |
144 | t = strdup(t1); | |
145 | } else | |
146 | t = my_strcat("struct ", modsym(mymodule, id, "type")); | |
147 | ||
148 | if ((yp->yp_flags & YP_PARMVAL) && yp->yp_parm) { | |
149 | if ((f = getfield(yp->yp_parm)) == NULLCP) { | |
150 | fprintf(stderr, "\ntprnt_typ:can't extract field from %s\n", | |
151 | yp->yp_parm); | |
152 | exit(1); | |
153 | } | |
154 | f = strdup(f); | |
155 | } else | |
156 | f = yp->yp_varexp; | |
157 | ||
158 | if ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT)) | |
159 | == (YP_OPTIONAL|YP_OPTCONTROL)) { | |
160 | yp->yp_flags &= ~YP_OPTCONTROL; | |
161 | flag = 1; | |
162 | } else | |
163 | flag = 0; | |
164 | ||
165 | if (yp->yp_flags & YP_TAG && !(yp->yp_flags & YP_IMPLICIT)) { | |
166 | prte_enoff(fp, "ETAG", yp, ptr_tblidx); | |
167 | } | |
168 | ||
169 | if (yp->yp_yfn && yp->yp_yfn->yfn_prt) { | |
170 | gen_fn(fp, yp, yp->yp_yfn->yfn_prt); | |
171 | if (yp->yp_flags & YP_DEFAULT) | |
172 | gdflt(fp, yp, G_DEC); | |
173 | ||
174 | if (yp->yp_aft_alist && yp->yp_aft_alist->yal_prn) | |
175 | gen_act(fp, yp->yp_aft_alist->yal_prn); | |
176 | ||
177 | return; | |
178 | } | |
179 | ||
180 | switch (yp->yp_code) { | |
181 | ||
182 | case YP_UNDF: | |
183 | ferr(1, "tprnt_typ:Undefined type\n"); | |
184 | ||
185 | case YP_BOOL: | |
186 | if (yp->yp_intexp) | |
187 | f = setfield(yp->yp_intexp); | |
188 | if (noindirect(f)) | |
189 | ferr(1, "tdec_typ:BOOL: must specify a field [[ b .. ]]\n"); | |
190 | p1 = "BOOLEAN"; | |
191 | if (yp->yp_varexp || (yp->yp_intexp && !noindirect(f))) | |
192 | break; | |
193 | ferr(1, "tdec_typ:BOOL: can't find a type for boolean\n"); | |
194 | ||
195 | /* This needs to be fixed up in the action generating area */ | |
196 | case YP_INTLIST: | |
197 | ||
198 | case YP_INT: | |
199 | ||
200 | case YP_ENUMLIST: | |
201 | if (yp->yp_intexp) | |
202 | f = setfield(yp->yp_intexp); | |
203 | if (noindirect(f)) | |
204 | ferr(1, "tdec_typ:INT: must specify a field [[ i .. ]]\n"); | |
205 | p1 = "INTEGER"; | |
206 | if (yp->yp_varexp || (yp->yp_intexp && !noindirect(f))) | |
207 | break; | |
208 | ferr(1, "tdec_typ:INT: couldn't determine type\n"); | |
209 | ||
210 | case YP_REAL: | |
211 | if (yp->yp_strexp) | |
212 | f = setfield(yp->yp_strexp); | |
213 | if (noindirect(f)) | |
214 | ferr(1, "tdec_typ:REAL: must specify a field [[ r .. ]]\n"); | |
215 | p1 = "REALTYPE"; | |
216 | if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) | |
217 | break; | |
218 | ferr(1, "tdec_typ:INT: couldn't determine type\n"); | |
219 | ||
220 | ||
221 | case YP_BITLIST: | |
222 | ptr_tblidx = addptr (modsym(mymodule, | |
223 | yp->yp_varexp ? yp -> yp_varexp : id, | |
224 | "bits")); | |
225 | /* fall */ | |
226 | case YP_BIT: | |
227 | if (yp->yp_strexp && yp->yp_intexp) { | |
228 | if (yp->yp_strexp) | |
229 | f = setfield(yp->yp_strexp); | |
230 | if (noindirect(f)) | |
231 | ferr(1, "tdec_typ:BIT: must specify a field [[ x .. ]]\n"); | |
232 | p1 = "BITSTR_PTR"; | |
233 | prte_off(fp, p1, yp, t, f, ptr_tblidx); | |
234 | if (yp->yp_intexp) | |
235 | f = setfield(yp->yp_intexp); | |
236 | if (noindirect(f)) | |
237 | ferr(1, "tdec_typ:BIT: must specify a field [[ x .. ]]\n"); | |
238 | p1 = "BITSTR_LEN"; | |
239 | break; | |
240 | } | |
241 | if (yp->yp_strexp == NULLCP && yp->yp_intexp) | |
242 | f = setfield(yp->yp_intexp); | |
243 | if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) { | |
244 | p1 = "BITSTRING"; | |
245 | break; | |
246 | } | |
247 | t = NULL; | |
248 | p1 = NULL; | |
249 | (void) fprintf(fp, "\t{ SBITSTRING, %d, %s, %s, NULL },\n", | |
250 | ptr_tblidx, c_tag(yp), c_class(yp)); | |
251 | break; | |
252 | ||
253 | case YP_OCT: | |
254 | if (yp->yp_strexp) { | |
255 | switch (yp->yp_prfexp) { | |
256 | case 'q': /* [[ q parm->qbufptr ]] */ | |
257 | if (yp->yp_strexp) | |
258 | f = setfield(yp->yp_strexp); | |
259 | if (noindirect(f)) | |
260 | p1 = "SOCTETSTRING"; | |
261 | else | |
262 | p1 = "OCTETSTRING"; | |
263 | break; | |
264 | ||
265 | case 's': /* [[ s ptr ]] */ | |
266 | if (yp->yp_strexp) | |
267 | f = setfield(yp->yp_strexp); | |
268 | if (noindirect(f)) | |
269 | ferr(1, "tdec_typ:OCT: must specify a field [[ s .. ]]\n"); | |
270 | p1 = "T_STRING"; | |
271 | break; | |
272 | ||
273 | case 'o': /* [[ o ptr $ length ]] */ | |
274 | if (yp->yp_strexp) | |
275 | f = setfield(yp->yp_strexp); | |
276 | if (noindirect(f)) | |
277 | ferr(1, "tdec_typ:OCT: must specify a field [[ o .. ]]\n"); | |
278 | p1 = "OCTET_PTR"; | |
279 | prte_off(fp, p1, yp, t, f, ptr_tblidx); | |
280 | if (yp->yp_intexp) | |
281 | f = setfield(yp->yp_intexp); | |
282 | if (noindirect(f)) | |
283 | ferr(1, "tdec_typ:OCT: must specify a field [[ o .. ]]\n"); | |
284 | p1 = "OCTET_LEN"; | |
285 | break; | |
286 | ||
287 | default: | |
288 | fprintf(stderr,"\ntprnt_typ:Unknown Octet string specifier %c\n", | |
289 | yp->yp_prfexp); | |
290 | exit(1); | |
291 | } | |
292 | break; | |
293 | } | |
294 | ||
295 | if (f && !noindirect(f)) { | |
296 | p1 = "OCTETSTRING"; | |
297 | break; | |
298 | } | |
299 | t = NULL; | |
300 | p1 = NULL; | |
301 | prte_noff(fp, "SOCTETSTRING", yp, ptr_tblidx); | |
302 | break; | |
303 | ||
304 | case YP_OID: | |
305 | if (yp->yp_strexp) | |
306 | f = setfield(yp->yp_strexp); | |
307 | if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) { | |
308 | p1 = "OBJID"; | |
309 | break; | |
310 | } | |
311 | t = NULL; | |
312 | p1 = NULL; | |
313 | prte_noff(fp, "SOBJID", yp, ptr_tblidx); | |
314 | break; | |
315 | ||
316 | case YP_SEQ: | |
317 | case YP_SET: | |
318 | case YP_ANY: | |
319 | if (yp->yp_strexp) | |
320 | f = setfield(yp->yp_strexp); | |
321 | if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) { | |
322 | p1 = "ANY"; | |
323 | break; | |
324 | } | |
325 | t = NULL; | |
326 | p1 = NULL; | |
327 | prte_noff(fp, "SANY", yp, ptr_tblidx); | |
328 | break; | |
329 | ||
330 | case YP_NULL: | |
331 | p1 = "T_NULL"; | |
332 | t = NULL; | |
333 | break; | |
334 | ||
335 | case YP_IDEFINED: | |
336 | p1 = NULL; | |
337 | ||
338 | if ((yp->yp_flags & YP_PARMVAL) && yp->yp_prfexp) | |
339 | ferr(1, | |
340 | "\n[[ ? reference ]] [[ p reference ]] is illegal\n\t only one allowed\n"); | |
341 | ||
342 | if (yp->yp_prfexp) { /* [[ ? parm->field ]] - complex to process */ | |
343 | gen_identry(fp, t, f, yp, gen_pentry); | |
344 | ||
345 | if (yp->yp_flags & YP_DEFAULT) | |
346 | gdflt(fp, yp, G_DEC); | |
347 | ||
348 | break; | |
349 | } | |
350 | ||
351 | pr_deftyp(fp, yp, t, f); | |
352 | if (yp->yp_flags & YP_DEFAULT) | |
353 | gdflt(fp, yp, G_DEC); | |
354 | break; | |
355 | ||
356 | case YP_SEQLIST: | |
357 | p1 = NULL; | |
358 | /* support for -h flag */ | |
359 | cons_type++; | |
360 | save_ptr = ptr; | |
361 | if (yp->yp_varexp == NULL && type != NULL) | |
362 | ferr(1, "tprnt_typ:YP_SEQLIST:NULL varexp pointer\n"); | |
363 | if (type == NULL) | |
364 | prte_noff(fp, "SSEQ_START", yp, ptr_tblidx); | |
365 | else if (noindirect(f)) | |
366 | prte_noff(fp, "SSEQ_START", yp, ptr_tblidx); | |
367 | else | |
368 | prte_off(fp, "SEQ_START", yp, t, f, ptr_tblidx); | |
369 | ||
370 | if (yp->yp_flags & YP_DEFAULT) | |
371 | gdflt(fp, yp, G_DEC); | |
372 | if (y = yp->yp_type) { | |
373 | char *t1; | |
374 | ||
375 | if (yp->yp_param_type) { | |
376 | /* we have a [[ P type ]] specification */ | |
377 | if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) { | |
378 | fprintf(stderr, | |
379 | "\ntprnt_typ:SEQLIST can't extract direct type from %s\n", | |
380 | yp->yp_param_type); | |
381 | exit(1); | |
382 | } | |
383 | yp->yp_structname = strdup(t1); | |
384 | } else if (type) { | |
385 | if (yp->yp_declexp == NULL) | |
386 | ferr(1, "tprnt_typ:YP_SEQLIST:no declexp\n"); | |
387 | yp->yp_structname = my_strcat("struct ", yp->yp_declexp); | |
388 | } else | |
389 | yp->yp_structname = t; | |
390 | #ifdef DO_OFFSETS | |
391 | if (optfield(y)) { | |
392 | (void) fprintf(fp, | |
393 | "\t{ OPTL, OFFSET(%s, optionals), 0, 0, NULL },\n", | |
394 | yp->yp_structname); | |
395 | } | |
396 | #endif | |
397 | tprnt_loop(fp, y, id, yp->yp_structname); | |
398 | } | |
399 | (void) fprintf(fp, "\t{ PE_END, 0, 0, 0, NULL },\n"); | |
400 | ptr = save_ptr; | |
401 | cons_type--; | |
402 | break; | |
403 | ||
404 | case YP_SETLIST: | |
405 | p1 = NULL; | |
406 | /* support for -h flag */ | |
407 | cons_type++; | |
408 | if (yp->yp_varexp == NULL && type != NULL) | |
409 | ferr(1, "tprnt_typ:YP_SETLIST:NULL varexp pointer\n"); | |
410 | if (type == NULL) | |
411 | prte_noff(fp, "SSET_START", yp, ptr_tblidx); | |
412 | else if (noindirect(f)) | |
413 | prte_noff(fp, "SSET_START", yp, ptr_tblidx); | |
414 | else | |
415 | prte_off(fp, "SET_START", yp, t, f, ptr_tblidx); | |
416 | ||
417 | if (yp->yp_flags & YP_DEFAULT) | |
418 | ddflt(fp, yp); | |
419 | if (y = yp->yp_type) { | |
420 | char *t1; | |
421 | ||
422 | if (yp->yp_param_type) { | |
423 | /* we have a [[ P type ]] specification */ | |
424 | if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) { | |
425 | fprintf(stderr, | |
426 | "\ntprnt_typ:SETLIST can't extract direct type from %s\n", | |
427 | yp->yp_param_type); | |
428 | exit(1); | |
429 | } | |
430 | yp->yp_structname = strdup(t1); | |
431 | } else if (type) { | |
432 | if (yp->yp_declexp == NULL) | |
433 | ferr(1, "tprnt_typ:YP_SETLIST:no declexp\n"); | |
434 | yp->yp_structname = my_strcat("struct ", yp->yp_declexp); | |
435 | } else | |
436 | yp->yp_structname = t; | |
437 | #ifdef DO_OFFSETS | |
438 | if (optfield(y)) { | |
439 | (void) fprintf(fp, | |
440 | "\t{ OPTL, OFFSET(%s, optionals), 0, 0, NULL },\n", | |
441 | yp->yp_structname); | |
442 | } | |
443 | #endif | |
444 | tprnt_loop(fp, y, id, yp->yp_structname); | |
445 | } | |
446 | (void) fprintf(fp, "\t{ PE_END, 0, 0, 0, NULL },\n"); | |
447 | ptr = save_ptr; | |
448 | cons_type--; | |
449 | break; | |
450 | ||
451 | case YP_SEQTYPE: /* What is the difference ?? */ | |
452 | p1 = NULL; | |
453 | cons_type++; | |
454 | save_ptr = ptr; | |
455 | if (type == NULL) | |
456 | prte_noff(fp, "SSEQOF_START", yp, ptr_tblidx); | |
457 | else if (noindirect(f)) | |
458 | prte_noff(fp, "SSEQOF_START", yp, ptr_tblidx); | |
459 | else | |
460 | prte_off(fp, "SEQOF_START", yp, t, f, ptr_tblidx); | |
461 | if (yp->yp_flags & YP_DEFAULT) | |
462 | gdflt(fp, yp, G_DEC); | |
463 | ||
464 | if (y = yp->yp_type) { | |
465 | char *t1; | |
466 | ||
467 | if (yp->yp_param_type) { | |
468 | /* we have a [[ P type ]] specification */ | |
469 | if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) { | |
470 | fprintf(stderr, | |
471 | "\ntprnt_typ:SEQTYPE can't extract direct type from %s\n", | |
472 | yp->yp_param_type); | |
473 | exit(1); | |
474 | } | |
475 | yp->yp_structname = strdup(t1); | |
476 | } else if (type) { | |
477 | if (yp->yp_declexp == NULL) | |
478 | ferr(1, "tprnt_typ:YP_SEQTYPE:no declexp\n"); | |
479 | yp->yp_structname = my_strcat("struct ", yp->yp_declexp); | |
480 | } else | |
481 | yp->yp_structname = t; | |
482 | tprnt_loop(fp, y, id, yp->yp_structname); | |
483 | } | |
484 | #ifdef DO_OFFSETS | |
485 | if (yp->yp_flags & YP_CONTROLLED) { | |
486 | char *f1; | |
487 | ||
488 | if ((f1 = getfield(yp->yp_control)) == NULLCP) { | |
489 | fprintf(stderr, "\ntprnt_typ:SEQ OF: can't extract field from %s\n", | |
490 | yp->yp_control); | |
491 | exit(1); | |
492 | } | |
493 | (void) fprintf(fp, "\t{ PE_END, OFFSET(%s, %s), 0, 0 },\n", | |
494 | yp->yp_structname, f1); | |
495 | } else if (yp->yp_structname != NULL) | |
496 | (void) fprintf(fp, | |
497 | "\t{ PE_END, OFFSET(%s, next), 0, 0, NULL },\n", | |
498 | yp->yp_structname); | |
499 | else | |
500 | #endif | |
501 | (void) fprintf(fp, "\t{ PE_END, 0, 0, 0, NULL },\n"); | |
502 | ptr = save_ptr; | |
503 | cons_type--; | |
504 | break; | |
505 | ||
506 | case YP_SETTYPE: | |
507 | p1 = NULL; | |
508 | cons_type++; | |
509 | save_ptr = ptr; | |
510 | if (type == NULL) | |
511 | prte_noff(fp, "SSETOF_START", yp, ptr_tblidx); | |
512 | else if (noindirect(f)) | |
513 | prte_noff(fp, "SSETOF_START", yp, ptr_tblidx); | |
514 | else | |
515 | prte_off(fp, "SETOF_START", yp, t, f, ptr_tblidx); | |
516 | ||
517 | if (yp->yp_flags & YP_DEFAULT) | |
518 | gdflt(fp, yp, G_DEC); | |
519 | ||
520 | if (y = yp->yp_type) { | |
521 | char *t1; | |
522 | ||
523 | if (yp->yp_param_type) { | |
524 | /* we have a [[ P type ]] specification */ | |
525 | if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) { | |
526 | fprintf(stderr, | |
527 | "\ntprnt_typ:SETTYPE can't extract direct type from %s\n", | |
528 | yp->yp_param_type); | |
529 | exit(1); | |
530 | } | |
531 | yp->yp_structname = strdup(t1); | |
532 | } else if (type) { | |
533 | if (yp->yp_declexp == NULL) | |
534 | ferr(1, "tprnt_typ:YP_SETTYPE:no declexp\n"); | |
535 | yp->yp_structname = my_strcat("struct ", yp->yp_declexp); | |
536 | } else | |
537 | yp->yp_structname = t; | |
538 | tprnt_loop(fp, y, id, yp->yp_structname); | |
539 | } | |
540 | if (yp->yp_flags & YP_CONTROLLED) { | |
541 | char *f1; | |
542 | ||
543 | if ((f1 = getfield(yp->yp_control)) == NULLCP) { | |
544 | fprintf(stderr, "\ntprnt_typ:SET OF: can't extract field from %s\n", | |
545 | yp->yp_control); | |
546 | exit(1); | |
547 | } | |
548 | (void) fprintf(fp, "\t{ PE_END, OFFSET(%s, %s), 0, 0 },\n", | |
549 | yp->yp_structname, f1); | |
550 | } else if (yp->yp_structname != NULL) | |
551 | (void) fprintf(fp, | |
552 | "\t{ PE_END, OFFSET(%s, next), 0, 0, NULL },\n", | |
553 | yp->yp_structname); | |
554 | else | |
555 | (void) fprintf(fp, "\t{ PE_END, 0, 0, 0, NULL },\n"); | |
556 | ptr = save_ptr; | |
557 | cons_type--; | |
558 | break; | |
559 | ||
560 | case YP_CHOICE: | |
561 | p1 = NULL; | |
562 | /* support for -h flag */ | |
563 | if (hflag && (y = yp->yp_type) && !y->yp_next) { | |
564 | tprnt_typ(fp, y, id, yp->yp_structname); | |
565 | break; | |
566 | } | |
567 | cons_type++; | |
568 | save_ptr = ptr; | |
569 | /* Generates an unused tags field - so beware */ | |
570 | if (type == NULL) | |
571 | prte_noff(fp, "SCHOICE_START", yp, ptr_tblidx); | |
572 | else if (noindirect(f)) | |
573 | prte_noff(fp, "SCHOICE_START", yp, ptr_tblidx); | |
574 | else | |
575 | prte_off(fp, "CHOICE_START", yp, t, f, ptr_tblidx); | |
576 | ||
577 | if (yp->yp_flags & YP_DEFAULT) | |
578 | gdflt(fp, yp, G_DEC); | |
579 | if (y = yp->yp_type) { | |
580 | char *t1; | |
581 | char *f1; | |
582 | ||
583 | #ifdef DO_OFFSETS | |
584 | if (yp->yp_flags & YP_CONTROLLED) { | |
585 | ||
586 | if ((f1 = getfield(yp->yp_control)) == NULLCP) { | |
587 | fprintf(stderr, | |
588 | "\ntprnt_typ:CHOICE: can't extract field from %s\n", | |
589 | yp->yp_control); | |
590 | exit(1); | |
591 | } | |
592 | ||
593 | } else | |
594 | f1 = "offset"; | |
595 | ||
596 | if ((yp->yp_flags & YP_ID) && yp->yp_id) | |
597 | (void) fprintf(fp, | |
598 | "\t{ SCTRL, OFFSET(%s, %s), 0, 0, \"%s\" },\n", | |
599 | yp->yp_structname, f1, yp->yp_id); | |
600 | else | |
601 | (void) fprintf(fp, | |
602 | "\t{ SCTRL, OFFSET(%s, %s), 0, 0, NULL },\n", | |
603 | yp->yp_structname, f1); | |
604 | #else | |
605 | if ((yp->yp_flags & YP_ID) && yp->yp_id) | |
606 | (void) fprintf(fp,"\t{ SCTRL, 0, 0, 0, \"%s\" },\n", | |
607 | yp->yp_id); | |
608 | else | |
609 | (void) fprintf(fp, "\t{ SCTRL, 0, 0, 0, NULL },\n"); | |
610 | ||
611 | #endif | |
612 | if (yp->yp_param_type) { | |
613 | /* we have a [[ P type ]] specification */ | |
614 | if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) { | |
615 | fprintf(stderr, | |
616 | "\ntprnt_typ:CHOICE can't extract direct type from %s\n", | |
617 | yp->yp_param_type); | |
618 | exit(1); | |
619 | } | |
620 | yp->yp_structname = strdup(t1); | |
621 | } else if (type) { | |
622 | if (yp->yp_declexp == NULL) | |
623 | ferr(1, "tprnt_typ:YP_CHOICE:no declexp\n"); | |
624 | yp->yp_structname = my_strcat("struct ", yp->yp_declexp); | |
625 | } else | |
626 | yp->yp_structname = t; | |
627 | tprnt_loop(fp, y, id, yp->yp_structname); | |
628 | } | |
629 | (void) fprintf(fp, "\t{ PE_END, 0, 0, 0, NULL },\n"); | |
630 | ptr = save_ptr; | |
631 | cons_type--; | |
632 | break; | |
633 | ||
634 | default: | |
635 | ferrd(1, "tprnt_typ: yp_code = %d not implemented\n", yp->yp_code); | |
636 | } | |
637 | ||
638 | if (p1 != NULL) { | |
639 | if (t != NULL) | |
640 | prte_off(fp, p1, yp, t, f, ptr_tblidx); | |
641 | else | |
642 | prte_noff(fp, p1, yp, ptr_tblidx); | |
643 | ||
644 | if (yp->yp_flags & YP_DEFAULT) | |
645 | gdflt(fp, yp, G_DEC); | |
646 | } | |
647 | ||
648 | if (flag) | |
649 | yp->yp_flags |= YP_OPTCONTROL; | |
650 | ||
651 | if (yp->yp_aft_alist && yp->yp_aft_alist->yal_prn) | |
652 | gen_act(fp, yp->yp_aft_alist->yal_prn); | |
653 | ||
654 | } | |
655 | ||
656 | static int fflags[] = { | |
657 | 0, 1, 2, 2, 3, 3, 4, 5, 16, 16, 16, 17, 17, 17, | |
658 | 0, -1, 7,}; | |
659 | ||
660 | /* | |
661 | * generate tables for printing a contructed type | |
662 | */ | |
663 | YP | |
664 | tprnt_loop(fp, yp, id, type) | |
665 | FILE *fp; | |
666 | YP yp; | |
667 | char *id; | |
668 | char *type; | |
669 | { | |
670 | for (; yp != NULL; yp = yp->yp_next) { | |
671 | tprnt_typ(fp, yp, id, type); | |
672 | } | |
673 | } | |
674 | ||
675 | ||
676 | ddflt(fp, yp) | |
677 | FILE *fp; | |
678 | YP yp; | |
679 | { | |
680 | switch (yp->yp_code) { | |
681 | case YP_BOOL: | |
682 | case YP_INT: | |
683 | case YP_INTLIST: | |
684 | (void) fprintf(fp, "\t{DFLT_B, %d, 0, 0 },\n", | |
685 | yp->yp_default->yv_number); | |
686 | break; | |
687 | case YP_BIT: | |
688 | case YP_BITLIST: | |
689 | case YP_OCT: | |
690 | case YP_NULL: | |
691 | case YP_SEQ: | |
692 | case YP_SEQTYPE: | |
693 | case YP_SEQLIST: | |
694 | case YP_SET: | |
695 | case YP_SETTYPE: | |
696 | case YP_SETLIST: | |
697 | case YP_CHOICE: | |
698 | case YP_ANY: | |
699 | case YP_OID: | |
700 | case YP_IDEFINED: | |
701 | case YP_ENUMLIST: | |
702 | case YP_REAL: | |
703 | (void) fprintf(fp, "\t{DFLT_B, 0, 0, 0 },\n"); | |
704 | break; | |
705 | ||
706 | default: | |
707 | ferr(1, "ddflt:unknown type %d\n", yp->yp_code); | |
708 | } | |
709 | ||
710 | } | |
711 | ||
712 | /* | |
713 | * print a Non offset table entry | |
714 | */ | |
715 | prte_noff(fp, type, yp, idx) | |
716 | FILE *fp; | |
717 | char *type; | |
718 | YP yp; | |
719 | int idx; | |
720 | { | |
721 | char *tag; | |
722 | char *flags; | |
723 | char *typename; | |
724 | char buf1[BUFSIZ]; | |
725 | ||
726 | tag = c_tag(yp); | |
727 | flags = c_class(yp); | |
728 | if (mrose3) { /* need to append FL_PRTAG flag */ | |
729 | strncpy(buf1, flags, BUFSIZ); | |
730 | strncat(buf1, "|FL_PRTAG", BUFSIZ); | |
731 | flags = buf1; | |
732 | } | |
733 | if (mrose1) | |
734 | typename = yp->yp_id; | |
735 | else if (mrose2) | |
736 | typename = yp->yp_identifier; | |
737 | else | |
738 | typename = (char *)0; | |
739 | if (typename) | |
740 | (void) fprintf(fp, "\t{ %s, %d, %s, %s, \"%s\" },\n", | |
741 | type, idx, tag, flags, typename); | |
742 | else | |
743 | (void) fprintf(fp, "\t{ %s, %d, %s, %s, NULL},\n", | |
744 | type,idx, tag, flags); | |
745 | } | |
746 | ||
747 | /* | |
748 | * print a Non offset table entry for an ETAG - special case | |
749 | */ | |
750 | prte_enoff(fp, type, yp, idx) | |
751 | FILE *fp; | |
752 | char *type; | |
753 | YP yp; | |
754 | int idx; | |
755 | { | |
756 | char *tag; | |
757 | char *flags; | |
758 | char *typename; | |
759 | char buf1[BUFSIZ]; | |
760 | ||
761 | tag = ec_tag(yp); | |
762 | flags = ec_class(yp); | |
763 | if (mrose3) { /* need to append FL_PRTAG flag */ | |
764 | strncpy(buf1, flags, BUFSIZ); | |
765 | strncat(buf1, "|FL_PRTAG", BUFSIZ); | |
766 | flags = buf1; | |
767 | mrose3 = 0; /* don't want the next tag */ | |
768 | } | |
769 | if (mrose1) { | |
770 | typename = yp->yp_id; | |
771 | mrose1 = 0; | |
772 | } else if (mrose2) { | |
773 | typename = yp->yp_identifier; | |
774 | mrose2 = 0; | |
775 | } else | |
776 | typename = NULL; | |
777 | if (typename) | |
778 | (void) fprintf(fp, "\t{ %s, %d, %s, %s, \"%s\" },\n", | |
779 | type, idx, tag, flags, typename); | |
780 | else | |
781 | (void) fprintf(fp, "\t{ %s, %d, %s, %s, NULL },\n", | |
782 | type, idx, tag, flags); | |
783 | } | |
784 | ||
785 | /* | |
786 | * print an offset table entry | |
787 | */ | |
788 | prte_off(fp, type, yp, t, f, idx) | |
789 | FILE *fp; | |
790 | char *type; | |
791 | YP yp; | |
792 | char *t, *f; | |
793 | int idx; | |
794 | { | |
795 | char *tag; | |
796 | char *flags; | |
797 | char *typename; | |
798 | char buf1[BUFSIZ]; | |
799 | ||
800 | tag = c_tag(yp); | |
801 | flags = c_class(yp); | |
802 | if (mrose3) { /* need to append FL_PRTAG flag */ | |
803 | strncpy(buf1, flags, BUFSIZ); | |
804 | strncat(buf1, "|FL_PRTAG", BUFSIZ); | |
805 | flags = buf1; | |
806 | } | |
807 | if (mrose1) | |
808 | typename = yp->yp_id; | |
809 | else if (mrose2) | |
810 | typename = yp->yp_identifier; | |
811 | else | |
812 | typename = (char *)0; | |
813 | #ifdef DO_OFFSETS | |
814 | if (typename) | |
815 | (void) fprintf(fp, "\t{ %s, OFFSET(%s, %s), %s, %s, \"%s\" },\n", | |
816 | type, t, f, tag, flags, typename); | |
817 | else | |
818 | (void) fprintf(fp, "\t{ %s, OFFSET(%s, %s), %s, %s, NULL},\n", | |
819 | type, t, f, tag, flags); | |
820 | #else | |
821 | if (typename) | |
822 | (void) fprintf(fp, "\t{ %s, %d, %s, %s, \"%s\" },\n", | |
823 | type, idx, tag, flags, typename); | |
824 | else | |
825 | (void) fprintf(fp, "\t{ %s, %d, %s, %s, NULL},\n", | |
826 | type, idx, tag, flags); | |
827 | #endif | |
828 | } | |
829 | ||
830 | /* | |
831 | * handle the very complex task of defined types. | |
832 | * Basically generating object calls | |
833 | */ | |
834 | pr_deftyp(fp, yp, t, f) | |
835 | FILE *fp; | |
836 | YP yp; | |
837 | char *t; | |
838 | char *f; | |
839 | { | |
840 | /* Predefined Universal Type */ | |
841 | struct univ_typ *p, *univtyp(); | |
842 | ||
843 | if ((p = univtyp(yp->yp_identifier))) { | |
844 | if (p->univ_flags & UNF_EXTMOD) { | |
845 | yp->yp_module = p->univ_mod; | |
846 | goto do_obj; | |
847 | } | |
848 | prte_univt(fp, p, yp, t, f); | |
849 | return; | |
850 | } | |
851 | ||
852 | do_obj: | |
853 | if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT) | |
854 | prte_noff(fp, "IMP_OBJ", yp, -1); | |
855 | prte_obj(fp, yp, t, f); | |
856 | } | |
857 | ||
858 | /* | |
859 | * print an offset table entry for an OBJECT type entry | |
860 | */ | |
861 | prte_obj(fp, yp, t, f) | |
862 | FILE *fp; | |
863 | YP yp; | |
864 | char *t, *f; | |
865 | { | |
866 | char *type; | |
867 | char *obj; | |
868 | char *flags; | |
869 | char *typename; | |
870 | char *off; | |
871 | char buf1[BUFSIZ]; | |
872 | char buf2[BUFSIZ]; | |
873 | int extflag; | |
874 | ||
875 | if (yp->yp_module == NULL || strcmp(yp->yp_module, mymodule) == 0) { | |
876 | if (f && !noindirect(f)) | |
877 | type = "OBJECT"; | |
878 | else | |
879 | type = "SOBJECT"; | |
880 | obj = proc_name(yp->yp_identifier, 0); | |
881 | extflag = 0; | |
882 | } else { | |
883 | if (f && !noindirect(f)) | |
884 | type = "EXTOBJ"; | |
885 | else | |
886 | type = "SEXTOBJ"; | |
887 | obj = strp2name(yp->yp_identifier, yp->yp_module); | |
888 | extflag = 1; | |
889 | } | |
890 | flags = c_class(yp); | |
891 | if (mrose3) { /* need to append FL_PRTAG flag */ | |
892 | strncpy(buf1, flags, BUFSIZ); | |
893 | strncat(buf1, "|FL_PRTAG", BUFSIZ); | |
894 | flags = buf1; | |
895 | } | |
896 | if (mrose1) | |
897 | typename = yp->yp_id; | |
898 | else if (mrose2) | |
899 | typename = yp->yp_identifier; | |
900 | else | |
901 | typename = (char *)0; | |
902 | #ifdef DO_OFFSETS | |
903 | if (f && !noindirect(f)) { | |
904 | sprintf(buf2, "OFFSET(%s, %s)", t, f); | |
905 | off = buf2; | |
906 | } else if (f && *f == '&') { | |
907 | sprintf(buf2, "OFFSET(%s, %s)", t, f + 1); | |
908 | off = buf2; | |
909 | } else | |
910 | #endif | |
911 | off = "0"; | |
912 | if (typename) | |
913 | (void) fprintf(fp, "\t{ %s, %s, _Z%s, %s, \"%s\" },\n", | |
914 | type, off, obj, flags, typename); | |
915 | else | |
916 | (void) fprintf(fp, "\t{ %s, %s, _Z%s, %s, NULL},\n", | |
917 | type, off, obj, flags); | |
918 | if (extflag) | |
919 | (void) fprintf(fp, "\t{ EXTMOD, %d, 0, 0, NULL },\n", | |
920 | gen_modref(yp->yp_module)); | |
921 | } | |
922 | ||
923 | /* | |
924 | * print an table entry for Universal type with the given entry | |
925 | */ | |
926 | prte_univt(fp, p, yp, t, f) | |
927 | FILE *fp; | |
928 | struct univ_typ *p; | |
929 | YP yp; | |
930 | char *t, *f; | |
931 | { | |
932 | char *type; | |
933 | int tag; | |
934 | int class; | |
935 | char *flags; | |
936 | char *typename; | |
937 | char *off; | |
938 | char buf1[BUFSIZ]; | |
939 | char buf2[BUFSIZ]; | |
940 | char buf3[BUFSIZ]; | |
941 | ||
942 | if (f == NULL || noindirect(f)) { | |
943 | sprintf(buf3, "S%s", p->univ_tab); | |
944 | type = buf3; | |
945 | } else | |
946 | type = p->univ_tab; | |
947 | ||
948 | if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT) { | |
949 | tag = yp->yp_tag->yt_value->yv_number; | |
950 | class = yp->yp_tag->yt_class; | |
951 | } else { | |
952 | tag = p->univ_id; | |
953 | class = p->univ_class; | |
954 | } | |
955 | ||
956 | strncpy(buf1, c_flags(yp, class), BUFSIZ); | |
957 | flags = buf1; | |
958 | if (mrose3) { /* need to append FL_PRTAG flag */ | |
959 | strncat(buf1, "|FL_PRTAG", BUFSIZ); | |
960 | } | |
961 | if (mrose1) | |
962 | typename = yp->yp_id; | |
963 | else if (mrose2) | |
964 | typename = yp->yp_identifier; | |
965 | else | |
966 | typename = (char *)0; | |
967 | #ifdef DO_OFFSETS | |
968 | if (f && !noindirect(f)) { | |
969 | sprintf(buf2, "OFFSET(%s, %s)", t, f); | |
970 | off = buf2; | |
971 | } else if (f && *f == '&') { | |
972 | sprintf(buf2, "OFFSET(%s, %s)", t, f + 1); | |
973 | off = buf2; | |
974 | } else | |
975 | #endif | |
976 | off = "0"; | |
977 | if (typename) | |
978 | (void) fprintf(fp, "\t{ %s, %s, %d, %s, \"%s\" },\n", | |
979 | type, off, tag, flags, typename); | |
980 | else | |
981 | (void) fprintf(fp, "\t{ %s, %s, %d, %s, NULL},\n", | |
982 | type, off, tag, flags); | |
983 | } | |
984 | ||
985 | /* | |
986 | * generate the table entry for a value passing defined type which | |
987 | * is equivalent to the given primative type | |
988 | */ | |
989 | gen_pentry(fp, oyp, yp, t, f) | |
990 | FILE *fp; | |
991 | YP oyp, yp; | |
992 | char *t, *f; | |
993 | { | |
994 | char *p1; | |
995 | register char s = oyp->yp_prfexp; /* type of value passing */ | |
996 | int idx; | |
997 | ||
998 | ||
999 | if (noindirect(f) && s != 'q' && s != 'a') | |
1000 | ferrs(1, | |
1001 | "gen_ventry: must specify a field for primative value- not %s\n", f); | |
1002 | ||
1003 | #if 0 | |
1004 | /* can't get id from in here - yet */ | |
1005 | if (yp->yp_code == YP_BITLIST) { | |
1006 | idx = addptr (modsym(mymodule, yp->yp_varexp ? yp -> yp_varexp : id, | |
1007 | "bits")); | |
1008 | } else | |
1009 | #endif | |
1010 | idx = -1; | |
1011 | ||
1012 | switch (s) { | |
1013 | case 'q': /* [[ q parm->qbufptr ]] */ | |
1014 | if (yp->yp_code != YP_OCT) | |
1015 | warning("qbuf pointer passed for a %s by type %s", | |
1016 | code2name(yp->yp_code), yp2name(oyp)); | |
1017 | ||
1018 | f = setfield(oyp->yp_strexp); | |
1019 | if (noindirect(f)) | |
1020 | p1 = "SOCTETSTRING"; | |
1021 | else | |
1022 | p1 = "OCTETSTRING"; | |
1023 | break; | |
1024 | ||
1025 | case 's': /* [[ s ptr ]] */ | |
1026 | if (yp->yp_code != YP_OCT) | |
1027 | warning("string pointer passed for a %s by type %s", | |
1028 | code2name(yp->yp_code), yp2name(oyp)); | |
1029 | ||
1030 | f = setfield(oyp->yp_strexp); | |
1031 | p1 = "T_STRING"; | |
1032 | break; | |
1033 | ||
1034 | case 'o': /* [[ o ptr $ length ]] */ | |
1035 | if (yp->yp_code != YP_OCT) | |
1036 | warning("octet/length pair passed for a %s by type %s", | |
1037 | code2name(yp->yp_code), yp2name(oyp)); | |
1038 | f = setfield(oyp->yp_strexp); | |
1039 | p1 = "OCTET_PTR"; | |
1040 | prte_off(fp, p1, yp, t, f, idx); | |
1041 | if (oyp->yp_intexp) | |
1042 | f = setfield(oyp->yp_intexp); | |
1043 | if (noindirect(f)) | |
1044 | ferr(1, "gen_ventry:OCT: must specify a field [[ s .. ]]\n"); | |
1045 | p1 = "OCTET_LEN"; | |
1046 | break; | |
1047 | ||
1048 | case 'x': /* [[ x ptr $ length ]] */ | |
1049 | if (yp->yp_code != YP_BIT && yp->yp_code != YP_BITLIST) | |
1050 | warning("bit string/length pair passed for a %s by type %s", | |
1051 | code2name(yp->yp_code), yp2name(oyp)); | |
1052 | ||
1053 | f = setfield(oyp->yp_strexp); | |
1054 | p1 = "BITSTR_PTR"; | |
1055 | prte_off(fp, p1, yp, t, f, idx); | |
1056 | f = setfield(oyp->yp_intexp); | |
1057 | if (noindirect(f)) | |
1058 | ferr(1, "tenc_typ:BIT: must specify a field [[ x .. ]]\n"); | |
1059 | p1 = "BITSTR_LEN"; | |
1060 | break; | |
1061 | ||
1062 | case 'r': /* [[ r REAL ]] */ | |
1063 | if (yp->yp_code != YP_REAL) | |
1064 | warning("Real passed for a %s by type %s", | |
1065 | code2name(yp->yp_code), yp2name(oyp)); | |
1066 | ||
1067 | f = setfield(oyp->yp_strexp); | |
1068 | p1 = "REALTYPE"; | |
1069 | break; | |
1070 | ||
1071 | case 'i': /* [[ i INTEGER ]] */ | |
1072 | if (yp->yp_code != YP_INT && yp->yp_code != YP_INTLIST | |
1073 | && yp->yp_code != YP_ENUMLIST) | |
1074 | warning("integer passed for a %s by type %s", | |
1075 | code2name(yp->yp_code), yp2name(oyp)); | |
1076 | ||
1077 | if (oyp->yp_intexp) | |
1078 | f = setfield(oyp->yp_intexp); | |
1079 | p1 = "INTEGER"; | |
1080 | break; | |
1081 | ||
1082 | case 't': /* [[ t Bitvector ]] */ | |
1083 | if (yp->yp_code != YP_BIT && yp->yp_code != YP_BITLIST) | |
1084 | warning("Bitvector (PE) passed for a %s by type %s", | |
1085 | code2name(yp->yp_code), yp2name(oyp)); | |
1086 | ||
1087 | f = setfield(oyp->yp_intexp); | |
1088 | if (oyp->yp_varexp && !noindirect(f)) | |
1089 | p1 = "BITSTRING"; | |
1090 | else | |
1091 | p1 = "SBITSTRING"; | |
1092 | break; | |
1093 | ||
1094 | case 'b': /* [[ b BOOLEAN ]] */ | |
1095 | if (yp->yp_code != YP_BOOL) | |
1096 | warning("Boolean passed for a %s by type %s", | |
1097 | code2name(yp->yp_code), yp2name(oyp)); | |
1098 | ||
1099 | if (oyp->yp_intexp) | |
1100 | f = setfield(oyp->yp_intexp); | |
1101 | p1 = "BOOLEAN"; | |
1102 | break; | |
1103 | ||
1104 | case 'O': /* [[ O Object Identifier ]] */ | |
1105 | if (yp->yp_code != YP_OID) | |
1106 | warning("Object Identifier pointer passed for a %s by type %s", | |
1107 | code2name(yp->yp_code), yp2name(oyp)); | |
1108 | f = setfield(oyp->yp_strexp); | |
1109 | p1 = "OBJID"; | |
1110 | break; | |
1111 | ||
1112 | case 'a': /* [[ a ANY ]] */ | |
1113 | if (yp->yp_code != YP_ANY) | |
1114 | warning("PE pointer passed for a %s by type %s", | |
1115 | code2name(yp->yp_code), yp2name(oyp)); | |
1116 | f = setfield(oyp->yp_strexp); | |
1117 | if (noindirect(f)) | |
1118 | p1 = "SANY"; | |
1119 | else | |
1120 | p1 = "ANY"; | |
1121 | break; | |
1122 | default: | |
1123 | ferrd("gen_vident:unknown Value passed %d\n", (int )s); | |
1124 | } | |
1125 | ||
1126 | prte_off(fp, p1, yp, t, f, idx); | |
1127 | } |