|
|
1.1 root 1: /* pass2.c */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/pepsy/RCS/pass2.c,v 7.2 90/07/27 08:49:22 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/pepsy/RCS/pass2.c,v 7.2 90/07/27 08:49:22 mrose Exp $
9: *
10: *
11: * $Log: pass2.c,v $
12: * Revision 7.2 90/07/27 08:49:22 mrose
13: * update
14: *
15: * Revision 7.1 90/07/01 20:00:32 mrose
16: * update
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: #include <stdio.h>
32: #include <ctype.h>
33: #include "pepsydefs.h"
34: #include "pass2.h"
35: #include "mine.h"
36: #include "sym.h"
37:
38: extern int doexternals;
39: extern int sflag;
40:
41: #if 0
42: extern int hflag;
43: extern int bwidth;
44:
45: #endif
46: extern char *eval;
47:
48: #if 0
49: extern char *yyprefix;
50:
51: #endif
52: extern int Aflag;
53: extern SY mysymbols;
54: extern char *modsym();
55: extern char *my_strcat();
56: extern char *notidtoid();
57:
58: FILE *fptab, *ffopen();
59:
60: peri_pass2()
61: {
62:
63: int nentries;
64: int encflag = 1, decflag = 1, prntflag = 1;
65: char *buf, *inc, *tab, *act;
66: SY sy;
67: YP yp;
68: FILE *fph, *fphh, *fpe, *fpd, *fpp;
69: FILE *fpa;
70:
71: if (!sflag)
72: (void) fflush(stderr);
73:
74: if (bflag) {
75: register int i, j;
76:
77: i = 2, j = 10;
78: for (sy = mysymbols; sy; sy = sy->sy_next)
79: if (!(sy->sy_type->yp_flags & YP_IMPORTED))
80: if (++i >= j)
81: j *= 10;
82: }
83: if (strcmp(mymodule, "UNIV"))
84: (void) lookup_module("UNIV", NULLOID);
85:
86: fph = ffopen(my_strcat(mymodule, HFILE1));
87: inc = my_strcat (mymodule, HFILE2);
88: (void) fprintf (fph, "#ifndef\tPEPYPATH\n");
89: (void) fprintf (fph, "#include <isode/pepsy/%s>\n", inc);
90: (void) fprintf (fph, "#else\n");
91: (void) fprintf (fph, "#include \"%s\"\n", inc);
92: (void) fprintf (fph, "#endif\n\n\n");
93:
94: #ifdef ACT_CODE
95: act = my_strcat(mymodule, ACTIONDEFS);
96:
97: fpe = ffopen(my_strcat(mymodule, ENCFILENAME));
98: file_header(fpe, act);
99: fpd = ffopen(my_strcat(mymodule, DECFILENAME));
100: file_header(fpd, act);
101: fpp = ffopen(my_strcat(mymodule, PRNTFILENAME));
102: file_header(fpp, act);
103: fpa = ffopen(act);
104: #endif
105: tab = notidtoid(mymodule);
106: for (sy = mysymbols; sy; sy = sy->sy_next) {
107: eval = sy->sy_name;
108: yp = sy->sy_type;
109:
110: if (sy->sy_module == NULLCP)
111: yyerror("no module name associated with symbol");
112: if (yp->yp_flags & YP_IMPORTED)
113: continue;
114: if (strcmp(sy->sy_module, mymodule)) {
115: fprintf(stderr, "mymodule unsuitable for module name e.g %s and %s(mymodule)\n", sy->sy_module, mymodule);
116: exit(1);
117: }
118: if (yp->yp_direction & YP_ENCODER || Aflag) {
119: buf = modsym (sy -> sy_module, sy -> sy_name, yyencdflt);
120: fprintf(fph, "#define %s", buf);
121: fprintf(fph, "(pe, top, len, buffer, parm) \\\n");
122: fprintf(fph, " %s(%s%s, ", ENCFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
123: fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
124: fprintf(fph, "pe, top, len, buffer, (char *) parm)\n\n");
125: #ifdef ACT_CODE
126: if (encflag) {
127: fprintf(fpe, "%s%s", ENC_FNCNAME, tab);
128: open_func(fpe);
129: encflag--;
130: }
131: #endif
132: if (bflag)
133: init_new_file();
134: if (bflag)
135: end_file();
136: }
137: if (yp->yp_direction & YP_DECODER || Aflag) {
138: buf = modsym (sy -> sy_module, sy -> sy_name, yydecdflt);
139: if (bflag)
140: init_new_file();
141: fprintf(fph, "#define %s", buf);
142: fprintf(fph, "(pe, top, len, buffer, parm) \\\n");
143: fprintf(fph, " %s(%s%s, ", DECFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
144: fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
145: fprintf(fph, "pe, top, len, buffer, (char **) parm)\n\n");
146: #if ACT_CODE
147: if (decflag) {
148: fprintf(fpd, "%s%s", DEC_FNCNAME, tab);
149: open_func(fpd);
150: decflag--;
151: }
152: #endif
153: if (bflag)
154: end_file();
155: }
156: if (yp->yp_direction & YP_PRINTER || Aflag) {
157: buf = modsym (sy -> sy_module, sy -> sy_name, yyprfdflt);
158: if (bflag)
159: init_new_file();
160: fprintf(fph, "#define %s", buf);
161: fprintf(fph, "(pe, top, len, buffer, parm) \\\n");
162: fprintf(fph, " %s(%s%s, ", PRNTFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
163: fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
164: #if 0
165: /* no parm arguement to prnt_f now */
166: fprintf(fph, "pe, top, len, buffer, (char *) parm)\n");
167: #endif
168: fprintf(fph, "pe, top, len, buffer)\n");
169: fprintf(fph, "#define %s_P", buf);
170: fprintf(fph, " %s%s, ", PREFIX,
171: proc_name(sy->sy_name, 1));
172: fprintf(fph, "&%s%s%s\n\n", PREFIX, tab, MODTYP_SUFFIX);
173: #ifdef ACT_CODE
174: if (prntflag) {
175: fprintf(fpp, "%s%s", PRNT_FNCNAME, tab);
176: open_func(fpp);
177: prntflag--;
178: }
179: #endif
180: if (bflag)
181: end_file();
182: }
183: if (!bflag && ferror(stdout))
184: myyerror("write error - %s", sys_errname(errno));
185: }
186:
187: #ifdef ACT_CODE
188: if (!encflag) {
189: close_func(fpe);
190: }
191: if (!decflag) {
192: close_func(fpd);
193: }
194: if (!prntflag) {
195: close_func(fpp);
196: }
197: #endif
198:
199: close(fph);
200: #ifdef ACT_CODE
201: close(fpe);
202: close(fpd);
203: close(fpp);
204: close(fpa);
205: #endif
206:
207: fptab = ffopen(my_strcat(mymodule, TBLNAME));
208:
209: /* Only need two files <stdio.h> and our types file which includes
210: * everything else we need
211: * Assumption. types file in the same directory as the _tables
212: */
213: fprintf(fptab, "#include <stdio.h>\n");
214: fprintf(fptab, "#include \"%s%s\"\n\n", mymodule, GENTYPES);
215:
216:
217: #if 0
218: {
219: #define NFILES 5
220: char *files[NFILES];
221: char buf[BUFSIZ];
222: int last = 0; /* next free slot in files */
223:
224: strncpy(buf, mymodule, BUFSIZ);
225: strncat(buf, GENTYPES, BUFSIZ);
226:
227: files[last++] = buf;
228: files[last++] = inc;
229: files[last++] = (char *)0;
230:
231: fprintf(fptab, "#include <stdio.h>\n");
232: doincl(fptab, files);
233:
234: #undef NFILES
235: }
236:
237: /* already done in our types.h file */
238: proc_extmod(fptab); /* process the external modules here as well */
239: #endif
240:
241: #if 0
242: fprintf(fptab, "#include \"%s%s\"\n", mymodule, GENTYPES);
243: fprintf(fptab, "#include \"%s\"\n", inc);
244: #endif
245: #ifdef ACT_CODE
246: fprintf(fptab, "#include \"%s\"\n", act);
247: #endif
248: /*
249: * loop through and generate all the default values definitions
250: */
251: for (sy = mysymbols; sy; sy = sy->sy_next) {
252: yp = sy->sy_type;
253: if (yp->yp_flags & YP_IMPORTED)
254: continue;
255: if (yp->yp_direction & (YP_ENCODER | YP_DECODER | YP_PRINTER)
256: || Aflag) {
257: gen_dflts(sy->sy_type, sy->sy_name);
258: }
259: }
260: fprintf(fptab, "\n#define OFFSET(t,f)\t((int ) &(((t *)0)->f))\n\n");
261: nentries = 0;
262: head = NULL;
263: for (sy = mysymbols; sy; sy = sy->sy_next) {
264: yp = sy->sy_type;
265: if (yp->yp_flags & YP_IMPORTED)
266: continue;
267: if (yp->yp_direction & YP_ENCODER || Aflag) {
268: nentries++;
269: gen_enctbl(sy);
270: }
271: }
272: head = NULL;
273: for (sy = mysymbols; sy; sy = sy->sy_next) {
274: yp = sy->sy_type;
275: if (yp->yp_flags & YP_IMPORTED)
276: continue;
277: if (yp->yp_direction & YP_DECODER || Aflag)
278: gen_dectbl(sy);
279: }
280:
281: head = NULL;
282: for (sy = mysymbols; sy; sy = sy->sy_next) {
283: yp = sy->sy_type;
284: if (yp->yp_flags & YP_IMPORTED)
285: continue;
286: if (yp->yp_direction & YP_PRINTER || Aflag)
287: gen_prnttbl(sy);
288: }
289:
290: fphh = ffopen(inc);
291: fprintf(fphh, "\nextern modtyp %s%s%s;\n",
292: PREFIX, tab, MODTYP_SUFFIX);
293: out_final_defs(fphh);
294: close(fphh);
295:
296: gen_tpe();
297: gen_modtype(tab, nentries, encflag, decflag, prntflag);
298:
299: #if 0
300: write_ph_file();
301: print_list();
302: #endif
303:
304: gen_lint(fptab);
305:
306: fclose(fptab);
307: }
308:
309: gen_enctbl(sy)
310: SY sy;
311: {
312: fprintf(fptab, "static tpe %s%s[] = {\n", ETABLE, proc_name(sy->sy_name, 0));
313: fprintf(fptab, "\t{ PE_START, 0, 0, 0 },\n");
314: gen_enctbl_rest(sy->sy_type, sy->sy_name);
315: fprintf(fptab, "\t{ PE_END, 0, 0, 0 }\n");
316: fprintf(fptab, "\t};\n");
317: fprintf(fptab, "\n");
318: }
319:
320: gen_dectbl(sy)
321: SY sy;
322: {
323: fprintf(fptab, "static tpe %s%s[] = {\n", DTABLE, proc_name(sy->sy_name, 0));
324: fprintf(fptab, "\t{ PE_START, 0, 0, 0 },\n");
325: gen_dectbl_rest(sy->sy_type, sy->sy_name);
326: fprintf(fptab, "\t{ PE_END, 0, 0, 0 }\n");
327: fprintf(fptab, "\t};\n");
328: fprintf(fptab, "\n");
329: }
330:
331:
332: gen_prnttbl(sy)
333: SY sy;
334: {
335: fprintf(fptab, "static ptpe %s%s[] = {\n", PTABLE, proc_name(sy->sy_name, 0));
336: fprintf(fptab, "\t{ PE_START, 0, 0, 0, \"%s\" },\n", sy->sy_name);
337: gen_prnttbl_rest(sy->sy_type, sy->sy_name);
338: fprintf(fptab, "\t{ PE_END, 0, 0, 0, NULL }\n");
339: fprintf(fptab, "\t};\n");
340: fprintf(fptab, "\n");
341: }
342:
343:
344: gen_enctbl_rest(yp, id)
345: YP yp;
346: char *id;
347: {
348: int i;
349:
350: i = tenc_typ(yp, id, NULL);
351: }
352:
353: gen_dectbl_rest(yp, id)
354: YP yp;
355: char *id;
356: {
357: int i;
358:
359: i = tdec_typ(yp, id, NULL);
360: }
361:
362: gen_prnttbl_rest(yp, id)
363: YP yp;
364: char *id;
365: {
366: int i;
367:
368: i = tprnt_typ(yp, id, NULL);
369: }
370:
371:
372: /*
373: * define the tpe index tables and the pointer table
374: */
375: gen_tpe()
376: {
377: SY sy;
378:
379: fprintf(fptab, "static tpe *etabl[] = {\n");
380: for (sy = mysymbols; sy; sy = sy->sy_next) {
381: if (sy->sy_type->yp_flags & YP_IMPORTED)
382: continue;
383: if (sy->sy_type->yp_direction & YP_ENCODER || Aflag)
384: fprintf(fptab, "\t%s%s,\n", ETABLE, proc_name(sy->sy_name, 0));
385: }
386: fprintf(fptab, "\t};\n\n");
387:
388: fprintf(fptab, "static tpe *dtabl[] = {\n");
389: for (sy = mysymbols; sy; sy = sy->sy_next) {
390: if (sy->sy_type->yp_flags & YP_IMPORTED)
391: continue;
392: if (sy->sy_type->yp_direction & YP_DECODER || Aflag)
393: fprintf(fptab, "\t%s%s,\n", DTABLE, proc_name(sy->sy_name, 0));
394: }
395: fprintf(fptab, "\t};\n\n");
396:
397: fprintf(fptab, "static ptpe *ptabl[] = {\n");
398: for (sy = mysymbols; sy; sy = sy->sy_next) {
399: if (sy->sy_type->yp_flags & YP_IMPORTED)
400: continue;
401: if (sy->sy_type->yp_direction & YP_PRINTER || Aflag)
402: fprintf(fptab, "\t%s%s,\n", PTABLE, proc_name(sy->sy_name, 0));
403: }
404: fprintf(fptab, "\t};\n\n");
405:
406: /* produce pointer table */
407: dump_ptrtab(fptab);
408: }
409:
410: /*
411: * output the module structure for this module
412: */
413: gen_modtype(tab, no, f1, f2, f3)
414: char *tab;
415: int no;
416: int f1, f2, f3;
417: {
418: if (!f1)
419: fprintf(fptab, "extern PE\t%s%s();\n", ENC_FNCNAME, tab);
420: if (!f2)
421: fprintf(fptab, "extern PE\t%s%s();\n", DEC_FNCNAME, tab);
422: if (!f3)
423: fprintf(fptab, "extern PE\t%s%s();\n", PRNT_FNCNAME, tab);
424: fprintf(fptab, "\n");
425: fprintf(fptab, "modtyp %s%s%s = {\n", PREFIX, tab, MODTYP_SUFFIX);
426: fprintf(fptab, "\t\"%s\",\n", mymodule); /* name */
427: fprintf(fptab, "\t%d,\n", no); /* number of entries */
428: /* coding tables */
429: fprintf(fptab, "\tetabl,\n");
430: fprintf(fptab, "\tdtabl,\n");
431: fprintf(fptab, "\tptabl,\n");
432: /* action tables - may disappear */
433: fprintf(fptab, "\t0,\n"); /* no action code */
434: fprintf(fptab, "\t0,\n");
435: fprintf(fptab, "\t0,\n");
436:
437: fprintf(fptab, "\t%s%s%s,\n", PREFIX, PTR_TABNAME, tab);
438: fprintf(fptab, "\t};\n\n");
439: }
440:
441: /*
442: * open a file called name
443: */
444: FILE *
445: ffopen(name)
446: char *name;
447: {
448: FILE *fp;
449:
450: if ((fp = fopen(name, "w")) == NULL) {
451: fprintf(stderr, "Can't create the file %s", name);
452: exit(1);
453: }
454: return fp;
455: }
456:
457: #ifdef ACT_CODE
458: /*
459: * output the file prologue to the file specified by fp
460: */
461: file_header(fp, act)
462: FILE *fp;
463: char *act;
464: {
465: fprintf(fp, "#include %s\n", PSAP_DOT_H);
466: fprintf(fp, "#include \"%s\"\n", INCFILE1);
467: fprintf(fp, "#include \"%s\"\n", act);
468: fprintf(fp, "#include \"%s%s\"\n\n", mymodule, GENTYPES);
469: fprintf(fp, "#ifndef PEPYPARM\n");
470: fprintf(fp, "#define PEPYPARM char *\n");
471: fprintf(fp, "#endif\n");
472: fprintf(fp, "extern PEPYPARM NullParm;\n\n");
473: }
474:
475: #endif
476:
477: /*
478: * output the function prologue to the file specified by fp
479: */
480: open_func(fp)
481: FILE *fp;
482: {
483:
484: fprintf(fp, "(pe, parm, p, mod)\n");
485: fprintf(fp, "PE\tpe;\n");
486: fprintf(fp, "PEPYPARM\tparm;\n");
487: fprintf(fp, "tpe\t*p;\n");
488: fprintf(fp, "modtyp\t*mod;\n");
489: fprintf(fp, "{\n");
490: /* action 0 ???? */
491: fprintf(fp, "\tswitch (p->pe_ucode) {\n");
492: }
493:
494: /*
495: * output the function epilogue to the file specified by fp
496: */
497: close_func(fp)
498: FILE *fp;
499: {
500: fprintf(fp, "\t\tdefault:\n");
501: fprintf(fp, "\t\t\tbreak;\n");
502: fprintf(fp, "\t}\n");
503: fprintf(fp, "\treturn OK;\n}\n\n");
504: }
505:
506: /*
507: * print the table id_table
508: */
509: print_table()
510: {
511: int i;
512: id_entry *t;
513:
514: for (i = 0; i < TABLESIZE; i++) {
515: for (t = id_table[i]; t != NULL; t = t->next)
516: printf("%s(%d) --> ", t->r_value, t->def_value);
517: if (id_table[i] != NULL)
518: printf("NULL -- %d\n", i);
519: }
520: }
521:
522: static struct univ_typ univ_tab[] = {
523: {"EXTERNAL", "struct type_UNIV_EXTERNAL *", "EXTERNAL", 8, 0,
524: "UNIV", UNF_EXTMOD, YP_UNDF, },
525: {"GeneralString", "struct qbuf *", "OCTETSTRING", 27, 0,
526: "UNIV", 0, YP_OCT, },
527: {"GeneralisedTime", "struct qbuf *", "OCTETSTRING", 24, 0,
528: "UNIV", 0, YP_OCT, },
529: {"GeneralizedTime", "struct qbuf *", "OCTETSTRING", 24, 0,
530: "UNIV", 0, YP_OCT, },
531: {"GraphicString", "struct qbuf *", "OCTETSTRING", 25, 0,
532: "UNIV", 0, YP_OCT, },
533: {"IA5String", "struct qbuf *", "OCTETSTRING", 22, 0,
534: "UNIV", 0, YP_OCT, },
535: {"ISO646String", "struct qbuf *", "OCTETSTRING", 26, 0,
536: "UNIV", 0, YP_OCT, },
537: {"NumericString", "struct qbuf *", "OCTETSTRING", 18, 0,
538: "UNIV", 0, YP_OCT, },
539: {"PrintableString", "struct qbuf *", "OCTETSTRING", 19, 0,
540: "UNIV", 0, YP_OCT, },
541: {"TeletexString", "struct qbuf *", "OCTETSTRING", 20, 0,
542: "UNIV", 0, YP_OCT, },
543: {"T61String", "struct qbuf *", "OCTETSTRING", 20, 0,
544: "UNIV", 0, YP_OCT, },
545: {"UTCTime", "struct qbuf *", "OCTETSTRING", 23, 0,
546: "UNIV", 0, YP_OCT, },
547: {"UniversalTime", "struct qbuf *", "OCTETSTRING", 23, 0,
548: "UNIV", 0, YP_OCT, },
549: {"VideotexString", "struct qbuf *", "OCTETSTRING", 21, 0,
550: "UNIV", 0, YP_OCT, },
551: {"VisibleString", "struct qbuf *", "OCTETSTRING", 26, 0,
552: "UNIV", 0, YP_OCT, },
553: };
554:
555: extern struct univ_typ *simptyp();
556:
557: /*
558: * Determine wether the type name matches one of the Universal types
559: * which are to be treated specially. If so return a pointer to the
560: * data structure which contains the parameters describing how it
561: * should be processed
562: */
563: struct univ_typ *
564: univtyp(name)
565: char *name;
566: {
567: int low, high, i;
568: struct univ_typ *p;
569:
570: low = 0;
571: high = NENTRIES(univ_tab) - 1;
572: while (low <= high) {
573: p = univ_tab + (low + high) / 2;
574: if ((i = scmp(name, p->univ_name)) == 0)
575: return (p);
576: if (low == high)
577: return (NULL);
578: if (i < 0)
579: high = p - univ_tab - 1;
580: else
581: low = p - univ_tab + 1;
582: }
583:
584: #if OPTIMISED
585: if ((p = simptyp(name)) == NULL)
586: return (p);
587: #endif
588:
589: return (NULL);
590: }
591:
592: /*
593: * Compare two strings returning a number representing the character
594: * where they differ or 0 if are the same - I wrote this because I
595: * couldn't trust strcmp to work the same way between numbers and
596: * letters everywhere. longer strings are greater shorter strings
597: * numbers are greater then all letters lower case are greater then
598: * upper case There must be a better way !
599: */
600: scmp(s1, s2)
601: char *s1, *s2;
602: {
603: while (*s1 == *s2 && *s2)
604: s1++, s2++;
605: if (*s1 == '\0' && *s2 == '\0')
606: return (0);
607: if (*s1 == '\0')
608: return (-1);
609: if (*s2 == '\0')
610: return (1);
611: if (isalpha(*s1) && isalpha(*s2)) {
612: if (isupper(*s1) && isupper(*s2))
613: return (*s1 - *s2);
614: if (islower(*s1) && islower(*s1))
615: return (*s1 - *s2);
616: if (isupper(*s1))
617: return (-1);
618: if (islower(*s1))
619: return (1);
620: }
621: if (isdigit(*s1) && isdigit(*s2))
622: return (*s1 - *s2);
623: if (isdigit(*s1))
624: return (1);
625: if (isdigit(*s2))
626: return (-1);
627: return (*s1 - *s2);
628: }
629:
630: /*
631: * lookup a symbol and return a pointer to it
632: */
633: SY
634: syfind(name)
635: char *name;
636: {
637: SY sy;
638:
639: for (sy = mysymbols; sy; sy = sy->sy_next) {
640: if (sy->sy_type->yp_flags & YP_IMPORTED)
641: continue;
642: if (strcmp(name, sy->sy_name) == 0)
643: return (sy);
644: }
645: return (NULL);
646: }
647: /*
648: * determine if the symbol is a simple type that is optimised
649: */
650: struct univ_typ *
651: simptyp(yp)
652: YP yp;
653: {
654: struct univ_typ *p;
655: YP y;
656:
657: static struct univ_typ bitstring =
658: {"Bitstring", "struct PElement *", "BITSTRING", 3, 0},
659: octetstring =
660: {"GeneralString", "struct qbuf *", "OCTETSTRING", 4, 0},
661: oid =
662: {"Object Identifier", "struct OIDentifier *", "OBJIDENT", 6, 0},
663: obj =
664: {"Module", "struct OIDentifier *",
665: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 27, 0};
666:
667: #define MSTRING 30 /* number of Xs in the above string */
668:
669: switch (yp->yp_code) {
670: case YP_BIT:
671: case YP_BITLIST:
672: return (&bitstring);
673:
674: case YP_SEQ:
675: case YP_SET:
676: case YP_ANY:
677: return (&bitstring);
678:
679: case YP_OCT:
680: return (&octetstring);
681:
682: case YP_OID:
683: return (&oid);
684:
685: case YP_IDEFINED:
686: strncpy(p->univ_tab, yp->yp_identifier, MSTRING);
687: return (&obj);
688:
689:
690: case YP_SEQLIST:
691: case YP_SETLIST:
692: case YP_CHOICE:
693: #if 0
694: if (hflag && (y = yp->yp_type) && !y->yp_next) {
695: ferr(1, "simtyp: -h flag not implemented\n");
696: return (NULL);
697: }
698: #endif
699:
700: default:
701: return (NULL);
702: }
703: }
704:
705: /*
706: * Generate function definitions for all the macros so that lint
707: * can type check all thier uses
708: */
709: gen_lint(fp)
710: FILE *fp;
711: {
712: char *buf, *tab;
713: SY sy;
714: YP yp;
715:
716: fprintf(fp, "\n#ifdef\tlint\n");
717: tab = notidtoid(mymodule);
718: for (sy = mysymbols; sy; sy = sy->sy_next) {
719: eval = sy->sy_name;
720: yp = sy->sy_type;
721:
722: if (sy->sy_module == NULLCP)
723: yyerror("no module name associated with symbol");
724: if (yp->yp_flags & YP_IMPORTED)
725: continue;
726: if (strcmp(sy->sy_module, mymodule)) {
727: fprintf(stderr,
728: "mymodule unsuitable for module name e.g %s and %s(mymodule)\n",
729: sy->sy_module, mymodule);
730: exit(1);
731: }
732: /* Encoding routine */
733: buf = modsym (sy -> sy_module, sy -> sy_name, yyencdflt);
734: fprintf(fp, "\n#undef %s\n", buf);
735: fprintf(fp, "int %s", buf);
736: fprintf(fp, "(pe, top, len, buffer, parm)\n");
737: fprintf(fp, "PE *pe;\n");
738: fprintf(fp, "int top,\n\tlen;\n");
739: fprintf(fp, "char buffer;\n");
740: fprintf(fp, "struct %s parm;\n",
741: modsym(sy->sy_module, sy->sy_name, "type"));
742: fprintf(fp, "{\n return (%s(%s%s, ",
743: ENCFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
744: fprintf(fp, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
745: fprintf(fp, "pe, top, len, buffer, (char *) parm)\n}\n");
746:
747: /* Decoding routine */
748: buf = modsym (sy -> sy_module, sy -> sy_name, yydecdflt);
749: fprintf(fp, "\n#undef %s\n", buf);
750: fprintf(fp, "int %s", buf);
751: fprintf(fp, "(pe, top, len, buffer, parm)\n");
752: fprintf(fp, "PE pe;\n");
753: fprintf(fp, "int top,\n\t*len;\n");
754: fprintf(fp, "char *buffer;\n");
755: fprintf(fp, "struct %s parm;\n",
756: modsym(sy->sy_module, sy->sy_name, "type"));
757: fprintf(fp, "{\n return (%s(%s%s, ",
758: DECFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
759: fprintf(fp, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
760: fprintf(fp, "pe, top, len, buffer, (char *) parm)\n}\n");
761:
762:
763: /* Printing routine */
764: buf = modsym (sy -> sy_module, sy -> sy_name, yyprfdflt);
765: fprintf(fp, "\n#undef %s\n", buf);
766: fprintf(fp, "int %s", buf);
767: fprintf(fp, "(pe, top, len, buffer, parm)\n");
768: fprintf(fp, "PE pe;\n");
769: fprintf(fp, "int top,\n\t*len;\n");
770: fprintf(fp, "char *buffer;\n");
771: fprintf(fp, "struct %s parm;\n",
772: modsym(sy->sy_module, sy->sy_name, "type"));
773: fprintf(fp, "{\n return (%s(%s%s, ",
774: PRNTFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
775: fprintf(fp, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
776: fprintf(fp, "pe, top, len, buffer, (char *) parm)\n}\n");
777:
778: if (ferror(fp))
779: myyerror("write error - %s", sys_errname(errno));
780: }
781: fprintf(fp, "\n#endif\t/* lint */\n");
782: }
783:
784: /*
785: * pointer table support routines
786: */
787: static char *ptr_tab[MAXPTRS]; /* reference of the pointer */
788: static int ptr_cnt = 0;
789:
790: /*
791: * add the given pointer to the pointer table and return its index
792: */
793: addptr(p)
794: char *p;
795: {
796: int ind;
797: register int i;
798: register char *s;
799:
800: /*
801: * try to eliminate common pointers by returning a ponter if it matches
802: * previously
803: */
804: for (i = 0; i < ptr_cnt; i++)
805: if (strcmp(p, ptr_tab[i]) == 0)
806: return (i);
807:
808: if (ptr_cnt >= MAXPTRS) {
809: fprintf(stderr, "\npointer table overflow %d\n", ptr_cnt);
810: exit(1);
811: }
812:
813: if ((s = malloc ((unsigned) (strlen (p) + 1))) == NULLCP) {
814: fprintf(stderr, "\naddptr:out of memory\n");
815: exit(1);
816: }
817: (void) strcpy (s, p);
818:
819: ptr_tab[ind = ptr_cnt++] = s;
820:
821: return (ind);
822: }
823:
824:
825: dump_ptrtab(fp)
826: FILE *fp;
827: {
828: char *tab;
829: int i;
830:
831: tab = notidtoid(mymodule);
832:
833: fprintf(fp, "\n/* Pointer table %d entries */\n", ptr_cnt);
834: fprintf(fp, "static caddr_t %s%s%s[] = {\n", PREFIX, PTR_TABNAME, tab);
835:
836: for (i = 0; i < ptr_cnt; i++)
837: fprintf(fp, " (caddr_t ) %s,\n", ptr_tab[i]);
838:
839: if (ptr_cnt <= 0)
840: fprintf(fp, " (caddr_t ) 0,\n"); /* for fussy C compilers */
841:
842: fprintf(fp, "};\n");
843: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.