|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T p
Length: 15704 (0x3d58) Types: TextFile Names: »pass2.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦041b9c0f8⟧ »EurOpenD22/isode/pepsy.system-6.0.Z« └─⟦d49939f05⟧ └─⟦6a28ec38e⟧ »pepsy.tar« └─⟦this⟧ »pepy/pass2.c«
#include <stdio.h> #include <ctype.h> #include "pepy.h" #include "pass2.h" #include "mine.h" #include "posy.h" extern int doexternals; extern int sflag; #if 0 extern int hflag; extern int bwidth; #endif extern char *eval; #if 0 extern char *yyprefix; #endif extern int Aflag; extern SY mysymbols; extern char *modsym(); extern char *my_strcat(); extern char *notidtoid(); FILE *fptab, *ffopen(); peri_pass2 () { int nentries; int encflag = 1, decflag = 1, prntflag = 1; char *buf, *inc, *tab, *act; SY sy; YP yp; FILE *fph, *fphh, *fpe, *fpd, *fpp; FILE *fpa; if (!sflag) (void) fflush (stderr); if (bflag) { register int i, j; i = 2, j = 10; for (sy = mysymbols; sy; sy = sy -> sy_next) if (!(sy -> sy_type -> yp_flags & YP_IMPORTED)) if (++i >= j) j *= 10; #if 0 bwidth++, j *= 10; #endif } else /*prologue2 ()*/; if (strcmp (mymodule, "UNIV")) (void) lookup_module ("UNIV", NULLOID); fph = ffopen(my_strcat(mymodule, HFILE1)); fprintf(fph, "#include \"%s\"\n\n\n", inc = my_strcat(mymodule, HFILE2)); #ifdef ACT_CODE act = my_strcat(mymodule, ACTIONDEFS); fpe = ffopen(my_strcat(mymodule, ENCFILENAME)); file_header(fpe, act); fpd = ffopen(my_strcat(mymodule, DECFILENAME)); file_header(fpd, act); fpp = ffopen(my_strcat(mymodule, PRNTFILENAME)); file_header(fpp, act); fpa = ffopen(act); #endif tab = notidtoid(mymodule); for (sy = mysymbols; sy; sy = sy -> sy_next) { eval = sy->sy_name; yp = sy -> sy_type; if (sy -> sy_module == NULLCP) yyerror ("no module name associated with symbol"); if (yp -> yp_flags & YP_IMPORTED) continue; if (strcmp(sy->sy_module, mymodule)) { fprintf(stderr, "mymodule unsuitable for module name e.g %s and %s(mymodule)\n",sy->sy_module, mymodule); exit(1); } Printf(2, ("\n*** %s ***\n",sy->sy_name)); if (yp -> yp_direction & YP_ENCODER || Aflag) { Printf(1, ("\nEncoding\n")); #if 0 yyprefix = sy -> sy_encpref; #endif printf ("\n %s\n", buf = modsym (sy -> sy_module, sy -> sy_name, yyencdflt)); fprintf(fph, "#define %s", buf); fprintf(fph, "(pe, top, len, buffer, parm) \\\n"); fprintf(fph, " %s(%s%s, ", ENCFNCNAME, PREFIX, proc_name(sy->sy_name, 1)); fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX); fprintf(fph, "pe, top, len, buffer, parm)\n\n"); #ifdef ACT_CODE if (encflag) { fprintf(fpe, "%s%s", ENC_FNCNAME, tab); open_func(fpe); encflag--; } #endif /* do_sw_type(sy->sy_name, yp, fpe, fpa); */ if (bflag) init_new_file (); /* printf ("\n return OK;\n}\n"); */ if (bflag) end_file (); } if (yp -> yp_direction & YP_DECODER || Aflag) { Printf(1, ("\nDecoding\n")); if (bflag) init_new_file (); #if 0 yyprefix = sy -> sy_decpref; #endif printf ("\n %s\n", buf = modsym (sy -> sy_module, sy -> sy_name, yydecdflt)); fprintf(fph, "#define %s", buf); fprintf(fph, "(pe, top, len, buffer, parm) \\\n"); fprintf(fph, " %s(%s%s, ", DECFNCNAME, PREFIX, proc_name(sy->sy_name, 1)); fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX); fprintf(fph, "pe, top, len, buffer, parm)\n\n"); #if ACT_CODE if (decflag) { fprintf(fpd, "%s%s", DEC_FNCNAME, tab); open_func(fpd); decflag--; } /* do_sw_type(sy->sy_name, yp, fpd, fpa); printf ("\n return OK;\n}\n"); */ #endif if (bflag) end_file (); } if (yp -> yp_direction & YP_PRINTER || Aflag) { Printf(1, ("\nPrinting\n")); if (bflag) init_new_file (); #if 0 yyprefix = sy -> sy_prfpref; #endif printf ("\n %s\n", buf = modsym (sy -> sy_module, sy -> sy_name, yyprfdflt)); fprintf(fph, "#define %s", buf); fprintf(fph, "(pe, top, len, buffer, parm) \\\n"); fprintf(fph, " %s(%s%s, ", PRNTFNCNAME, PREFIX, proc_name(sy->sy_name, 1)); fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX); fprintf(fph, "pe, top, len, buffer, parm)\n"); fprintf(fph, "#define %s_P", buf); fprintf(fph, " %s%s, ", PREFIX, proc_name(sy->sy_name, 1)); fprintf(fph, "&%s%s%s\n\n", PREFIX, tab, MODTYP_SUFFIX); #ifdef ACT_CODE if (prntflag) { fprintf(fpp, "%s%s", PRNT_FNCNAME, tab); open_func(fpp); prntflag--; } #endif /* do_sw_type(sy->sy_name, yp, fpp, fpa); printf ("\n return OK;\n}\n"); */ if (bflag) end_file (); } if (!bflag && ferror (stdout)) myyerror ("write error - %s", sys_errname (errno)); } #ifdef ACT_CODE if (!encflag) { close_func(fpe); } if (!decflag) { close_func(fpd); } if (!prntflag) { close_func(fpp); } #endif close(fph); #ifdef ACT_CODE close(fpe); close(fpd); close(fpp); close(fpa); #endif fptab = ffopen(my_strcat(mymodule, TBLNAME)); #if 0 fprintf(fptab, "#define PEPYPATH\n"); #endif fprintf(fptab, "#include %s\n", PSAP_DOT_H); fprintf(fptab, "#include \"%s%s\"\n", mymodule, GENTYPES); #if 0 /* Don't need this now they include'd in GENTYPES file */ fprintf(fptab, "#include \"%s\"\n", INCFILE1); fprintf(fptab, "#include \"%s\"\n", INCFILE2); #endif fprintf(fptab, "#include \"%s\"\n", inc); #ifdef ACT_CODE fprintf(fptab, "#include \"%s\"\n", act); #endif /* Generate includes for any external type references used */ for (sy = mysymbols; sy; sy = sy -> sy_next) { yp = sy->sy_type; if (yp->yp_flags & YP_IMPORTED) continue; if (yp->yp_direction & (YP_ENCODER|YP_DECODER|YP_PRINTER) || Aflag) { gen_extincl(sy); } } fprintf(fptab, "\n#define OFFSET(t,f)\t((int ) &(((t *)0)->f))\n\n"); nentries = 0; Printf(1, ("\nStart generating Encoding tables\n")); head = NULL; for (sy = mysymbols; sy; sy = sy -> sy_next) { yp = sy->sy_type; if (yp->yp_flags & YP_IMPORTED) continue; if (yp->yp_direction & YP_ENCODER || Aflag) { nentries++; gen_enctbl(sy); } } Printf(1, ("\nStart generating Decoding tables\n")); head = NULL; for (sy = mysymbols; sy; sy = sy -> sy_next) { yp = sy->sy_type; if (yp->yp_flags & YP_IMPORTED) continue; if (yp->yp_direction & YP_DECODER || Aflag) gen_dectbl(sy); } Printf(1, ("\nStart generating Printing tables\n")); head = NULL; for (sy = mysymbols; sy; sy = sy -> sy_next) { yp = sy->sy_type; if (yp->yp_flags & YP_IMPORTED) continue; if (yp->yp_direction & YP_PRINTER || Aflag) gen_prnttbl(sy); } fphh = ffopen(inc); fprintf(fphh, "\nextern modtyp %s%s%s;\n", PREFIX, tab, MODTYP_SUFFIX); out_final_defs(fphh); close(fphh); Printf(1, ("\nAfter generating #defines\n")); gen_tpe(); gen_modtype(tab, nentries, encflag, decflag, prntflag); Printf(1, ("\nAfter generating modtype sructure\n")); #if 0 write_ph_file (); #endif print_list(); } gen_extincl(sy) SY sy; { extincl(sy->sy_type, sy->sy_name); } gen_enctbl(sy) SY sy; { fprintf(fptab, "static tpe %s%s[] = {\n", ETABLE, proc_name(sy->sy_name, 0)); fprintf(fptab, "\t{ PE_START, 0, 0, 0 },\n"); gen_enctbl_rest(sy->sy_type, sy->sy_name); fprintf(fptab, "\t{ PE_END, 0, 0, 0 }\n"); fprintf(fptab, "\t};\n"); fprintf(fptab, "\n"); } gen_dectbl(sy) SY sy; { fprintf(fptab, "static tpe %s%s[] = {\n", DTABLE, proc_name(sy->sy_name, 0)); fprintf(fptab, "\t{ PE_START, 0, 0, 0 },\n"); gen_dectbl_rest(sy->sy_type, sy->sy_name); fprintf(fptab, "\t{ PE_END, 0, 0, 0 }\n"); fprintf(fptab, "\t};\n"); fprintf(fptab, "\n"); } gen_prnttbl(sy) SY sy; { fprintf(fptab, "static ptpe %s%s[] = {\n", PTABLE, proc_name(sy->sy_name, 0)); fprintf(fptab, "\t{ PE_START, 0, 0, 0, \"%s\" },\n", sy->sy_name); gen_prnttbl_rest(sy->sy_type, sy->sy_name); fprintf(fptab, "\t{ PE_END, 0, 0, 0, NULL }\n"); fprintf(fptab, "\t};\n"); fprintf(fptab, "\n"); } gen_enctbl_rest(yp, id) YP yp; char *id; { int i; i = tenc_typ(yp, id, NULL); } gen_dectbl_rest(yp, id) YP yp; char *id; { int i; i = tdec_typ(yp, id, NULL); } gen_prnttbl_rest(yp, id) YP yp; char *id; { int i; i = tprnt_typ(yp, id, NULL); } gen_tpe() { SY sy; fprintf(fptab, "static tpe *etabl[] = {\n"); for (sy = mysymbols; sy; sy = sy->sy_next){ if (sy->sy_type->yp_flags & YP_IMPORTED) continue; if (sy->sy_type->yp_direction & YP_ENCODER || Aflag) fprintf(fptab, "\t%s%s,\n", ETABLE, proc_name(sy->sy_name, 0)); } fprintf(fptab, "\t};\n\n"); fprintf(fptab, "static tpe *dtabl[] = {\n"); for (sy = mysymbols; sy; sy = sy->sy_next){ if (sy->sy_type->yp_flags & YP_IMPORTED) continue; if (sy->sy_type->yp_direction & YP_DECODER || Aflag) fprintf(fptab, "\t%s%s,\n", DTABLE, proc_name(sy->sy_name, 0)); } fprintf(fptab, "\t};\n\n"); fprintf(fptab, "static ptpe *ptabl[] = {\n"); for (sy = mysymbols; sy; sy = sy->sy_next){ if (sy->sy_type->yp_flags & YP_IMPORTED) continue; if (sy->sy_type->yp_direction & YP_PRINTER || Aflag) fprintf(fptab, "\t%s%s,\n", PTABLE, proc_name(sy->sy_name, 0)); } fprintf(fptab, "\t};\n\n"); } /* output the module structure for this module */ gen_modtype(tab, no, f1, f2, f3) char *tab; int no; int f1, f2, f3; { if (!f1) fprintf(fptab, "extern PE\t%s%s();\n", ENC_FNCNAME, tab); if (!f2) fprintf(fptab, "extern PE\t%s%s();\n", DEC_FNCNAME, tab); if (!f3) fprintf(fptab, "extern PE\t%s%s();\n", PRNT_FNCNAME, tab); fprintf(fptab, "\n"); fprintf(fptab, "modtyp %s%s%s = {\n", PREFIX, tab, MODTYP_SUFFIX); fprintf(fptab, "\t\"%s\",\n",mymodule); fprintf(fptab, "\t%d,\n",no); fprintf(fptab, "\tetabl,\n"); fprintf(fptab, "\tdtabl,\n"); fprintf(fptab, "\tptabl,\n"); fprintf(fptab, "\t0,\n"); /* action code no directly executed */ fprintf(fptab, "\t0,\n"); fprintf(fptab, "\t0,\n"); /* if (!f1) fprintf(fptab, "\t%s%s,\n", ENC_FNCNAME, tab); else fprintf(fptab, "\t0,\n"); if (!f2) fprintf(fptab, "\t%s%s,\n", DEC_FNCNAME, tab); else fprintf(fptab, "\t0,\n"); if (!f3) fprintf(fptab, "\t%s%s,\n", PRNT_FNCNAME, tab); else fprintf(fptab, "\t0,\n"); */ fprintf(fptab, "\t};\n\n"); } /* open a file called name */ FILE *ffopen(name) char *name; { FILE *fp; if ((fp = fopen(name, "w")) == NULL) { fprintf(stderr, "Can't create the file %s", name); exit(1); } return fp; } /* output the file prologue to the file specified by fp */ file_header(fp, act) FILE *fp; char *act; { fprintf(fp, "#include %s\n", PSAP_DOT_H); fprintf(fp, "#include \"%s\"\n", INCFILE1); fprintf(fp, "#include \"%s\"\n", INCFILE2); fprintf(fp, "#include \"%s\"\n", act); fprintf(fp, "#include \"%s%s\"\n\n", mymodule, GENTYPES); fprintf(fp, "#ifndef PEPYPARM\n"); fprintf(fp, "#define PEPYPARM char *\n"); fprintf(fp, "#endif\n"); fprintf(fp, "extern PEPYPARM NullParm;\n\n"); } /* output the function prologue to the file specified by fp */ open_func(fp) FILE *fp; { fprintf(fp, "(pe, parm, p, mod)\n"); fprintf(fp, "PE\tpe;\n"); fprintf(fp, "PEPYPARM\tparm;\n"); fprintf(fp, "tpe\t*p;\n"); fprintf(fp, "modtyp\t*mod;\n"); fprintf(fp, "{\n"); /*action 0 ????*/ fprintf(fp, "\tswitch (p->pe_ucode) {\n"); } /* output the function epilogue to the file specified by fp */ close_func(fp) FILE *fp; { fprintf(fp, "\t\tdefault:\n"); fprintf(fp, "\t\t\tbreak;\n"); fprintf(fp, "\t}\n"); fprintf(fp, "\treturn OK;\n}\n\n"); } /* print the table id_table */ print_table() { int i; id_entry *t; for (i = 0; i < TABLESIZE; i++) { for (t = id_table[i]; t != NULL; t = t->next) printf("%s(%d) --> ",t->r_value, t->def_value); if (id_table[i] != NULL) printf("NULL -- %d\n",i); } } static struct univ_typ univ_tab[] = { { "EXTERNAL", "struct type_UNIV_EXTERNAL *", "EXTERNAL", 8, 0, "UNIV", UNF_EXTMOD, }, { "GeneralString", "struct qbuf *", "OCTETSTRING", 27, 0, "UNIV", 0, }, { "GeneralisedTime", "struct qbuf *", "OCTETSTRING", 24, 0, "UNIV", 0, }, { "GeneralizedTime", "struct qbuf *", "OCTETSTRING", 24, 0, "UNIV", 0, }, { "GraphicString", "struct qbuf *", "OCTETSTRING", 25, 0, "UNIV", 0, }, { "IA5String", "struct qbuf *", "OCTETSTRING", 22, 0, "UNIV", 0, }, { "ISO646String", "struct qbuf *", "OCTETSTRING", 26, 0, "UNIV", 0, }, { "NumericString", "struct qbuf *", "OCTETSTRING", 18, 0, "UNIV", 0, }, { "PrintableString", "struct qbuf *", "OCTETSTRING", 19, 0, "UNIV", 0, }, { "TeletexString", "struct qbuf *", "OCTETSTRING", 20, 0, "UNIV", 0, }, { "T61String", "struct qbuf *", "OCTETSTRING", 20, 0, "UNIV", 0, }, { "UTCTime", "struct qbuf *", "OCTETSTRING", 23, 0, "UNIV", 0, }, { "UniversalTime", "struct qbuf *", "OCTETSTRING", 23, 0, "UNIV", 0, }, { "VideotexString", "struct qbuf *", "OCTETSTRING", 21, 0, "UNIV", 0, }, { "VisibleString", "struct qbuf *", "OCTETSTRING", 26, 0, "UNIV", 0, }, }; extern struct univ_typ *simptyp(); /* * Determine wether the type name matches one of the Universal types * which are to be treated specially. If so return a pointer to the * data structure which contains the parameters describing how it should * be processed */ struct univ_typ * univtyp(name) char *name; { int low, high, i; struct univ_typ *p; low = 0; high = NENTRIES(univ_tab) - 1; while (low <= high) { p = univ_tab + (low + high)/2; if ((i = scmp(name, p->univ_name)) == 0) return (p); if (low == high) return (NULL); if (i < 0) high = p - univ_tab - 1; else low = p - univ_tab + 1; } #if OPTIMISED if ((p = simptyp(name)) == NULL) return (p); #endif return (NULL); } /* Compare two strings returning a number representing the character where they * differ or 0 if are the same - I wrote this because I couldn't trust strcmp * to work the same way between numbers and letters everywhere. * longer strings are greater shorter strings * numbers are greater then all letters * lower case are greater then upper case * There must be a better way ! */ scmp(s1, s2) char *s1, *s2; { while (*s1 == *s2 && *s2) s1++, s2++; if (*s1 == '\0' && *s2 == '\0') return (0); if (*s1 == '\0') return (-1); if (*s2 == '\0') return (1); if (isalpha(*s1) && isalpha(*s2)) { if (isupper(*s1) && isupper(*s2)) return (*s1 - *s2); if (islower(*s1) && islower(*s1)) return (*s1 - *s2); if (isupper(*s1)) return (-1); if (islower(*s1)) return (1); } if (isdigit(*s1) && isdigit(*s2)) return (*s1 - *s2); if (isdigit(*s1)) return (1); if (isdigit(*s2)) return (-1); return (*s1 - *s2); } /* * lookup a symbol and return a pointer to it */ SY syfind(name) char *name; { SY sy; for (sy = mysymbols; sy; sy = sy -> sy_next) { if (sy->sy_type->yp_flags & YP_IMPORTED) continue; if (strcmp(name, sy->sy_name) == 0) return (sy); } return (NULL); } /* * determine if the symbol is a simple type that is optimised */ struct univ_typ * simptyp(yp) YP yp; { struct univ_typ *p; YP y; static struct univ_typ bitstring = { "Bitstring", "struct PElement *", "BITSTRING", 3, 0 }, octetstring = { "GeneralString", "struct qbuf *", "OCTETSTRING", 4, 0 }, oid = { "Object Identifier", "struct OIDentifier *", "OBJIDENT", 6, 0 }, obj = { "Module", "struct OIDentifier *", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 27, 0 }; #define MSTRING 30 /* number of Xs in the above string */ switch (yp -> yp_code) { case YP_BIT: case YP_BITLIST: return (&bitstring); case YP_SEQ: case YP_SET: case YP_ANY: return (&bitstring); case YP_OCT: return (&octetstring); case YP_OID: return (&oid); case YP_IDEFINED: strncpy(p->univ_tab, yp->yp_identifier, MSTRING); return (&obj); case YP_SEQLIST: case YP_SETLIST: case YP_CHOICE: #if 0 if (hflag && (y = yp -> yp_type) && !y -> yp_next) { ferr(1, "simtyp: -h flag not implemented\n"); return (NULL); } #endif default: return (NULL); } }