Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / contrib / isode / pepsy / etabs.c
CommitLineData
459ebbd7
C
1/* etabs.c */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/pepsy/RCS/etabs.c,v 7.8 91/02/22 09:48:54 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/pepsy/RCS/etabs.c,v 7.8 91/02/22 09:48:54 mrose Interim $
9 *
10 *
11 * $Log: etabs.c,v $
12 * Revision 7.8 91/02/22 09:48:54 mrose
13 * Interim 6.8
14 *
15 * Revision 7.7 91/01/08 12:49:27 mrose
16 * update
17 *
18 * Revision 7.6 90/12/11 10:33:33 mrose
19 * sync
20 *
21 * Revision 7.5 90/11/11 10:53:43 mrose
22 * update
23 *
24 * Revision 7.4 90/11/04 19:18:31 mrose
25 * update
26 *
27 * Revision 7.3 90/08/18 00:44:20 mrose
28 * touch-up
29 *
30 * Revision 7.2 90/07/27 08:49:15 mrose
31 * update
32 *
33 * Revision 7.1 90/07/09 14:52:33 mrose
34 * sync
35 *
36 * Revision 7.0 90/07/01 19:54:18 mrose
37 * *** empty log message ***
38 *
39 */
40
41/*
42 * NOTICE
43 *
44 * Acquisition, use, and distribution of this module and related
45 * materials are subject to the restrictions of a license agreement.
46 * Consult the Preface in the User's Manual for the full terms of
47 * this agreement.
48 *
49 */
50
51
52#include <stdio.h>
53#include <ctype.h>
54#include "pepsydefs.h"
55#include "sym.h"
56#include "pass2.h"
57#include "mine.h"
58
59s_table *head;
60
61extern s_table *lookup_list(), *proc_def();
62
63extern char *c_tag(), *c_class();
64extern char *ec_tag(), *ec_class();
65extern char *strip_last();
66extern char *get_val(), *get_comp(), *get_string();
67extern s_table *get_offset();
68extern char *my_strcat(), *strp2name();
69extern char *my_new_str();
70extern char *mymodule;
71extern char *modsym();
72extern char *concat();
73extern char *genlabel();
74extern char *notidtoid();
75extern char *code2name();
76extern char *yp2name();
77extern YV calc_yv();
78extern SY syfind();
79static s_table *en_ptr;
80extern s_table *ptr;
81extern char *rm_indirect();
82extern char *getfield();
83extern char *setfield();
84
85static int cons_type = 0;
86/* int explicit; */
87
88s_table *save_ptr;
89
90extern YT gen_etag();
91
92#define WORDSIZE 20
93#define MAXNAME 256 /* maximum size of a identifier */
94
95#ifdef DEBUG
96char *str_yp_code[] = {
97 "Undefined", "Boolean", "Integer", "Named number list", "Bitstring",
98 "Named Bitstring list", "Octet String", "Null", "Sequence",
99 "Sequence of", "Sequence list", "Set", "Set of", "Set list",
100 "Choice", "Any", "Object Identifier",
101 "", "", "", "", "", "", "", "",
102 "", "", "", "", "", "", "", "Identifier",
103
104};
105
106#endif
107
108/*
109 * table encode a type. generate tables for the encoding of a type
110 */
111tenc_typ(fp, yp, id, type)
112FILE *fp;
113YP yp;
114char *id;
115char *type;
116{
117
118 char *t, *f;
119 char *p1;
120 char *s1, *s2, *s3;
121 char *s;
122 s_table *ptr1, *ptr2;
123 YP y;
124 YAL yal;
125
126
127 if (yp->yp_code < 0 || yp->yp_code > YP_REAL)
128 ferrd(1, "tenc_typ: unimplemented type %d\n", yp->yp_code);
129
130 if (yp == NULL) {
131 ferr(0, "tenc_typ:NULL argument\n");
132 return;
133 }
134
135 /* Preserve the type of the containing object */
136 if (type)
137 t = type;
138 else if (yp->yp_param_type) {
139 char *t1;
140 /* we have a [[ P type ]] specification */
141 if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) {
142 fprintf(stderr,
143 "\ntenc_typ:SETLIST can't extract direct type from %s\n",
144 yp->yp_param_type);
145 exit(1);
146 }
147 t = strdup(t1);
148 } else
149 t = my_strcat("struct ", modsym(mymodule, id, "type"));
150
151 if (yal = yp->yp_bef_alist) {
152 yal->yal_type = t;
153 if (yal->yal_enc)
154 gen_act(fp, yp->yp_bef_alist->yal_enc);
155 }
156 if (yal = yp->yp_aft_alist) {
157 yal->yal_type = t;
158 }
159 if (yal = yp->yp_control_act)
160 yal -> yal_type = t;
161
162 if (yal = yp->yp_optional_act)
163 yal -> yal_type = t;
164
165 if (yp->yp_flags & YP_DEFAULT)
166 gdflt(fp, yp, G_ENC);
167
168 if ((yp->yp_flags & YP_PARMVAL) && yp->yp_parm) {
169 if ((f = getfield(yp->yp_parm)) == NULLCP) {
170 fprintf(stderr, "\ntenc_typ: can't extract field from %s\n",
171 yp->yp_parm);
172 exit(1);
173 }
174 f = strdup(f);
175 } else
176 f = yp->yp_varexp;
177
178 if ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT))
179 == (YP_OPTIONAL|YP_OPTCONTROL)) {
180 char *f1;
181 char *bitno;
182
183 if (yp -> yp_optional_act && yp -> yp_optional_act -> yal_enc) {
184 fprintf (fp, "\t{ BOPTIONAL, %d, 0, FL_USELECT},\n",
185 yp -> yp_optional_act -> yal_enc -> a_num);
186 }
187 else {
188 if ((f1 = getfldbit(yp->yp_optcontrol, &bitno)) == NULLCP) {
189 fprintf(stderr,
190 "\ntenc_typ:BOPTIONAL: can't extract field from %s\n",
191 yp->yp_optcontrol);
192 exit(1);
193 }
194 (void) fprintf(fp, "\t{ BOPTIONAL, AOFFSET(%s, %s), %s, 0},\n",
195 t, f1, bitno);
196 }
197 }
198
199 /* handle explicit tags - one day may have to change this if anyone
200 * ever defines a type with more than one explicit tag
201 */
202 if (yp->yp_flags & YP_TAG && !(yp->yp_flags & YP_IMPLICIT)) {
203 (void) fprintf(fp, "\t{ ETAG, 0, ");
204 (void) fprintf(fp, "%s, %s },\n", ec_tag(yp), ec_class(yp));
205 }
206
207 if (yp->yp_yfn && yp->yp_yfn->yfn_enc) {
208 gen_fn(fp, yp, yp->yp_yfn->yfn_enc);
209
210 if (yp->yp_aft_alist && yp->yp_aft_alist->yal_enc)
211 gen_act(fp, yp->yp_aft_alist->yal_enc);
212
213 return;
214 }
215
216 switch (yp->yp_code) {
217
218 case YP_UNDF:
219 ferr(1, "tenc_typ:Undefined type\n");
220
221 case YP_BOOL:
222 p1 = "BOOLEAN";
223 if (yp->yp_intexp)
224 f = setfield(yp->yp_intexp);
225 if (noindirect(f))
226 ferr(1, "tenc_typ:BOOL: must specify a field [[ b .. ]]\n");
227 if (yp->yp_varexp || (yp->yp_intexp && !noindirect(f)))
228 break;
229 ferr(1, "tenc_typ:BOOL: couldn't determine type\n");
230
231 case YP_INTLIST:
232
233 case YP_INT:
234
235 case YP_ENUMLIST:
236 if (yp->yp_intexp)
237 f = setfield(yp->yp_intexp);
238 if (noindirect(f))
239 ferr(1, "tenc_typ:INT: must specify a field [[ i .. ]]\n");
240 if (yp->yp_varexp || (yp->yp_intexp && !noindirect(f))) {
241 p1 = "INTEGER";
242 break;
243 }
244 ferr(1, "tenc_typ:INT: couldn't determine type\n");
245 break;
246
247 case YP_REAL:
248 if (yp->yp_strexp)
249 f = setfield(yp->yp_strexp);
250 if (noindirect(f))
251 ferr(1, "tenc_typ:REAL: must specify a field [[ r .. ]]\n");
252 if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) {
253 p1 = "REALTYPE";
254 break;
255 }
256 ferr(1, "tenc_typ:REAL: couldn't determine type\n");
257 break;
258
259 case YP_BIT:
260 case YP_BITLIST:
261 if (yp->yp_strexp && yp->yp_intexp) {
262 if (yp->yp_strexp)
263 f = setfield(yp->yp_strexp);
264 if (noindirect(f))
265 ferr(1, "tenc_typ:BIT: must specify a field [[ x .. ]]\n");
266 p1 = "BITSTR_PTR";
267 prnte(fp, t, f, yp, p1);
268 if (yp->yp_intexp)
269 f = setfield(yp->yp_intexp);
270 if (noindirect(f))
271 ferr(1, "tenc_typ:BIT: must specify a field [[ x .. ]]\n");
272 p1 = "BITSTR_LEN";
273 break;
274 }
275 if (yp->yp_strexp == NULLCP && yp->yp_intexp)
276 f = setfield(yp->yp_intexp);
277 if (yp->yp_varexp || (yp->yp_intexp && !noindirect(f))) {
278 p1 = "BITSTRING";
279 break;
280 }
281 t = NULL;
282 p1 = NULL;
283 (void) fprintf(fp, "\t{ SBITSTRING, 0, %s, %s },\n",
284 c_tag(yp), c_class(yp));
285 break;
286
287 case YP_OCT:
288 if (yp->yp_strexp) {
289 switch (yp->yp_prfexp) {
290 case 'q': /* [[ q parm->qbufptr ]] */
291 if (yp->yp_strexp)
292 f = setfield(yp->yp_strexp);
293 if (noindirect(f))
294 p1 = "SOCTETSTRING";
295 else
296 p1 = "OCTETSTRING";
297 break;
298
299 case 's': /* [[ s ptr ]] */
300 if (yp->yp_strexp)
301 f = setfield(yp->yp_strexp);
302 if (noindirect(f))
303 ferr(1, "tenc_typ:OCT: must specify a field [[ s .. ]]\n");
304 p1 = "T_STRING";
305 break;
306
307 case 'o': /* [[ o ptr $ length ]] */
308 if (yp->yp_strexp)
309 f = setfield(yp->yp_strexp);
310 if (noindirect(f))
311 ferr(1, "tenc_typ:OCT: must specify a field [[ s .. ]]\n");
312 p1 = "OCTET_PTR";
313 prnte(fp, t, f, yp, p1);
314 if (yp->yp_intexp)
315 f = setfield(yp->yp_intexp);
316 if (noindirect(f))
317 ferr(1, "tenc_typ:OCT: must specify a field [[ s .. ]]\n");
318 p1 = "OCTET_LEN";
319 break;
320
321 default:
322 fprintf(stderr,"\ntenc_typ: Unknown Octet string specifier %c\n",
323 yp->yp_prfexp);
324 exit(1);
325 }
326 break;
327 }
328
329 if (f && !noindirect(f)) {
330 p1 = "OCTETSTRING";
331 break;
332 }
333 t = NULL;
334 p1 = NULL;
335 (void) fprintf(fp, "\t{ SOCTETSTRING, 0, %s, %s },\n",
336 c_tag(yp), c_class(yp));
337 break;
338
339 case YP_OID:
340 if (yp->yp_strexp)
341 f = setfield(yp->yp_strexp);
342 if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) {
343 p1 = "OBJID";
344 break;
345 }
346 t = NULL;
347 p1 = NULL;
348 (void) fprintf(fp, "\t{ SOBJID, 0, %s, %s },\n",
349 c_tag(yp), c_class(yp));
350 break;
351
352
353 case YP_SEQ:
354 case YP_SET:
355 case YP_ANY:
356 if (yp->yp_strexp)
357 f = setfield(yp->yp_strexp);
358 if (yp->yp_varexp || (yp->yp_strexp && !noindirect(f))) {
359 p1 = "ANY";
360 break;
361 }
362 t = NULL;
363 p1 = NULL;
364 (void) fprintf(fp, "\t{ SANY, 0, %s, %s },\n",
365 c_tag(yp), c_class(yp));
366 break;
367
368 case YP_NULL:
369 p1 = "T_NULL";
370 t = NULL;
371 break;
372
373 case YP_IDEFINED:
374 p1 = NULL;
375 if ((yp->yp_flags & YP_PARMVAL) && yp->yp_prfexp)
376 ferr(1,
377 "\n[[ ? reference ]] [[ p reference ]] is illegal\n\t only one allowed\n");
378
379 if (yp->yp_prfexp) { /* [[ ? parm->field ]] - complex to process */
380 gen_identry(fp, t, f, yp, gen_ventry);
381 break;
382 }
383
384 {
385 /* Predefined Universal Type */
386 struct univ_typ *p, *univtyp();
387
388 if ((p = univtyp(yp->yp_identifier))) {
389 if (p->univ_flags & UNF_EXTMOD) {
390 yp->yp_module = p->univ_mod;
391 goto do_obj;
392 }
393 if (f == NULL || noindirect(f)) {/* No offset type */
394 if (yp->yp_flags & YP_TAG
395 && yp->yp_flags & YP_IMPLICIT)
396 prstfield(fp, p->univ_tab, t, f,
397 int2tstr(yp->yp_tag->yt_value->yv_number),
398 c_flags(yp, yp->yp_tag->yt_class));
399 /*
400 (void) fprintf(fp, "\t{ S%s, 0, %d, %s },\n",
401 p->univ_tab,
402 yp->yp_tag->yt_value->yv_number,
403 c_flags(yp, yp->yp_tag->yt_class));
404 */
405 else
406 prstfield(fp, p->univ_tab, t, f, int2tstr(p->univ_id),
407 c_flags(yp, p->univ_class));
408 /*
409 (void) fprintf(fp, "\t{ S%s, 0, %d, %s },\n",
410 p->univ_tab, p->univ_id,
411 c_flags(yp, p->univ_class));
412 */
413 break;
414 }
415 if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
416 prtfield(fp, p->univ_tab, t, f,
417 int2tstr(yp->yp_tag->yt_value->yv_number),
418 c_flags(yp, yp->yp_tag->yt_class));
419 /*
420 (void) fprintf(fp, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
421 p->univ_tab, t, f,
422 yp->yp_tag->yt_value->yv_number,
423 c_flags(yp, yp->yp_tag->yt_class));
424 */
425 else
426 prtfield(fp, p->univ_tab, t, f, int2tstr(p->univ_id),
427 c_flags(yp, p->univ_class));
428 /*
429 (void) fprintf(fp, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
430 p->univ_tab, t, f, p->univ_id,
431 c_flags(yp, p->univ_class));
432 */
433 break;
434 }
435 }
436do_obj:
437 if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
438 (void) fprintf(fp, "\t{ IMP_OBJ, 0, %s, %s },\n", c_tag(yp), c_class(yp));
439 if (yp->yp_module == NULL
440 || strcmp(yp->yp_module, mymodule) == 0) {
441 if (f == NULL || noindirect(f)) { /* No offset type */
442 prstfield(fp, "OBJECT", t, f,
443 concat("_Z", proc_name(yp->yp_identifier, 0)),
444 c_class(yp));
445 /*
446 (void) fprintf(fp, "\t{ SOBJECT, 0, _Z%s, %s },\n",
447 proc_name(yp->yp_identifier, 0), c_class(yp));
448 */
449 } else
450 prtfield(fp, "OBJECT", t, f,
451 concat("_Z", proc_name(yp->yp_identifier, 0)),
452 c_class(yp));
453 /*
454 (void) fprintf(fp,
455 "\t{ OBJECT, OFFSET(%s, %s), _Z%s, %s },\n",
456 t, f, proc_name(yp->yp_identifier, 0), c_class(yp));
457 */
458 } else {
459 if (f == NULL || noindirect(f)) { /* No offset type */
460 prstfield(fp, "EXTOBJ", t, f,
461 concat("_Z", strp2name(yp->yp_identifier, yp->yp_module)),
462 c_class(yp));
463 /*
464 (void) fprintf(fp, "\t{ SEXTOBJ, 0, _Z%s, %s },\n",
465 strp2name(yp->yp_identifier, yp->yp_module),
466 c_class(yp));
467 */
468 } else
469 prtfield(fp, "EXTOBJ", t, f,
470 concat("_Z", strp2name(yp->yp_identifier, yp->yp_module)),
471 c_class(yp));
472 /*
473 (void) fprintf(fp,
474 "\t{ EXTOBJ, OFFSET(%s, %s), _Z%s, %s },\n",
475 t, f, strp2name(yp->yp_identifier, yp->yp_module),
476 c_class(yp));
477 */
478
479 (void) fprintf(fp, "\t{ EXTMOD, %d, 0, 0 },\n",
480 gen_modref(yp->yp_module));
481 }
482 break;
483
484 case YP_SEQLIST:
485 p1 = NULL;
486 /* support for -h flag */
487 cons_type++;
488 save_ptr = en_ptr;
489 if (yp->yp_varexp == NULL && type != NULL)
490 ferr(1, "tenc_typ:YP_SEQLIST:NULL varexp pointer\n");
491 prcte(fp, type, t, f, yp, "SEQ_START");
492 if (y = yp->yp_type) {
493 char *t1;
494
495 /* compute the type of data */
496 if (yp->yp_param_type) {
497 /* we have a [[ P type ]] specification */
498 if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) {
499 fprintf(stderr,
500 "\ntenc_typ:SEQLIST: can't extract direct type from %s\n",
501 yp->yp_param_type);
502 exit(1);
503 }
504 yp->yp_structname = strdup(t1);
505 } else if (type) {
506 if (yp->yp_declexp == NULL)
507 ferr(1, "tenc_typ:YP_SEQLIST:no declexp\n");
508 yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
509 } else
510 yp->yp_structname = t;
511
512 if (optfield(y)) {
513 (void) fprintf(fp,
514 "\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
515 yp->yp_structname);
516 }
517 tenc_loop(fp, y, id, yp->yp_structname);
518 }
519 (void) fprintf(fp, "\t{ PE_END, 0, 0, 0 },\n");
520 en_ptr = save_ptr;
521 cons_type--;
522 break;
523
524 case YP_SETLIST:
525 p1 = NULL;
526 /* support for -h flag */
527 cons_type++;
528 if (yp->yp_varexp == NULL && type != NULL)
529 ferr(1, "tenc_typ:YP_SETLIST:NULL varexp pointer\n");
530 prcte(fp, type, t, f, yp, "SET_START");
531 if (y = yp->yp_type) {
532 char *t1;
533
534 if (yp->yp_param_type) {
535 /* we have a [[ P type ]] specification */
536 if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) {
537 fprintf(stderr,
538 "\ntenc_typ:SETLIST can't extract direct type from %s\n",
539 yp->yp_param_type);
540 exit(1);
541 }
542 yp->yp_structname = strdup(t1);
543 } else if (type) {
544 if (yp->yp_declexp == NULL)
545 ferr(1, "tenc_typ:YP_SETLIST:no declexp\n");
546 yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
547 } else
548 yp->yp_structname = t;
549 if (optfield(y)) {
550 (void) fprintf(fp,
551 "\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
552 yp->yp_structname);
553 }
554 tenc_loop(fp, y, id, yp->yp_structname);
555 }
556 (void) fprintf(fp, "\t{ PE_END, 0, 0, 0 },\n");
557 en_ptr = save_ptr;
558 cons_type--;
559 break;
560
561 case YP_SEQTYPE:
562 p1 = NULL;
563 cons_type++;
564 save_ptr = en_ptr;
565 prcte(fp, type, t, f, yp, "SEQOF_START");
566 if (y = yp->yp_type) {
567 char *t1;
568
569 if (yp->yp_param_type) {
570 /* we have a [[ P type ]] specification */
571 if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) {
572 fprintf(stderr,
573 "\ntenc_typ:SETLIST can't extract direct type from %s\n",
574 yp->yp_param_type);
575 exit(1);
576 }
577 yp->yp_structname = strdup(t1);
578 } else if (type) {
579 if (yp->yp_declexp == NULL)
580 ferr(1, "tenc_typ:YP_SEQTYPE:no declexp\n");
581 yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
582 } else
583 yp->yp_structname = t;
584 tenc_loop(fp, y, id, yp->yp_structname);
585 }
586 if (yp->yp_flags & YP_CONTROLLED) {
587 char *f1;
588
589 if ((f1 = getfield(yp->yp_control)) == NULLCP) {
590 fprintf(stderr, "\ntenc_typ:SEQ OF: can't extract field from %s\n",
591 yp->yp_control);
592 exit(1);
593 }
594 (void) fprintf(fp, "\t{ PE_END, OFFSET(%s, %s), 0, 0 },\n",
595 yp->yp_structname, f1);
596 } else if (yp->yp_structname != NULL)
597 (void) fprintf(fp, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
598 yp->yp_structname);
599 else
600 (void) fprintf(fp, "\t{ PE_END, 0, 0, 0 },\n");
601 en_ptr = save_ptr;
602 cons_type--;
603 break;
604
605 case YP_SETTYPE:
606 p1 = NULL;
607 cons_type++;
608 save_ptr = en_ptr;
609 prcte(fp, type, t, f, yp, "SETOF_START");
610
611 if (y = yp->yp_type) {
612 char *t1;
613
614 if (yp->yp_param_type) {
615 /* we have a [[ P type ]] specification */
616 if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) {
617 fprintf(stderr,
618 "\ntenc_typ:SETTYPE can't extract direct type from %s\n",
619 yp->yp_param_type);
620 exit(1);
621 }
622 yp->yp_structname = strdup(t1);
623 } else if (type) {
624 if (yp->yp_declexp == NULL)
625 ferr(1, "tenc_typ:YP_SETTYPE:no declexp\n");
626 yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
627 } else
628 yp->yp_structname = t;
629 tenc_loop(fp, y, id, yp->yp_structname);
630 }
631 if (yp->yp_flags & YP_CONTROLLED) {
632 char *f1;
633
634 if ((f1 = getfield(yp->yp_control)) == NULLCP) {
635 fprintf(stderr, "\ntenc_typ:SET OF: can't extract field from %s\n",
636 yp->yp_control);
637 exit(1);
638 }
639 (void) fprintf(fp, "\t{ PE_END, OFFSET(%s, %s), 0, 0 },\n",
640 yp->yp_structname, f1);
641 } else if (yp->yp_structname != NULL)
642 (void) fprintf(fp, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
643 yp->yp_structname);
644 else
645 (void) fprintf(fp, "\t{ PE_END, 0, 0, 0 },\n");
646 en_ptr = save_ptr;
647 cons_type--;
648 break;
649
650 case YP_CHOICE:
651 p1 = NULL;
652 /* support for -h flag */
653 if (hflag && (y = yp->yp_type) && !y->yp_next) {
654 tenc_typ(fp, y, id, yp->yp_structname);
655 break;
656 }
657 cons_type++;
658 save_ptr = en_ptr;
659 if (type == NULL || type && noindirect(f))
660 prstfield(fp, "CHOICE_START", t, f, 0, c_class(yp));
661 else
662 prtfield(fp, "CHOICE_START", t, type ? f : NULLCP, 0, c_class(yp));
663 if (y = yp->yp_type) {
664 char *t1;
665
666 if (yp->yp_param_type) {
667 /* we have a [[ P type ]] specification */
668 if ((t1 = rm_indirect(yp->yp_param_type)) == NULLCP) {
669 fprintf(stderr,
670 "\ntenc_typ:CHOICE can't extract direct type from %s\n",
671 yp->yp_param_type);
672 exit(1);
673 }
674 yp->yp_structname = strdup(t1);
675 } else if (type) {
676 if (yp->yp_declexp == NULL)
677 ferr(1, "tenc_typ:YP_CHOICE:no declexp\n");
678 yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
679 } else
680 yp->yp_structname = t;
681
682 if (yp -> yp_control_act && yp->yp_control_act->yal_enc) {
683 (void) fprintf (fp, "\t{ SCTRL, %d, 0, FL_USELECT },\n",
684 yp -> yp_control_act -> yal_enc -> a_num);
685 }
686 else if (yp->yp_flags & YP_CONTROLLED) {
687 char *f1;
688
689 if ((f1 = getfield(yp->yp_control)) == NULLCP) {
690 fprintf(stderr, "\ntenc_typ:CHOICE: can't extract field from %s\n",
691 yp->yp_control);
692 exit(1);
693 }
694 (void) fprintf(fp, "\t{ SCTRL, OFFSET(%s, %s), 0, 0 },\n",
695 yp->yp_structname, f1);
696 } else if (yp->yp_structname != NULL)
697 (void) fprintf(fp, "\t{ SCTRL, OFFSET(%s, offset), 0, 0 },\n",
698 yp->yp_structname);
699 else
700 ferr(1, "\nCHOICE missing SCTRL\n");
701 tenc_loop(fp, y, id, yp->yp_structname);
702 }
703 (void) fprintf(fp, "\t{ PE_END, 0, 0, 0 },\n");
704 en_ptr = save_ptr;
705 cons_type--;
706 break;
707
708 default:
709 ferrd(1, "tenc_typ: yp_code = %d not implemented\n", yp->yp_code);
710 }
711
712 if (p1 != NULL)
713 prnte(fp, t, f, yp, p1);
714
715 if (yp->yp_aft_alist && yp->yp_aft_alist->yal_enc)
716 gen_act(fp, yp->yp_aft_alist->yal_enc);
717
718}
719
720static int fflags[] = {
721 0, 1, 2, 2, 3, 3, 4, 5, 16, 16, 16, 17, 17, 17,
7220, -1, 6, 0, 10, 9};
723
724/*
725 * calculate the tag string of the given type and return it
726 */
727char *
728c_tag(yp)
729YP yp;
730{
731 static char buf[WORDSIZE];
732 int i;
733
734 if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT) {
735 i = yp->yp_tag->yt_value->yv_number;
736 } else {
737 if (yp->yp_code < 0 || yp->yp_code > YP_REAL
738 || yp->yp_code == YP_CHOICE)
739 i = 0;
740 else
741 i = fflags[yp->yp_code];
742 /* Choice now legal argument - to allow prte_* routines to work */
743 if (i == 0 && yp->yp_code != YP_CHOICE)
744 ferrd (1, "c_tag:Unknown Tag %d", yp->yp_code);
745 }
746
747 (void) sprintf(buf, "%d", i);
748
749 return (buf);
750}
751
752/*
753 * calculate the tag string of the explicit tag and return it
754 */
755char *
756ec_tag(yp)
757YP yp;
758{
759 static char buf[WORDSIZE];
760 int i;
761
762 if (!(yp->yp_flags & YP_TAG) || yp->yp_flags & YP_IMPLICIT)
763 ferr(1, "ec_tag:internal error:called with out explicit tag\n");
764
765 i = yp->yp_tag->yt_value->yv_number;
766
767 (void) sprintf(buf, "%d", i);
768
769 return (buf);
770}
771
772/*
773 * produce a string that represents the class/flags field for a given
774 * yp entry taking the class to be that given in cl
775 */
776char *
777c_flags(yp, cl)
778YP yp;
779int cl;
780{
781 char *p1;
782 static char buf[STRSIZE];
783
784 switch (yp->yp_code) {
785 case YP_IDEFINED:
786 case YP_CHOICE:
787 if (yp->yp_flags & YP_TAG)
788 break;
789 if (yp->yp_flags & YP_OPTIONAL
790 && ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT))
791 != (YP_OPTIONAL|YP_OPTCONTROL))) {
792 p1 = "FL_OPTIONAL";
793 } else if (yp->yp_flags & YP_DEFAULT) {
794 p1 = "FL_DEFAULT";
795 } else
796 p1 = "0";
797 return (p1);
798
799 default:
800 break;
801 }
802 p1 = class2str(cl);
803 if (yp->yp_flags & YP_OPTIONAL
804 && ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT))
805 != (YP_OPTIONAL|YP_OPTCONTROL))) {
806 strncpy(buf, p1, STRSIZE);
807 p1 = strncat(buf, "|FL_OPTIONAL", STRSIZE);
808 } else if (yp->yp_flags & YP_DEFAULT) {
809 strncpy(buf, p1, STRSIZE);
810 p1 = strncat(buf, "|FL_DEFAULT", STRSIZE);
811 }
812 return (p1);
813}
814/*
815 * turn the class number into its corresponding string
816 */
817char *
818class2str(cl)
819int cl;
820{
821 register char *p1;
822
823 switch (cl) {
824 case PE_CLASS_UNIV:
825 p1 = "FL_UNIVERSAL";
826 break;
827
828 case PE_CLASS_APPL:
829 p1 = "FL_APPLICATION";
830 break;
831
832 case PE_CLASS_PRIV:
833 p1 = "FL_PRIVATE";
834 break;
835
836 case PE_CLASS_CONT:
837 p1 = "FL_CONTEXT";
838 break;
839
840 default:
841 ferrd(1, "class2str: illegal class found %d\n", cl);
842
843 }
844 return (p1);
845}
846
847/*
848 * calculate a string specifying the class for the given type and
849 * return it
850 */
851char *
852c_class(yp)
853YP yp;
854{
855 int i;
856
857 if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT) {
858 i = yp->yp_tag->yt_class;
859 } else {
860 i = PE_CLASS_UNIV;
861 }
862 return (c_flags(yp, i));
863
864}
865/*
866 * calculate a string specifying the class for the explicit tag and
867 * return it
868 */
869char *
870ec_class(yp)
871YP yp;
872{
873 int i;
874 char *p1;
875 static char buf[STRSIZE];
876
877 if (!(yp->yp_flags & YP_TAG) || yp->yp_flags & YP_IMPLICIT)
878 ferr(1, "ec_class:internal error:called with out explicit tag\n");
879 switch (yp->yp_code) {
880 case YP_IDEFINED:
881 case YP_CHOICE:
882 if (yp->yp_flags & YP_TAG)
883 break;
884 if (yp->yp_flags & YP_OPTIONAL
885 && ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT))
886 != (YP_OPTIONAL|YP_OPTCONTROL))) {
887 p1 = "FL_OPTIONAL";
888 } else if (yp->yp_flags & YP_DEFAULT) {
889 p1 = "FL_DEFAULT";
890 } else
891 p1 = "0";
892 return (p1);
893
894 default:
895 break;
896 }
897
898 i = yp->yp_tag->yt_class;
899
900 switch (i) {
901 case PE_CLASS_UNIV:
902 p1 = "FL_UNIVERSAL";
903 break;
904
905 case PE_CLASS_APPL:
906 p1 = "FL_APPLICATION";
907 break;
908
909 case PE_CLASS_PRIV:
910 p1 = "FL_PRIVATE";
911 break;
912
913 case PE_CLASS_CONT:
914 p1 = "FL_CONTEXT";
915 break;
916
917 default:
918 ferrd(1, "c_class: illegal class found %d\n", i);
919
920 }
921 if ((yp->yp_flags & YP_OPTIONAL)
922 && ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT))
923 != (YP_OPTIONAL|YP_OPTCONTROL))) {
924 strncpy(buf, p1, STRSIZE);
925 p1 = strncat(buf, "|FL_OPTIONAL", STRSIZE);
926 } else if (yp->yp_flags & YP_DEFAULT) {
927 strncpy(buf, p1, STRSIZE);
928 p1 = strncat(buf, "|FL_DEFAULT", STRSIZE);
929 }
930 return (p1);
931}
932
933/*
934 * generate tables for encoding a contructed type
935 */
936tenc_loop(fp, yp, id, type)
937FILE *fp;
938YP yp;
939char *id;
940char *type;
941{
942 for (; yp != NULL; yp = yp->yp_next) {
943 tenc_typ(fp, yp, id, type);
944 }
945}
946
947/*
948 * Print the string and exit if argument greater than zero
949 */
950ferr(i, s)
951int i;
952char *s;
953{
954 (void) fprintf(stderr, "%s", s);
955 if (i > 0)
956 exit(i);
957}
958
959/*
960 * Print the integer and exit if argument greater than zero
961 */
962ferrd(i, s, d)
963int i;
964char *s;
965int d;
966{
967 (void) fprintf(stderr, s, d);
968 if (i > 0)
969 exit(i);
970}
971
972/*
973 * Print the string and exit if argument greater than zero
974 */
975ferrs(i, s, d)
976int i;
977char *s;
978char *d;
979{
980 (void) fprintf(stderr, s, d);
981 if (i > 0)
982 exit(i);
983}
984
985/*
986 * return a copy of the string s minus its last character
987 */
988char *
989strip_last(s)
990char *s;
991{
992 char *t, *r;
993
994 if (s) {
995 t = new_string(s);
996 for (r = t; *r != '\0'; r++);
997 ;
998 *--r = '\0';
999 return t;
1000 } else
1001 return NULL;
1002}
1003
1004/*
1005 * add the declaration specified by the strings type and id to the
1006 * start of the declaration list
1007 */
1008add_list(type, id)
1009char *type, *id;
1010{
1011
1012 s_table *prev;
1013
1014 if ((prev = (s_table *) malloc(sizeof(s_table))) == NULL)
1015 ferr(1, "add_list: Out of memory\n");
1016 prev->type = type;
1017 prev->name = id;
1018 prev->parent = NULL;
1019 prev->defined = 0;
1020 prev->next = head;
1021 head = prev;
1022}
1023
1024/*
1025 * print the declaration list
1026 */
1027print_list()
1028{
1029 s_table *prev;
1030
1031 for (prev = head; prev != NULL; prev = prev->next) {
1032 (void) printf("type is %s\n", prev->type);
1033 (void) printf("name is %s\n", prev->name);
1034 (void) printf("\n");
1035 }
1036}
1037
1038/*
1039 * parse the declaration in the string s returning the type in v1 and
1040 * the name in v2
1041 */
1042parse_decl(s, v1, v2)
1043char **s, **v1, **v2;
1044{
1045 char *t;
1046
1047 for (t = *s; *t != '\0' && !(isalnum(*t) || *t == '_'); t++);
1048
1049 *s = t;
1050 if (*t != '\0') {
1051 for (; *t != '*'; t++);
1052 *t = '\0';
1053 *v1 = my_strcat(*s, "*");
1054 Printf(3, ("the type is %s\n", *v1));
1055 if (*++t == '*')
1056 t++;
1057 for (*s = t; isalnum(*t) || *t == '_'; t++);
1058 if (*t != '\0') {
1059 *t = '\0';
1060 t++;
1061 }
1062 *v2 = new_string(*s); /* don't really need new_string */
1063 Printf(2, ("the name is %s\n", *v2));
1064 *s = t;
1065 }
1066}
1067
1068/*
1069 * return the next identifier in the string s
1070 */
1071char *
1072get_val(s)
1073char **s;
1074{
1075 char *t, *r;
1076
1077 for (t = *s; *t != '\0' && !(isalnum(*t) || *t == '_' || *t == '.'); t++);
1078
1079 if (*t != '\0') {
1080 for (*s = t; isalnum(*t) || *t == '_' || *t == '.'; t++);
1081 *t = '\0';
1082 r = *s;
1083 Printf(3, ("arg is |%s|\n", r));
1084 *s = ++t;
1085 return r;
1086 } else
1087 return NULL;
1088}
1089
1090/*
1091 * return the next component (sequence of characters up to the next
1092 * ';' or '\0') of the string s
1093 */
1094char *
1095get_comp(s)
1096char **s;
1097{
1098 char *t, *r;
1099
1100 for (t = *s; *t != '\0' && !(isalnum(*t) || *t == '_' || *t == ';'); t++);
1101
1102 if (*t != '\0') {
1103 for (*s = t; *t != '\0' && *t != ';'; t++);
1104 *t = '\0';
1105 r = *s;
1106 Printf(3, ("component is |%s|\n", r));
1107 *s = ++t;
1108 return r;
1109 } else
1110 return NULL;
1111}
1112
1113/*
1114 * return a copy of that part of the string s which may contain
1115 * definitions for the variables generated by posy
1116 */
1117char *
1118get_string(s, direction)
1119char *s;
1120int direction;
1121{
1122 char *t, *t1;
1123
1124 if (direction & YP_ENCODER)
1125 return new_string(s);
1126 if (direction & YP_DECODER) {
1127 t = new_string(s);
1128 for (t1 = t; !(isalnum(*t1) || *t1 == '_'); t1++);
1129 if (*t1 == 'i' && *++t1 == 'f' && *++t1 == ' ') { /* MEMALLOC code */
1130 for (; *t1 != '}'; t1++) /* skip MEMALLOC code */
1131 ;
1132 t1++;
1133 Printf(4, ("returning the string %s\n", t1));
1134 return t1;
1135 } else
1136 return t;
1137 }
1138}
1139
1140/*
1141 * Determine wether this list contains any items that will generate
1142 * an optional field. If so return non zero
1143 */
1144optfield(yp)
1145YP yp;
1146{
1147 for (; yp; yp = yp->yp_next) {
1148 if (yp->yp_flags & YP_OPTIONAL) {
1149
1150 if ((yp->yp_flags & (YP_OPTIONAL|YP_OPTCONTROL|YP_DEFAULT))
1151 == (YP_OPTIONAL|YP_OPTCONTROL))
1152 return (0);
1153
1154 switch (yp->yp_code) {
1155 case YP_BOOL:
1156 case YP_INT:
1157 case YP_INTLIST:
1158 case YP_ENUMLIST:
1159 case YP_NULL:
1160 return (1);
1161 }
1162 }
1163 }
1164 return (0);
1165}
1166
1167gen_dflts(fp, yp, type)
1168YP yp;
1169char *type;
1170{
1171 YP y;
1172
1173 if (yp == NULL)
1174 return;
1175 switch (yp->yp_code) {
1176 case YP_IDEFINED:
1177 break;
1178
1179 case YP_CHOICE:
1180 case YP_SEQTYPE:
1181 case YP_SETTYPE:
1182 case YP_SEQLIST:
1183 case YP_SETLIST:
1184 for (y = yp->yp_type; y != NULL; y = y->yp_next) {
1185 gen_dflts(fp, y, type);
1186 }
1187 break;
1188
1189 default:
1190 break;
1191 }
1192 /* Output definitions for default entries */
1193 if (yp->yp_flags & YP_DEFAULT)
1194 defdflt(fp, yp, type);
1195
1196 if (yp->yp_yfn)
1197 declfns(fp, yp->yp_yfn);
1198}
1199/*
1200 * Compute the concatenation into a temporary buffer of two strings
1201 * after having run notid on them first
1202 */
1203char *
1204strp2name(s1, s2)
1205char *s1, *s2;
1206{
1207 char *p;
1208 static char buf[STRSIZE * 2 + 5];
1209
1210 if (strlen(s1) > STRSIZE || strlen(s2) > STRSIZE)
1211 ferr(1, "strp2name:string to big\n");
1212 strcpy(buf, p = notidtoid(s1));
1213 free(p);
1214 strcat(buf, p = notidtoid(s2));
1215 free(p);
1216
1217 return (buf);
1218}
1219
1220/*
1221 * Output the definitions for default entries and initialise the yp's
1222 * to have pointers which reference these definitions for use by
1223 * gdflt routine.
1224 */
1225defdflt(fp, yp, name)
1226YP yp;
1227char *name;
1228{
1229 YV yv;
1230 YV yv1;
1231 SY sy;
1232 YP yp1;
1233 int size, i;
1234 char *str;
1235 char *label;
1236 struct univ_typ *p;
1237 int code;
1238
1239 if ((yp->yp_flags & YP_DEFAULT) == 0)
1240 ferrd(1, "defdflt:called with out a default code = %d\n", yp->yp_code);
1241 yv = yp->yp_default;
1242
1243 yp1 = yp;
1244
1245 /* Find the bottom definition */
1246 code = yp1->yp_code;
1247 while (code == YP_IDEFINED) {
1248 if ((sy = syfind(yp1->yp_identifier)) == NULL) {
1249 if ((p = univtyp(yp1->yp_identifier)) == NULL
1250 || p->univ_type <= YP_UNDF)
1251 ferrs(1,
1252 "defdflt:IDEFINED:cannot find definition of symbol %s\n",
1253 yp1->yp_identifier);
1254 code = p->univ_type;
1255 break;
1256
1257 }
1258 yp1 = sy->sy_type;
1259 code = yp1->yp_code;
1260 }
1261
1262 switch (code) {
1263 case YP_BOOL:
1264 case YP_INT:
1265 case YP_INTLIST:
1266 case YP_ENUMLIST:
1267 switch (yv->yv_code) {
1268 case YV_NUMBER:
1269 case YV_BOOL:
1270 /* None needed */
1271 break;
1272
1273 case YV_IDEFINED:
1274 if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1275 ferrs(1, "defdflt:BOOL/INT:cannot find definition of %s\n",
1276 yv->yv_identifier);
1277 }
1278 /* None Needed */
1279 break;
1280
1281 default:
1282 ferrd(1, "defdflt:INT/BOOL:unimplemented value code = %d\n",
1283 yv->yv_code);
1284 }
1285 break;
1286
1287 case YP_REAL:
1288 switch (yv->yv_code) {
1289 case YV_REAL:
1290 yv1 = yv;
1291 goto dumpdef3;
1292
1293 case YV_IDEFINED:
1294 if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1295 ferrs(1, "defdflt:REAL:cannot find definition of %s\n",
1296 yv->yv_identifier);
1297 }
1298 goto dumpdef3;
1299 break;
1300
1301 default:
1302 ferrd(1, "defdflt:REAL:unimplemented value code = %d\n",
1303 yv->yv_code);
1304 }
1305 break;
1306
1307 case YP_BIT:
1308 case YP_BITLIST:
1309 switch (yv->yv_code) {
1310 /*
1311 * This is an illegal value for a bit string ! - BUT ACSE
1312 * uses it !
1313 */
1314 /* gdflt also patched to support it */
1315 case YV_IDEFINED:
1316 ferrs(0,
1317 "warning:bitstring default specified illegally with identifier %s\n",
1318 yv->yv_identifier);
1319 if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1320 ferrs(1, "defdflt:BIT:cannot find definition of %s\n",
1321 yv->yv_identifier);
1322 }
1323 /* doesn't work fix posy-yacc.y */
1324 size = numtobstr(yv1, &str);
1325 goto dumpdef1;
1326
1327 case YV_NUMBER:
1328 size = numtobstr(yv, &str);
1329 goto dumpdef1;
1330
1331 case YV_VALIST:
1332 if ((size = valisttobs(yp1, yv, &str)) < 0) {
1333 ferrs(1, "defdflt:bad default value for bit string %s\n",
1334 yp->yp_flags & YP_ID ? yp->yp_identifier : "");
1335 }
1336 goto dumpdef1;
1337
1338 case YV_HSTRING:
1339 str = yv->yv_xstring;
1340 size = yv->yv_xlength*4;
1341 goto dumpdef1;
1342
1343 case YV_BSTRING:
1344 str = yv->yv_xstring;
1345 size = yv->yv_xlength;
1346 goto dumpdef1;
1347
1348 default:
1349 /* Could be a syntax error */
1350 ferrd(1, "defdflt:BIT:illegal value code = %d\n", yv->yv_code);
1351 }
1352 break;
1353
1354 case YP_IDEFINED:
1355 ferrs(1, "defdflt:IDEFINED:internal error on symbol %s\n",
1356 yp1->yp_identifier);
1357 break;
1358
1359 case YP_OCT:
1360 switch (yv->yv_code) {
1361 case YV_NUMBER:
1362 size = numtobstr(yv, &str);
1363 goto dumpdef2;
1364
1365 case YV_STRING:
1366 str = yv->yv_string;
1367 size = strlen(str);
1368 goto dumpdef2;
1369
1370 case YV_HSTRING:
1371 str = yv->yv_xstring;
1372 size = (yv->yv_xlength + 1)/2;
1373 goto dumpdef2;
1374
1375 case YV_BSTRING:
1376 str = yv->yv_xstring;
1377 size = (yv->yv_xlength + 7)/8; /* round up */
1378 goto dumpdef2;
1379
1380 default:
1381 /* Could be a syntax error */
1382 ferrd(1, "defdflt:OCT:illegal value code = %d\n", yv->yv_code);
1383 }
1384 break;
1385
1386 case YP_NULL:
1387 case YP_SEQ:
1388 case YP_SEQTYPE:
1389 case YP_SEQLIST:
1390 case YP_SET:
1391 case YP_SETTYPE:
1392 case YP_SETLIST:
1393 case YP_CHOICE:
1394 case YP_ANY:
1395 case YP_OID:
1396 /* None yet */
1397 break;
1398
1399 default:
1400 ferrd(1, "defdflt:unknown type %d\n", code);
1401 }
1402
1403 return;
1404
1405dumpdef1: /* Bitstrings */
1406 label = genlabel(name, yp);
1407 yp->yp_action0 = label;
1408 yp->yp_act0_lineno = size;
1409 i = (size + NBPC - 1) / NBPC;
1410 (void) fprintf(fp, "\nstatic char %s[] = ", label);
1411 if (printable(str, i))
1412 prstr(fp, str, i);
1413 else
1414 prhstr(fp, str, i);
1415 (void) fprintf(fp, ";\n");
1416 return;
1417
1418dumpdef2: /* Octet strings (and aliases) */
1419 label = genlabel(name, yp);
1420 yp->yp_action0 = label;
1421 yp->yp_act0_lineno = size;
1422 (void) fprintf(fp, "\nstatic char %s[] = ", label);
1423 if (printable(str, size))
1424 prstr(fp, str, size);
1425 else
1426 prhstr(fp, str, size);
1427 (void) fprintf(fp, ";\n");
1428 return;
1429
1430dumpdef3: /* Reals */
1431 label = genlabel(name, yp);
1432 yp->yp_action0 = label;
1433 (void) fprintf(fp, "\nstatic double %s = %f;\n", label, yv1->yv_real);
1434 return;
1435
1436}
1437/*
1438 * generate the default entry for encoding/decoding fields. This
1439 * should contain the default value which the encoder will know means
1440 * default encoding
1441 */
1442gdflt(fp, yp, which)
1443FILE *fp;
1444YP yp;
1445int which; /* Which type of entries to generate
1446 * G_ENC encode G_DEC decode */
1447{
1448 YV yv;
1449 YV yv1;
1450 SY sy;
1451 YP yp1;
1452 int size;
1453 char *str;
1454
1455 char *ndflt;
1456 struct univ_typ *p;
1457 int code;
1458
1459
1460 if (which == G_ENC)
1461 ndflt = "DFLT_F";
1462 else
1463 ndflt = "DFLT_B";
1464
1465 if ((yp->yp_flags & YP_DEFAULT) == 0)
1466 ferrd(1, "gdflt:called with out a default code = %d\n", yp->yp_code);
1467 yv = yp->yp_default;
1468
1469 yp1 = yp;
1470
1471 /* Find the bottom definition */
1472 code = yp1->yp_code;
1473 while (code == YP_IDEFINED) {
1474 if ((sy = syfind(yp1->yp_identifier)) == NULL) {
1475 if ((p = univtyp(yp1->yp_identifier)) == NULL
1476 || p->univ_type <= YP_UNDF)
1477 ferrs(1,
1478 "gdflt:IDEFINED:cannot find definition of symbol %s\n",
1479 yp1->yp_identifier);
1480 code = p->univ_type;
1481 break;
1482
1483 }
1484 yp1 = sy->sy_type;
1485 code = yp1->yp_code;
1486 }
1487
1488 switch (code) {
1489 case YP_BOOL:
1490 case YP_INT:
1491 case YP_INTLIST:
1492 case YP_ENUMLIST:
1493 switch (yv->yv_code) {
1494 case YV_NUMBER:
1495 case YV_BOOL:
1496 (void) fprintf(fp, "\t{ %s, %d, 0, 0 },\n", ndflt,
1497 yp->yp_default->yv_number);
1498 break;
1499
1500 case YV_IDEFINED:
1501 if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1502 ferrs(1, "gdflt:BOOL/INT:cannot find definition of %s\n",
1503 yv->yv_identifier);
1504 }
1505 (void) fprintf(fp, "\t{ %s, %d, 0, 0 },\n", ndflt,
1506 yv1->yv_number);
1507 break;
1508
1509 default:
1510 ferrd(1, "gdflt:INT/BOOL:unimplemented value code = %d\n",
1511 yv->yv_code);
1512 }
1513 break;
1514
1515 case YP_BIT:
1516 case YP_BITLIST:
1517 switch (yv->yv_code) {
1518#ifdef ILLEGAL_DEFAULTS
1519 case YV_IDEFINED: /* supporting illegal default
1520 * specification */
1521#endif
1522 case YV_NUMBER:
1523 case YV_HSTRING:
1524 case YV_BSTRING:
1525 case YV_VALIST:
1526 (void) fprintf(fp, "\t{ %s, %d, %d, 0 },\n", ndflt,
1527 yp->yp_act0_lineno, addptr(yp->yp_action0));
1528 break;
1529
1530 default:
1531 /* Could be a syntax error */
1532 ferrd(1, "gdflt:BIT:illegal value code = %d\n", yv->yv_code);
1533 }
1534 break;
1535
1536 case YP_IDEFINED:
1537 ferrs(1, "gdflt:IDEFINED:internal error on symbol %s\n",
1538 yp1->yp_identifier);
1539 break;
1540
1541 case YP_REAL:
1542 switch (yv->yv_code) {
1543#ifdef ILLEGAL_DEFAULTS
1544 case YV_IDEFINED: /* Illegal according to ASN.1 but we can do it
1545 * so why not support it
1546 */
1547#endif
1548 case YV_REAL:
1549 (void) fprintf(fp, "\t{ %s, 0, %d, 0 },\n", ndflt,
1550 addptr(concat("&", yp->yp_action0)));
1551 break;
1552
1553 default:
1554 /* Could be a syntax error */
1555 ferrd(1, "gdflt:REAL:illegal value code = %d\n", yv->yv_code);
1556 }
1557 break;
1558
1559 case YP_OCT:
1560 switch (yv->yv_code) {
1561 case YV_NUMBER:
1562 case YV_STRING:
1563 case YV_HSTRING:
1564 case YV_BSTRING:
1565 (void) fprintf(fp, "\t{ %s, %d, %d, 0 },\n", ndflt,
1566 yp->yp_act0_lineno, addptr(yp->yp_action0));
1567 break;
1568
1569 default:
1570 /* Could be a syntax error */
1571 ferrd(1, "gdflt:OCT:illegal value code = %d\n", yv->yv_code);
1572 }
1573 break;
1574
1575 case YP_NULL:
1576 case YP_SEQ:
1577 case YP_SEQTYPE:
1578 case YP_SEQLIST:
1579 case YP_SET:
1580 case YP_SETTYPE:
1581 case YP_SETLIST:
1582 case YP_CHOICE:
1583 case YP_ANY:
1584 case YP_OID:
1585 (void) fprintf(fp, "\t{ %s, 0, 0, 0 },\n", ndflt);
1586 break;
1587
1588 default:
1589 ferrd(1, "gdflt:unknown type %d\n", yp->yp_code);
1590 }
1591
1592}
1593/*
1594 * Calculate the value associated with the given identifier id by
1595 * looking at the value definitions associated with type definition
1596 * yp. Returns the value definition if found or NULL if not.
1597 */
1598YV
1599calc_yv(yp, id)
1600YP yp;
1601char *id;
1602{
1603 YV yv;
1604
1605 for (yv = yp->yp_value; yv != NULL; yv = yv->yv_next) {
1606 if (yv->yv_flags & YV_NAMED && strcmp(yv->yv_named, id) == 0)
1607 return (yv);
1608 }
1609
1610 return (NULL);
1611}
1612
1613/*
1614 * ******* This does not work. posy needs to be fixed for case of
1615 * '01'b ***** Turn a Literal number value in yv into a bistring
1616 * initialisation. Return the length of the bit string or less than
1617 * zero on error. Set the (char *) pointer, whose address is in
1618 * ppstr, to point to a string containing the a reference to a
1619 * character array which contains the bits.
1620 */
1621
1622numtobstr(yv, ppstr)
1623YV yv;
1624char **ppstr;
1625{
1626
1627 int ibits, lastb, i;
1628 char *buf;
1629
1630 buf = malloc(NBPI / NBPC + 1);
1631 bzero(buf, NBPI / NBPC + 1);
1632 lastb = -1;
1633 ibits = yv->yv_number;
1634 for (i = 0; i < NBPI; i++) {
1635 if ((1 << i) & ibits) {
1636 buf[i / NBPC] |= 1 << (NBPC - 1 - (i % NBPC));
1637 lastb = i;
1638 }
1639 }
1640
1641 *ppstr = buf;
1642 return (lastb + 1);
1643}
1644#define ROUNDUP 10
1645/*
1646 * Take a list of Values (YV_VALIST) which should contain a list of
1647 * bits and convert them into a bitstring initialisation. As in
1648 * numtobstr return the size of the bit string or a negative number
1649 * if there is an error. Put a reference to a character array which
1650 * contains the definition of the bits in the character pointer whose
1651 * address is in ppstr. yp is the definition of the type which
1652 * contains the names of all the defined bits.
1653 */
1654valisttobs(yp, yv, ppstr)
1655YP yp;
1656YV yv;
1657char **ppstr;
1658{
1659
1660 YV yv1, yv2;
1661 int lastb, val, nsize, size;
1662 char *buf;
1663
1664 lastb = -1;
1665 size = ROUNDUP;
1666 if ((buf = malloc(size)) == NULL) {
1667 ferrd(1, "valisttobs:malloc:failed on %d\n", size);
1668 }
1669 bzero(buf, size);
1670 for (yv1 = yv->yv_idlist; yv1 != NULL; yv1 = yv1->yv_next) {
1671 if ((yv2 = calc_yv(yp, yv1->yv_identifier)) == NULL) {
1672 return (-1);
1673 }
1674 val = yv2->yv_number;
1675 /* Bug here probably */
1676 if (size < val / NBPC) {
1677 nsize = val / NBPC + ROUNDUP;
1678 if ((buf = realloc(buf, nsize)) == NULL) {
1679 ferrd(1, "valisttobs:realloc:failed on %d\n", nsize);
1680 }
1681 bzero(buf + size, nsize - size);
1682 size = nsize;
1683 }
1684 buf[val / NBPC] |= 1 << (NBPC - 1 - (val % NBPC));
1685 if (val > lastb)
1686 lastb = val;
1687 }
1688 *ppstr = buf;
1689 return (lastb + 1);
1690}
1691/*
1692 * Print the string out in a format acceptable as a quoted string in
1693 * a C program including the quotes. Using \ escapes for unprintable
1694 * characters
1695 */
1696prstr(fp, str, len)
1697FILE *fp;
1698char *str;
1699int len;
1700{
1701 (void) fputc('"', fp);
1702 while (len-- > 0) {
1703 if (isprint(*str & 0xff)) {
1704 (void) fputc(*str & 0xff, fp);
1705 str++;
1706 continue;
1707 }
1708 (void) fprintf(fp, "\\%0o", *str & 0xff);
1709 }
1710 (void) fputc('"', fp);
1711#define MAXPLINE 16
1712}
1713/*
1714 * output a initialisation for a character array as unsigned hex
1715 * numbers
1716 */
1717prhstr(fp, str, len)
1718FILE *fp;
1719char *str;
1720int len;
1721{
1722 int npline; /* number on this line */
1723
1724 (void) fprintf(fp, "{\n");
1725 npline = 0;
1726 while (len > 0) {
1727 if (npline >= MAXPLINE) {
1728 (void) fputc('\n', fp);
1729 npline = 0;
1730 }
1731 npline++;
1732 (void) fprintf(fp, " 0x%02x,", *str++ & 0xff);
1733 len--;
1734 }
1735 (void) fprintf(fp, "}");
1736}
1737/*
1738 * determine if the string is printable i.e. only sensible to be read
1739 * as a character string. 1 (true) if it is 0, if it isn't
1740 */
1741printable(str, i)
1742char *str;
1743int i;
1744{
1745 while (i-- > 0) {
1746 if (!isprint(*str & 0xff))
1747 return (0); /* look for the first non printable
1748 * character */
1749 str++;
1750 }
1751 return (1);
1752}
1753/*
1754 * generate a unique identifier using the name given and the name if
1755 * present in yp. Return a pointer to it in a space malloc'ed out
1756 */
1757char *
1758genlabel(name, yp)
1759char *name;
1760YP yp;
1761{
1762 char buf[MAXNAME];
1763 static int cnt;
1764 char *p1, *p2;
1765
1766 p1 = notidtoid(name);
1767 if (yp->yp_flags & YP_ID) {
1768 p2 = notidtoid(yp->yp_id);
1769 (void) sprintf(buf, "L%s_%s_%d", p1, p2, cnt++);
1770 free(p2);
1771 } else
1772 (void) sprintf(buf, "L%s_X_%d", p1, cnt++);
1773 free(p1);
1774
1775 return (my_new_str(buf));
1776}
1777/*
1778 * generate a ptr table reference for the given module table entry
1779 */
1780gen_modref(mod)
1781char *mod;
1782{
1783 char buf[BUFSIZ];
1784 char *p1;
1785 int ind;
1786
1787 p1 = notidtoid(mod);
1788 (void) sprintf(buf, "&%s%s%s", PREFIX, p1, MODTYP_SUFFIX);
1789 ind = addptr(buf);
1790 free(p1);
1791
1792 return (ind);
1793}
1794
1795char *
1796setfield(p)
1797char *p;
1798{
1799 char *f;
1800
1801 if ((f = getfield(p)) == NULLCP) {
1802 fprintf(stderr, "\nsetfield: can't extract field from %s\n", p);
1803 exit(1);
1804 }
1805 return (strdup(f));
1806}
1807
1808/*
1809 * print a normal table entry
1810 */
1811prnte(fp, t, f, yp, p1)
1812FILE *fp;
1813char *t; /* parent type */
1814char *f; /* field name */
1815YP *yp; /* object */
1816char *p1; /* table entry name */
1817{
1818 if (p1 == NULL)
1819 ferr(1, "prnte: called with a NULL p1\n");
1820
1821 if (t && noindirect(f))
1822 prstfield(fp, p1, t, f, c_tag(yp), c_class(yp));
1823 else
1824 prtfield(fp, p1, t, f, c_tag(yp), c_class(yp));
1825}
1826
1827/*
1828 * generate the entry allowing for defined types and then call the given
1829 * function to generate the base entry
1830 * Algorithm:
1831 * If we can find the base type
1832 * i) generate any ETAG that subsequent definitions might have
1833 * ii) call the function to generate the base entry
1834 * iii) and the function checks that it matches the type of the value pass
1835 * else - can't find the base type - probably because it is external
1836 * i) generate a warning and exit
1837 */
1838gen_identry(fp, t, f, yp, fn)
1839FILE *fp;
1840char *t, *f;
1841YP yp;
1842int (*fn)();
1843{
1844 YP yp1;
1845 int code;
1846 SY sy;
1847 YT pd_yt = NULLYT; /* Passed down tag if any */
1848 YT yt;
1849 struct univ_typ *p = NULL;
1850 char *flags; /* the flags if any which each subtype must have */
1851 int save_flags;
1852
1853 yp1 = yp;
1854 code = yp1->yp_code;
1855
1856 if (yp->yp_flags & YP_OPTIONAL)
1857 flags = "|FL_OPTIONAL";
1858 else if (yp->yp_flags & YP_DEFAULT)
1859 flags = "|FL_DEFAULT";
1860 else
1861 flags = "";
1862
1863 /* any explicit tag for original yp type is handled before this
1864 * routine is called so don't call gen_etag for it here
1865 * but we do need to initialise pd_yt for the case of an IMPLICIT TAG.
1866 */
1867 if ((yp->yp_flags & (YP_TAG|YP_IMPLICIT))== (YP_TAG|YP_IMPLICIT))
1868 pd_yt = yp->yp_tag;
1869
1870 while (code == YP_IDEFINED) {
1871 if ((sy = syfind(yp1->yp_identifier)) == NULL) {
1872 if ((p = univtyp(yp1->yp_identifier)) == NULL
1873 || p->univ_type <= YP_UNDF)
1874 ferrs(1,
1875 "\ngen_identry:symbol %s is not defined in this file:\npepsy cannot support value passing for this type, sorry\n",
1876 yp1->yp_identifier);
1877 code = p->univ_type;
1878 break;
1879
1880 }
1881 yp1 = sy->sy_type;
1882 /* check for Explicit tags & generate ETAG entries */
1883 pd_yt = gen_etag(fp, pd_yt, yp1, flags);
1884 code = yp1->yp_code;
1885 }
1886
1887 if (p) {
1888 /* how do we check type is consistent with value passed ? */
1889 yp1 = new_type(code, -1);
1890
1891 yp1->yp_flags |= yp->yp_flags & (YP_OPTIONAL|YP_DEFAULT);
1892
1893 if (pd_yt == NULLYT) {
1894 yp1->yp_tag = new_tag(p->univ_class);
1895 yp1->yp_tag->yt_value = new_value(YV_NUMBER);
1896 yp1->yp_tag->yt_value->yv_number = p->univ_id;
1897 } else
1898 yp1->yp_tag = pd_yt;
1899 yp1->yp_flags |= YP_TAG|YP_IMPLICIT;
1900
1901 (*fn)(fp, yp, yp1, t, f);
1902
1903 /* lets free the yp1 allocated above */
1904 if (pd_yt == NULLYT) {
1905 free(yp1->yp_tag->yt_value);
1906 free(yp1->yp_tag);
1907 }
1908 free(yp1);
1909
1910 return;
1911 }
1912 /* check type is consistent with value passed some where??*/
1913
1914 save_flags = yp1->yp_flags;
1915 yp1->yp_flags |= yp->yp_flags & (YP_OPTIONAL|YP_DEFAULT);
1916
1917 if (pd_yt) {
1918 yt = yp1->yp_tag;
1919 yp1->yp_tag = pd_yt;
1920 yp1->yp_flags |= YP_TAG|YP_IMPLICIT;
1921 }
1922
1923 (*fn)(fp, yp, yp1, t, f);
1924
1925 if (pd_yt) { /* restore the tag for later */
1926 yp1->yp_tag = yt;
1927 }
1928 yp1->yp_flags = save_flags;
1929
1930}
1931
1932/*
1933 * generate the ETAG entry if needed for following the given defined type
1934 * down to what it is. Given that its use above has an IMPLICIT tag pd_yt
1935 * if it is non Null
1936 */
1937YT
1938gen_etag(fp, pd_yt, yp, flags)
1939FILE *fp;
1940YT pd_yt;
1941YP yp;
1942char *flags;
1943{
1944 YT yt;
1945
1946 yt = yp->yp_tag;
1947 if (yt && yt->yt_value) {
1948 if ((yp->yp_flags & (YP_TAG|YP_IMPLICIT)) == YP_TAG) {
1949 /* EXPLICIT TAG so generate an ETAG */
1950 if (pd_yt)
1951 yt = pd_yt; /* if we have a value passed down use that */
1952 (void) fprintf(fp, "\t{ ETAG, 0, %d, %s%s },\n",
1953 yt->yt_value->yv_number, class2str(yt->yt_class), flags);
1954 pd_yt = NULLYT; /* non't pass on any value */
1955
1956 } else if ((yp->yp_flags & (YP_TAG|YP_IMPLICIT))== YP_TAG|YP_IMPLICIT) {
1957 /* otherwise it is implicit and so pass its tag down
1958 * unless we already have a tag being passed in which case
1959 * the passed down tag overrides this current tag
1960 */
1961 if (pd_yt == NULLYT)
1962 pd_yt = yt;
1963 }
1964 }
1965
1966 return (pd_yt);
1967}
1968
1969/*
1970 * generate the table entry for a value passing defined type which
1971 * is equivalent to the given primative type
1972 */
1973gen_ventry(fp, oyp, yp, t, f)
1974FILE *fp;
1975YP oyp, yp;
1976char *t, *f;
1977{
1978 char *p1;
1979 register char s = oyp->yp_prfexp; /* type of value passing */
1980
1981
1982 if (noindirect(f) && s != 'q' && s != 'a')
1983 ferrs(1,
1984 "gen_ventry: must specify a field for primative value- not %s\n", f);
1985
1986 switch (s) {
1987 case 'q': /* [[ q parm->qbufptr ]] */
1988 if (yp->yp_code != YP_OCT)
1989 warning("qbuf pointer passed for a %s by type %s",
1990 code2name(yp->yp_code), yp2name(oyp));
1991
1992 f = setfield(oyp->yp_strexp);
1993 if (noindirect(f))
1994 p1 = "SOCTETSTRING";
1995 else
1996 p1 = "OCTETSTRING";
1997 break;
1998
1999 case 's': /* [[ s ptr ]] */
2000 if (yp->yp_code != YP_OCT)
2001 warning("string pointer passed for a %s by type %s",
2002 code2name(yp->yp_code), yp2name(oyp));
2003
2004 f = setfield(oyp->yp_strexp);
2005 p1 = "T_STRING";
2006 break;
2007
2008 case 'o': /* [[ o ptr $ length ]] */
2009 if (yp->yp_code != YP_OCT)
2010 warning("octet/length pair passed for a %s by type %s",
2011 code2name(yp->yp_code), yp2name(oyp));
2012 f = setfield(oyp->yp_strexp);
2013 p1 = "OCTET_PTR";
2014 prnte(fp, t, f, yp, p1);
2015 if (oyp->yp_intexp)
2016 f = setfield(oyp->yp_intexp);
2017 if (noindirect(f))
2018 ferr(1, "gen_ventry:OCT: must specify a field [[ s .. ]]\n");
2019 p1 = "OCTET_LEN";
2020 break;
2021
2022 case 'x': /* [[ x ptr $ length ]] */
2023 if (yp->yp_code != YP_BIT && yp->yp_code != YP_BITLIST)
2024 warning("bit string/length pair passed for a %s by type %s",
2025 code2name(yp->yp_code), yp2name(oyp));
2026
2027 f = setfield(oyp->yp_strexp);
2028 p1 = "BITSTR_PTR";
2029 prnte(fp, t, f, yp, p1);
2030 f = setfield(oyp->yp_intexp);
2031 if (noindirect(f))
2032 ferr(1, "tenc_typ:BIT: must specify a field [[ x .. ]]\n");
2033 p1 = "BITSTR_LEN";
2034 break;
2035
2036 case 'r': /* [[ r REAL ]] */
2037 if (yp->yp_code != YP_REAL)
2038 warning("Real passed for a %s by type %s",
2039 code2name(yp->yp_code), yp2name(oyp));
2040
2041 f = setfield(oyp->yp_strexp);
2042 p1 = "REALTYPE";
2043 break;
2044
2045 case 'i': /* [[ i INTEGER ]] */
2046 if (yp->yp_code != YP_INT && yp->yp_code != YP_INTLIST
2047 && yp->yp_code != YP_ENUMLIST)
2048 warning("integer passed for a %s by type %s",
2049 code2name(yp->yp_code), yp2name(oyp));
2050
2051 if (oyp->yp_intexp)
2052 f = setfield(oyp->yp_intexp);
2053 p1 = "INTEGER";
2054 break;
2055
2056 case 't': /* [[ t Bitvector ]] */
2057 if (yp->yp_code != YP_BIT && yp->yp_code != YP_BITLIST)
2058 warning("Bitvector (PE) passed for a %s by type %s",
2059 code2name(yp->yp_code), yp2name(oyp));
2060
2061 f = setfield(oyp->yp_intexp);
2062 if (oyp->yp_varexp && !noindirect(f))
2063 p1 = "BITSTRING";
2064 else
2065 p1 = "SBITSTRING";
2066 break;
2067
2068 case 'b': /* [[ b BOOLEAN ]] */
2069 if (yp->yp_code != YP_BOOL)
2070 warning("Boolean passed for a %s by type %s",
2071 code2name(yp->yp_code), yp2name(oyp));
2072
2073 if (oyp->yp_intexp)
2074 f = setfield(oyp->yp_intexp);
2075 p1 = "BOOLEAN";
2076 break;
2077
2078 case 'O': /* [[ O Object Identifier ]] */
2079 if (yp->yp_code != YP_OID)
2080 warning("Object Identifier pointer passed for a %s by type %s",
2081 code2name(yp->yp_code), yp2name(oyp));
2082 f = setfield(oyp->yp_strexp);
2083 p1 = "OBJID";
2084 break;
2085
2086 case 'a': /* [[ a ANY ]] */
2087 if (yp->yp_code != YP_ANY)
2088 warning("PE pointer passed for a %s by type %s",
2089 code2name(yp->yp_code), yp2name(oyp));
2090 f = setfield(oyp->yp_strexp);
2091 if (noindirect(f))
2092 p1 = "SANY";
2093 else
2094 p1 = "ANY";
2095 break;
2096 default:
2097 ferrd("gen_vident:unknown Value passed %d\n", (int )s);
2098 }
2099
2100 prnte(fp, t, f, yp, p1);
2101}
2102
2103/*
2104 * generate a table entry for a function call that handles this type
2105 */
2106gen_fn(fp, yp, fn)
2107FILE *fp;
2108YP yp;
2109char *fn; /* name of routine to generate */
2110{
2111
2112 gen_identry(fp, fn, NULLCP, yp, gen_fnentry);
2113}
2114
2115/*
2116 * generate a table entry for a function call that handles this type
2117 */
2118gen_fnentry(fp, oyp, yp, fn, dummy)
2119FILE *fp;
2120YP oyp;
2121YP yp;
2122char *fn; /* name of routine to generate */
2123char *dummy;
2124{
2125
2126 (void) fprintf(fp, "\t{ FN_CALL, %d, %s, %s },\n",
2127 addptr(fn), c_tag(yp), c_class(yp));
2128}
2129/*
2130 * declare the functions that are used
2131 * One day generate ANSII C definitions as well
2132 */
2133declfns(fp, fn)
2134FILE *fp;
2135YFN fn;
2136{
2137 if (fn->yfn_enc) {
2138 (void) fprintf(fp, "extern int %s();\n", fn->yfn_enc);
2139 }
2140 if (fn->yfn_dec) {
2141 (void) fprintf(fp, "extern int %s();\n", fn->yfn_dec);
2142 }
2143 if (fn->yfn_prt) {
2144 (void) fprintf(fp, "extern int %s();\n", fn->yfn_prt);
2145 }
2146 if (fn->yfn_fre) {
2147 (void) fprintf(fp, "extern int %s();\n", fn->yfn_fre);
2148 }
2149}
2150/*
2151 * generate the table entry to handle an action - UCODE
2152 */
2153gen_act(fp, act)
2154FILE *fp;
2155Action act;
2156{
2157 (void) fprintf(fp, "\t{ UCODE, %d, 0, 0 }, /* line %d */\n", act->a_num,
2158 act->a_line);
2159}
2160
2161/*
2162 * print out the field entry for a type where all the parameters are given
2163 */
2164prtfield(fp, typ, t, f, cl, fl)
2165FILE *fp;
2166char *typ, *t, *f, *cl, *fl;
2167{
2168 if (cl == NULLCP)
2169 cl = "0";
2170
2171 if (f && t) {
2172 if (*f == '&')
2173 f++;
2174 (void) fprintf(fp, "\t{ %s, OFFSET(%s, %s), %s, %s },\n", typ, t, f,
2175 cl, fl);
2176 } else
2177 (void) fprintf(fp, "\t{ %s, 0, %s, %s },\n", typ, cl, fl);
2178}
2179
2180/*
2181 * print out the field entry for a Simple type where all the parameters
2182 * are given
2183 */
2184prstfield(fp, typ, t, f, cl, fl)
2185FILE *fp;
2186char *typ, *t, *f, *cl, *fl;
2187{
2188 if (cl == NULLCP)
2189 cl = "0";
2190
2191 if (f && t && *f == '&') {
2192 f++;
2193 (void) fprintf(fp, "\t{ S%s, OFFSET(%s, %s), %s, %s },\n", typ, t, f,
2194 cl, fl);
2195 } else
2196 (void) fprintf(fp, "\t{ S%s, 0, %s, %s },\n", typ, cl, fl);
2197}
2198
2199/*
2200 * convert an integer into a temporary string. Useful for calling
2201 * the printing routines with
2202 */
2203char *
2204int2tstr(i)
2205int i;
2206{
2207 static char buf[STRSIZE];
2208
2209 sprintf(buf, "%d", i);
2210
2211 return (buf);
2212}
2213
2214static char *codetab[] = {
2215 "Undefined", "BOOLEAN", "INTEGER", "INTEGER (named numbers)", "BIT STRING",
2216 "BIT STRING (named bits)", "OCTET STRING", "NULL", "SEQUENCE",
2217 "SEQUENCE OF", "SEQUENCE", "SET", "SET OF", "SET", "CHOICE",
2218 "ANY", "OBJECT IDENTIFIER", "Defined type", "ENUMERATED",
2219 "REAL", "Imported type",
2220
2221 NULL
2222};
2223/*
2224 * produce a user readable name for a yp_code value
2225 */
2226char *
2227code2name(code)
2228int code;
2229{
2230 static char buf[STRSIZE];
2231
2232 if (code < 0 || code > YP_IMPTYPE) {
2233 sprintf(buf, "Unknown code (%d)", code);
2234 return (buf);
2235 }
2236
2237 return (codetab[code]);
2238}
2239/*
2240 * print out a description of the yp type for the user that is good enough
2241 * for them to identifier the entry if possible
2242 */
2243char *
2244yp2name(yp)
2245YP yp;
2246{
2247 static char buf[STRSIZE*4];
2248 char *p;
2249
2250 p = buf;
2251 if (yp->yp_code == YP_IDEFINED) {
2252 if (yp->yp_module) {
2253 sprintf(p, "%s.", yp->yp_module);
2254 p += strlen(p);
2255 }
2256 if (yp->yp_identifier)
2257 sprintf(p, "%s", yp->yp_identifier);
2258 else
2259 strcpy(p, "(no identifier)");
2260 p += strlen(p);
2261 if (yp->yp_modid) {
2262 sprintf(p, " (%s)", sprintoid(yp->yp_modid));
2263 p += strlen(p);
2264 }
2265 } else {
2266 sprintf(p, "%s", code2name(yp->yp_code));
2267 p += strlen(p);
2268 }
2269
2270 if (yp->yp_flags & YP_ID) {
2271 sprintf(p, " %s", yp->yp_id);
2272 p += strlen(p);
2273 }
2274
2275 if (yp->yp_lineno > 0) {
2276 sprintf(p, " on line %d", yp->yp_lineno);
2277 p += strlen(p);
2278 }
2279
2280 return (buf);
2281
2282}
2283/*
2284 * generate a table entry for the given compound type. It determines wether to
2285 * generate a simple type (prstfield) or not.
2286 */
2287prcte(fp, type, t, f, yp, p1)
2288FILE *fp;
2289char *type; /* zero if we are foundation type of the table */
2290char *t; /* parent type */
2291char *f; /* field name */
2292YP *yp; /* object */
2293char *p1; /* table entry name */
2294{
2295 if (type == NULL || type && noindirect(f))
2296 prstfield(fp, p1, t, f, c_tag(yp), c_class(yp));
2297 else
2298 prtfield(fp, p1, t, type ? f : NULLCP, c_tag(yp), c_class(yp));
2299}