|
|
1.1 root 1: /* etabs.c */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/pepsy/RCS/etabs.c,v 7.2 90/07/27 08:49:15 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/pepsy/RCS/etabs.c,v 7.2 90/07/27 08:49:15 mrose Exp $
9: *
10: *
11: * $Log: etabs.c,v $
12: * Revision 7.2 90/07/27 08:49:15 mrose
13: * update
14: *
15: * Revision 7.1 90/07/09 14:52:33 mrose
16: * sync
17: *
18: * Revision 7.0 90/07/01 19:54:18 mrose
19: * *** empty log message ***
20: *
21: */
22:
23: /*
24: * NOTICE
25: *
26: * Acquisition, use, and distribution of this module and related
27: * materials are subject to the restrictions of a license agreement.
28: * Consult the Preface in the User's Manual for the full terms of
29: * this agreement.
30: *
31: */
32:
33:
34: #include <stdio.h>
35: #include <ctype.h>
36: #include "pepsydefs.h"
37: #include "sym.h"
38: #include "pass2.h"
39: #include "mine.h"
40:
41: s_table *head;
42:
43: extern s_table *lookup_list(), *proc_def();
44:
45: extern FILE *fptab;
46: extern char *c_tag(), *c_class();
47: extern char *ec_tag(), *ec_class();
48: extern char *strip_last();
49: extern char *get_val(), *get_comp(), *get_string();
50: extern s_table *get_offset();
51: extern char *my_strcat(), *strp2name();
52: extern char *my_new_str();
53: extern char *mymodule;
54: extern char *modsym();
55: extern char *concat();
56: extern char *genlabel();
57: extern char *notidtoid();
58: extern YV calc_yv();
59: extern SY syfind();
60: static s_table *en_ptr;
61: extern s_table *ptr;
62:
63: static int cons_type = 0;
64: /* int explicit; */
65:
66: s_table *save_ptr;
67:
68: #define WORDSIZE 20
69: #define MAXNAME 256 /* maximum size of a identifier */
70:
71: #ifdef DEBUG
72: char *str_yp_code[] = {
73: "Undefined", "Boolean", "Integer", "Named number list", "Bitstring",
74: "Named Bitstring list", "Octet String", "Null", "Sequence",
75: "Sequence of", "Sequence list", "Set", "Set of", "Set list",
76: "Choice", "Any", "Object Identifier",
77: "", "", "", "", "", "", "", "",
78: "", "", "", "", "", "", "", "Identifier",
79:
80: };
81:
82: #endif
83:
84: /*
85: * table encode a type. generate tables for the encoding of a type
86: */
87: tenc_typ(yp, id, type)
88: YP yp;
89: char *id;
90: char *type;
91: {
92:
93: char *t, *f;
94: char *p1;
95: char *s1, *s2, *s3;
96: char *s;
97: s_table *ptr1, *ptr2;
98: YP y;
99:
100:
101: if (yp->yp_code < 0 || yp->yp_code > YP_REAL)
102: ferrd(1, "tdec_typ: unimplemented type %d\n", yp->yp_code);
103:
104: if (yp == NULL) {
105: ferr(0, "tenc_typ:NULL argument\n");
106: return;
107: }
108: if (yp->yp_flags & YP_DEFAULT)
109: gdflt(yp, G_ENC);
110:
111: if (yp->yp_flags & YP_TAG && !(yp->yp_flags & YP_IMPLICIT)) {
112: (void) fprintf(fptab, "\t{ ETAG, 0, ");
113: (void) fprintf(fptab, "%s, %s },\n", ec_tag(yp), ec_class(yp));
114: }
115: /* Preserve the type of the containing object */
116: if (type)
117: t = type;
118: else
119: t = my_strcat("struct ", modsym(mymodule, id, "type"));
120: f = yp->yp_varexp;
121: switch (yp->yp_code) {
122:
123: case YP_UNDF:
124: ferr(1, "tenc_typ:Undefined type\n");
125:
126: case YP_BOOL:
127: p1 = "BOOLEAN";
128: if (yp->yp_varexp) {
129: } else
130: t = NULL;
131: break;
132:
133: case YP_INTLIST:
134:
135: case YP_INT:
136:
137: case YP_ENUMLIST:
138: if (yp->yp_varexp) {
139: p1 = "INTEGER";
140: break;
141: }
142: t = NULL;
143: p1 = NULL;
144: (void) fprintf(fptab, "\t{ SINTEGER, 0, %s, %s },\n",
145: c_tag(yp), c_class(yp));
146: break;
147:
148: case YP_REAL:
149: if (yp->yp_varexp) {
150: p1 = "REALTYPE";
151: break;
152: }
153: t = NULL;
154: p1 = NULL;
155: (void) fprintf(fptab, "\t{ SREALTYPE, 0, %s, %s },\n",
156: c_tag(yp), c_class(yp));
157: break;
158:
159: case YP_BIT:
160: case YP_BITLIST:
161: if (yp->yp_varexp) {
162: p1 = "BITSTRING";
163: break;
164: }
165: t = NULL;
166: p1 = NULL;
167: (void) fprintf(fptab, "\t{ SBITSTRING, 0, %s, %s },\n",
168: c_tag(yp), c_class(yp));
169: break;
170:
171: case YP_OCT:
172: if (yp->yp_varexp) {
173: p1 = "OCTETSTRING";
174: break;
175: }
176: t = NULL;
177: p1 = NULL;
178: (void) fprintf(fptab, "\t{ SOCTETSTRING, 0, %s, %s },\n",
179: c_tag(yp), c_class(yp));
180: break;
181:
182: case YP_OID:
183: if (yp->yp_varexp) {
184: p1 = "OBJID";
185: break;
186: }
187: t = NULL;
188: p1 = NULL;
189: (void) fprintf(fptab, "\t{ SOBJID, 0, %s, %s },\n",
190: c_tag(yp), c_class(yp));
191: break;
192:
193:
194: case YP_SEQ:
195: case YP_SET:
196: case YP_ANY:
197: if (yp->yp_varexp) {
198: p1 = "ANY";
199: break;
200: }
201: t = NULL;
202: p1 = NULL;
203: (void) fprintf(fptab, "\t{ SANY, 0, %s, %s },\n",
204: c_tag(yp), c_class(yp));
205: break;
206:
207: case YP_NULL:
208: p1 = "T_NULL";
209: t = NULL;
210: break;
211:
212: case YP_IDEFINED:
213: p1 = NULL;
214: {
215: /* Predefined Universal Type */
216: struct univ_typ *p, *univtyp();
217:
218: if ((p = univtyp(yp->yp_identifier))) {
219: if (p->univ_flags & UNF_EXTMOD) {
220: yp->yp_module = p->univ_mod;
221: goto do_obj;
222: }
223: if (f == NULL) {/* No offset type */
224: if (yp->yp_flags & YP_TAG
225: && yp->yp_flags & YP_IMPLICIT)
226: (void) fprintf(fptab, "\t{ S%s, 0, %d, %s },\n",
227: p->univ_tab,
228: yp->yp_tag->yt_value->yv_number,
229: c_flags(yp, yp->yp_tag->yt_class));
230: else
231: (void) fprintf(fptab, "\t{ S%s, 0, %d, %s },\n",
232: p->univ_tab, p->univ_id,
233: c_flags(yp, p->univ_class));
234: break;
235: }
236: if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
237: (void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
238: p->univ_tab, t, f,
239: yp->yp_tag->yt_value->yv_number,
240: c_flags(yp, yp->yp_tag->yt_class));
241: else
242: (void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %d, %s },\n",
243: p->univ_tab, t, f, p->univ_id,
244: c_flags(yp, p->univ_class));
245: break;
246: }
247: }
248: do_obj:
249: if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT)
250: (void) fprintf(fptab, "\t{ IMP_OBJ, 0, %s, %s },\n", c_tag(yp), c_class(yp));
251: if (yp->yp_parm) {
252: ferr(1, "tenc_typ:YP_IDEFINED:yp_parm found\n");
253: }
254: if (yp->yp_module == NULL
255: || strcmp(yp->yp_module, mymodule) == 0) {
256: if (f == NULL) { /* No offset type */
257: (void) fprintf(fptab, "\t{ SOBJECT, 0, _Z%s, %s },\n",
258: proc_name(yp->yp_identifier, 0), c_class(yp));
259: } else
260: (void) fprintf(fptab,
261: "\t{ OBJECT, OFFSET(%s, %s), _Z%s, %s },\n",
262: t, f, proc_name(yp->yp_identifier, 0), c_class(yp));
263: } else {
264: if (f == NULL) { /* No offset type */
265: (void) fprintf(fptab, "\t{ SEXTOBJ, 0, _Z%s, %s },\n",
266: strp2name(yp->yp_identifier, yp->yp_module),
267: c_class(yp));
268: } else
269: (void) fprintf(fptab,
270: "\t{ EXTOBJ, OFFSET(%s, %s), _Z%s, %s },\n",
271: t, f, strp2name(yp->yp_identifier, yp->yp_module),
272: c_class(yp));
273:
274: (void) fprintf(fptab, "\t{ EXTMOD, %d, 0, 0 },\n",
275: gen_modref(yp->yp_module));
276: }
277: break;
278:
279: case YP_SEQLIST:
280: p1 = NULL;
281: /* support for -h flag */
282: #if 0
283: if (hflag && (y = yp->yp_type) && !y->yp_next) {
284: tenc_typ(y, id, yp->yp_structname);
285: break;
286: }
287: #endif
288: cons_type++;
289: save_ptr = en_ptr;
290: if (yp->yp_varexp == NULL && type != NULL)
291: ferr(1, "tenc_typ:YP_SEQLIST:NULL varexp pointer\n");
292: if (type != NULL)
293: (void) fprintf(fptab, "\t{ SEQ_START, OFFSET(%s, %s), %s, %s },\n",
294: t, f, c_tag(yp), c_class(yp));
295: else
296: (void) fprintf(fptab, "\t{ SEQ_START, 0, %s, %s },\n",
297: c_tag(yp), c_class(yp));
298: if (y = yp->yp_type) {
299: if (type) {
300: if (yp->yp_declexp == NULL)
301: ferr(1, "tenc_typ:YP_SEQLIST:no declexp\n");
302: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
303: } else
304: yp->yp_structname = t;
305: if (optfield(y)) {
306: (void) fprintf(fptab,
307: "\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
308: yp->yp_structname);
309: }
310: tenc_loop(y, id, yp->yp_structname);
311: }
312: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
313: en_ptr = save_ptr;
314: cons_type--;
315: break;
316:
317: case YP_SETLIST:
318: p1 = NULL;
319: /* support for -h flag */
320: #if 0
321: if (hflag && (y = yp->yp_type) && !y->yp_next) {
322: tenc_typ(y, id, yp->yp_structname);
323: break;
324: }
325: #endif
326: cons_type++;
327: if (yp->yp_varexp == NULL && type != NULL)
328: ferr(1, "tenc_typ:YP_SETLIST:NULL varexp pointer\n");
329: if (type != NULL)
330: (void) fprintf(fptab, "\t{ SET_START, OFFSET(%s, %s), %s, %s },\n",
331: t, f, c_tag(yp), c_class(yp));
332: else
333: (void) fprintf(fptab, "\t{ SET_START, 0, %s, %s },\n",
334: c_tag(yp), c_class(yp));
335: if (y = yp->yp_type) {
336: if (type) {
337: if (yp->yp_declexp == NULL)
338: ferr(1, "tenc_typ:YP_SETLIST:no declexp\n");
339: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
340: } else
341: yp->yp_structname = t;
342: if (optfield(y)) {
343: (void) fprintf(fptab,
344: "\t{ OPTL, OFFSET(%s, optionals), 0, 0 },\n",
345: yp->yp_structname);
346: }
347: tenc_loop(y, id, yp->yp_structname);
348: }
349: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
350: en_ptr = save_ptr;
351: cons_type--;
352: break;
353:
354: case YP_SEQTYPE:
355: p1 = NULL;
356: cons_type++;
357: save_ptr = en_ptr;
358: if (type != NULL)
359: (void) fprintf(fptab, "\t{ SEQOF_START, OFFSET(%s, %s), %s, %s },\n",
360: t, f, c_tag(yp), c_class(yp));
361: else
362: (void) fprintf(fptab, "\t{ SEQOF_START, 0, %s, %s },\n",
363: c_tag(yp), c_class(yp));
364: if (y = yp->yp_type) {
365: if (type) {
366: if (yp->yp_declexp == NULL)
367: ferr(1, "tenc_typ:YP_SEQTYPE:no declexp\n");
368: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
369: } else
370: yp->yp_structname = t;
371: tenc_loop(y, id, yp->yp_structname);
372: }
373: if (yp->yp_structname != NULL)
374: (void) fprintf(fptab, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
375: yp->yp_structname);
376: else
377: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
378: en_ptr = save_ptr;
379: cons_type--;
380: break;
381:
382: case YP_SETTYPE:
383: p1 = NULL;
384: cons_type++;
385: save_ptr = en_ptr;
386: if (type != NULL)
387: (void) fprintf(fptab, "\t{ SETOF_START, OFFSET(%s, %s), %s, %s },\n",
388: t, f, c_tag(yp), c_class(yp));
389: else
390: (void) fprintf(fptab, "\t{ SETOF_START, 0, %s, %s },\n",
391: c_tag(yp), c_class(yp));
392:
393: if (y = yp->yp_type) {
394: if (type) {
395: if (yp->yp_declexp == NULL)
396: ferr(1, "tenc_typ:YP_SETTYPE:no declexp\n");
397: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
398: } else
399: yp->yp_structname = t;
400: tenc_loop(y, id, yp->yp_structname);
401: }
402: if (yp->yp_structname != NULL)
403: (void) fprintf(fptab, "\t{ PE_END, OFFSET(%s, next), 0, 0 },\n",
404: yp->yp_structname);
405: else
406: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
407: en_ptr = save_ptr;
408: cons_type--;
409: break;
410:
411: case YP_CHOICE:
412: p1 = NULL;
413: /* support for -h flag */
414: if (hflag && (y = yp->yp_type) && !y->yp_next) {
415: tenc_typ(y, id, yp->yp_structname);
416: break;
417: }
418: cons_type++;
419: save_ptr = en_ptr;
420: if (type != NULL)
421: (void) fprintf(fptab, "\t{ CHOICE_START, OFFSET(%s, %s), 0, %s },\n",
422: t, f, c_class(yp));
423: else
424: (void) fprintf(fptab, "\t{ CHOICE_START, 0, 0, 0 },\n");
425: if (y = yp->yp_type) {
426: if (type) {
427: if (yp->yp_declexp == NULL)
428: ferr(1, "tenc_typ:YP_CHOICE:no declexp\n");
429: yp->yp_structname = my_strcat("struct ", yp->yp_declexp);
430: } else
431: yp->yp_structname = t;
432: (void) fprintf(fptab, "\t{ SCTRL, OFFSET(%s, offset), 0, 0 },\n",
433: yp->yp_structname);
434: tenc_loop(y, id, yp->yp_structname);
435: }
436: (void) fprintf(fptab, "\t{ PE_END, 0, 0, 0 },\n");
437: en_ptr = save_ptr;
438: cons_type--;
439: break;
440:
441: default:
442: ferrd(1, "tenc_typ: yp_code = %d not implemented\n", yp->yp_code);
443: }
444:
445: if (p1 != NULL)
446: if (t != NULL)
447: (void) fprintf(fptab, "\t{ %s, OFFSET(%s, %s), %s, %s },\n",
448: p1, t, f, c_tag(yp), c_class(yp));
449: else
450: (void) fprintf(fptab, "\t{ %s, 0, %s, %s },\n",
451: p1, c_tag(yp), c_class(yp));
452: }
453:
454: static int fflags[] = {
455: 0, 1, 2, 2, 3, 3, 4, 5, 16, 16, 16, 17, 17, 17,
456: 0, -1, 6, 0, 10, 9};
457:
458: /*
459: * calculate the tag string of the given type and return it
460: */
461: char *
462: c_tag(yp)
463: YP yp;
464: {
465: static char buf[WORDSIZE];
466: int i;
467:
468: if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT) {
469: i = yp->yp_tag->yt_value->yv_number;
470: } else {
471: if (yp->yp_code < 0 || yp->yp_code > YP_REAL
472: || yp->yp_code == YP_CHOICE)
473: i = 0;
474: else
475: i = fflags[yp->yp_code];
476: /* Choice now legal argument - to allow prte_* routines to work */
477: if (i == 0 && yp->yp_code != YP_CHOICE)
478: ferrd (1, "c_tag:Unknown Tag %d", yp->yp_code);
479: }
480:
481: (void) sprintf(buf, "%d", i);
482:
483: return (buf);
484: }
485:
486: /*
487: * calculate the tag string of the explicit tag and return it
488: */
489: char *
490: ec_tag(yp)
491: YP yp;
492: {
493: static char buf[WORDSIZE];
494: int i;
495:
496: if (!(yp->yp_flags & YP_TAG) || yp->yp_flags & YP_IMPLICIT)
497: ferr(1, "ec_tag:internal error:called with out explicit tag\n");
498:
499: i = yp->yp_tag->yt_value->yv_number;
500:
501: (void) sprintf(buf, "%d", i);
502:
503: return (buf);
504: }
505:
506: /*
507: * produce a string that represents the class/flags field for a given
508: * yp entry taking the class to be that given in cl
509: */
510: char *
511: c_flags(yp, cl)
512: YP yp;
513: int cl;
514: {
515: char *p1;
516: static char buf[STRSIZE];
517:
518: switch (yp->yp_code) {
519: case YP_IDEFINED:
520: case YP_CHOICE:
521: if (yp->yp_flags & YP_TAG)
522: break;
523: if (yp->yp_flags & YP_OPTIONAL) {
524: p1 = "FL_OPTIONAL";
525: } else if (yp->yp_flags & YP_DEFAULT) {
526: p1 = "FL_DEFAULT";
527: } else
528: p1 = "0";
529: return (p1);
530:
531: default:
532: break;
533: }
534: switch (cl) {
535: case PE_CLASS_UNIV:
536: p1 = "FL_UNIVERSAL";
537: break;
538:
539: case PE_CLASS_APPL:
540: p1 = "FL_APPLICATION";
541: break;
542:
543: case PE_CLASS_PRIV:
544: p1 = "FL_PRIVATE";
545: break;
546:
547: case PE_CLASS_CONT:
548: p1 = "FL_CONTEXT";
549: break;
550:
551: default:
552: ferrd(1, "c_flags: illegal class found %d\n", cl);
553:
554: }
555: if (yp->yp_flags & YP_OPTIONAL) {
556: strncpy(buf, p1, STRSIZE);
557: p1 = strncat(buf, "|FL_OPTIONAL", STRSIZE);
558: } else if (yp->yp_flags & YP_DEFAULT) {
559: strncpy(buf, p1, STRSIZE);
560: p1 = strncat(buf, "|FL_DEFAULT", STRSIZE);
561: }
562: return (p1);
563: }
564: /*
565: * calculate a string specifying the class for the given type and
566: * return it
567: */
568: char *
569: c_class(yp)
570: YP yp;
571: {
572: int i;
573:
574: if (yp->yp_flags & YP_TAG && yp->yp_flags & YP_IMPLICIT) {
575: i = yp->yp_tag->yt_class;
576: } else {
577: i = PE_CLASS_UNIV;
578: }
579: return (c_flags(yp, i));
580:
581: }
582: /*
583: * calculate a string specifying the class for the explicit tag and
584: * return it
585: */
586: char *
587: ec_class(yp)
588: YP yp;
589: {
590: int i;
591: char *p1;
592: static char buf[STRSIZE];
593:
594: if (!(yp->yp_flags & YP_TAG) || yp->yp_flags & YP_IMPLICIT)
595: ferr(1, "ec_class:internal error:called with out explicit tag\n");
596: switch (yp->yp_code) {
597: case YP_IDEFINED:
598: case YP_CHOICE:
599: if (yp->yp_flags & YP_TAG)
600: break;
601: if (yp->yp_flags & YP_OPTIONAL) {
602: p1 = "FL_OPTIONAL";
603: } else if (yp->yp_flags & YP_DEFAULT) {
604: p1 = "FL_DEFAULT";
605: } else
606: p1 = "0";
607: return (p1);
608:
609: default:
610: break;
611: }
612:
613: i = yp->yp_tag->yt_class;
614:
615: switch (i) {
616: case PE_CLASS_UNIV:
617: p1 = "FL_UNIVERSAL";
618: break;
619:
620: case PE_CLASS_APPL:
621: p1 = "FL_APPLICATION";
622: break;
623:
624: case PE_CLASS_PRIV:
625: p1 = "FL_PRIVATE";
626: break;
627:
628: case PE_CLASS_CONT:
629: p1 = "FL_CONTEXT";
630: break;
631:
632: default:
633: ferrd(1, "c_class: illegal class found %d\n", i);
634:
635: }
636: if (yp->yp_flags & YP_OPTIONAL) {
637: strncpy(buf, p1, STRSIZE);
638: p1 = strncat(buf, "|FL_OPTIONAL", STRSIZE);
639: } else if (yp->yp_flags & YP_DEFAULT) {
640: strncpy(buf, p1, STRSIZE);
641: p1 = strncat(buf, "|FL_DEFAULT", STRSIZE);
642: }
643: return (p1);
644: }
645:
646: /*
647: * generate tables for encoding a contructed type
648: */
649: tenc_loop(yp, id, type)
650: YP yp;
651: char *id;
652: char *type;
653: {
654: for (; yp != NULL; yp = yp->yp_next) {
655: tenc_typ(yp, id, type);
656: }
657: }
658:
659: /*
660: * Print the string and exit if argument greater than zero
661: */
662: ferr(i, s)
663: int i;
664: char *s;
665: {
666: (void) fprintf(stderr, "%s", s);
667: if (i > 0)
668: exit(i);
669: }
670:
671: /*
672: * Print the integer and exit if argument greater than zero
673: */
674: ferrd(i, s, d)
675: int i;
676: char *s;
677: int d;
678: {
679: (void) fprintf(stderr, s, d);
680: if (i > 0)
681: exit(i);
682: }
683:
684: /*
685: * Print the string and exit if argument greater than zero
686: */
687: ferrs(i, s, d)
688: int i;
689: char *s;
690: char *d;
691: {
692: (void) fprintf(stderr, s, d);
693: if (i > 0)
694: exit(i);
695: }
696:
697: /*
698: * return a copy of the string s minus its last character
699: */
700: char *
701: strip_last(s)
702: char *s;
703: {
704: char *t, *r;
705:
706: if (s) {
707: t = new_string(s);
708: for (r = t; *r != '\0'; r++);
709: ;
710: *--r = '\0';
711: return t;
712: } else
713: return NULL;
714: }
715:
716: /*
717: * add the declaration specified by the strings type and id to the
718: * start of the declaration list
719: */
720: add_list(type, id)
721: char *type, *id;
722: {
723:
724: s_table *prev;
725:
726: if ((prev = (s_table *) malloc(sizeof(s_table))) == NULL)
727: ferr(1, "add_list: Out of memory\n");
728: prev->type = type;
729: prev->name = id;
730: prev->parent = NULL;
731: prev->defined = 0;
732: prev->next = head;
733: head = prev;
734: }
735:
736: #if 0
737: /*
738: * return the element in the declaration list whose name field is id
739: */
740: s_table *
741: lookup_list(id)
742: char *id;
743: {
744: s_table *prev;
745:
746: for (prev = head; prev != NULL; prev = prev->next)
747: if (!strcmp(prev->name, id))
748: return prev;
749: return (NULL);
750: /* ferrs(1, "lookup_list: the id %s is not present\n",id); */
751: }
752: #endif
753:
754: /*
755: * print the declaration list
756: */
757: print_list()
758: {
759: s_table *prev;
760:
761: for (prev = head; prev != NULL; prev = prev->next) {
762: (void) printf("type is %s\n", prev->type);
763: (void) printf("name is %s\n", prev->name);
764: (void) printf("\n");
765: }
766: }
767:
768: /*
769: * parse the declaration in the string s returning the type in v1 and
770: * the name in v2
771: */
772: parse_decl(s, v1, v2)
773: char **s, **v1, **v2;
774: {
775: char *t;
776:
777: for (t = *s; *t != '\0' && !(isalnum(*t) || *t == '_'); t++);
778:
779: *s = t;
780: if (*t != '\0') {
781: for (; *t != '*'; t++);
782: *t = '\0';
783: *v1 = my_strcat(*s, "*");
784: Printf(3, ("the type is %s\n", *v1));
785: if (*++t == '*')
786: t++;
787: for (*s = t; isalnum(*t) || *t == '_'; t++);
788: if (*t != '\0') {
789: *t = '\0';
790: t++;
791: }
792: *v2 = new_string(*s); /* don't really need new_string */
793: Printf(2, ("the name is %s\n", *v2));
794: *s = t;
795: }
796: }
797:
798: /*
799: * return the next identifier in the string s
800: */
801: char *
802: get_val(s)
803: char **s;
804: {
805: char *t, *r;
806:
807: for (t = *s; *t != '\0' && !(isalnum(*t) || *t == '_' || *t == '.'); t++);
808:
809: if (*t != '\0') {
810: for (*s = t; isalnum(*t) || *t == '_' || *t == '.'; t++);
811: *t = '\0';
812: r = *s;
813: Printf(3, ("arg is |%s|\n", r));
814: *s = ++t;
815: return r;
816: } else
817: return NULL;
818: }
819:
820: #if 0
821: /*
822: * add the definition contained in s to the start of the declaration
823: * list
824: */
825: s_table *
826: proc_def(s)
827: char *s;
828: {
829: char *s1, *s2, *s3;
830: s_table *ptr1, *ptr2;
831:
832: s1 = get_val(&s);
833: ptr1 = lookup_list(s1);
834: if (!ptr1->defined) {
835: s2 = get_val(&s);
836: ptr2 = lookup_list(s2);
837: ptr1->parent = ptr2;
838: s3 = get_val(&s);
839: ptr1->field = s3;
840: ptr1->defined++;
841: }
842: return ptr1;
843: }
844: #endif
845:
846: /*
847: * return the next component (sequence of characters up to the next
848: * ';' or '\0') of the string s
849: */
850: char *
851: get_comp(s)
852: char **s;
853: {
854: char *t, *r;
855:
856: for (t = *s; *t != '\0' && !(isalnum(*t) || *t == '_' || *t == ';'); t++);
857:
858: if (*t != '\0') {
859: for (*s = t; *t != '\0' && *t != ';'; t++);
860: *t = '\0';
861: r = *s;
862: Printf(3, ("component is |%s|\n", r));
863: *s = ++t;
864: return r;
865: } else
866: return NULL;
867: }
868:
869: #if 0
870: /*
871: * work out what the offset for the type yp should be and return a
872: * pointer to the element in the declaration list which can be used
873: * to calculate the offset
874: */
875: s_table *
876: get_offset(yp, level)
877: YP yp;
878: int level;
879: {
880: char *s, *s1;
881: s_table *ptr1;
882:
883: switch (yp->yp_code) {
884:
885: case YP_UNDF:
886: ferr(1, "get_offset: Undefined type\n");
887: break;
888:
889: case YP_BOOL:
890: case YP_INT:
891: case YP_INTLIST:
892: case YP_NULL:
893: if (yp->yp_varexp) {
894: s = new_string(yp->yp_intexp);
895: s1 = get_val(&s);
896: ptr1 = lookup_list(s1);
897: return ptr1;
898: } else {
899: ferr(0, "get_offset: No intexp\n");
900: return NULL;
901: }
902: break;
903:
904: case YP_BIT:
905: case YP_BITLIST:
906: if (yp->yp_direction & YP_DECODER)
907: if (yp->yp_action2) {
908: s = new_string(yp->yp_action2);
909: s1 = get_val(&s);
910: if (strcmp(s1, "if"))
911: ferrs(1, "get_offset: What to do, action2 = %s\n", yp->yp_action2);
912: else {
913: s1 = get_val(&s);
914: ptr1 = lookup_list(s1);
915: return ptr1;
916: }
917: } else
918: return NULL;
919: else if (yp->yp_varexp) {
920: s = new_string(yp->yp_varexp);
921: s1 = get_val(&s);
922: s1 = get_val(&s);
923: ptr1 = lookup_list(s1);
924: return ptr1;
925: } else {
926: ferr(0, "get_offset: No strexp (BIT)\n");
927: return NULL;
928: }
929: break;
930: case YP_OCT:
931: case YP_OID:
932: case YP_SEQ:
933: case YP_SET:
934: case YP_ANY:
935: if (yp->yp_varexp) {
936: s = new_string(yp->yp_varexp);
937: s1 = get_val(&s);
938: ptr1 = lookup_list(s1);
939: return ptr1;
940: } else {
941: ferr(0, "get_offset: No strexp\n");
942: return NULL;
943: }
944: break;
945:
946: case YP_IDEFINED:
947: if (yp->yp_parm) {
948: s = new_string(yp->yp_parm);
949: s1 = get_val(&s);
950: ptr1 = lookup_list(s1);
951: return ptr1;
952: } else {
953: ferr(0, "get_offset: No parm\n");
954: return NULL;
955: }
956: break;
957:
958: case YP_SEQLIST:
959: case YP_SETLIST:
960: case YP_CHOICE:
961: if (yp->yp_action1) {
962: s = get_string(yp->yp_action1, yp->yp_direction);
963: while ((s1 = get_comp(&s)) != NULL)
964: (void) proc_def(s1);
965: }
966: if (yp->yp_type == NULL) {
967: if (level > 0)
968: ferr(0, "get_offset: There exists an embeded empty SEQUENCE/SET/CHOICE\n");
969: return (yp->yp_direction & YP_ENCODER ? en_ptr : ptr);
970: }
971: if ((ptr1 = get_offset(yp->yp_type, level + 1)) != NULL)
972: if (ptr1->parent != NULL && level > 0)
973: return ptr1->parent;
974: else
975: return ptr1;
976: else {
977: ferr(0, "get_offset: returning NULL (SEQLIST/SETLIST/CHOICE)\n");
978: return NULL;
979: }
980: break;
981:
982: case YP_SEQTYPE:
983: case YP_SETTYPE:
984: if (yp->yp_action3) {
985: s = get_string(yp->yp_action3, yp->yp_direction);
986: while ((s1 = get_comp(&s)) != NULL)
987: (void) proc_def(s1);
988: }
989: if ((ptr1 = get_offset(yp->yp_type, level + 1)) != NULL)
990: if (ptr1->parent != NULL && level > 0)
991: return ptr1->parent;
992: else
993: return ptr1;
994: else {
995: ferr(0, "get_offset: returning NULL (SEQTYPE/SETTYPE)\n");
996: return NULL;
997: }
998: break;
999:
1000: default:
1001: ferrd(1, "get_offset: yp_code = %d not implemented\n", yp->yp_code);
1002: return NULL;
1003: break;
1004: }
1005: }
1006: #endif
1007:
1008: /*
1009: * return a copy of that part of the string s which may contain
1010: * definitions for the variables generated by posy
1011: */
1012: char *
1013: get_string(s, direction)
1014: char *s;
1015: int direction;
1016: {
1017: char *t, *t1;
1018:
1019: if (direction & YP_ENCODER)
1020: return new_string(s);
1021: if (direction & YP_DECODER) {
1022: t = new_string(s);
1023: for (t1 = t; !(isalnum(*t1) || *t1 == '_'); t1++);
1024: if (*t1 == 'i' && *++t1 == 'f' && *++t1 == ' ') { /* MALLOC code */
1025: for (; *t1 != '}'; t1++) /* skip MALLOC code */
1026: ;
1027: t1++;
1028: Printf(4, ("returning the string %s\n", t1));
1029: return t1;
1030: } else
1031: return t;
1032: }
1033: }
1034:
1035: #if 0
1036: c_type(yp)
1037: YP yp;
1038: {
1039: switch (yp->yp_code) {
1040:
1041: case YP_IDEFINED:
1042: return T_OBJ;
1043: break;
1044:
1045:
1046: default:
1047: return T_PRIM;
1048: break;
1049: }
1050: }
1051:
1052: #endif
1053: /*
1054: * Determine wether this list contains any items that will generate
1055: * an optional field. If so return non zero
1056: */
1057: optfield(yp)
1058: YP yp;
1059: {
1060: for (; yp; yp = yp->yp_next) {
1061: if (yp->yp_flags & YP_OPTIONAL)
1062: switch (yp->yp_code) {
1063: case YP_BOOL:
1064: case YP_INT:
1065: case YP_INTLIST:
1066: case YP_ENUMLIST:
1067: case YP_NULL:
1068: return (1);
1069: }
1070: }
1071: return (0);
1072: }
1073:
1074: gen_dflts(yp, type)
1075: YP yp;
1076: char *type;
1077: {
1078: YP y;
1079:
1080: if (yp == NULL)
1081: return;
1082: switch (yp->yp_code) {
1083: case YP_IDEFINED:
1084: #if 0
1085: if (yp->yp_module == NULL
1086: || strcmp(yp->yp_module, mymodule) == 0)
1087: break;
1088: if (lookup_list(yp->yp_module))
1089: break; /* already done */
1090: /* Got an external reference */
1091: (void) fprintf(fptab, "#include \"%s%s\"\n", yp->yp_module, HFILE2);
1092: add_list("module", yp->yp_module);
1093: #endif
1094: break;
1095:
1096: case YP_CHOICE:
1097: case YP_SEQTYPE:
1098: case YP_SETTYPE:
1099: case YP_SEQLIST:
1100: case YP_SETLIST:
1101: for (y = yp->yp_type; y != NULL; y = y->yp_next) {
1102: gen_dflts(y, type);
1103: }
1104: break;
1105:
1106: default:
1107: break;
1108: }
1109: /* Output definitions for default entries */
1110: if (yp->yp_flags & YP_DEFAULT)
1111: defdflt(yp, type);
1112: }
1113: /*
1114: * Compute the concatenation into a temporary buffer of two strings
1115: * after having run notid on them first
1116: */
1117: char *
1118: strp2name(s1, s2)
1119: char *s1, *s2;
1120: {
1121: char *p;
1122: static char buf[STRSIZE * 2 + 5];
1123:
1124: if (strlen(s1) > STRSIZE || strlen(s2) > STRSIZE)
1125: ferr(1, "strp2name:string to big\n");
1126: strcpy(buf, p = notidtoid(s1));
1127: free(p);
1128: strcat(buf, p = notidtoid(s2));
1129: free(p);
1130:
1131: return (buf);
1132: }
1133:
1134: /*
1135: * Output the definitions for default entries and initialise the yp's
1136: * to have pointers which reference these definitions for use by
1137: * gdflt routine.
1138: */
1139: defdflt(yp, name)
1140: YP yp;
1141: char *name;
1142: {
1143: YV yv;
1144: YV yv1;
1145: SY sy;
1146: YP yp1;
1147: int size, i;
1148: char *str;
1149: char *label;
1150: struct univ_typ *p;
1151: int code;
1152:
1153: if ((yp->yp_flags & YP_DEFAULT) == 0)
1154: ferrd(1, "defdflt:called with out a default code = %d\n", yp->yp_code);
1155: yv = yp->yp_default;
1156:
1157: yp1 = yp;
1158:
1159: /* Find the bottom definition */
1160: code = yp1->yp_code;
1161: while (code == YP_IDEFINED) {
1162: if ((sy = syfind(yp1->yp_identifier)) == NULL) {
1163: if ((p = univtyp(yp1->yp_identifier)) == NULL
1164: || p->univ_type <= YP_UNDF)
1165: ferrs(1,
1166: "defdflt:IDEFINED:cannot find definition of symbol %s\n",
1167: yp1->yp_identifier);
1168: code = p->univ_type;
1169: break;
1170:
1171: }
1172: yp1 = sy->sy_type;
1173: code = yp1->yp_code;
1174: }
1175:
1176: switch (code) {
1177: case YP_BOOL:
1178: case YP_INT:
1179: case YP_INTLIST:
1180: case YP_ENUMLIST:
1181: switch (yv->yv_code) {
1182: case YV_NUMBER:
1183: case YV_BOOL:
1184: /* None needed */
1185: break;
1186:
1187: case YV_IDEFINED:
1188: if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1189: ferrs(1, "defdflt:BOOL/INT:cannot find definition of %s\n",
1190: yv->yv_identifier);
1191: }
1192: /* None Needed */
1193: break;
1194:
1195: default:
1196: ferrd(1, "defdflt:INT/BOOL:unimplemented value code = %d\n",
1197: yv->yv_code);
1198: }
1199: break;
1200:
1201: case YP_REAL:
1202: switch (yv->yv_code) {
1203: case YV_REAL:
1204: yv1 = yv;
1205: goto dumpdef3;
1206:
1207: case YV_IDEFINED:
1208: if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1209: ferrs(1, "defdflt:REAL:cannot find definition of %s\n",
1210: yv->yv_identifier);
1211: }
1212: goto dumpdef3;
1213: break;
1214:
1215: default:
1216: ferrd(1, "defdflt:REAL:unimplemented value code = %d\n",
1217: yv->yv_code);
1218: }
1219: break;
1220:
1221: case YP_BIT:
1222: case YP_BITLIST:
1223: switch (yv->yv_code) {
1224: /*
1225: * This is an illegal value for a bit string ! - BUT ACSE
1226: * uses it !
1227: */
1228: /* gdflt also patched to support it */
1229: case YV_IDEFINED:
1230: ferrs(0,
1231: "warning:bitstring default specified illegally with identifier %s\n",
1232: yv->yv_identifier);
1233: if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1234: ferrs(1, "defdflt:BIT:cannot find definition of %s\n",
1235: yv->yv_identifier);
1236: }
1237: /* doesn't work fix posy-yacc.y */
1238: size = numtobstr(yv1, &str);
1239: goto dumpdef1;
1240:
1241: case YV_NUMBER:
1242: /* doesn't work fix posy-yacc.y */
1243: size = numtobstr(yv, &str);
1244: goto dumpdef1;
1245:
1246: case YV_VALIST:
1247: if ((size = valisttobs(yp1, yv, &str)) < 0) {
1248: ferrs(1, "defdflt:bad default value for bistring %s\n",
1249: yp->yp_flags & YP_ID ? yp->yp_identifier : "");
1250: }
1251: goto dumpdef1;
1252:
1253: default:
1254: /* Could be a syntax error */
1255: ferrd(1, "defdflt:BIT:illegal value code = %d\n", yv->yv_code);
1256: }
1257: break;
1258:
1259: case YP_IDEFINED:
1260: ferrs(1, "defdflt:IDEFINED:internal error on symbol %s\n",
1261: yp1->yp_identifier);
1262: break;
1263:
1264: case YP_OCT:
1265: switch (yv->yv_code) {
1266: case YV_NUMBER:
1267: /* doesn't work fix posy-yacc.y */
1268: size = numtobstr(yv, &str);
1269: goto dumpdef2;
1270:
1271: case YV_STRING:
1272: str = yv->yv_string;
1273: size = strlen(str);
1274: goto dumpdef2;
1275:
1276: default:
1277: /* Could be a syntax error */
1278: ferrd(1, "defdflt:OCT:illegal value code = %d\n", yv->yv_code);
1279: }
1280: break;
1281:
1282: case YP_NULL:
1283: case YP_SEQ:
1284: case YP_SEQTYPE:
1285: case YP_SEQLIST:
1286: case YP_SET:
1287: case YP_SETTYPE:
1288: case YP_SETLIST:
1289: case YP_CHOICE:
1290: case YP_ANY:
1291: case YP_OID:
1292: /* None yet */
1293: break;
1294:
1295: default:
1296: ferrd(1, "defdflt:unknown type %d\n", code);
1297: }
1298:
1299: return;
1300:
1301: dumpdef1: /* Bitstrings */
1302: label = genlabel(name, yp);
1303: yp->yp_action0 = label;
1304: yp->yp_act0_lineno = size;
1305: i = (size + NBPC - 1) / NBPC;
1306: (void) fprintf(fptab, "\nstatic char %s[] = ", label);
1307: if (printable(str, i))
1308: prstr(fptab, str, i);
1309: else
1310: prhstr(fptab, str, i);
1311: (void) fprintf(fptab, ";\n");
1312: return;
1313:
1314: dumpdef2: /* Octet strings (and aliases) */
1315: label = genlabel(name, yp);
1316: yp->yp_action0 = label;
1317: yp->yp_act0_lineno = size;
1318: (void) fprintf(fptab, "\nstatic char %s[] = ", label);
1319: if (printable(str, size))
1320: prstr(fptab, str, size);
1321: else
1322: prhstr(fptab, str, size);
1323: (void) fprintf(fptab, ";\n");
1324: return;
1325:
1326: dumpdef3: /* Reals */
1327: label = genlabel(name, yp);
1328: yp->yp_action0 = label;
1329: (void) fprintf(fptab, "\nstatic double %s = %f;\n", label, yv1->yv_real);
1330: return;
1331:
1332: }
1333: /*
1334: * generate the default entry for encoding/decoding fields. This
1335: * should contain the default value which the encoder will know means
1336: * default encoding
1337: */
1338: gdflt(yp, which)
1339: YP yp;
1340: int which; /* Which type of entries to generate
1341: * G_ENC encode G_DEC decode */
1342: {
1343: YV yv;
1344: YV yv1;
1345: SY sy;
1346: YP yp1;
1347: int size;
1348: char *str;
1349:
1350: char *ndflt;
1351: struct univ_typ *p;
1352: int code;
1353:
1354:
1355: if (which == G_ENC)
1356: ndflt = "DFLT_F";
1357: else
1358: ndflt = "DFLT_B";
1359:
1360: if ((yp->yp_flags & YP_DEFAULT) == 0)
1361: ferrd(1, "gdflt:called with out a default code = %d\n", yp->yp_code);
1362: yv = yp->yp_default;
1363:
1364: yp1 = yp;
1365:
1366: /* Find the bottom definition */
1367: code = yp1->yp_code;
1368: while (code == YP_IDEFINED) {
1369: if ((sy = syfind(yp1->yp_identifier)) == NULL) {
1370: if ((p = univtyp(yp1->yp_identifier)) == NULL
1371: || p->univ_type <= YP_UNDF)
1372: ferrs(1,
1373: "gdflt:IDEFINED:cannot find definition of symbol %s\n",
1374: yp1->yp_identifier);
1375: code = p->univ_type;
1376: break;
1377:
1378: }
1379: yp1 = sy->sy_type;
1380: code = yp1->yp_code;
1381: }
1382:
1383: switch (code) {
1384: case YP_BOOL:
1385: case YP_INT:
1386: case YP_INTLIST:
1387: case YP_ENUMLIST:
1388: switch (yv->yv_code) {
1389: case YV_NUMBER:
1390: case YV_BOOL:
1391: (void) fprintf(fptab, "\t{ %s, %d, 0, 0 },\n", ndflt,
1392: yp->yp_default->yv_number);
1393: break;
1394:
1395: case YV_IDEFINED:
1396: if ((yv1 = calc_yv(yp1, yv->yv_identifier)) == NULL) {
1397: ferrs(1, "gdflt:BOOL/INT:cannot find definition of %s\n",
1398: yv->yv_identifier);
1399: }
1400: (void) fprintf(fptab, "\t{ %s, %d, 0, 0 },\n", ndflt,
1401: yv1->yv_number);
1402: break;
1403:
1404: default:
1405: ferrd(1, "gdflt:INT/BOOL:unimplemented value code = %d\n",
1406: yv->yv_code);
1407: }
1408: break;
1409:
1410: case YP_BIT:
1411: case YP_BITLIST:
1412: switch (yv->yv_code) {
1413: #ifdef ILLEGAL_DEFAULTS
1414: case YV_IDEFINED: /* supporting illegal default
1415: * specification */
1416: #endif
1417: case YV_NUMBER:
1418: case YV_VALIST:
1419: (void) fprintf(fptab, "\t{ %s, %d, %d, 0 },\n", ndflt,
1420: yp->yp_act0_lineno, addptr(yp->yp_action0));
1421: break;
1422:
1423: default:
1424: /* Could be a syntax error */
1425: ferrd(1, "gdflt:BIT:illegal value code = %d\n", yv->yv_code);
1426: }
1427: break;
1428:
1429: case YP_IDEFINED:
1430: ferrs(1, "gdflt:IDEFINED:internal error on symbol %s\n",
1431: yp1->yp_identifier);
1432: break;
1433:
1434: case YP_REAL:
1435: switch (yv->yv_code) {
1436: #ifdef ILLEGAL_DEFAULTS
1437: case YV_IDEFINED: /* Illegal according to ASN.1 but we can do it
1438: * so why not support it
1439: */
1440: #endif
1441: case YV_REAL:
1442: (void) fprintf(fptab, "\t{ %s, 0, %d, 0 },\n", ndflt,
1443: addptr(concat("&", yp->yp_action0)));
1444: break;
1445:
1446: default:
1447: /* Could be a syntax error */
1448: ferrd(1, "gdflt:REAL:illegal value code = %d\n", yv->yv_code);
1449: }
1450: break;
1451:
1452: case YP_OCT:
1453: switch (yv->yv_code) {
1454: case YV_NUMBER:
1455: case YV_STRING:
1456: (void) fprintf(fptab, "\t{ %s, %d, %d, 0 },\n", ndflt,
1457: yp->yp_act0_lineno, addptr(yp->yp_action0));
1458: break;
1459:
1460: default:
1461: /* Could be a syntax error */
1462: ferrd(1, "gdflt:OCT:illegal value code = %d\n", yv->yv_code);
1463: }
1464: break;
1465:
1466: case YP_NULL:
1467: case YP_SEQ:
1468: case YP_SEQTYPE:
1469: case YP_SEQLIST:
1470: case YP_SET:
1471: case YP_SETTYPE:
1472: case YP_SETLIST:
1473: case YP_CHOICE:
1474: case YP_ANY:
1475: case YP_OID:
1476: (void) fprintf(fptab, "\t{ %s, 0, 0, 0 },\n", ndflt);
1477: break;
1478:
1479: default:
1480: ferrd(1, "gdflt:unknown type %d\n", yp->yp_code);
1481: }
1482:
1483: }
1484: /*
1485: * Calculate the value associated with the given identifier id by
1486: * looking at the value definitions associated with type definition
1487: * yp. Returns the value definition if found or NULL if not.
1488: */
1489: YV
1490: calc_yv(yp, id)
1491: YP yp;
1492: char *id;
1493: {
1494: YV yv;
1495:
1496: for (yv = yp->yp_value; yv != NULL; yv = yv->yv_next) {
1497: if (yv->yv_flags & YV_NAMED && strcmp(yv->yv_named, id) == 0)
1498: return (yv);
1499: }
1500:
1501: return (NULL);
1502: }
1503:
1504: /*
1505: * ******* This does not work. posy needs to be fixed for case of
1506: * '01'b ***** Turn a Literal number value in yv into a bistring
1507: * initialisation. Return the length of the bit string or less than
1508: * zero on error. Set the (char *) pointer, whose address is in
1509: * ppstr, to point to a string containing the a reference to a
1510: * character array which contains the bits.
1511: */
1512:
1513: numtobstr(yv, ppstr)
1514: YV yv;
1515: char **ppstr;
1516: {
1517:
1518: int ibits, lastb, i;
1519: char *buf;
1520:
1521: buf = malloc(NBPI / NBPC + 1);
1522: bzero(buf, NBPI / NBPC + 1);
1523: lastb = -1;
1524: ibits = yv->yv_number;
1525: for (i = 0; i < NBPI; i++) {
1526: if ((1 << i) & ibits) {
1527: buf[i / NBPC] |= 1 << (NBPC - 1 - (i % NBPC));
1528: lastb = i;
1529: }
1530: }
1531:
1532: *ppstr = buf;
1533: return (lastb + 1);
1534: }
1535: #define ROUNDUP 10
1536: /*
1537: * Take a list of Values (YV_VALIST) which should contain a list of
1538: * bits and convert them into a bitstring initialisation. As in
1539: * numtobstr return the size of the bit string or a negative number
1540: * if there is an error. Put a reference to a character array which
1541: * contains the definition of the bits in the character pointer whose
1542: * address is in ppstr. yp is the definition of the type which
1543: * contains the names of all the defined bits.
1544: */
1545: valisttobs(yp, yv, ppstr)
1546: YP yp;
1547: YV yv;
1548: char **ppstr;
1549: {
1550:
1551: YV yv1, yv2;
1552: int lastb, val, nsize, size;
1553: char *buf;
1554:
1555: lastb = -1;
1556: size = ROUNDUP;
1557: if ((buf = malloc(size)) == NULL) {
1558: ferrd(1, "valisttobs:malloc:failed on %d\n", size);
1559: }
1560: bzero(buf, size);
1561: for (yv1 = yv->yv_idlist; yv1 != NULL; yv1 = yv1->yv_next) {
1562: if ((yv2 = calc_yv(yp, yv1->yv_identifier)) == NULL) {
1563: return (-1);
1564: }
1565: val = yv2->yv_number;
1566: /* Bug here probably */
1567: if (size < val / NBPC) {
1568: nsize = val / NBPC + ROUNDUP;
1569: if ((buf = realloc(buf, nsize)) == NULL) {
1570: ferrd(1, "valisttobs:realloc:failed on %d\n", nsize);
1571: }
1572: bzero(buf + size, nsize - size);
1573: size = nsize;
1574: }
1575: buf[val / NBPC] |= 1 << (NBPC - 1 - (val % NBPC));
1576: if (val > lastb)
1577: lastb = val;
1578: }
1579: *ppstr = buf;
1580: return (lastb + 1);
1581: }
1582: /*
1583: * Print the string out in a format acceptable as a quoted string in
1584: * a C program including the quotes. Using \ escapes for unprintable
1585: * characters
1586: */
1587: prstr(fp, str, len)
1588: FILE *fp;
1589: char *str;
1590: int len;
1591: {
1592: (void) fputc('"', fp);
1593: while (len-- > 0) {
1594: if (isprint(*str & 0xff)) {
1595: (void) fputc(*str & 0xff, fptab);
1596: str++;
1597: continue;
1598: }
1599: (void) fprintf(fptab, "\\%0o", *str);
1600: }
1601: (void) fputc('"', fp);
1602: #define MAXPLINE 16
1603: }
1604: /*
1605: * output a initialisation for a character array as unsigned hex
1606: * numbers
1607: */
1608: prhstr(fptab, str, len)
1609: FILE *fptab;
1610: char *str;
1611: int len;
1612: {
1613: int npline; /* number on this line */
1614:
1615: (void) fprintf(fptab, "{\n");
1616: npline = 0;
1617: while (len > 0) {
1618: if (npline >= MAXPLINE) {
1619: (void) fputc('\n', fptab);
1620: npline = 0;
1621: }
1622: npline++;
1623: (void) fprintf(fptab, " 0x%02x,", *str++ & 0xff);
1624: len--;
1625: }
1626: (void) fprintf(fptab, "}");
1627: }
1628: /*
1629: * determine if the string is printable i.e. only sensible to be read
1630: * as a character string. 1 (true) if it is 0, if it isn't
1631: */
1632: printable(str, i)
1633: char *str;
1634: int i;
1635: {
1636: while (i-- > 0) {
1637: if (!isprint(*str & 0xff))
1638: return (0); /* look for the first non printable
1639: * character */
1640: }
1641: return (1);
1642: }
1643: /*
1644: * generate a unique identifier using the name given and the name if
1645: * present in yp. Return a pointer to it in a space malloc'ed out
1646: */
1647: char *
1648: genlabel(name, yp)
1649: char *name;
1650: YP yp;
1651: {
1652: char buf[MAXNAME];
1653: static int cnt;
1654: char *p1, *p2;
1655:
1656: p1 = notidtoid(name);
1657: if (yp->yp_flags & YP_ID) {
1658: p2 = notidtoid(yp->yp_id);
1659: (void) sprintf(buf, "L%s_%s_%d", p1, p2, cnt++);
1660: free(p2);
1661: } else
1662: (void) sprintf(buf, "L%s_X_%d", p1, cnt++);
1663: free(p1);
1664:
1665: return (my_new_str(buf));
1666: }
1667: /*
1668: * generate a ptr table reference for the given module table entry
1669: */
1670: gen_modref(mod)
1671: char *mod;
1672: {
1673: char buf[BUFSIZ];
1674: char *p1;
1675: int ind;
1676:
1677: p1 = notidtoid(mod);
1678: (void) sprintf(buf, "&%s%s%s", PREFIX, p1, MODTYP_SUFFIX);
1679: ind = addptr(buf);
1680: free(p1);
1681:
1682: return (ind);
1683: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.