|
|
1.1 ! root 1: /* pepsy.c - table driven posy/pepy replacement system */ ! 2: ! 3: /* OPEN QUESTIONS: ! 4: ! 5: How to do smarter DEFAULT determination for the other types and NULLs ! 6: ! 7: Perhaps pull-up primitive IDentifiers ! 8: ! 9: Abort a CHOICE encoding if the structure is empty ! 10: ! 11: ! 12: HEURISTICS ! 13: ! 14: 1. LANGUAGE SIMPLIFICATIONS: ! 15: ! 16: ! 17: Pull-up uni-member SEQUENCEs/SETs/CHOICEs ! 18: ! 19: ! 20: 2. LANGUAGE ASSUMPTIONS: ! 21: ! 22: Unique tags to avoid conflicts for internal structures (-h1 option) ! 23: ! 24: ! 25: 3. STYLE ISSUES: ! 26: ! 27: SEQUENCE/SET OF Type should have Type be an ID for nicer naming ! 28: */ ! 29: ! 30: #ifndef lint ! 31: static char *rcsid = "$Header: /f/osi/pepsy/RCS/pepsy.c,v 7.1 90/07/09 14:52:50 mrose Exp $"; ! 32: #endif ! 33: ! 34: /* ! 35: * $Header: /f/osi/pepsy/RCS/pepsy.c,v 7.1 90/07/09 14:52:50 mrose Exp $ ! 36: * ! 37: * ! 38: * $Log: pepsy.c,v $ ! 39: * Revision 7.1 90/07/09 14:52:50 mrose ! 40: * sync ! 41: * ! 42: * Revision 7.0 90/07/01 19:54:25 mrose ! 43: * *** empty log message *** ! 44: * ! 45: * Revision 7.3 90/02/23 17:50:09 mrose ! 46: * update ! 47: * ! 48: * Revision 7.2 90/02/19 13:09:35 mrose ! 49: * update ! 50: * ! 51: * Revision 7.1 90/01/11 18:37:05 mrose ! 52: * real-sync ! 53: * ! 54: * Revision 7.0 89/11/23 22:11:59 mrose ! 55: * Release 6.0 ! 56: * ! 57: */ ! 58: ! 59: /* ! 60: * NOTICE ! 61: * ! 62: * Acquisition, use, and distribution of this module and related ! 63: * materials are subject to the restrictions of a license agreement. ! 64: * Consult the Preface in the User's Manual for the full terms of ! 65: * this agreement. ! 66: * ! 67: */ ! 68: ! 69: ! 70: #include <ctype.h> ! 71: #include <stdio.h> ! 72: #include <varargs.h> ! 73: #include "pepsydefs.h" ! 74: #include "pass2.h" ! 75: ! 76: ! 77: #define SVAL(s) ((s) ? (s) : "") ! 78: #define PARVAL(s) ((s) ? (s) : "parm") ! 79: ! 80: /* DATA */ ! 81: ! 82: static int aflag = 0; ! 83: int Aflag = 0; /* Don't so all modes by default */ ! 84: int Cflag = 0; /* posy */ ! 85: int dflag = 0; ! 86: int Pflag = 0; /* pepy compat ... */ ! 87: char *bflag = NULL; /* .. */ ! 88: char *module_actions = NULL; ! 89: int pepydebug = 0; ! 90: int doexternals = 1; ! 91: static int fflag = 0; ! 92: static int linepos = 0; ! 93: static int mflag = 0; ! 94: int sflag = 0; ! 95: ! 96: int p_debug = 3; ! 97: int options[NOPTIONS]; ! 98: ! 99: char *eval = NULLCP; ! 100: ! 101: char *mymodule = ""; ! 102: OID mymoduleid = NULLOID; ! 103: static char modulename[BUFSIZ]; ! 104: ! 105: int yysection = YP_DECODER; ! 106: char *yyencpref = "encode"; ! 107: char *yydecpref = "decode"; ! 108: char *yyprfpref = "print"; ! 109: char *yyencdflt = "encode"; ! 110: char *yydecdflt = "decode"; ! 111: char *yyprfdflt = "print"; ! 112: ! 113: static char *classes[] = { ! 114: "UNIVERSAL ", ! 115: "APPLICATION ", ! 116: "", ! 117: "PRIVATE " ! 118: }; ! 119: ! 120: static char *tags[] = { ! 121: "", "BOOLEAN", "INTEGER", "INTEGER", "BIT STRING", "BIT STRING", ! 122: "OCTET STRING", "NULL", "SEQUENCE", "SEQUENCE OF", "SEQUENCE", "SET", ! 123: "SET OF", "SET", "CHOICE", "ANY", "OBJECT IDENTIFIER", "", ! 124: ! 125: NULL ! 126: }; ! 127: ! 128: struct tuple tuples[] = { ! 129: YP_BOOL, "PE_CLASS_UNIV", "PE_FORM_PRIM", "PE_PRIM_BOOL", ! 130: PE_CLASS_UNIV, PE_PRIM_BOOL, ! 131: YP_INT, "PE_CLASS_UNIV", "PE_FORM_PRIM", "PE_PRIM_INT", ! 132: PE_CLASS_UNIV, PE_PRIM_INT, ! 133: YP_INTLIST, "PE_CLASS_UNIV", "PE_FORM_PRIM", "PE_PRIM_INT", ! 134: PE_CLASS_UNIV, PE_PRIM_INT, ! 135: YP_BIT, "PE_CLASS_UNIV", NULLCP, "PE_PRIM_BITS", ! 136: PE_CLASS_UNIV, PE_PRIM_BITS, ! 137: YP_BITLIST, "PE_CLASS_UNIV", NULLCP, "PE_PRIM_BITS", ! 138: PE_CLASS_UNIV, PE_PRIM_BITS, ! 139: YP_OCT, "PE_CLASS_UNIV", NULLCP, "PE_PRIM_OCTS", ! 140: PE_CLASS_UNIV, PE_PRIM_OCTS, ! 141: YP_NULL, "PE_CLASS_UNIV", NULLCP, "PE_PRIM_NULL", ! 142: PE_CLASS_UNIV, PE_PRIM_NULL, ! 143: YP_OID, "PE_CLASS_UNIV", "PE_FORM_PRIM", "PE_PRIM_OID", ! 144: PE_CLASS_UNIV, PE_PRIM_OID, ! 145: YP_SEQ, "PE_CLASS_UNIV", "PE_FORM_CONS", "PE_CONS_SEQ", ! 146: PE_CLASS_UNIV, PE_CONS_SEQ, ! 147: YP_SEQTYPE, "PE_CLASS_UNIV", "PE_FORM_CONS", "PE_CONS_SEQ", ! 148: PE_CLASS_UNIV, PE_CONS_SEQ, ! 149: YP_SEQLIST, "PE_CLASS_UNIV", "PE_FORM_CONS", "PE_CONS_SEQ", ! 150: PE_CLASS_UNIV, PE_CONS_SEQ, ! 151: YP_SET, "PE_CLASS_UNIV", "PE_FORM_CONS", "PE_CONS_SET", ! 152: PE_CLASS_UNIV, PE_CONS_SET, ! 153: YP_SETTYPE, "PE_CLASS_UNIV", "PE_FORM_CONS", "PE_CONS_SET", ! 154: PE_CLASS_UNIV, PE_CONS_SET, ! 155: YP_SETLIST, "PE_CLASS_UNIV", "PE_FORM_CONS", "PE_CONS_SET", ! 156: PE_CLASS_UNIV, PE_CONS_SET, ! 157: YP_ENUMLIST, "PE_CLASS_UNIV", "PE_FORM_PRIM", "PE_PRIM_ENUM", ! 158: PE_CLASS_UNIV, PE_PRIM_ENUM, ! 159: YP_REAL, "PE_CLASS_UNIV", "PE_FORM_PRIM", "PE_PRIM_REAL", ! 160: PE_CLASS_UNIV, PE_PRIM_REAL, ! 161: ! 162: YP_UNDF ! 163: }; ! 164: ! 165: ! 166: static char autogen[BUFSIZ]; ! 167: ! 168: char *sysin = NULLCP; ! 169: static char sysout[BUFSIZ]; ! 170: static char sysdef[BUFSIZ]; ! 171: static char sysact[BUFSIZ]; ! 172: ! 173: #if 0 ! 174: static FILE *fact; ! 175: #endif ! 176: static FILE *fdef; ! 177: ! 178: typedef struct modlist { ! 179: char *md_module; ! 180: OID md_oid; ! 181: int md_flags; ! 182: #define MDF_SEEN 1 /* Seen this module */ ! 183: ! 184: struct modlist *md_next; ! 185: } modlist, *MD; ! 186: #define NULLMD ((MD) 0) ! 187: ! 188: static MD mymodules = NULLMD; ! 189: ! 190: typedef struct symlist { ! 191: char *sy_encpref; ! 192: char *sy_decpref; ! 193: char *sy_prfpref; ! 194: char *sy_module; ! 195: char *sy_name; ! 196: ! 197: YP sy_type; ! 198: ! 199: struct symlist *sy_next; ! 200: } symlist, *SY; ! 201: #define NULLSY ((SY) 0) ! 202: ! 203: SY mysymbols = NULLSY; ! 204: ! 205: ! 206: char *gensym (), *modsym (), *array (); ! 207: extern char *my_strcat(), *gfree(), *concat(), *my_new_str(); ! 208: MD lookup_module (); ! 209: SY new_symbol (), add_symbol (); ! 210: static double val2real (); ! 211: static void prime_default (); ! 212: ! 213: FILE *open_ph_file (); ! 214: ! 215: YP lookup_type (); ! 216: ! 217: YT lookup_tag (); ! 218: ! 219: /* MAIN */ ! 220: ! 221: /* ARGSUSED */ ! 222: ! 223: main (argc, argv, envp) ! 224: int argc; ! 225: char **argv, ! 226: **envp; ! 227: { ! 228: int i; ! 229: register char *cp, ! 230: *dp; ! 231: ! 232: dp = pepsyversion + strlen ("pepsy "); ! 233: (void) fprintf (stderr, "pepsy %s\n", dp); ! 234: ! 235: sysout[0] = sysdef[0] = sysact[0] = NULL; ! 236: for (argc--, argv++; argc > 0; argc--, argv++) { ! 237: cp = *argv; ! 238: ! 239: if (strcmp (cp, "-A") == 0) { ! 240: Aflag++; ! 241: continue; ! 242: } ! 243: if (strcmp (cp, "-a") == 0) { ! 244: aflag++; ! 245: continue; ! 246: } ! 247: if (strcmp (cp, "-d") == 0) { ! 248: dflag++; ! 249: continue; ! 250: } ! 251: if (strcmp (cp, "-f") == 0) { ! 252: dflag++, fflag++; ! 253: continue; ! 254: } ! 255: if (strncmp (cp, "-h", 2) == 0) { ! 256: if (cp[2] == NULL) { ! 257: hflag++; ! 258: continue; ! 259: } ! 260: if (sscanf (cp + 2, "%d", &i) != 1 || i >= NOPTIONS) ! 261: goto usage; ! 262: hflag++, options[i]++; ! 263: continue; ! 264: } ! 265: if (strcmp (cp, "-m") == 0) { ! 266: mflag++; ! 267: continue; ! 268: } ! 269: if (strcmp (cp, "-s") == 0) { ! 270: sflag++; ! 271: continue; ! 272: } ! 273: ! 274: if (sysin) { ! 275: usage: ; ! 276: (void) fprintf (stderr, ! 277: "usage: pepsy [-A] [-a] [-d] [-f] [-h] [-s] module.py\n"); ! 278: exit (1); ! 279: } ! 280: ! 281: if (*cp == '-') { ! 282: if (*++cp != NULL) ! 283: goto usage; ! 284: sysin = ""; ! 285: } ! 286: sysin = cp; ! 287: } ! 288: ! 289: switch (pepydebug = (cp = getenv ("PEPSYTEST")) && *cp ? atoi (cp) : 0) { ! 290: case 2: ! 291: yydebug++; /* fall */ ! 292: case 1: ! 293: sflag++; /* .. */ ! 294: case 0: ! 295: break; ! 296: } ! 297: ! 298: if (sysin == NULLCP) ! 299: sysin = ""; ! 300: ! 301: if (*sysin && freopen (sysin, "r", stdin) == NULL) { ! 302: (void) fprintf (stderr, "unable to read "), perror (sysin); ! 303: exit (1); ! 304: } ! 305: ! 306: if (strcmp (sysout, "-") == 0) ! 307: sysout[0] = NULL; ! 308: if (*sysout && freopen (sysout, "w", stdout) == NULL) { ! 309: (void) fprintf (stderr, "unable to write "), perror (sysout); ! 310: exit (1); ! 311: } ! 312: ! 313: if (cp = index (dp, ')')) { ! 314: for (cp++; *cp != ' '; cp++) ! 315: if (*cp == NULL) ! 316: break; ! 317: if (*cp == NULL) ! 318: cp = NULL; ! 319: } ! 320: if (cp == NULL) ! 321: cp = dp + strlen (dp); ! 322: (void) sprintf (autogen, "pepsy %*.*s", cp - dp, cp - dp, dp); ! 323: ! 324: initoidtbl (); ! 325: ! 326: exit (yyparse ()); /* NOTREACHED */ ! 327: } ! 328: ! 329: /* ERRORS */ ! 330: ! 331: yyerror (s) ! 332: register char *s; ! 333: { ! 334: yyerror_aux (s); ! 335: ! 336: if (*sysout) ! 337: (void) unlink (sysout); ! 338: if (*sysdef) ! 339: (void) unlink (sysdef); ! 340: if (*sysact) ! 341: (void) unlink (sysact); ! 342: ! 343: exit (1); ! 344: } ! 345: ! 346: #ifndef lint ! 347: warning (va_alist) ! 348: va_dcl ! 349: { ! 350: char buffer[BUFSIZ]; ! 351: char buffer2[BUFSIZ]; ! 352: char *cp; ! 353: va_list ap; ! 354: ! 355: va_start (ap); ! 356: ! 357: _asprintf (buffer, NULLCP, ap); ! 358: ! 359: va_end (ap); ! 360: ! 361: (void) sprintf (buffer2, "Warning: %s", buffer); ! 362: yyerror_aux (buffer2); ! 363: } ! 364: ! 365: #else ! 366: ! 367: /* VARARGS1 */ ! 368: warning (fmt) ! 369: char *fmt; ! 370: { ! 371: warning (fmt); ! 372: } ! 373: #endif ! 374: ! 375: static yyerror_aux (s) ! 376: register char *s; ! 377: { ! 378: if (linepos) ! 379: (void) fprintf (stderr, "\n"), linepos = 0; ! 380: ! 381: if (eval) ! 382: (void) fprintf (stderr, "type %s: ", eval); ! 383: else ! 384: (void) fprintf (stderr, "line %d: ", yylineno); ! 385: (void) fprintf (stderr, "%s\n", s); ! 386: if (!eval) ! 387: (void) fprintf (stderr, "last token read was \"%s\"\n", yytext); ! 388: } ! 389: ! 390: /* */ ! 391: ! 392: #ifndef lint ! 393: myyerror (va_alist) ! 394: va_dcl ! 395: { ! 396: char buffer[BUFSIZ]; ! 397: va_list ap; ! 398: ! 399: va_start (ap); ! 400: ! 401: _asprintf (buffer, NULLCP, ap); ! 402: ! 403: va_end (ap); ! 404: ! 405: yyerror (buffer); ! 406: } ! 407: #else ! 408: /* VARARGS */ ! 409: ! 410: myyerror (fmt) ! 411: char *fmt; ! 412: { ! 413: myyerror (fmt); ! 414: } ! 415: #endif ! 416: ! 417: ! 418: #ifndef lint ! 419: static pyyerror (va_alist) ! 420: va_dcl ! 421: { ! 422: char buffer[BUFSIZ]; ! 423: register YP yp; ! 424: va_list ap; ! 425: ! 426: va_start (ap); ! 427: ! 428: yp = va_arg (ap, YP); ! 429: ! 430: _asprintf (buffer, NULLCP, ap); ! 431: ! 432: va_end (ap); ! 433: ! 434: yyerror_aux (buffer); ! 435: print_type (yp, 0); ! 436: ! 437: ! 438: if (*sysout) ! 439: (void) unlink (sysout); ! 440: if (*sysdef) ! 441: (void) unlink (sysdef); ! 442: if (*sysact) ! 443: (void) unlink (sysact); ! 444: ! 445: exit (1); ! 446: } ! 447: #else ! 448: /* VARARGS */ ! 449: ! 450: static pyyerror (yp, fmt) ! 451: YP yp; ! 452: char *fmt; ! 453: { ! 454: pyyerror (yp, fmt); ! 455: } ! 456: #endif ! 457: ! 458: /* */ ! 459: ! 460: yywrap () { ! 461: if (linepos) ! 462: (void) fprintf (stderr, "\n"), linepos = 0; ! 463: ! 464: return 1; ! 465: } ! 466: ! 467: /* */ ! 468: ! 469: /* ARGSUSED */ ! 470: ! 471: yyprint (s, f, top) ! 472: char *s; ! 473: int f; ! 474: int top; ! 475: { ! 476: int len; ! 477: static int nameoutput = 0; ! 478: static int outputlinelen = 79; ! 479: ! 480: if (sflag || !s) ! 481: return; ! 482: ! 483: if (!nameoutput) { ! 484: if (linepos) ! 485: (void) fprintf (stderr, "\n\n"); ! 486: ! 487: (void) fprintf (stderr, "%s", mymodule); ! 488: nameoutput = (linepos = strlen (mymodule)) + 1; ! 489: ! 490: (void) fprintf (stderr, " types:"); ! 491: linepos += 7; ! 492: ! 493: if (top) ! 494: return; ! 495: } ! 496: ! 497: len = strlen (s); ! 498: if (linepos != nameoutput) ! 499: if (len + linepos + 1 > outputlinelen) ! 500: (void) fprintf (stderr, "\n%*s", linepos = nameoutput, ""); ! 501: else ! 502: (void) fprintf (stderr, " "), linepos++; ! 503: (void) fprintf (stderr, "%s", s); ! 504: linepos += len; ! 505: } ! 506: ! 507: /* PASS1 */ ! 508: ! 509: pass1 () ! 510: { ! 511: #if 0 ! 512: (void) printf ("%s ", mymodule); ! 513: if (mymoduleid) { ! 514: (void) printf ("%s ", oidprint(mymoduleid)); ! 515: } ! 516: (void) printf ("DEFINITIONS ::=\n\n"); ! 517: #endif ! 518: } ! 519: ! 520: /* */ ! 521: ! 522: pass1_type (encpref, decpref, prfpref, mod, id, yp) ! 523: register char *encpref, ! 524: *decpref, ! 525: *prfpref, ! 526: *mod, ! 527: *id; ! 528: register YP yp; ! 529: { ! 530: register SY sy; ! 531: ! 532: if (lookup_type (mod, id)) /* no duplicate entries, please... */ ! 533: return; ! 534: ! 535: if (pepydebug) { ! 536: if (linepos) ! 537: (void) fprintf (stderr, "\n"), linepos = 0; ! 538: ! 539: (void) fprintf (stderr, "%s.%s\n", mod ? mod : mymodule, id); ! 540: print_type (yp, 0); ! 541: (void) fprintf (stderr, "--------\n"); ! 542: } ! 543: else ! 544: if (!(yp -> yp_flags & YP_IMPORTED)) ! 545: yyprint (id, 0, 0); ! 546: ! 547: sy = new_symbol (encpref, decpref, prfpref, mod, id, yp); ! 548: mysymbols = add_symbol (mysymbols, sy); ! 549: } ! 550: ! 551: /* PASS2 */ ! 552: ! 553: pass2 () { ! 554: register SY sy; ! 555: register YP yp; ! 556: ! 557: if (!sflag) ! 558: (void) fflush (stderr); ! 559: ! 560: modsym_aux (mymodule, modulename); ! 561: ! 562: (void) sprintf (sysdef, "%s-types.h", mymodule); ! 563: if ((fdef = fopen (sysdef, "w")) == NULL) ! 564: myyerror ("unable to write %s", sysdef); ! 565: (void) fprintf (fdef, "/* automatically generated by %s, do not edit! */\n\n", ! 566: autogen); ! 567: (void) fprintf (fdef, "#ifndef\t_module_%s_defined_\n", modulename); ! 568: (void) fprintf (fdef, "#define\t_module_%s_defined_\n\n", modulename); ! 569: ! 570: (void) fprintf (fdef, "#ifndef\tPEPSY_VERSION\n"); ! 571: (void) fprintf (fdef, "#define\tPEPSY_VERSION\t\t%d\n", PEPSY_VERSION_NUMBER); ! 572: (void) fprintf (fdef, "#endif\n\n"); ! 573: ! 574: { ! 575: #define NFILES 5 ! 576: char *files[NFILES]; ! 577: /* { "psap.h", "pepsy.h", "UNIV-types.h", (char *)0 }; */ ! 578: ! 579: int last = 0; /* last slot available in files */ ! 580: ! 581: files[last++] = "psap.h"; ! 582: files[last++] = "pepsy.h"; ! 583: ! 584: if (strcmp (mymodule, "UNIV")) { ! 585: files[last++] = "pepsy/UNIV-types.h"; ! 586: } ! 587: ! 588: files[last++] = (char *)0; ! 589: ! 590: doincl(fdef, files); ! 591: ! 592: #undef NFILES ! 593: } ! 594: ! 595: (void) fprintf (fdef, "#ifndef\tPEPYPATH\n"); ! 596: (void) fprintf (fdef, "#include <isode/pepsy/%s%s>\n", mymodule, HFILE1); ! 597: (void) fprintf (fdef, "#else\n"); ! 598: (void) fprintf (fdef, "#include \"%s%s\"\n", mymodule, HFILE1); ! 599: (void) fprintf (fdef, "#endif\n"); ! 600: ! 601: #if 0 ! 602: if (fflag) { ! 603: (void) sprintf (sysact, "%s-types.tmp", mymodule); ! 604: if ((fact = fopen (sysact, "w+")) == NULL) ! 605: myyerror ("unable to write %s", sysact); ! 606: } ! 607: #endif ! 608: ! 609: for (sy = mysymbols; sy; sy = sy -> sy_next) { ! 610: eval = sy -> sy_name; ! 611: yp = sy -> sy_type; ! 612: if (sy -> sy_module == NULLCP) ! 613: yyerror ("no module name associated with symbol"); ! 614: if (yp -> yp_flags & YP_IMPORTED) ! 615: continue; ! 616: ! 617: do_struct0 (yp, eval); ! 618: #if 0 ! 619: if (ferror (stdout) || ferror (fdef) || (fflag && ferror (fact))) ! 620: myyerror ("write error - %s", sys_errname (errno)); ! 621: #endif ! 622: if (ferror (stdout) || ferror (fdef)) ! 623: myyerror ("write error - %s", sys_errname (errno)); ! 624: } ! 625: /* dump out the references to the external types */ ! 626: proc_extmod(fdef); ! 627: ! 628: for (sy = mysymbols; sy; sy = sy -> sy_next) { ! 629: eval = sy -> sy_name; ! 630: yp = sy -> sy_type; ! 631: if (yp -> yp_flags & YP_IMPORTED) ! 632: continue; ! 633: ! 634: do_struct1 (yp, eval, NULLCP); ! 635: #if 0 ! 636: if (ferror (stdout) || ferror (fdef) || (fflag && ferror (fact))) ! 637: myyerror ("write error - %s", sys_errname (errno)); ! 638: #endif ! 639: if (ferror (stdout) || ferror (fdef)) ! 640: myyerror ("write error - %s", sys_errname (errno)); ! 641: } ! 642: ! 643: for (sy = mysymbols; sy; sy = sy -> sy_next) { ! 644: eval = sy -> sy_name; ! 645: yp = sy -> sy_type; ! 646: if (yp -> yp_flags & YP_IMPORTED) ! 647: continue; ! 648: ! 649: do_struct2 (yp, eval, NULLCP); ! 650: #if 0 ! 651: if (ferror (stdout) || ferror (fdef) || (fflag && ferror (fact))) ! 652: myyerror ("write error - %s", sys_errname (errno)); ! 653: #endif ! 654: if (ferror (stdout) || ferror (fdef)) ! 655: myyerror ("write error - %s", sys_errname (errno)); ! 656: } ! 657: ! 658: peri_pass2(); ! 659: ! 660: #if 0 ! 661: if (fflag) { ! 662: register int c; ! 663: ! 664: (void) fflush (fact); ! 665: (void) fseek (fact, 0L, 0); ! 666: ! 667: (void) printf ("\n%%{\n"); ! 668: while ((c = getc (fact)) != EOF) ! 669: (void) putchar (c); ! 670: (void) printf ("\n%%}\n"); ! 671: ! 672: (void) fclose (fact); ! 673: if (*sysact) ! 674: (void) unlink (sysact); ! 675: } ! 676: #endif ! 677: ! 678: (void) fprintf (fdef, "#endif\n"); ! 679: (void) fflush (fdef); ! 680: (void) fflush (stdout); ! 681: if (ferror (stdout) || ferror (fdef)) ! 682: myyerror ("write error - %s", sys_errname (errno)); ! 683: (void) fclose (fdef); ! 684: ! 685: write_ph_file(); ! 686: } ! 687: ! 688: /* */ ! 689: ! 690: /* ARGSUSED */ ! 691: ! 692: static do_struct0 (yp, id) ! 693: register YP yp; ! 694: char *id; ! 695: { ! 696: register YP y; ! 697: MD md; ! 698: ! 699: switch (yp -> yp_code) { ! 700: case YP_SEQLIST: ! 701: case YP_SETLIST: ! 702: components_pullup (yp); ! 703: break; ! 704: ! 705: default: ! 706: break; ! 707: } ! 708: ! 709: switch (yp -> yp_code) { ! 710: case YP_SEQTYPE: ! 711: case YP_SETTYPE: ! 712: do_struct0 (yp -> yp_type, id); ! 713: break; ! 714: ! 715: case YP_CHOICE: ! 716: case YP_SETLIST: ! 717: choice_pullup (yp, yp -> yp_code == YP_CHOICE ? CH_FULLY ! 718: : CH_PARTIAL); ! 719: /* and fall */ ! 720: case YP_SEQLIST: ! 721: for (y = yp -> yp_type; y; y = y -> yp_next) ! 722: do_struct0 (y, id); ! 723: break; ! 724: ! 725: case YP_IDEFINED: ! 726: if (yp -> yp_module && strcmp (yp -> yp_module, mymodule)) { ! 727: if ((md = lookup_module (yp -> yp_module, yp -> yp_modid)) ! 728: == NULLMD || (md->md_flags & MDF_SEEN) == 0) { ! 729: addextmod(yp -> yp_module); ! 730: #if 0 ! 731: (void) fprintf(fdef, "#include \"%s-types.h\"\n", ! 732: yp -> yp_module); ! 733: #endif ! 734: if (md) ! 735: md->md_flags |= MDF_SEEN; ! 736: } ! 737: } ! 738: break; ! 739: ! 740: default: ! 741: break; ! 742: } ! 743: } ! 744: ! 745: /* */ ! 746: ! 747: static do_struct1 (yp, id, pullup) ! 748: register YP yp; ! 749: char *id, ! 750: *pullup; ! 751: { ! 752: register int i, ! 753: j; ! 754: char buf1[BUFSIZ]; ! 755: register YP y; ! 756: register YV yv; ! 757: ! 758: switch (yp -> yp_code) { ! 759: case YP_BIT: ! 760: case YP_BITLIST: ! 761: case YP_SEQ: ! 762: case YP_SET: ! 763: case YP_ANY: ! 764: (void) fprintf (fdef, "\n"); ! 765: if (aflag) ! 766: printag (yp, 4, pullup); ! 767: (void) fprintf (fdef, "#define\t%s\tPElement\n", ! 768: modsym (mymodule, id, "type")); ! 769: if (yp -> yp_code == YP_BITLIST) { ! 770: i = -1; ! 771: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) ! 772: if ((j = val2int (yv)) < 0) ! 773: pyyerror (yp, "invalid bit number in BIT STRING"); ! 774: else ! 775: if (j > i) ! 776: i = j; ! 777: if (i < sizeof (int) * 8) { /* NBBY */ ! 778: (void) fprintf (fdef, "#define\t%s\t\"\\020", ! 779: modsym (mymodule, eval, "bits")); ! 780: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) ! 781: if (yv -> yv_flags & YV_NAMED) ! 782: (void) fprintf (fdef, "\\0%o%s", ! 783: val2int (yv) + 1, yv -> yv_named); ! 784: else ! 785: (void) fprintf (fdef, "\\0%oBIT%d", ! 786: val2int (yv) + 1, val2int (yv)); ! 787: (void) fprintf (fdef, "\"\n"); ! 788: } ! 789: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) { ! 790: modsym_aux (yv -> yv_named, buf1); ! 791: (void) fprintf (fdef, "#define\t%s_%s\t%d\n", ! 792: modsym (mymodule, eval, "bit"), ! 793: buf1, val2int (yv)); ! 794: } ! 795: } ! 796: if (fflag) ! 797: (void) fprintf (fdef, "#define\t%s\tpe_free\n", ! 798: modsym (mymodule, id, "free")); ! 799: break; ! 800: ! 801: case YP_OCT: ! 802: (void) fprintf (fdef, "\n"); ! 803: if (aflag) ! 804: printag (yp, 4, pullup); ! 805: (void) fprintf (fdef, "#define\t%s\tqbuf\n", ! 806: modsym (mymodule, id, "type")); ! 807: if (fflag) ! 808: (void) fprintf (fdef, "#define\t%s\tqb_free\n", ! 809: modsym (mymodule, id, "free")); ! 810: break; ! 811: ! 812: case YP_OID: ! 813: (void) fprintf (fdef, "\n"); ! 814: if (aflag) ! 815: printag (yp, 4, pullup); ! 816: (void) fprintf (fdef, "#define\t%s\tOIDentifier\n", ! 817: modsym (mymodule, id, "type")); ! 818: if (fflag) ! 819: (void) fprintf (fdef, "#define\t%s\toid_free\n", ! 820: modsym (mymodule, id, "free")); ! 821: break; ! 822: ! 823: case YP_IDEFINED: ! 824: (void) fprintf (fdef, "\n"); ! 825: if (aflag) ! 826: printag (yp, 4, pullup); ! 827: (void) fprintf (fdef, "#define\t%s\t", ! 828: modsym (mymodule, id, "type")); ! 829: (void) fprintf (fdef, "%s\n", ! 830: modsym (yp -> yp_module, yp -> yp_identifier, "type")); ! 831: if (fflag) { ! 832: (void) fprintf (fdef, "#define\t%s\t", ! 833: modsym (mymodule, id, "free")); ! 834: (void) fprintf (fdef, "%s\n", ! 835: modsym (yp -> yp_module, yp -> yp_identifier, "free")); ! 836: } ! 837: break; ! 838: ! 839: case YP_SEQLIST: ! 840: case YP_SETLIST: ! 841: case YP_CHOICE: ! 842: if (hflag && (y = yp -> yp_type) && !y -> yp_next) { ! 843: do_struct1 (y, id, tags[yp -> yp_code]); ! 844: break; ! 845: } ! 846: /* else fall */ ! 847: ! 848: default: ! 849: break; ! 850: } ! 851: } ! 852: ! 853: /* */ ! 854: ! 855: static do_struct2 (yp, id, pullup) ! 856: register YP yp; ! 857: char *id, ! 858: *pullup; ! 859: { ! 860: register YP y; ! 861: int flg = (yp -> yp_code == YP_SEQTYPE || yp -> yp_code == YP_SETTYPE); ! 862: ! 863: switch (yp -> yp_code) { ! 864: case YP_BIT: ! 865: case YP_BITLIST: ! 866: case YP_SEQ: ! 867: case YP_SET: ! 868: case YP_ANY: ! 869: case YP_OCT: ! 870: case YP_OID: ! 871: case YP_IDEFINED: ! 872: break; ! 873: ! 874: case YP_SEQLIST: ! 875: case YP_SETLIST: ! 876: case YP_CHOICE: ! 877: if (hflag && (y = yp -> yp_type) && !y -> yp_next) { ! 878: do_struct2 (y, id, tags[yp -> yp_code]); ! 879: break; ! 880: } ! 881: /* else fall */ ! 882: ! 883: default: ! 884: (void) fprintf (fdef, "\n"); ! 885: if (aflag) ! 886: printag (yp, 4, pullup); ! 887: (void) fprintf (fdef, "struct %s {\n", modsym (mymodule, id, "type")); ! 888: #if 0 ! 889: if (fflag) { ! 890: (void) fprintf (fact, "\n%s (arg)\n", modsym (mymodule, id, "free")); ! 891: (void) fprintf (fact, "struct %s *arg;\n{\n", ! 892: modsym (mymodule, id, "type")); ! 893: (void) fprintf (fact, " struct %s *parm = arg;\n", ! 894: modsym (mymodule, id, "type")); ! 895: if (h2flag && flg) ! 896: (void) fprintf (fact, " int\tn_parm;\n"); ! 897: (void) fprintf (fact, "\n if (parm == NULL)\n\treturn;\n\n"); ! 898: } ! 899: #endif ! 900: pepsy (yp, 1, 1, "parm", id, "parm", flg && h2flag); ! 901: (void) fprintf (fdef, "};\n"); ! 902: (void) fprintf (fdef, "#define\t%s(parm)\\\n\t%s\n", modsym (mymodule, id, "free"), gfree(mymodule, id, "parm")); ! 903: #if 0 ! 904: if (fflag) { ! 905: if (yp -> yp_code != YP_SEQTYPE && ! 906: yp -> yp_code != YP_SETTYPE) ! 907: (void) fprintf (fact, "\n free ((char *) arg);"); ! 908: (void) fprintf (fact, "\n}\n"); ! 909: } ! 910: #endif ! 911: ! 912: break; ! 913: } ! 914: } ! 915: ! 916: /* */ ! 917: ! 918: #if 0 ! 919: static int type0_brackets; ! 920: ! 921: static do_type0 (yp, direction) ! 922: register YP yp; ! 923: int direction; ! 924: { ! 925: type0_brackets = type0_bit = 0; ! 926: do_type0_aux (yp, direction); ! 927: if (type0_brackets) ! 928: (void) printf (" %%}\n "); ! 929: } ! 930: ! 931: static do_type0_aux (yp, direction) ! 932: register YP yp; ! 933: int direction; ! 934: { ! 935: register YP y; ! 936: ! 937: if (yp -> yp_declexp) { ! 938: if (type0_brackets++ == 0) ! 939: (void) printf ("\n %%{\n"); ! 940: (void) printf ("\tstruct %s *%s%s;\n", yp -> yp_declexp, ! 941: direction == YP_DECODER ? "*" : "", yp -> yp_declexp); ! 942: } ! 943: ! 944: switch (yp -> yp_code) { ! 945: case YP_SEQTYPE: ! 946: case YP_SETTYPE: ! 947: if (h2flag) { ! 948: if (type0_brackets++ == 0) ! 949: (void) printf ("\n %%{\n"); ! 950: (void) printf ("\tint n_%s = 0;\n", yp -> yp_declexp ? ! 951: yp -> yp_declexp : "parm"); ! 952: } ! 953: do_type0_aux (yp -> yp_type, direction); ! 954: break; ! 955: ! 956: case YP_SEQLIST: ! 957: case YP_SETLIST: ! 958: case YP_CHOICE: ! 959: for (y = yp -> yp_type; y; y = y -> yp_next) ! 960: do_type0_aux (y, direction); ! 961: break; ! 962: ! 963: case YP_BIT: ! 964: case YP_BITLIST: ! 965: if (direction == YP_ENCODER) { ! 966: if (type0_brackets++ == 0) ! 967: (void) printf ("\n %%{\n"); ! 968: if (type0_bit++ == 0) ! 969: (void) printf ("\tchar *bit_parm;\n"); ! 970: } ! 971: break; ! 972: ! 973: default: ! 974: break; ! 975: } ! 976: } ! 977: #endif ! 978: ! 979: /* */ ! 980: ! 981: /* ARGSUSED */ ! 982: ! 983: static do_type1 (yp, top, level, id, var, action2, direction) ! 984: register YP yp; ! 985: int top, ! 986: level; ! 987: char *id, ! 988: *var, ! 989: *action2; ! 990: int direction; ! 991: { ! 992: int i; ! 993: char *cp, ! 994: *ep, ! 995: buffer[BUFSIZ], ! 996: varbuf[BUFSIZ]; ! 997: register YP y; ! 998: register YV yv; ! 999: register YT yt; ! 1000: ! 1001: (void) printf ("%*s", level * 4, ""); ! 1002: ! 1003: if (yp -> yp_flags & YP_ID) { ! 1004: (void) printf ("%s", yp -> yp_id); ! 1005: if (!(yp -> yp_flags & YP_TAG)) ! 1006: (void) printf ("\n%*s", ++level * 4, ""); ! 1007: } ! 1008: ! 1009: if (yp -> yp_flags & YP_TAG) { ! 1010: yt = yp -> yp_tag; ! 1011: (void) printf ("[%s%d]\n", classes[yt -> yt_class], val2int (yt -> yt_value)); ! 1012: level++; ! 1013: (void) printf ("%*s", level * 4, ""); ! 1014: } ! 1015: if (yp -> yp_flags & YP_OPTIONAL && yp -> yp_varexp) { ! 1016: if ((ep = index (yp -> yp_varexp, ' ')) == NULL) ! 1017: yyerror ("Bug in varexp!"); ! 1018: ! 1019: (void) sprintf (varbuf, "%*.*s", ep - yp -> yp_varexp, ! 1020: ep - yp -> yp_varexp, yp -> yp_varexp); ! 1021: } ! 1022: ! 1023: switch (yp -> yp_code) { ! 1024: case YP_BOOL: ! 1025: if ((yp -> yp_flags & (YP_OPTIONAL|YP_DEFAULT)) && ! 1026: direction == YP_DECODER) { ! 1027: if (!top && !(yp -> yp_flags & (YP_ID | YP_TAG))) ! 1028: (void) printf ("dummy-for-default\n%*s", ++level * 4, ""); ! 1029: if (yp -> yp_flags & YP_OPTIONAL) ! 1030: (void) printf ("%%{ %s -> optionals |= %s; %%}\n%*s", ! 1031: varbuf, yp -> yp_optcontrol, level * 4, ""); ! 1032: else ! 1033: (void) printf ("%%{ %s%s = %d; %%}\n%*s", ! 1034: var, SVAL (yp -> yp_varexp), ! 1035: val2int (yp -> yp_default) ? 1 : 0, level * 4, ""); ! 1036: } ! 1037: break; ! 1038: ! 1039: case YP_INT: ! 1040: if ((yp -> yp_flags & (YP_OPTIONAL|YP_DEFAULT)) && ! 1041: direction == YP_DECODER) { ! 1042: if (!top && !(yp -> yp_flags & (YP_ID | YP_TAG))) ! 1043: (void) printf ("dummy-for-default\n%*s", ++level * 4, ""); ! 1044: if (yp -> yp_flags & YP_OPTIONAL) ! 1045: (void) printf ("%%{ %s -> optionals |= %s; %%}\n%*s", ! 1046: varbuf, yp -> yp_optcontrol, level * 4, ""); ! 1047: else ! 1048: (void) printf ("%%{ %s%s = %d; %%}\n%*s", ! 1049: var, SVAL (yp -> yp_varexp), ! 1050: val2int (yp -> yp_default), level * 4, ""); ! 1051: } ! 1052: break; ! 1053: ! 1054: case YP_INTLIST: ! 1055: case YP_ENUMLIST: ! 1056: if ((yp -> yp_flags & (YP_OPTIONAL|YP_DEFAULT)) && ! 1057: direction == YP_DECODER) { ! 1058: if (!top && !(yp -> yp_flags & (YP_ID | YP_TAG))) ! 1059: (void) printf ("dummy-for-default\n%*s", ++level * 4, ""); ! 1060: if (yp -> yp_flags & YP_OPTIONAL) ! 1061: (void) printf ("%%{ %s -> optionals |= %s; %%}\n%*s", ! 1062: varbuf, yp -> yp_optcontrol, level * 4, ""); ! 1063: else ! 1064: (void) printf ("%%{ %s%s = %d; %%}\n%*s", ! 1065: var, SVAL (yp -> yp_varexp), dfl2int (yp), ! 1066: level * 4, ""); ! 1067: } ! 1068: break; ! 1069: ! 1070: case YP_REAL: ! 1071: if ((yp -> yp_flags & (YP_OPTIONAL|YP_DEFAULT)) && ! 1072: direction == YP_DECODER) { ! 1073: if (!top && !(yp -> yp_flags & (YP_ID | YP_TAG))) ! 1074: (void) printf ("dummy-for-default\n%*s", ++level * 4, ""); ! 1075: if (yp -> yp_flags & YP_OPTIONAL) ! 1076: (void) printf ("%%{ %s -> optionals |= %s; %%}\n%*s", ! 1077: varbuf, yp -> yp_optcontrol, level * 4, ""); ! 1078: else ! 1079: (void) printf ("%%{ %s%s = %g; %%}\n%*s", ! 1080: var, SVAL (yp -> yp_varexp), ! 1081: val2real (yp -> yp_default), level * 4, ""); ! 1082: } ! 1083: break; ! 1084: ! 1085: case YP_NULL: ! 1086: if ((yp -> yp_flags & YP_OPTIONAL) && direction == YP_DECODER) { ! 1087: if (!top && !(yp -> yp_flags & (YP_ID | YP_TAG))) ! 1088: (void) printf ("dummy-for-default\n%*s", ++level * 4, ""); ! 1089: (void) printf ("%%{ %s -> optionals |= %s; %%}\n%*s", ! 1090: varbuf, yp -> yp_optcontrol, level * 4, ""); ! 1091: } ! 1092: break; ! 1093: } ! 1094: ! 1095: if ((yp -> yp_flags & (YP_TAG | YP_IMPLICIT)) == (YP_TAG | YP_IMPLICIT)) ! 1096: (void) printf ("IMPLICIT "); ! 1097: if (yp -> yp_flags & YP_BOUND) ! 1098: (void) printf ("%s < ", yp -> yp_bound); ! 1099: if (yp -> yp_flags & YP_COMPONENTS) ! 1100: (void) printf ("COMPONENTS OF "); ! 1101: if (yp -> yp_flags & YP_ENCRYPTED) ! 1102: (void) printf ("ENCRYPTED "); ! 1103: ! 1104: switch (yp -> yp_code) { ! 1105: case YP_BOOL: ! 1106: (void) printf ("BOOLEAN"); ! 1107: switch (direction) { ! 1108: case YP_ENCODER: ! 1109: case YP_DECODER: ! 1110: (void) printf (top ? "\n%*s[[b %s -> %s ]]" : "\n%*s[[b %s%s ]]", ! 1111: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1112: break; ! 1113: } ! 1114: break; ! 1115: ! 1116: case YP_INT: ! 1117: (void) printf ("INTEGER"); ! 1118: switch (direction) { ! 1119: case YP_ENCODER: ! 1120: case YP_DECODER: ! 1121: (void) printf (top ? "\n%*s[[i %s -> %s ]]" : "\n%*s[[i %s%s ]]", ! 1122: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1123: break; ! 1124: } ! 1125: break; ! 1126: ! 1127: case YP_INTLIST: ! 1128: case YP_ENUMLIST: ! 1129: if (yp -> yp_code == YP_ENUMLIST) ! 1130: (void) printf ("ENUMERATED"); ! 1131: else ! 1132: (void) printf ("INTEGER"); ! 1133: switch (direction) { ! 1134: case YP_ENCODER: ! 1135: case YP_DECODER: ! 1136: (void) printf (top ? "\n%*s[[i %s -> %s ]]\n%*s{\n" ! 1137: : "\n%*s[[i %s%s ]]\n%*s{\n", ! 1138: level * 4, "", var, SVAL (yp -> yp_varexp), ! 1139: level * 4, ""); ! 1140: break; ! 1141: ! 1142: default: ! 1143: (void) printf (" {\n"); ! 1144: break; ! 1145: } ! 1146: level++; ! 1147: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) ! 1148: (void) printf ("%*s%s(%d)%s\n", level * 4, "", yv -> yv_named, ! 1149: val2int (yv), yv -> yv_next ? "," : ""); ! 1150: level--; ! 1151: (void) printf ("%*s}", level * 4, ""); ! 1152: break; ! 1153: ! 1154: case YP_BIT: ! 1155: (void) printf ("BIT STRING"); ! 1156: switch (direction) { ! 1157: case YP_ENCODER: ! 1158: (void) printf ("\n%*s[[x bit_parm = bitstr2strb (%s%s, &len) $ len]]", ! 1159: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1160: (void) printf ("\n%*s%%{\n%*sfree (bit_parm);\n", level * 4, "", ! 1161: (level + 1) * 4, ""); ! 1162: if (action2) ! 1163: (void) printf ("%*s%s\n", (level + 1) * 4, "", action2); ! 1164: (void) printf ("%*s%%}\n", level * 4, ""); ! 1165: break; ! 1166: ! 1167: case YP_DECODER: ! 1168: balloc (yp, var, action2, level); ! 1169: break; ! 1170: } ! 1171: break; ! 1172: ! 1173: case YP_BITLIST: ! 1174: (void) printf ("BIT STRING"); ! 1175: switch (direction) { ! 1176: case YP_ENCODER: ! 1177: (void) printf ("\n%*s[[x bit_parm = bitstr2strb (%s%s, &len) $ len]]\n%*s{\n", ! 1178: level * 4, "", var, SVAL (yp -> yp_varexp), ! 1179: level * 4, ""); ! 1180: break; ! 1181: ! 1182: case YP_DECODER: ! 1183: default: ! 1184: (void) printf (" {\n"); ! 1185: break; ! 1186: } ! 1187: level++; ! 1188: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) ! 1189: (void) printf ("%*s%s(%d)%s\n", level * 4, "", yv -> yv_named, ! 1190: val2int (yv), yv -> yv_next ? "," : ""); ! 1191: level--; ! 1192: (void) printf ("%*s}", level * 4, ""); ! 1193: switch (direction) { ! 1194: case YP_DECODER: ! 1195: balloc (yp, var, action2, level); ! 1196: break; ! 1197: ! 1198: case YP_ENCODER: ! 1199: (void) printf ("\n%*s%%{\n%*sfree (bit_parm);\n", level * 4, "", ! 1200: (level + 1) * 4, ""); ! 1201: if (action2) ! 1202: (void) printf ("%*s%s\n", (level + 1) * 4, "", action2); ! 1203: (void) printf ("%*s%%}\n", level * 4, ""); ! 1204: break; ! 1205: } ! 1206: break; ! 1207: ! 1208: case YP_OCT: ! 1209: (void) printf ("OCTET STRING"); ! 1210: switch (direction) { ! 1211: case YP_ENCODER: ! 1212: (void) printf ("\n%*s[[q %s%s ]]", level * 4, "", ! 1213: var, SVAL (yp -> yp_varexp)); ! 1214: break; ! 1215: ! 1216: case YP_DECODER: ! 1217: (void) printf ("\n%*s[[q %s%s ]]", level * 4, "", ! 1218: var, SVAL (yp -> yp_varexp)); ! 1219: break; ! 1220: } ! 1221: break; ! 1222: ! 1223: case YP_REAL: ! 1224: (void) printf ("REAL"); ! 1225: (void) printf (top ? "\n%*s[[r %s -> %s ]]" : "\n%*s[[r %s%s ]]", ! 1226: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1227: break; ! 1228: ! 1229: case YP_NULL: ! 1230: (void) printf ("NULL"); ! 1231: break; ! 1232: ! 1233: case YP_SEQ: ! 1234: case YP_SET: ! 1235: case YP_ANY: ! 1236: (void) printf ("%s", tags[yp -> yp_code]); ! 1237: switch (direction) { ! 1238: case YP_ENCODER: ! 1239: case YP_DECODER: ! 1240: (void) printf ("\n%*s[[a %s%s ]]", ! 1241: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1242: break; ! 1243: } ! 1244: break; ! 1245: ! 1246: case YP_SEQTYPE: ! 1247: case YP_SETTYPE: ! 1248: ep = yp -> yp_code != YP_SETTYPE ? "element" : "member"; ! 1249: (void) printf ("%s\n", tags [yp -> yp_code]); ! 1250: switch (direction) { ! 1251: case YP_ENCODER: ! 1252: if ((y = yp -> yp_type) -> yp_declexp) { ! 1253: (void) printf ("%*s%%{ %s = %s; %%}\n", ! 1254: (level + 1) * 4, "", y -> yp_declexp, ! 1255: SVAL (y -> yp_varexp)); ! 1256: } ! 1257: if (h2flag) { ! 1258: if (top) { ! 1259: (void) printf ("%*s<<n_parm = 0; ", (level + 1) * 4, ""); ! 1260: (void) printf ("n_parm < parm -> nelem; n_parm++>>\n"); ! 1261: } ! 1262: else { ! 1263: (void) printf ("%*s<<n_%s = 0;\n%*sn_%s < %s -> nelem;\n", ! 1264: (level + 1) * 4, "", yp -> yp_declexp, ! 1265: (level + 3) * 4, "", yp -> yp_declexp, ! 1266: yp -> yp_declexp); ! 1267: (void) printf ("%*sn_%s++>>\n", ! 1268: (level + 3) * 4, "", yp -> yp_declexp); ! 1269: } ! 1270: } ! 1271: else { ! 1272: if (top) ! 1273: (void) printf ("%*s<<; parm; parm = parm -> next>>\n", ! 1274: (level + 1) * 4, ""); ! 1275: else ! 1276: (void) printf ("%*s<<%s = %s%s;\n%*s%s;\n%*s%s = %s -> next>>\n", ! 1277: (level + 1) * 4, "", yp -> yp_declexp, ! 1278: var, SVAL (yp -> yp_varexp), ! 1279: (level + 3) * 4, "", yp -> yp_declexp, ! 1280: (level + 3) * 4, "", yp -> yp_declexp, ! 1281: yp -> yp_declexp); ! 1282: } ! 1283: break; ! 1284: ! 1285: case YP_DECODER: ! 1286: if (h2flag) { ! 1287: y = yp -> yp_type; ! 1288: xalloc (y, 0, level + 2, y -> yp_declexp, ! 1289: y -> yp_declexp, 1); ! 1290: } ! 1291: else ! 1292: xalloc (yp, 0, level + 1, ! 1293: top ? "parm" : yp -> yp_declexp, ! 1294: top ? modsym (mymodule, eval, "type") ! 1295: : yp -> yp_declexp, 1); ! 1296: break; ! 1297: } ! 1298: do_type1 (yp -> yp_type, 0, level + 1, ep, "", NULLCP, direction); ! 1299: switch (direction) { ! 1300: case YP_DECODER: ! 1301: (void) printf ("\n%*s%%{ ", (level + 1) * 4, ""); ! 1302: if (h2flag) ! 1303: (void) printf ("n_%s++;", top ? "parm" : yp -> yp_declexp); ! 1304: else ! 1305: if (top) ! 1306: (void) printf ("parm = &((*parm) -> next);"); ! 1307: else ! 1308: (void) printf ("%s = &((*%s) -> next);", ! 1309: yp -> yp_declexp, yp -> yp_declexp); ! 1310: if (action2) ! 1311: (void) printf (" %s", action2); ! 1312: (void) printf (" %%}"); ! 1313: break; ! 1314: } ! 1315: break; ! 1316: ! 1317: case YP_SEQLIST: ! 1318: case YP_SETLIST: ! 1319: ep = yp -> yp_code != YP_SETLIST ? "element" : "member"; ! 1320: (void) printf ("%s", tags [yp -> yp_code]); ! 1321: (void) printf ("\n%*s%%{\n", (level + 1) * 4, ""); ! 1322: if (direction == YP_DECODER) ! 1323: xalloc (yp, 1, level + 2, yp -> yp_declexp, ! 1324: yp -> yp_declexp, 0); ! 1325: for (y = yp -> yp_type; y; y = y -> yp_next) { ! 1326: if (y -> yp_declexp) ! 1327: switch (direction) { ! 1328: case YP_ENCODER: ! 1329: (void) printf ("%*s%s = %s;\n", ! 1330: (level + 2) * 4, "", ! 1331: y -> yp_declexp, y -> yp_varexp); ! 1332: break; ! 1333: ! 1334: case YP_DECODER: ! 1335: (void) printf ("%*s%s = &(%s);\n", ! 1336: (level + 2) * 4, "", ! 1337: y -> yp_declexp, y -> yp_varexp); ! 1338: break; ! 1339: } ! 1340: if (direction == YP_DECODER && ! 1341: y -> yp_flags & YP_DEFAULT) { ! 1342: prime_default (y, level + 2); ! 1343: } ! 1344: } ! 1345: (void) printf ("%*s%%}\n%*s{\n", (level + 1) * 4, "", ! 1346: level * 4, ""); ! 1347: ! 1348: if (!hflag || !(y = yp -> yp_type) || y -> yp_next) { ! 1349: var = ""; ! 1350: top = 0; ! 1351: } ! 1352: for (y = yp -> yp_type; y; y = y -> yp_next) { ! 1353: do_type1 (y, top, ! 1354: level + ((y -> yp_flags & (YP_ID | YP_TAG)) ? 1 : 2), ! 1355: ep, var, NULLCP, direction); ! 1356: (void) printf ("%s\n", y -> yp_next ? ",\n" : ""); ! 1357: } ! 1358: (void) printf ("%*s}", level * 4, ""); ! 1359: break; ! 1360: ! 1361: case YP_CHOICE: ! 1362: (void) printf ("CHOICE"); ! 1363: if (!hflag || !(y = yp -> yp_type) || y -> yp_next) ! 1364: var = ""; ! 1365: i = 0; ! 1366: for (y = yp -> yp_type; y; y = y -> yp_next) ! 1367: if (y -> yp_declexp) ! 1368: i++; ! 1369: switch (direction) { ! 1370: case YP_ENCODER: ! 1371: if (i) { ! 1372: (void) printf ("\n%*s%%{\n", (level + 1) * 4, ""); ! 1373: for (y = yp -> yp_type; y; y = y -> yp_next) ! 1374: if (y -> yp_declexp) ! 1375: (void) printf ("%*s%s = %s;\n", (level + 2) * 4, "", ! 1376: y -> yp_declexp, y -> yp_varexp); ! 1377: (void) printf ("%*s%%}\n%*s", (level + 1) * 4, "", ! 1378: (level + 1) * 4 - 1, "" ); ! 1379: } ! 1380: if (*var) ! 1381: (void) printf (" <<1>>"); ! 1382: else ! 1383: if (top) ! 1384: (void) printf (" <<parm -> offset>>"); ! 1385: else ! 1386: (void) printf (" <<%s -> offset>>", ! 1387: yp -> yp_declexp); ! 1388: (void) printf (i ? "\n%*s{\n" : " {\n", level * 4, ""); ! 1389: break; ! 1390: ! 1391: case YP_DECODER: ! 1392: (void) printf ("\n"); ! 1393: xalloc (yp, 0, level + 1, yp -> yp_declexp, ! 1394: yp -> yp_declexp, 1); ! 1395: (void) printf ("%*s{\n", level * 4, ""); ! 1396: break; ! 1397: ! 1398: default: ! 1399: (void) printf (" {\n"); ! 1400: break; ! 1401: } ! 1402: if (direction == YP_DECODER) { ! 1403: (void) sprintf (cp = buffer, "(*(%s)) -> offset = ", ! 1404: top ? "parm" : yp -> yp_declexp); ! 1405: cp += strlen (cp); ! 1406: } ! 1407: else ! 1408: cp = NULL; ! 1409: if (!hflag || !(y = yp -> yp_type) || y -> yp_next) ! 1410: top = 0; ! 1411: else ! 1412: if (top) ! 1413: cp = NULL; ! 1414: for (y = yp -> yp_type; y; y = y -> yp_next) { ! 1415: if (cp) ! 1416: (void) sprintf (cp, "%s;", y -> yp_offset); ! 1417: do_type1 (y, top, level + 1, "choice", var, ! 1418: cp ? buffer : NULLCP, direction); ! 1419: (void) printf ("%s\n", y -> yp_next ? ",\n" : ""); ! 1420: } ! 1421: (void) printf ("%*s}", level * 4, ""); ! 1422: break; ! 1423: ! 1424: case YP_OID: ! 1425: (void) printf ("OBJECT IDENTIFIER"); ! 1426: switch (direction) { ! 1427: case YP_ENCODER: ! 1428: case YP_DECODER: ! 1429: (void) printf ("\n%*s[[O %s%s ]]", ! 1430: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1431: break; ! 1432: } ! 1433: break; ! 1434: ! 1435: case YP_IDEFINED: ! 1436: if (yp -> yp_module && strcmp (yp -> yp_module, mymodule)) ! 1437: (void) printf ("%s.", yp -> yp_module); ! 1438: (void) printf ("%s", yp -> yp_identifier); ! 1439: switch (direction) { ! 1440: case YP_ENCODER: ! 1441: (void) printf ("\n%*s[[p %s%s ]]", ! 1442: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1443: break; ! 1444: ! 1445: case YP_DECODER: ! 1446: (void) printf ("\n%*s[[p &(%s%s)]]", ! 1447: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 1448: break; ! 1449: } ! 1450: break; ! 1451: ! 1452: default: ! 1453: myyerror ("unknown type: %d", yp -> yp_code); ! 1454: } ! 1455: ! 1456: if (action2) ! 1457: switch (yp -> yp_code) { ! 1458: case YP_BIT: ! 1459: case YP_BITLIST: ! 1460: if (direction == YP_ENCODER) ! 1461: break; ! 1462: case YP_SEQTYPE: ! 1463: case YP_SETTYPE: ! 1464: if (direction == YP_DECODER) ! 1465: break; ! 1466: /* else fall */ ! 1467: ! 1468: default: ! 1469: (void) printf ("\n%*s%%{ %s %%}", level * 4, "", action2); ! 1470: break; ! 1471: } ! 1472: ! 1473: if (yp -> yp_flags & YP_OPTIONAL) { ! 1474: (void) printf ("\n%*sOPTIONAL", level * 4, ""); ! 1475: ! 1476: if (direction == YP_ENCODER) ! 1477: switch (yp -> yp_code) { ! 1478: case YP_BOOL: ! 1479: case YP_INT: ! 1480: case YP_INTLIST: ! 1481: case YP_ENUMLIST: ! 1482: case YP_NULL: ! 1483: case YP_REAL: ! 1484: (void) printf (" <<%s -> optionals & %s >>", ! 1485: varbuf, yp -> yp_optcontrol); ! 1486: default: ! 1487: break; ! 1488: ! 1489: case YP_BIT: ! 1490: case YP_BITLIST: ! 1491: case YP_OCT: ! 1492: case YP_SEQ: ! 1493: case YP_SEQTYPE: ! 1494: case YP_SEQLIST: ! 1495: case YP_SET: ! 1496: case YP_SETTYPE: ! 1497: case YP_SETLIST: ! 1498: case YP_CHOICE: ! 1499: case YP_ANY: ! 1500: case YP_OID: ! 1501: case YP_IDEFINED: ! 1502: (void) printf (" <<%s%s>>", var, SVAL (yp -> yp_varexp)); ! 1503: break; ! 1504: } ! 1505: } ! 1506: else ! 1507: if (yp -> yp_flags & YP_DEFAULT) { ! 1508: (void) printf ("\n%*sDEFAULT ", level * 4, ""); ! 1509: val2prf (yp -> yp_default, level + 2); ! 1510: ! 1511: if (direction == YP_ENCODER) ! 1512: switch (yp -> yp_code) { ! 1513: case YP_BOOL: ! 1514: (void) printf (" <<%s%s%s>>", ! 1515: val2int (yp -> yp_default) ? "!" : "", ! 1516: var, SVAL (yp -> yp_varexp)); ! 1517: break; ! 1518: ! 1519: case YP_INT: ! 1520: case YP_INTLIST: ! 1521: case YP_ENUMLIST: ! 1522: (void) printf (" <<%s%s != %d>>", var, SVAL (yp -> yp_varexp), ! 1523: dfl2int (yp)); ! 1524: break; ! 1525: ! 1526: case YP_REAL: ! 1527: (void) printf (" << %s%s != %g >>", ! 1528: var, SVAL (yp -> yp_varexp), ! 1529: val2real (yp -> yp_default)); ! 1530: break; ! 1531: ! 1532: case YP_NULL: ! 1533: default: ! 1534: break; ! 1535: ! 1536: case YP_BIT: ! 1537: case YP_BITLIST: ! 1538: case YP_OCT: ! 1539: case YP_SEQ: ! 1540: case YP_SEQTYPE: ! 1541: case YP_SEQLIST: ! 1542: case YP_SET: ! 1543: case YP_SETTYPE: ! 1544: case YP_SETLIST: ! 1545: case YP_CHOICE: ! 1546: case YP_ANY: ! 1547: case YP_OID: ! 1548: case YP_IDEFINED: ! 1549: (void) printf (" <<%s%s>>", var, SVAL (yp -> yp_varexp)); ! 1550: break; ! 1551: } ! 1552: } ! 1553: ! 1554: if (direction == YP_ENCODER ! 1555: && yp -> yp_varexp ! 1556: && (cp = index (yp -> yp_varexp, ' ')) ! 1557: && strncmp (cp + 1, "-> ", 3) == 0) { ! 1558: *cp = NULL; ! 1559: (void) sprintf (buffer, "(*%s) -> %s", yp -> yp_varexp, cp + 4); ! 1560: yp -> yp_varexp = new_string (buffer); ! 1561: } ! 1562: } ! 1563: ! 1564: /* TYPE HANDLING */ ! 1565: ! 1566: static YP lookup_type (mod, id) ! 1567: register char *mod, ! 1568: *id; ! 1569: { ! 1570: register SY sy; ! 1571: ! 1572: for (sy = mysymbols; sy; sy = sy -> sy_next) { ! 1573: if (mod) { ! 1574: if (strcmp (sy -> sy_module, mod)) ! 1575: continue; ! 1576: } ! 1577: else ! 1578: if (strcmp (sy -> sy_module, mymodule) ! 1579: && strcmp (sy -> sy_module, "UNIV")) ! 1580: continue; ! 1581: ! 1582: if (strcmp (sy -> sy_name, id) == 0) ! 1583: return sy -> sy_type; ! 1584: } ! 1585: ! 1586: return NULLYP; ! 1587: } ! 1588: ! 1589: /* */ ! 1590: ! 1591: pepsy (yp, top, level, id, val, var, arrayflg) ! 1592: register YP yp; ! 1593: int top, ! 1594: level, ! 1595: arrayflg; ! 1596: char *id, ! 1597: *val, ! 1598: *var; ! 1599: { ! 1600: register int i, ! 1601: j; ! 1602: register char *bp; ! 1603: char *cp, ! 1604: *dp, ! 1605: *ep, ! 1606: *newid, ! 1607: buf1[BUFSIZ], ! 1608: buf2[BUFSIZ], ! 1609: buf3[BUFSIZ]; ! 1610: register YP y; ! 1611: register YV yv; ! 1612: ! 1613: (void) strcpy (bp = buf2, var); ! 1614: bp += strlen (bp); ! 1615: /* Preserve the name of the field */ ! 1616: yp->yp_varexp = new_string(yp -> yp_ptrname ? yp -> yp_ptrname : id); ! 1617: ! 1618: switch (yp -> yp_code) { ! 1619: case YP_BOOL: ! 1620: if (aflag) ! 1621: printag (yp, level + 4, NULLCP); ! 1622: (void) fprintf (fdef, "%*schar %s;\n", level * 4, "", ! 1623: array(id, arrayflg)); ! 1624: break; ! 1625: ! 1626: case YP_INT: ! 1627: case YP_INTLIST: ! 1628: case YP_ENUMLIST: ! 1629: if (aflag) ! 1630: printag (yp, level + 4, NULLCP); ! 1631: (void) fprintf (fdef, "%*sint %s;\n", level * 4, "", ! 1632: array(id, arrayflg)); ! 1633: if (yp -> yp_code == YP_INT) ! 1634: break; ! 1635: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) { ! 1636: modsym_aux (yv -> yv_named, buf1); ! 1637: (void) fprintf (fdef, "#define\t%s_%s\t%d\n", ! 1638: modsym (mymodule, top ? eval : id, "int"), ! 1639: buf1, val2int (yv)); ! 1640: } ! 1641: break; ! 1642: ! 1643: case YP_BIT: ! 1644: case YP_BITLIST: ! 1645: if (!top) { ! 1646: if (aflag) ! 1647: printag (yp, level + 4, NULLCP); ! 1648: (void) fprintf (fdef, "%*sPE %s;\n", level * 4, "", ! 1649: array(id, arrayflg)); ! 1650: } ! 1651: #if 0 ! 1652: if (fflag) { ! 1653: (void) fprintf (fact, "%*sif (%s)\n", level * 4, "", buf2); ! 1654: (void) fprintf (fact, ! 1655: "%*spe_free (%s),\n%*s%s = NULLPE;\n", ! 1656: (level + 1) * 4, "", buf2, ! 1657: (level + 2) * 4, "", buf2); ! 1658: } ! 1659: #endif ! 1660: if (yp -> yp_code != YP_BITLIST) ! 1661: break; ! 1662: i = -1; ! 1663: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) ! 1664: if ((j = val2int (yv)) < 0) ! 1665: pyyerror (yp, "invalid bit number in BIT STRING"); ! 1666: else ! 1667: if (j > i) ! 1668: i = j; ! 1669: if (i < sizeof (int) * 8) { /* NBBY */ ! 1670: (void) fprintf (fdef, "#define\t%s\t\"\\020", ! 1671: modsym (mymodule, top ? eval : id, "bits")); ! 1672: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) ! 1673: if (yv -> yv_flags & YV_NAMED) ! 1674: (void) fprintf (fdef, "\\0%o%s", ! 1675: val2int (yv) + 1, yv -> yv_named); ! 1676: else ! 1677: (void) fprintf (fdef, "\\0%oBIT%d", ! 1678: val2int (yv) + 1, val2int (yv)); ! 1679: (void) fprintf (fdef, "\"\n"); ! 1680: } ! 1681: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) { ! 1682: modsym_aux (yv -> yv_named, buf1); ! 1683: (void) fprintf (fdef, "#define\t%s_%s\t%d\n", ! 1684: modsym (mymodule, top ? eval : id, "bit"), ! 1685: buf1, val2int (yv)); ! 1686: } ! 1687: break; ! 1688: ! 1689: case YP_REAL: ! 1690: if (aflag) ! 1691: printag (yp, level + 4, NULLCP); ! 1692: (void) fprintf (fdef, "%*sdouble %s;\n", level * 4, "", ! 1693: array(id, arrayflg)); ! 1694: yp -> yp_varexp = new_string (buf2); ! 1695: break; ! 1696: ! 1697: case YP_OCT: ! 1698: if (!top) { ! 1699: if (aflag) ! 1700: printag (yp, level + 4, NULLCP); ! 1701: (void) fprintf (fdef, "%*sstruct qbuf *%s;\n", level * 4, "", ! 1702: array(id, arrayflg)); ! 1703: } ! 1704: #if 0 ! 1705: if (fflag) { ! 1706: (void) fprintf (fact, "%*sif (%s)\n", level * 4, "", buf2); ! 1707: (void) fprintf (fact, ! 1708: "%*sqb_free (%s),\n%*s%s = NULL;\n", ! 1709: (level + 1) * 4, "", buf2, ! 1710: (level + 2) * 4, "", buf2); ! 1711: } ! 1712: #endif ! 1713: break; ! 1714: ! 1715: case YP_NULL: ! 1716: if (aflag) ! 1717: printag (yp, level + 4, NULLCP); ! 1718: (void) fprintf (fdef, "%*schar %s;\n", level * 4, "", ! 1719: array(id, arrayflg)); ! 1720: break; ! 1721: ! 1722: case YP_SEQ: ! 1723: case YP_SET: ! 1724: case YP_ANY: ! 1725: if (!top) { ! 1726: if (aflag) ! 1727: printag (yp, level + 4, NULLCP); ! 1728: (void) fprintf (fdef, "%*sPE %s;\n", level * 4, "", ! 1729: array(id, arrayflg)); ! 1730: } ! 1731: #if 0 ! 1732: if (fflag) { ! 1733: (void) fprintf (fact, "%*sif (%s)\n", level * 4, "", buf2); ! 1734: (void) fprintf (fact, ! 1735: "%*spe_free (%s),\n%*s%s = NULLPE;\n", ! 1736: (level + 1) * 4, "", buf2, ! 1737: (level + 2) * 4, "", buf2); ! 1738: } ! 1739: #endif ! 1740: break; ! 1741: ! 1742: case YP_SEQTYPE: ! 1743: case YP_SETTYPE: ! 1744: ep = yp -> yp_code != YP_SETTYPE ? "element" : "member"; ! 1745: if ((cp = rindex (buf2, ' ')) && *++cp) { ! 1746: if ((dp = rindex (cp, '.')) && *++dp) ! 1747: cp = dp; ! 1748: (void) sprintf (dp = buf1, "%*.*s", ! 1749: cp - buf2, cp - buf2, buf2); ! 1750: dp += strlen (dp); ! 1751: } ! 1752: else { ! 1753: (void) strcpy (buf1, buf2); ! 1754: dp = NULL; ! 1755: } ! 1756: newid = yp -> yp_ptrname ? yp -> yp_ptrname : id; ! 1757: if (h2flag && top) ! 1758: (void) fprintf (fdef, "%*sint\tnelem;\n", level * 4, ""); ! 1759: if (!top) { ! 1760: if (yp -> yp_structname) ! 1761: id = yp -> yp_structname; ! 1762: else if (!Hflag) ! 1763: id = gensym (ep, NULLCP); ! 1764: if (aflag) ! 1765: printag (yp, level + 4, NULLCP); ! 1766: (void) fprintf (fdef, "%*sstruct %s {\n", level * 4, "", id); ! 1767: if (h2flag) ! 1768: (void) fprintf (fdef, "%*sint\tnelem;\n", (level + 1) * 4, ""); ! 1769: } ! 1770: if (dp) ! 1771: (void) strcpy (dp, newid); ! 1772: (void) strcpy (bp = buf2, id); ! 1773: bp += strlen (bp); ! 1774: ! 1775: if (!top) ! 1776: yp -> yp_declexp = new_string (id); ! 1777: ! 1778: if (dp) ! 1779: (void) strcpy (dp, newid); ! 1780: if ((y = yp -> yp_type) -> yp_code == YP_IDEFINED && hflag) { ! 1781: modsym_aux (y -> yp_identifier, cp = buf3); ! 1782: if (h2flag) { ! 1783: cp += strlen(cp); ! 1784: (void) sprintf (cp, "[n_%s]", PARVAL (yp->yp_declexp)); ! 1785: cp = buf3; ! 1786: } ! 1787: } ! 1788: else { ! 1789: switch (y -> yp_code) { ! 1790: case YP_SEQLIST: ! 1791: case YP_SETLIST: ! 1792: case YP_SETTYPE: ! 1793: case YP_SEQTYPE: ! 1794: case YP_CHOICE: ! 1795: case YP_IDEFINED: ! 1796: cp = gensym (ep, h2flag ? PARVAL(yp->yp_declexp) : NULLCP); ! 1797: break; ! 1798: default: ! 1799: cp = gensym (ep, NULLCP); ! 1800: break; ! 1801: } ! 1802: } ! 1803: (void) sprintf (bp, " -> %s", cp); ! 1804: #if 0 ! 1805: if (fflag) { ! 1806: if (!top) { ! 1807: (void) fprintf (fact, "%*s{\n", level * 4, ""); ! 1808: level++; ! 1809: if (h2flag) { ! 1810: (void) fprintf (fact, "%*sint n_%s;\n", ! 1811: level * 4, "", PARVAL (yp->yp_declexp)); ! 1812: (void) fprintf (fact, "%*sstruct %s *%s = %s;\n\n", ! 1813: level * 4, "", id, id, var); ! 1814: } ! 1815: else ! 1816: (void) fprintf (fact, "%*sstruct %s *%s;\n\n", ! 1817: level * 4, "", id, id); ! 1818: } ! 1819: if (h2flag) { ! 1820: (void) fprintf (fact, "%*sfor (n_%s = 0;\n", ! 1821: level * 4, "", PARVAL(yp -> yp_declexp)); ! 1822: (void) fprintf (fact, "%*sn_%s < %s -> nelem;\n", ! 1823: (level + 2) * 4, "", PARVAL(yp->yp_declexp), id); ! 1824: (void) fprintf (fact, "%*sn_%s++) {\n", ! 1825: (level + 2) * 4, "", PARVAL(yp->yp_declexp)); ! 1826: } ! 1827: else { ! 1828: (void) fprintf (fact, ! 1829: "%*sfor (%s = %s; %s;) {\n", ! 1830: level * 4, "", id, buf1, id); ! 1831: (void) fprintf (fact, "%*sstruct %s *f_%s = %s -> next;\n\n", ! 1832: (level + 1) * 4, "", ! 1833: top ? modsym (mymodule, val, "type") : id, ! 1834: id, id); ! 1835: } ! 1836: } ! 1837: #endif ! 1838: level++; ! 1839: pepsy (y, 0, level, cp, ep, buf2, h2flag); ! 1840: *bp = NULL; ! 1841: if (y -> yp_code != YP_IDEFINED) ! 1842: free (cp); ! 1843: if (!h2flag) ! 1844: (void) fprintf (fdef, "\n%*sstruct %s *next;\n", level * 4, "", ! 1845: top ? modsym (mymodule, val, "type") : id); ! 1846: ! 1847: level--; ! 1848: ! 1849: (void) strcpy (bp = buf2, var); ! 1850: bp += strlen (bp); ! 1851: #if 0 ! 1852: if (fflag) { ! 1853: if (!h2flag) { ! 1854: (void) fprintf (fact, "\n%*sif (%s)\n%*sfree ((char *) %s);", ! 1855: (level + 1) * 4, "", id, ! 1856: (level + 2) * 4, "", id); ! 1857: (void) fprintf (fact, "\n%*s%s = f_%s;", (level + 1) * 4, "", ! 1858: id, id); ! 1859: } ! 1860: (void) fprintf (fact, "\n%*s}\n", level * 4, ""); ! 1861: ! 1862: if (!top) { ! 1863: if (h2flag) ! 1864: (void) fprintf (fact, "\n%*s%s = NULL;\n", ! 1865: level * 4, "", var); ! 1866: else ! 1867: (void) fprintf (fact, "\n%*s%s = NULL;\n", ! 1868: level * 4, "", yp -> yp_varexp); ! 1869: ! 1870: level--; ! 1871: (void) fprintf (fact, "%*s}\n", level * 4, ""); ! 1872: } ! 1873: } ! 1874: #endif ! 1875: ! 1876: if (!top) { ! 1877: (void) fprintf (fdef, "%*s} *%s;\n", level * 4, "", ! 1878: array(newid, arrayflg)); ! 1879: if (!Hflag) ! 1880: free (id); ! 1881: } ! 1882: break; ! 1883: ! 1884: case YP_SEQLIST: ! 1885: case YP_SETLIST: ! 1886: ep = yp -> yp_code != YP_SETLIST ? "element" : "member"; ! 1887: if ((cp = rindex (buf2, ' ')) && *++cp) { ! 1888: if ((dp = rindex (cp, '.')) && *++dp) ! 1889: cp = dp; ! 1890: (void) sprintf (dp = buf1, "%*.*s", ! 1891: cp - buf2, cp - buf2, buf2); ! 1892: dp += strlen (dp); ! 1893: } ! 1894: else { ! 1895: (void) strcpy (buf1, buf2); ! 1896: dp = NULL; ! 1897: } ! 1898: newid = yp -> yp_ptrname ? yp -> yp_ptrname : id; ! 1899: if (!top) { ! 1900: if (yp -> yp_structname) ! 1901: id = yp -> yp_structname; ! 1902: else if (!Hflag) ! 1903: id = gensym (ep, NULLCP); ! 1904: if (aflag) ! 1905: printag (yp, level + 4, NULLCP); ! 1906: (void) fprintf (fdef, "%*sstruct %s {\n", level * 4, "", id); ! 1907: ! 1908: if (dp) ! 1909: (void) strcpy (dp, newid); ! 1910: ! 1911: #if 0 ! 1912: if (fflag) { ! 1913: (void) fprintf (fact, "%*sif (%s) {\n", ! 1914: level * 4, "", buf1); ! 1915: i = 0; ! 1916: for (y = yp -> yp_type; y; y = y -> yp_next) { ! 1917: switch (y -> yp_code) { ! 1918: case YP_BOOL: ! 1919: case YP_INT: ! 1920: case YP_INTLIST: ! 1921: case YP_ENUMLIST: ! 1922: case YP_REAL: ! 1923: case YP_NULL: ! 1924: continue; ! 1925: ! 1926: default: ! 1927: i = 1; ! 1928: break; ! 1929: } ! 1930: break; ! 1931: } ! 1932: if (i) ! 1933: (void) fprintf (fact, "%*sstruct %s *%s = %s;\n\n", ! 1934: (level + 1) * 4, "", id, id, buf1); ! 1935: } ! 1936: #endif ! 1937: (void) strcpy (bp = buf2, id); ! 1938: bp += strlen (bp); ! 1939: yp -> yp_declexp = new_string (id); ! 1940: ! 1941: level++; ! 1942: } ! 1943: if (dp) ! 1944: (void) strcpy (dp, newid); ! 1945: for (y = yp -> yp_type, i = 0; y; y = y -> yp_next) { ! 1946: if (y -> yp_flags & YP_OPTIONAL) ! 1947: switch (y -> yp_code) { ! 1948: case YP_BOOL: ! 1949: case YP_INT: ! 1950: case YP_INTLIST: ! 1951: case YP_ENUMLIST: ! 1952: case YP_REAL: ! 1953: case YP_NULL: ! 1954: { ! 1955: char obuf[BUFSIZ]; ! 1956: ! 1957: if (i == 0) ! 1958: (void) fprintf (fdef, "%*sint optionals;\n", ! 1959: level * 4, ""); ! 1960: if (y -> yp_flags & YP_ID) ! 1961: modsym_aux (y -> yp_id, cp = buf1); ! 1962: else { ! 1963: cp = gensym (ep, NULLCP); ! 1964: (void) strcpy (buf1, cp); ! 1965: free (cp); ! 1966: cp = buf1; ! 1967: } ! 1968: (void) sprintf (obuf, "%s_%s", ! 1969: modsym (mymodule, ! 1970: top ? eval : id, ! 1971: "opt"), cp); ! 1972: (void) fprintf (fdef, "#define\t%s (0%08o)\n", obuf, ! 1973: 1 << i); ! 1974: y -> yp_optcontrol = new_string (obuf); ! 1975: y -> yp_flags |= YP_OPTCONTROL; ! 1976: ! 1977: i ++; ! 1978: if (i >= 8 * sizeof (int)) ! 1979: yyerror ("too many optionals in structure"); ! 1980: } ! 1981: break; ! 1982: } ! 1983: } ! 1984: if (i > 0) (void) fprintf (fdef, "\n"); ! 1985: ! 1986: for (y = yp -> yp_type, i = 1; y; y = y -> yp_next, i++) { ! 1987: if (y -> yp_flags & YP_ID) ! 1988: modsym_aux (y -> yp_id, cp = buf1); ! 1989: else ! 1990: cp = gensym (ep, NULLCP); ! 1991: (void) sprintf (bp, " -> %s", cp); ! 1992: pepsy (y, 0, level, cp, ep, buf2, 0); ! 1993: *bp = NULL; ! 1994: if (!(y -> yp_flags & YP_ID)) ! 1995: free (cp); ! 1996: if (y -> yp_next) ! 1997: (void) fprintf (fdef, "\n"); ! 1998: } ! 1999: if (i == 1) ! 2000: (void) fprintf (fdef, "%*schar dummy;\n", level * 4, ""); ! 2001: if (!top) { ! 2002: level--; ! 2003: ! 2004: (void) strcpy (bp = buf2, var); ! 2005: bp += strlen (bp); ! 2006: #if 0 ! 2007: if (fflag) { ! 2008: (void) fprintf (fact, "\n%*sif (%s)\n%*sfree ((char *) %s);\n%*s%s = NULL;\n", ! 2009: (level + 1) * 4, "", yp -> yp_varexp, ! 2010: (level + 2) * 4, "", yp -> yp_varexp, ! 2011: (level + 1) * 4, "", yp -> yp_varexp); ! 2012: (void) fprintf (fact, "%*s}\n", level * 4, ""); ! 2013: } ! 2014: #endif ! 2015: ! 2016: (void) fprintf (fdef, "%*s} *%s;\n", level * 4, "", ! 2017: array(newid, arrayflg)); ! 2018: if (!Hflag) ! 2019: free (id); ! 2020: } ! 2021: break; ! 2022: ! 2023: case YP_CHOICE: ! 2024: if ((cp = rindex (buf2, ' ')) && *++cp) { ! 2025: if ((dp = rindex (cp, '.')) && *++dp) ! 2026: cp = dp; ! 2027: (void) sprintf (dp = buf1, "%*.*s", ! 2028: cp - buf2, cp - buf2, buf2); ! 2029: dp += strlen (dp); ! 2030: } ! 2031: else { ! 2032: (void) strcpy (buf1, buf2); ! 2033: dp = NULL; ! 2034: } ! 2035: newid = yp -> yp_ptrname ? yp -> yp_ptrname : id; ! 2036: if (!top) { ! 2037: if (yp -> yp_structname) ! 2038: id = yp -> yp_structname; ! 2039: else if (!Hflag) ! 2040: id = gensym ("choice", NULLCP); ! 2041: if (aflag) ! 2042: printag (yp, level + 4, NULLCP); ! 2043: (void) fprintf (fdef, "%*sstruct %s {\n", level * 4, "", id); ! 2044: ! 2045: if (dp) ! 2046: (void) strcpy (dp, newid); ! 2047: #if 0 ! 2048: if (fflag) { ! 2049: (void) fprintf (fact, "%*sif (%s) {\n%*sstruct %s *%s = %s;\n\n", ! 2050: level * 4, "", buf1, ! 2051: (level + 1) * 4, "", id, id, buf1); ! 2052: } ! 2053: #endif ! 2054: (void) strcpy (bp = buf2, id); ! 2055: bp += strlen (bp); ! 2056: yp -> yp_declexp = new_string (id); ! 2057: ! 2058: level++; ! 2059: } ! 2060: if (dp) ! 2061: (void) strcpy (dp, newid); ! 2062: (void) fprintf (fdef, "%*sint offset;\n", level * 4, ""); ! 2063: #if 0 ! 2064: if (fflag) ! 2065: (void) fprintf (fact, "%*sswitch (%s -> offset) {\n", ! 2066: level * 4, "", id); ! 2067: #endif ! 2068: if (top) ! 2069: cp = modsym (mymodule, val, "type"); ! 2070: else ! 2071: cp = id; ! 2072: (void) sprintf (ep = buf1, "%s_", cp); ! 2073: ep += strlen (ep); ! 2074: for (y = yp -> yp_type, i = 1; y; y = y -> yp_next, i++) { ! 2075: if (y -> yp_flags & YP_ID) ! 2076: modsym_aux (y -> yp_id, ep); ! 2077: else ! 2078: (void) sprintf (ep, "%d", i); ! 2079: y -> yp_offset = new_string (buf1); ! 2080: (void) fprintf (fdef, "#define\t%s\t%d\n", y -> yp_offset, i); ! 2081: } ! 2082: (void) fprintf (fdef, "\n%*sunion {\n", level * 4, ""); ! 2083: level++; ! 2084: for (y = yp -> yp_type; y; y = y -> yp_next) { ! 2085: char *t; ! 2086: ! 2087: if (y -> yp_flags & YP_ID) ! 2088: modsym_aux (y -> yp_id, cp = buf1); ! 2089: else ! 2090: cp = gensym ("choice", NULLCP); ! 2091: #if 0 ! 2092: if (fflag) { ! 2093: (void) fprintf (fact, "%*scase %s:\n", level * 4, "", ! 2094: y -> yp_offset); ! 2095: level++; ! 2096: } ! 2097: #endif ! 2098: (void) sprintf (bp, " -> un.%s", cp); ! 2099: pepsy (y, 0, level, cp, "choice", buf2, 0); ! 2100: /* prefix yp_varexp (field name) with un. so we will generate offsets that ! 2101: * allow for the union all the CHOICE fields are imbedded in ! 2102: */ ! 2103: t = y->yp_varexp; ! 2104: y->yp_varexp = my_strcat("un.", t); ! 2105: free(t); ! 2106: ! 2107: *bp = NULL; ! 2108: #if 0 ! 2109: if (fflag) { ! 2110: (void) fprintf (fact, "%*sbreak;\n", level * 4, ""); ! 2111: if (y -> yp_next) ! 2112: (void) fprintf (fact, "\n"); ! 2113: level--; ! 2114: } ! 2115: #endif ! 2116: if (!(y -> yp_flags & YP_ID)) ! 2117: free (cp); ! 2118: if (y -> yp_next) ! 2119: (void) fprintf (fdef, "\n"); ! 2120: } ! 2121: level--; ! 2122: (void) fprintf (fdef, "%*s} un;\n", level * 4, ""); ! 2123: #if 0 ! 2124: if (fflag) ! 2125: (void) fprintf (fact, "%*s}\n", level * 4, ""); ! 2126: #endif ! 2127: if (!top) { ! 2128: level--; ! 2129: ! 2130: (void) strcpy (bp = buf2, var); ! 2131: bp += strlen (bp); ! 2132: #if 0 ! 2133: if (fflag) { ! 2134: (void) fprintf (fact, "\n%*sif (%s)\n%*sfree ((char *) %s);\n%*s%s = NULL;\n", ! 2135: (level + 1) * 4, "", yp -> yp_varexp, ! 2136: (level + 2) * 4, "", yp -> yp_varexp, ! 2137: (level + 1) * 4, "", yp -> yp_varexp); ! 2138: (void) fprintf (fact, "%*s}\n", level * 4, ""); ! 2139: } ! 2140: #endif ! 2141: ! 2142: (void) fprintf (fdef, "%*s} *%s;\n", level * 4, "", ! 2143: array(newid, arrayflg)); ! 2144: if (!Hflag) ! 2145: free (id); ! 2146: } ! 2147: break; ! 2148: ! 2149: case YP_OID: ! 2150: if (!top) { ! 2151: if (aflag) ! 2152: printag (yp, level + 4, NULLCP); ! 2153: (void) fprintf (fdef, "%*sOID %s;\n", level * 4, "", ! 2154: array(id, arrayflg)); ! 2155: } ! 2156: #if 0 ! 2157: if (fflag) { ! 2158: (void) fprintf (fact, "%*sif (%s)\n", level * 4, "", buf2); ! 2159: (void) fprintf (fact, ! 2160: "%*soid_free (%s),\n%*s%s = NULLOID;\n", ! 2161: (level + 1) * 4, "", buf2, ! 2162: (level + 2) * 4, "", buf2); ! 2163: } ! 2164: #endif ! 2165: break; ! 2166: ! 2167: case YP_IDEFINED: ! 2168: if (aflag) ! 2169: printag (yp, level + 4, NULLCP); ! 2170: { ! 2171: /* Predefined Universal Type */ ! 2172: struct univ_typ *p; ! 2173: if ((p = univtyp(yp->yp_identifier))) { ! 2174: (void) fprintf (fdef, "%*s%s%s;\n", level * 4, "", ! 2175: p->univ_data, array(id, arrayflg)); ! 2176: /* ! 2177: if (fflag) ! 2178: ferr(1, "pepsy:YP_IDEFINED:fflag not implemented\n"); ! 2179: */ ! 2180: break; ! 2181: } ! 2182: } ! 2183: (void) fprintf (fdef, "%*sstruct %s *%s;\n", level * 4, "", ! 2184: modsym (yp -> yp_module, yp -> yp_identifier, "type"), ! 2185: array(id, arrayflg)); ! 2186: #if 0 ! 2187: if (fflag) { ! 2188: (void) fprintf (fact, "%*sif (%s)\n", level * 4, "", buf2); ! 2189: (void) fprintf (fact, ! 2190: "%*s%s (%s),\n%*s%s = NULL;\n", ! 2191: (level + 1) * 4, "", ! 2192: modsym (yp -> yp_module, yp -> yp_identifier, "free"), ! 2193: buf2, (level + 2) * 4, "", buf2); ! 2194: } ! 2195: #endif ! 2196: break; ! 2197: ! 2198: default: ! 2199: myyerror ("unknown type: %d", yp -> yp_code); ! 2200: } ! 2201: } ! 2202: ! 2203: /* */ ! 2204: ! 2205: static printag (yp, level, pullup) ! 2206: register YP yp; ! 2207: int level; ! 2208: char *pullup; ! 2209: { ! 2210: (void) fprintf (fdef, "%*s/* ", level * 4, ""); ! 2211: switch (yp -> yp_code) { ! 2212: case YP_IDEFINED: ! 2213: if (yp -> yp_module && strcmp (yp -> yp_module, mymodule)) ! 2214: (void) fprintf (fdef, "%s.", yp -> yp_module); ! 2215: (void) fprintf (fdef, "%s", yp -> yp_identifier); ! 2216: break; ! 2217: ! 2218: default: ! 2219: (void) fprintf (fdef, "%s", tags[yp -> yp_code]); ! 2220: break; ! 2221: } ! 2222: if (pullup) ! 2223: (void) fprintf (fdef, " pulled up from %s", pullup); ! 2224: (void) fprintf (fdef, " */\n"); ! 2225: } ! 2226: ! 2227: /* */ ! 2228: ! 2229: static xalloc (yp, top, level, arg, type, brackets) ! 2230: register YP yp; ! 2231: int top, ! 2232: level, ! 2233: brackets; ! 2234: char *arg, ! 2235: *type; ! 2236: { ! 2237: int didone; ! 2238: register YP y; ! 2239: ! 2240: if (hflag && !arg && !type) ! 2241: return; ! 2242: ! 2243: didone = 0; ! 2244: ! 2245: if (arg && type) { ! 2246: if (brackets && !didone) { ! 2247: (void) printf ("%*s%%{\n", level * 4, ""); ! 2248: level++, didone++; ! 2249: } ! 2250: ! 2251: if (h2flag && (yp -> yp_code == YP_SEQTYPE || ! 2252: yp -> yp_code == YP_SETTYPE)) { ! 2253: (void) printf ("%*s{\n%*sPE xx_pe = prim2%s ($$);\n\n", ! 2254: level * 4, "", (level +1) * 4, "", ! 2255: yp -> yp_code == YP_SEQTYPE ? "seq" : "set"); ! 2256: (void) printf ("%*sn_%s = xx_pe -> pe_cardinal > 0 ", ! 2257: (level + 1) * 4, "", arg); ! 2258: (void) printf ("? xx_pe -> pe_cardinal : 0;\n%*s}\n", level * 4, ""); ! 2259: (void) printf ("%*sif ((*(%s) = (struct %s *)\n", ! 2260: level * 4, "", arg, type); ! 2261: (void) printf ("%*scalloc (1 + (unsigned) n_%s, sizeof **(%s)", ! 2262: (level + 2) * 4, "", arg, arg); ! 2263: (void) printf (")) == ((struct %s *) 0)) {\n", type); ! 2264: (void) printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n", ! 2265: (level + 1) * 4, ""); ! 2266: (void) printf ("%*sreturn NOTOK;\n%*s}\n", (level + 1) * 4, "", ! 2267: level * 4, ""); ! 2268: (void) printf ("%*s(*%s) -> nelem = n_%s;\n", level * 4, "", arg, arg); ! 2269: (void) printf ("%*sn_%s = 0;\n", level * 4, "", arg); ! 2270: } else { ! 2271: (void) printf ("%*sif ((*(%s) = (struct %s *)\n", ! 2272: level * 4, "", arg, type); ! 2273: (void) printf ("%*scalloc (1, sizeof **(%s))) == ((struct %s *) 0)) {\n", ! 2274: (level + 2) * 4, "", arg, type); ! 2275: (void) printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n", ! 2276: (level + 1) * 4, ""); ! 2277: (void) printf ("%*sreturn NOTOK;\n%*s}\n", (level + 1) * 4, "", ! 2278: level * 4, ""); ! 2279: } ! 2280: } ! 2281: switch (yp -> yp_code) { ! 2282: case YP_SEQTYPE: ! 2283: case YP_SETTYPE: ! 2284: if (top) break; ! 2285: case YP_CHOICE: ! 2286: case YP_SEQLIST: ! 2287: case YP_SETLIST: ! 2288: for (y = yp -> yp_type; y; y = y -> yp_next) ! 2289: switch (y -> yp_code) { ! 2290: case YP_SEQTYPE: ! 2291: case YP_SETTYPE: ! 2292: if (h2flag && (yp -> yp_code == YP_SETLIST || ! 2293: yp -> yp_code == YP_SEQLIST)) { ! 2294: /* include allocation here - no chance later */ ! 2295: if (brackets && !didone) { ! 2296: (void) printf ("%*s%%{\n", level * 4, ""); ! 2297: level++, didone++; ! 2298: } ! 2299: if (y -> yp_declexp) ! 2300: (void) printf ("%*s%s = &(%s);\n", level * 4, "", ! 2301: y -> yp_declexp, ! 2302: y -> yp_varexp); ! 2303: xalloc (y, top, level, y -> yp_declexp, ! 2304: y -> yp_declexp, 0); ! 2305: } ! 2306: /* and continue ... */ ! 2307: case YP_SEQLIST: ! 2308: case YP_SETLIST: ! 2309: case YP_CHOICE: ! 2310: if (brackets && !didone) { ! 2311: (void) printf ("%*s%%{\n", level * 4, ""); ! 2312: level++, didone++; ! 2313: } ! 2314: (void) printf ("%*s%s = &(%s);\n", ! 2315: level * 4, "", y -> yp_declexp, ! 2316: y -> yp_varexp); ! 2317: break; ! 2318: } ! 2319: break; ! 2320: } ! 2321: ! 2322: if (brackets && didone) { ! 2323: level--; ! 2324: (void) printf ("%*s%%}\n", level * 4, ""); ! 2325: } ! 2326: } ! 2327: ! 2328: ! 2329: static balloc (yp, var, action2, level) ! 2330: register YP yp; ! 2331: char *var, *action2; ! 2332: int level; ! 2333: { ! 2334: (void) printf ("\n%*s%%{\n", level * 4, ""); ! 2335: level++; ! 2336: ! 2337: (void) printf ("%*sif ((%s%s = prim2bit (pe_cpy ($$))) == NULLPE) {\n", ! 2338: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 2339: (void) printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n", (level + 1) * 4, ""); ! 2340: (void) printf ("%*sreturn NOTOK;\n%*s}\n", (level + 1) * 4, "", level * 4, ""); ! 2341: ! 2342: if (action2) ! 2343: (void) printf ("\n%*s%s\n", level * 4, "", action2); ! 2344: ! 2345: level--; ! 2346: (void) printf ("%*s%%}", level * 4, ""); ! 2347: } ! 2348: ! 2349: #ifdef notdef ! 2350: static qalloc (yp, var, action2, level) ! 2351: register YP yp; ! 2352: char *var, ! 2353: *action2; ! 2354: int level; ! 2355: { ! 2356: (void) printf ("\n%*s%%{\n", level * 4, ""); ! 2357: level++; ! 2358: ! 2359: (void) printf ("%*sif ((%s%s = str2qb ($$, $$_len, 1)) == ((struct qbuf *) 0)) {\n", ! 2360: level * 4, "", var, SVAL (yp -> yp_varexp)); ! 2361: (void) printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n", (level + 1) * 4, ""); ! 2362: (void) printf ("%*sreturn NOTOK;\n%*s}\n", (level + 1) * 4, "", level * 4, ""); ! 2363: ! 2364: if (action2) ! 2365: (void) printf ("\n%*s%s\n", level * 4, "", action2); ! 2366: ! 2367: level--; ! 2368: (void) printf ("%*s%%}", level * 4, ""); ! 2369: } ! 2370: #endif ! 2371: ! 2372: /* */ ! 2373: ! 2374: static choice_pullup (yp, partial) ! 2375: register YP yp; ! 2376: int partial; ! 2377: { ! 2378: register YP *x, ! 2379: y, ! 2380: z, ! 2381: *z1, ! 2382: z2, ! 2383: z3; ! 2384: ! 2385: for (x = &yp -> yp_type; y = *x; x = &y -> yp_next) { ! 2386: if (y -> yp_flags & (YP_TAG | YP_BOUND)) ! 2387: continue; ! 2388: ! 2389: switch (y -> yp_code) { ! 2390: case YP_IDEFINED: ! 2391: if ((z = lookup_type (y -> yp_module, y -> yp_identifier)) ! 2392: == NULLYP ! 2393: || z -> yp_code != YP_CHOICE) ! 2394: continue; ! 2395: choice_pullup (z2 = copy_type (z), CH_FULLY); ! 2396: goto patch; ! 2397: ! 2398: case YP_CHOICE: ! 2399: choice_pullup (z2 = copy_type (y), CH_FULLY); ! 2400: patch: ; ! 2401: if (partial) { ! 2402: *x = z2; ! 2403: z2 -> yp_next = y -> yp_next; ! 2404: continue; ! 2405: } ! 2406: break; ! 2407: ! 2408: default: ! 2409: continue; ! 2410: } ! 2411: z = z3 = z2 -> yp_type; ! 2412: for (z1 = &z -> yp_next; z2 = *z1; z1 = &z2 -> yp_next) ! 2413: z3 = z2; ! 2414: *z1 = y -> yp_next; ! 2415: *x = z; ! 2416: y = z3; ! 2417: } ! 2418: } ! 2419: ! 2420: /* */ ! 2421: ! 2422: static components_pullup (yp) ! 2423: register YP yp; ! 2424: { ! 2425: register YP *x, ! 2426: y, ! 2427: z, ! 2428: z1, ! 2429: z2; ! 2430: ! 2431: for (x = &yp -> yp_type; y = *x; x = &y -> yp_next) { ! 2432: if (!(y -> yp_flags & YP_COMPONENTS)) ! 2433: continue; ! 2434: ! 2435: switch (y -> yp_code) { ! 2436: case YP_SEQLIST: ! 2437: case YP_SETLIST: ! 2438: z = y; ! 2439: break; ! 2440: ! 2441: case YP_IDEFINED: ! 2442: if ((z = lookup_type (y -> yp_module, y -> yp_identifier)) ! 2443: == NULLYP) { ! 2444: warning ("COMPONENTS OF target \"%s\" is undefined", ! 2445: y -> yp_identifier); ! 2446: continue; ! 2447: } ! 2448: break; ! 2449: } ! 2450: if (yp -> yp_code != z -> yp_code) { ! 2451: warning ("COMPONENTS OF target \"%s\" is wrong type, should be %s", ! 2452: y -> yp_code == YP_IDEFINED ? y -> yp_identifier ! 2453: : y -> yp_id ? y -> yp_id ! 2454: : "", ! 2455: yp -> yp_code == YP_SEQLIST ? "SEQUENCE" : "SET"); ! 2456: continue; ! 2457: } ! 2458: if (z -> yp_type == NULLYP) ! 2459: continue; ! 2460: components_pullup (z = copy_type (z)); ! 2461: *x = z2 = z -> yp_type; ! 2462: for (x = &z -> yp_type; z1 = *x; x = &z1 -> yp_next) ! 2463: z2 = z1; ! 2464: *x = y -> yp_next; ! 2465: y = z2; ! 2466: } ! 2467: } ! 2468: ! 2469: /* VALUE HANDLING */ ! 2470: ! 2471: static int val2int (yv) ! 2472: register YV yv; ! 2473: { ! 2474: switch (yv -> yv_code) { ! 2475: case YV_BOOL: ! 2476: case YV_NUMBER: ! 2477: return yv -> yv_number; ! 2478: ! 2479: case YV_STRING: ! 2480: yyerror ("need an integer, not a string"); ! 2481: ! 2482: case YV_IDEFINED: ! 2483: case YV_IDLIST: ! 2484: yyerror ("haven't written symbol table for values yet"); ! 2485: ! 2486: case YV_NULL: ! 2487: yyerror ("need an integer, not NULL"); ! 2488: ! 2489: default: ! 2490: myyerror ("unknown value: %d", yv -> yv_code); ! 2491: } ! 2492: /* NOTREACHED */ ! 2493: } ! 2494: ! 2495: static double val2real (yv) ! 2496: register YV yv; ! 2497: { ! 2498: switch (yv -> yv_code) { ! 2499: case YV_NUMBER: ! 2500: return yv -> yv_number; ! 2501: ! 2502: case YV_REAL: ! 2503: return yv -> yv_real; ! 2504: ! 2505: case YV_STRING: ! 2506: yyerror ("need an integer, not a string"); ! 2507: ! 2508: case YV_IDEFINED: ! 2509: case YV_IDLIST: ! 2510: yyerror ("haven't written symbol table for values yet"); ! 2511: ! 2512: case YV_NULL: ! 2513: yyerror ("need an integer, not NULL"); ! 2514: ! 2515: default: ! 2516: myyerror ("unknown value: %d", yv -> yv_code); ! 2517: } ! 2518: /* NOTREACHED */ ! 2519: } ! 2520: ! 2521: /* */ ! 2522: ! 2523: static val2prf (yv, level) ! 2524: register YV yv; ! 2525: int level; ! 2526: { ! 2527: register YV y; ! 2528: ! 2529: if (yv -> yv_flags & YV_ID) ! 2530: (void) printf ("%s ", yv -> yv_id); ! 2531: ! 2532: if (yv -> yv_flags & YV_TYPE) /* will this REALLY work??? */ ! 2533: do_type1 (yv -> yv_type, 0, level, NULLCP, NULLCP, NULLCP, NULL); ! 2534: ! 2535: switch (yv -> yv_code) { ! 2536: case YV_BOOL: ! 2537: (void) printf (yv -> yv_number ? "TRUE" : "FALSE"); ! 2538: break; ! 2539: ! 2540: case YV_NUMBER: ! 2541: if (yv -> yv_named) ! 2542: (void) printf ("%s", yv -> yv_named); ! 2543: else ! 2544: (void) printf ("%d", yv -> yv_number); ! 2545: break; ! 2546: ! 2547: case YV_REAL: ! 2548: dump_real (yv -> yv_real); ! 2549: break; ! 2550: ! 2551: case YV_STRING: ! 2552: (void) printf ("\"%s\"", yv -> yv_string); ! 2553: break; ! 2554: ! 2555: case YV_IDEFINED: ! 2556: if (yv -> yv_module) ! 2557: (void) printf ("%s.", yv -> yv_module); ! 2558: (void) printf ("%s", yv -> yv_identifier); ! 2559: break; ! 2560: ! 2561: case YV_IDLIST: ! 2562: case YV_VALIST: ! 2563: (void) printf ("{"); ! 2564: for (y = yv -> yv_idlist; y; y = y -> yv_next) { ! 2565: (void) printf (" "); ! 2566: val2prf (y, level + 1); ! 2567: (void) printf (y -> yv_next ? ", " : " "); ! 2568: } ! 2569: (void) printf ("}"); ! 2570: break; ! 2571: ! 2572: case YV_NULL: ! 2573: (void) printf ("NULL"); ! 2574: break; ! 2575: ! 2576: default: ! 2577: myyerror ("unknown value: %d", yv -> yv_code); ! 2578: /* NOTREACHED */ ! 2579: } ! 2580: } ! 2581: static dump_real (r) ! 2582: double r; ! 2583: { ! 2584: #ifndef BSD44 ! 2585: extern char *ecvt (); ! 2586: char *cp; ! 2587: char sbuf[128]; ! 2588: int decpt, sign; ! 2589: ! 2590: cp = ecvt (r, 20, &decpt, &sign); ! 2591: (void) strcpy (sbuf, cp); /* cp gets overwritten by printf */ ! 2592: (void) printf ("{ %s%s, 10, %d }", sign ? "-" : "", sbuf, ! 2593: decpt - strlen (sbuf)); ! 2594: #else ! 2595: register char *cp, ! 2596: *dp, ! 2597: *sp; ! 2598: char sbuf[128]; ! 2599: ! 2600: (void) sprintf (sbuf, "%.19e", r); ! 2601: if (*(dp = sbuf) == '-') ! 2602: sp = "-", dp++; ! 2603: else ! 2604: sp = ""; ! 2605: ! 2606: if (dp[1] != '.' || (cp = index (dp, 'e')) == NULL) { ! 2607: (void) printf ("{ 0, 10, 0 } -- %s --", sbuf); ! 2608: return; ! 2609: } ! 2610: *cp++ = NULL; ! 2611: (void) printf ("{ %s%c%s, 10, %d }", ! 2612: sp, *dp, dp + 2, atoi (cp) - strlen (dp + 2)); ! 2613: #endif ! 2614: } ! 2615: ! 2616: /* */ ! 2617: ! 2618: static int dfl2int (yp) ! 2619: register YP yp; ! 2620: { ! 2621: register YV yv, ! 2622: y; ! 2623: ! 2624: yv = yp -> yp_default; ! 2625: switch (yv -> yv_code) { ! 2626: case YV_BOOL: ! 2627: case YV_NUMBER: ! 2628: return yv -> yv_number; ! 2629: ! 2630: case YV_STRING: ! 2631: yyerror ("need an integer, not a string"); ! 2632: ! 2633: case YV_REAL: ! 2634: yyerror ("need an integer, not a real"); ! 2635: ! 2636: case YV_IDEFINED: ! 2637: for (y = yp -> yp_value; y; y = y -> yv_next) ! 2638: if (y -> yv_code == YV_NUMBER ! 2639: && (y -> yv_flags & YV_NAMED) ! 2640: && strcmp (yv -> yv_identifier, y -> yv_named) == 0) ! 2641: return y -> yv_number; ! 2642: /* and fall */ ! 2643: ! 2644: case YV_IDLIST: ! 2645: yyerror ("haven't written symbol table for values yet"); ! 2646: ! 2647: case YV_NULL: ! 2648: yyerror ("need an integer, not NULL"); ! 2649: ! 2650: default: ! 2651: myyerror ("unknown value: %d", yv -> yv_code); ! 2652: } ! 2653: /* NOTREACHED */ ! 2654: } ! 2655: ! 2656: /* DEBUG */ ! 2657: ! 2658: print_type (yp, level) ! 2659: register YP yp; ! 2660: register int level; ! 2661: { ! 2662: register YP y; ! 2663: register YV yv; ! 2664: ! 2665: if (yp == NULLYP) ! 2666: return; ! 2667: ! 2668: (void) fprintf (stderr, "%*scode=0x%x flags=%s direction=0x%x\n", level * 4, "", ! 2669: yp -> yp_code, sprintb (yp -> yp_flags, YPBITS), ! 2670: yp -> yp_direction); ! 2671: (void) fprintf (stderr, ! 2672: "%*sintexp=\"%s\" strexp=\"%s\" prfexp=0%o declexp=\"%s\" varexp=\"%s\"\n", ! 2673: level * 4, "", yp -> yp_intexp, yp -> yp_strexp, yp -> yp_prfexp, ! 2674: yp -> yp_declexp, yp -> yp_varexp); ! 2675: if (yp -> yp_param_type) ! 2676: (void) fprintf (stderr, "%*sparameter type=\"%s\"\n", level * 4, "", ! 2677: yp -> yp_param_type); ! 2678: if (yp -> yp_action0) ! 2679: (void) fprintf (stderr, "%*saction0 at line %d=\"%s\"\n", level * 4, "", ! 2680: yp -> yp_act0_lineno, yp -> yp_action0); ! 2681: if (yp -> yp_action05) ! 2682: (void) fprintf (stderr, "%*saction05 at line %d=\"%s\"\n", level * 4, "", ! 2683: yp -> yp_act05_lineno, yp -> yp_action05); ! 2684: if (yp -> yp_action1) ! 2685: (void) fprintf (stderr, "%*saction1 at line %d=\"%s\"\n", level * 4, "", ! 2686: yp -> yp_act1_lineno, yp -> yp_action1); ! 2687: if (yp -> yp_action2) ! 2688: (void) fprintf (stderr, "%*saction2 at line %d=\"%s\"\n", level * 4, "", ! 2689: yp -> yp_act2_lineno, yp -> yp_action2); ! 2690: if (yp -> yp_action3) ! 2691: (void) fprintf (stderr, "%*saction3 at line %d=\"%s\"\n", level * 4, "", ! 2692: yp -> yp_act3_lineno, yp -> yp_action3); ! 2693: ! 2694: if (yp -> yp_flags & YP_TAG) { ! 2695: (void) fprintf (stderr, "%*stag class=0x%x value=0x%x\n", level * 4, "", ! 2696: yp -> yp_tag -> yt_class, yp -> yp_tag -> yt_value); ! 2697: print_value (yp -> yp_tag -> yt_value, level + 1); ! 2698: } ! 2699: ! 2700: if (yp -> yp_flags & YP_DEFAULT) { ! 2701: (void) fprintf (stderr, "%*sdefault=0x%x\n", level * 4, "", yp -> yp_default); ! 2702: print_value (yp -> yp_default, level + 1); ! 2703: } ! 2704: ! 2705: if (yp -> yp_flags & YP_ID) ! 2706: (void) fprintf (stderr, "%*sid=\"%s\"\n", level * 4, "", yp -> yp_id); ! 2707: ! 2708: if (yp -> yp_flags & YP_BOUND) ! 2709: (void) fprintf (stderr, "%*sbound=\"%s\"\n", level * 4, "", yp -> yp_bound); ! 2710: ! 2711: if (yp -> yp_offset) ! 2712: (void) fprintf (stderr, "%*soffset=\"%s\"\n", level * 4, "", yp -> yp_offset); ! 2713: ! 2714: switch (yp -> yp_code) { ! 2715: case YP_INTLIST: ! 2716: case YP_ENUMLIST: ! 2717: case YP_BITLIST: ! 2718: (void) fprintf (stderr, "%*svalue=0x%x\n", level * 4, "", yp -> yp_value); ! 2719: for (yv = yp -> yp_value; yv; yv = yv -> yv_next) { ! 2720: print_value (yv, level + 1); ! 2721: (void) fprintf (stderr, "%*s----\n", (level + 1) * 4, ""); ! 2722: } ! 2723: break; ! 2724: ! 2725: case YP_SEQTYPE: ! 2726: case YP_SEQLIST: ! 2727: case YP_SETTYPE: ! 2728: case YP_SETLIST: ! 2729: case YP_CHOICE: ! 2730: (void) fprintf (stderr, "%*stype=0x%x\n", level * 4, "", yp -> yp_type); ! 2731: for (y = yp -> yp_type; y; y = y -> yp_next) { ! 2732: print_type (y, level + 1); ! 2733: (void) fprintf (stderr, "%*s----\n", (level + 1) * 4, ""); ! 2734: } ! 2735: break; ! 2736: ! 2737: case YP_IDEFINED: ! 2738: (void) fprintf (stderr, "%*smodule=\"%s\" identifier=\"%s\"\n", ! 2739: level * 4, "", yp -> yp_module ? yp -> yp_module : "", ! 2740: yp -> yp_identifier); ! 2741: break; ! 2742: ! 2743: default: ! 2744: break; ! 2745: } ! 2746: } ! 2747: ! 2748: /* */ ! 2749: ! 2750: static print_value (yv, level) ! 2751: register YV yv; ! 2752: register int level; ! 2753: { ! 2754: register YV y; ! 2755: ! 2756: if (yv == NULLYV) ! 2757: return; ! 2758: ! 2759: (void) fprintf (stderr, "%*scode=0x%x flags=%s\n", level * 4, "", ! 2760: yv -> yv_code, sprintb (yv -> yv_flags, YVBITS)); ! 2761: ! 2762: if (yv -> yv_action) ! 2763: (void) fprintf (stderr, "%*saction at line %d=\"%s\"\n", level * 4, "", ! 2764: yv -> yv_act_lineno, yv -> yv_action); ! 2765: ! 2766: if (yv -> yv_flags & YV_ID) ! 2767: (void) fprintf (stderr, "%*sid=\"%s\"\n", level * 4, "", yv -> yv_id); ! 2768: ! 2769: if (yv -> yv_flags & YV_NAMED) ! 2770: (void) fprintf (stderr, "%*snamed=\"%s\"\n", level * 4, "", yv -> yv_named); ! 2771: ! 2772: if (yv -> yv_flags & YV_TYPE) { ! 2773: (void) fprintf (stderr, "%*stype=0x%x\n", level * 4, "", yv -> yv_type); ! 2774: print_type (yv -> yv_type, level + 1); ! 2775: } ! 2776: ! 2777: switch (yv -> yv_code) { ! 2778: case YV_NUMBER: ! 2779: case YV_BOOL: ! 2780: (void) fprintf (stderr, "%*snumber=0x%x\n", level * 4, "", ! 2781: yv -> yv_number); ! 2782: break; ! 2783: ! 2784: case YV_STRING: ! 2785: (void) fprintf (stderr, "%*sstring=0x%x\n", level * 4, "", ! 2786: yv -> yv_string); ! 2787: break; ! 2788: ! 2789: case YV_IDEFINED: ! 2790: if (yv -> yv_flags & YV_BOUND) ! 2791: (void) fprintf (stderr, "%*smodule=\"%s\" identifier=\"%s\"\n", ! 2792: level * 4, "", yv -> yv_module, yv -> yv_identifier); ! 2793: else ! 2794: (void) fprintf (stderr, "%*sbound identifier=\"%s\"\n", ! 2795: level * 4, "", yv -> yv_identifier); ! 2796: break; ! 2797: ! 2798: case YV_IDLIST: ! 2799: case YV_VALIST: ! 2800: for (y = yv -> yv_idlist; y; y = y -> yv_next) { ! 2801: print_value (y, level + 1); ! 2802: (void) fprintf (stderr, "%*s----\n", (level + 1) * 4, ""); ! 2803: } ! 2804: break; ! 2805: ! 2806: default: ! 2807: break; ! 2808: } ! 2809: } ! 2810: ! 2811: /* SYMBOLS */ ! 2812: ! 2813: static SY new_symbol (encpref, decpref, prfpref, mod, id, type) ! 2814: register char *encpref, ! 2815: *decpref, ! 2816: *prfpref, ! 2817: *mod, ! 2818: *id; ! 2819: register YP type; ! 2820: { ! 2821: register SY sy; ! 2822: ! 2823: if ((sy = (SY) calloc (1, sizeof *sy)) == NULLSY) ! 2824: yyerror ("out of memory"); ! 2825: sy -> sy_encpref = encpref; ! 2826: sy -> sy_decpref = decpref; ! 2827: sy -> sy_prfpref = prfpref; ! 2828: sy -> sy_module = mod; ! 2829: sy -> sy_name = id; ! 2830: sy -> sy_type = type; ! 2831: ! 2832: return sy; ! 2833: } ! 2834: ! 2835: ! 2836: static SY add_symbol (s1, s2) ! 2837: register SY s1, ! 2838: s2; ! 2839: { ! 2840: register SY sy; ! 2841: ! 2842: if (s1 == NULLSY) ! 2843: return s2; ! 2844: ! 2845: for (sy = s1; sy -> sy_next; sy = sy -> sy_next) ! 2846: continue; ! 2847: sy -> sy_next = s2; ! 2848: ! 2849: return s1; ! 2850: } ! 2851: ! 2852: /* MODULES */ ! 2853: ! 2854: MD lookup_module (module, oid) ! 2855: char *module; ! 2856: OID oid; ! 2857: { ! 2858: register MD md; ! 2859: ! 2860: for (md = mymodules; md; md = md -> md_next) { ! 2861: if (module && md -> md_module && strcmp (md -> md_module, module) == 0) ! 2862: return md; ! 2863: if (oid && md -> md_oid && oid_cmp(oid, md->md_oid) == 0) ! 2864: return md; ! 2865: } ! 2866: ! 2867: read_ph_file (module, oid); ! 2868: ! 2869: if ((md = (MD) calloc (1, sizeof *md)) == NULLMD) ! 2870: yyerror ("out of memory"); ! 2871: md -> md_module = new_string (module); ! 2872: if (oid) ! 2873: md -> md_oid = oid_cpy(oid); ! 2874: else ! 2875: md -> md_oid = NULLOID; ! 2876: ! 2877: if (mymodules != NULLMD) ! 2878: md -> md_next = mymodules; ! 2879: ! 2880: return (mymodules = md); ! 2881: } ! 2882: ! 2883: /* TYPES */ ! 2884: ! 2885: YP new_type (code) ! 2886: int code; ! 2887: { ! 2888: register YP yp; ! 2889: ! 2890: if ((yp = (YP) calloc (1, sizeof *yp)) == NULLYP) ! 2891: yyerror ("out of memory"); ! 2892: yp -> yp_code = code; ! 2893: ! 2894: return yp; ! 2895: } ! 2896: ! 2897: ! 2898: YP add_type (y, z) ! 2899: register YP y, ! 2900: z; ! 2901: { ! 2902: register YP yp; ! 2903: ! 2904: for (yp = y; yp -> yp_next; yp = yp -> yp_next) ! 2905: continue; ! 2906: yp -> yp_next = z; ! 2907: ! 2908: return y; ! 2909: } ! 2910: ! 2911: /* */ ! 2912: ! 2913: YP copy_type (yp) ! 2914: register YP yp; ! 2915: { ! 2916: register YP y; ! 2917: ! 2918: if (yp == NULLYP) ! 2919: return NULLYP; ! 2920: ! 2921: y = new_type (yp -> yp_code); ! 2922: y -> yp_direction = yp -> yp_direction; ! 2923: ! 2924: switch (yp -> yp_code) { ! 2925: case YP_IDEFINED: ! 2926: if (yp -> yp_module) ! 2927: y -> yp_module = new_string (yp -> yp_module); ! 2928: y -> yp_identifier = new_string (yp -> yp_identifier); ! 2929: y -> yp_modid = oid_cpy (yp -> yp_modid); ! 2930: break; ! 2931: ! 2932: case YP_SEQTYPE: ! 2933: case YP_SEQLIST: ! 2934: case YP_SETTYPE: ! 2935: case YP_SETLIST: ! 2936: case YP_CHOICE: ! 2937: y -> yp_type = copy_type (yp -> yp_type); ! 2938: break; ! 2939: ! 2940: case YP_INTLIST: ! 2941: case YP_ENUMLIST: ! 2942: case YP_BITLIST: ! 2943: y -> yp_value = copy_value (yp -> yp_value); ! 2944: break; ! 2945: ! 2946: default: ! 2947: break; ! 2948: } ! 2949: ! 2950: y -> yp_intexp = yp -> yp_intexp; ! 2951: y -> yp_strexp = yp -> yp_strexp; ! 2952: y -> yp_prfexp = yp -> yp_prfexp; ! 2953: ! 2954: y -> yp_declexp = yp -> yp_declexp; ! 2955: y -> yp_varexp = yp -> yp_varexp; ! 2956: ! 2957: if (yp -> yp_structname) ! 2958: y -> yp_structname = new_string (yp -> yp_structname); ! 2959: if (yp -> yp_ptrname) ! 2960: y -> yp_ptrname = new_string (yp -> yp_ptrname); ! 2961: ! 2962: if (yp -> yp_param_type) ! 2963: y -> yp_param_type = new_string (yp -> yp_param_type); ! 2964: ! 2965: if (yp -> yp_action0) { ! 2966: y -> yp_action0 = new_string (yp -> yp_action0); ! 2967: y -> yp_act0_lineno = yp -> yp_act0_lineno; ! 2968: } ! 2969: ! 2970: if (yp -> yp_action05) { ! 2971: y -> yp_action05 = new_string (yp -> yp_action05); ! 2972: y -> yp_act05_lineno = yp -> yp_act05_lineno; ! 2973: } ! 2974: ! 2975: if (yp -> yp_action1) { ! 2976: y -> yp_action1 = new_string (yp -> yp_action1); ! 2977: y -> yp_act1_lineno = yp -> yp_act1_lineno; ! 2978: } ! 2979: ! 2980: if (yp -> yp_action2) { ! 2981: y -> yp_action2 = new_string (yp -> yp_action2); ! 2982: y -> yp_act2_lineno = yp -> yp_act2_lineno; ! 2983: } ! 2984: ! 2985: if (yp -> yp_action3) { ! 2986: y -> yp_action3 = new_string (yp -> yp_action3); ! 2987: y -> yp_act3_lineno = yp -> yp_act3_lineno; ! 2988: } ! 2989: ! 2990: y -> yp_flags = yp -> yp_flags; ! 2991: ! 2992: if (yp -> yp_flags & YP_DEFAULT) ! 2993: y -> yp_default = copy_value (yp -> yp_default); ! 2994: ! 2995: if (yp -> yp_flags & YP_ID) ! 2996: y -> yp_id = new_string (yp -> yp_id); ! 2997: ! 2998: if (yp -> yp_flags & YP_TAG) ! 2999: y -> yp_tag = copy_tag (yp -> yp_tag); ! 3000: ! 3001: if (yp -> yp_flags & YP_BOUND) ! 3002: y -> yp_bound = new_string (yp -> yp_bound); ! 3003: ! 3004: if (yp -> yp_flags & YP_PARMVAL) ! 3005: y -> yp_parm = new_string (yp -> yp_parm); ! 3006: ! 3007: if (yp -> yp_flags & YP_CONTROLLED) ! 3008: y -> yp_control = new_string (yp -> yp_control); ! 3009: ! 3010: if (yp -> yp_flags & YP_OPTCONTROL) ! 3011: y -> yp_optcontrol = new_string (yp -> yp_optcontrol); ! 3012: ! 3013: if (yp -> yp_offset) ! 3014: y -> yp_offset = new_string (yp -> yp_offset); ! 3015: ! 3016: if (yp -> yp_next) ! 3017: y -> yp_next = copy_type (yp -> yp_next); ! 3018: ! 3019: return y; ! 3020: } ! 3021: ! 3022: /* VALUES */ ! 3023: ! 3024: YV new_value (code) ! 3025: int code; ! 3026: { ! 3027: register YV yv; ! 3028: ! 3029: if ((yv = (YV) calloc (1, sizeof *yv)) == NULLYV) ! 3030: yyerror ("out of memory"); ! 3031: yv -> yv_code = code; ! 3032: ! 3033: return yv; ! 3034: } ! 3035: ! 3036: ! 3037: YV add_value (y, z) ! 3038: register YV y, ! 3039: z; ! 3040: { ! 3041: register YV yv; ! 3042: ! 3043: for (yv = y; yv -> yv_next; yv = yv -> yv_next) ! 3044: continue; ! 3045: yv -> yv_next = z; ! 3046: ! 3047: return y; ! 3048: } ! 3049: ! 3050: /* */ ! 3051: ! 3052: YV copy_value (yv) ! 3053: register YV yv; ! 3054: { ! 3055: register YV y; ! 3056: ! 3057: if (yv == NULLYV) ! 3058: return NULLYV; ! 3059: ! 3060: y = new_value (yv -> yv_code); ! 3061: y -> yv_flags = yv -> yv_flags; ! 3062: ! 3063: if (yv -> yv_action) { ! 3064: y -> yv_action = new_string (yv -> yv_action); ! 3065: y -> yv_act_lineno = yv -> yv_act_lineno; ! 3066: } ! 3067: ! 3068: if (yv -> yv_flags & YV_ID) ! 3069: y -> yv_id = new_string (yv -> yv_id); ! 3070: ! 3071: if (yv -> yv_flags & YV_NAMED) ! 3072: y -> yv_named = new_string (yv -> yv_named); ! 3073: ! 3074: if (yv -> yv_flags & YV_TYPE) ! 3075: y -> yv_type = copy_type (yv -> yv_type); ! 3076: ! 3077: switch (yv -> yv_code) { ! 3078: case YV_NUMBER: ! 3079: case YV_BOOL: ! 3080: y -> yv_number = yv -> yv_number; ! 3081: break; ! 3082: ! 3083: case YV_STRING: ! 3084: y -> yv_string = new_string (yv -> yv_string); ! 3085: break; ! 3086: ! 3087: case YV_IDEFINED: ! 3088: if (yv -> yv_module) ! 3089: y -> yv_module = new_string (yv -> yv_module); ! 3090: y -> yv_identifier = new_string (yv -> yv_identifier); ! 3091: break; ! 3092: ! 3093: case YV_IDLIST: ! 3094: case YV_VALIST: ! 3095: y -> yv_idlist = copy_value (yv -> yv_idlist); ! 3096: break; ! 3097: ! 3098: default: ! 3099: break; ! 3100: } ! 3101: ! 3102: if (yv -> yv_next) ! 3103: y -> yv_next = copy_value (yv -> yv_next); ! 3104: ! 3105: return y; ! 3106: } ! 3107: ! 3108: /* TAGS */ ! 3109: ! 3110: YT new_tag (class) ! 3111: PElementClass class; ! 3112: { ! 3113: register YT yt; ! 3114: ! 3115: if ((yt = (YT) calloc (1, sizeof *yt)) == NULLYT) ! 3116: yyerror ("out of memory"); ! 3117: yt -> yt_class = class; ! 3118: ! 3119: return yt; ! 3120: } ! 3121: ! 3122: /* */ ! 3123: ! 3124: YT copy_tag (yt) ! 3125: register YT yt; ! 3126: { ! 3127: register YT y; ! 3128: ! 3129: if (yt == NULLYT) ! 3130: return NULLYT; ! 3131: ! 3132: y = new_tag (yt -> yt_class); ! 3133: ! 3134: y -> yt_value = copy_value (yt -> yt_value); ! 3135: ! 3136: return y; ! 3137: } ! 3138: ! 3139: /* STRINGS */ ! 3140: ! 3141: char *new_string (s) ! 3142: register char *s; ! 3143: { ! 3144: register char *p; ! 3145: ! 3146: if ((p = malloc ((unsigned) (strlen (s) + 1))) == NULLCP) ! 3147: yyerror ("out of memory"); ! 3148: ! 3149: (void) strcpy (p, s); ! 3150: return p; ! 3151: } ! 3152: ! 3153: /* SYMBOLS */ ! 3154: ! 3155: static struct triple { ! 3156: char *t_name; ! 3157: PElementClass t_class; ! 3158: PElementID t_id; ! 3159: } triples[] = { ! 3160: "IA5String", PE_CLASS_UNIV, PE_DEFN_IA5S, ! 3161: "ISO646String", PE_CLASS_UNIV, PE_DEFN_IA5S, ! 3162: "NumericString", PE_CLASS_UNIV, PE_DEFN_NUMS, ! 3163: "PrintableString", PE_CLASS_UNIV, PE_DEFN_PRTS, ! 3164: "T61String", PE_CLASS_UNIV, PE_DEFN_T61S, ! 3165: "TeletexString", PE_CLASS_UNIV, PE_DEFN_T61S, ! 3166: "VideotexString", PE_CLASS_UNIV, PE_DEFN_VTXS, ! 3167: "GeneralizedTime", PE_CLASS_UNIV, PE_DEFN_GENT, ! 3168: "GeneralisedTime", PE_CLASS_UNIV, PE_DEFN_GENT, ! 3169: "UTCTime", PE_CLASS_UNIV, PE_DEFN_UTCT, ! 3170: "UniversalTime", PE_CLASS_UNIV, PE_DEFN_UTCT, ! 3171: "GraphicString", PE_CLASS_UNIV, PE_DEFN_GFXS, ! 3172: "VisibleString", PE_CLASS_UNIV, PE_DEFN_VISS, ! 3173: "GeneralString", PE_CLASS_UNIV, PE_DEFN_GENS, ! 3174: "EXTERNAL", PE_CLASS_UNIV, PE_CONS_EXTN, ! 3175: "ObjectDescriptor", PE_CLASS_UNIV, PE_PRIM_ODE, ! 3176: ! 3177: NULL ! 3178: }; ! 3179: ! 3180: /* */ ! 3181: ! 3182: char *modsym (module, id, prefix) ! 3183: register char *module, ! 3184: *id; ! 3185: char *prefix; ! 3186: { ! 3187: char buf1[BUFSIZ], ! 3188: buf2[BUFSIZ], ! 3189: buf3[BUFSIZ]; ! 3190: register struct triple *t; ! 3191: static char buffer[BUFSIZ]; ! 3192: ! 3193: if (module == NULLCP) ! 3194: for (t = triples; t -> t_name; t++) ! 3195: if (strcmp (t -> t_name, id) == 0) { ! 3196: module = "UNIV"; ! 3197: break; ! 3198: } ! 3199: ! 3200: if (prefix) ! 3201: modsym_aux (prefix, buf1); ! 3202: modsym_aux (module ? module : mymodule, buf2); ! 3203: modsym_aux (id, buf3); ! 3204: if (prefix) ! 3205: (void) sprintf (buffer, "%s_%s_%s", buf1, buf2, buf3); ! 3206: else ! 3207: (void) sprintf (buffer, "%s_%s", buf2, buf3); ! 3208: ! 3209: return buffer; ! 3210: } ! 3211: ! 3212: ! 3213: static modsym_aux (name, bp) ! 3214: register char *name, ! 3215: *bp; ! 3216: { ! 3217: register char c; ! 3218: ! 3219: while (c = *name++) ! 3220: switch (c) { ! 3221: case '-': ! 3222: *bp++ = '_'; ! 3223: *bp++ = '_'; ! 3224: break; ! 3225: ! 3226: default: ! 3227: *bp++ = c; ! 3228: break; ! 3229: } ! 3230: ! 3231: *bp = NULL; ! 3232: } ! 3233: ! 3234: /* */ ! 3235: ! 3236: static char *gensym (s, a) ! 3237: char *s, *a; ! 3238: { ! 3239: int i; ! 3240: register char *p; ! 3241: char buffer[BUFSIZ]; ! 3242: static int cP = 0; ! 3243: static int eP = 0; ! 3244: static int mP = 0; ! 3245: ! 3246: switch (*s) { ! 3247: case 'c': ! 3248: i = cP++; ! 3249: break; ! 3250: case 'e': ! 3251: i = eP++; ! 3252: break; ! 3253: case 'm': ! 3254: i = mP++; ! 3255: break; ! 3256: ! 3257: default: ! 3258: myyerror ("unknown gensym argument \"%s\"", s); ! 3259: /* NOTREACHED */ ! 3260: } ! 3261: if (a) ! 3262: (void) sprintf (buffer, "%s_%s_%d[n_%s]", s, modulename, i, a); ! 3263: else ! 3264: (void) sprintf (buffer, "%s_%s_%d", s, modulename, i); ! 3265: ! 3266: if ((p = malloc ((unsigned) (strlen (buffer) + 11))) == NULLCP) ! 3267: yyerror ("out of memory"); ! 3268: ! 3269: (void) strcpy (p, buffer); ! 3270: return p; ! 3271: } ! 3272: ! 3273: /* pepy compatible routines - you know how it is ... */ ! 3274: init_new_file () ! 3275: { ! 3276: ; ! 3277: } ! 3278: ! 3279: end_file () ! 3280: { ! 3281: ; ! 3282: } ! 3283: ! 3284: static char *array (s, flg) ! 3285: char *s; ! 3286: int flg; ! 3287: { ! 3288: static char buf[BUFSIZ]; ! 3289: char *p; ! 3290: ! 3291: if (!flg) return s; ! 3292: ! 3293: if (p = index (s, '[')) { ! 3294: (void) sprintf (buf, "%*.*s[1]", p - s, p - s, s); ! 3295: return buf; ! 3296: } ! 3297: return s; ! 3298: } ! 3299: ! 3300: static void prime_default (yp, level) ! 3301: YP yp; ! 3302: int level; ! 3303: { ! 3304: switch (yp -> yp_code) { ! 3305: case YP_BOOL: ! 3306: (void) printf ("%*s%s = %d;\n", level * 4, "", ! 3307: SVAL (yp->yp_varexp), ! 3308: val2int (yp -> yp_default) ? 1 : 0); ! 3309: break; ! 3310: ! 3311: case YP_INT: ! 3312: (void) printf ("%*s%s = %d;\n", level * 4, "", ! 3313: SVAL (yp -> yp_varexp), val2int (yp -> yp_default)); ! 3314: break; ! 3315: ! 3316: case YP_INTLIST: ! 3317: case YP_ENUMLIST: ! 3318: (void) printf ("%*s%s = %d;\n", level * 4, "", ! 3319: SVAL (yp -> yp_varexp), dfl2int (yp)); ! 3320: break; ! 3321: ! 3322: case YP_REAL: ! 3323: (void) printf ("%*s%s = %g;\n", level * 4, "", ! 3324: SVAL (yp -> yp_varexp), ! 3325: val2real (yp -> yp_default)); ! 3326: ! 3327: default: ! 3328: break; ! 3329: } ! 3330: } ! 3331: /* PH FILES */ ! 3332: ! 3333: /* really need much more information in the .ph file... */ ! 3334: ! 3335: static read_ph_file (module, oid) ! 3336: register char *module; ! 3337: OID oid; ! 3338: { ! 3339: int class, ! 3340: value, ! 3341: direction; ! 3342: char buffer[BUFSIZ], ! 3343: file[BUFSIZ], ! 3344: id[BUFSIZ], ! 3345: encpref[BUFSIZ], ! 3346: decpref[BUFSIZ], ! 3347: printpref[BUFSIZ]; ! 3348: char *p, *ep, *dp, *ppp; ! 3349: register FILE *fp; ! 3350: register YP yp; ! 3351: register YT yt; ! 3352: register YV yv; ! 3353: ! 3354: (void) sprintf (file, "%s.ph", module); ! 3355: if (oid) ! 3356: (void) sprintf (p = buffer, "%s.ph", sprintoid(oid)); ! 3357: else ! 3358: p = NULLCP; ! 3359: if ((fp = open_ph_file (file, p, "r")) == NULL) ! 3360: { ! 3361: warning ("Can't find file %s%s%s failed\n", ! 3362: file, p ? "/" : "", p ? p : ""); ! 3363: return; ! 3364: } ! 3365: ! 3366: if (strcmp (module, "UNIV")) ! 3367: yyprint (module, 1, 0); ! 3368: ! 3369: while (fgets (buffer, sizeof buffer, fp)) { ! 3370: if (sscanf (buffer, "%d/%d/%d: %s", ! 3371: &class, &value, &direction, id) !=4) { ! 3372: myyerror ("bad external definition in %s: %s", ! 3373: file, buffer); ! 3374: continue; ! 3375: } ! 3376: ppp = dp = ep = NULLCP; ! 3377: if (p = index(buffer, '|')) { ! 3378: if( sscanf (p+1, "%s %s %s\n", encpref, decpref, printpref) == 3) { ! 3379: ppp = new_string (printpref); ! 3380: dp = new_string (decpref); ! 3381: ep = new_string (encpref); ! 3382: } ! 3383: } ! 3384: ! 3385: yp = new_type (YP_ANY); ! 3386: yp -> yp_flags = YP_IMPORTED; ! 3387: if (class >= 0) { ! 3388: yp -> yp_flags |= YP_TAG; ! 3389: yp -> yp_tag = yt = new_tag ((PElementClass) class); ! 3390: yt -> yt_value = yv = new_value (YV_NUMBER); ! 3391: yv -> yv_number = value; ! 3392: } ! 3393: yp -> yp_direction = direction; ! 3394: pass1_type (ep, dp, ppp, new_string (module), ! 3395: new_string (id), yp); ! 3396: } ! 3397: ! 3398: (void) fclose (fp); ! 3399: } ! 3400: ! 3401: /* */ ! 3402: ! 3403: static write_ph_file () { ! 3404: int msave; ! 3405: char file[BUFSIZ]; ! 3406: char fileoid[BUFSIZ]; ! 3407: char *cp; ! 3408: register FILE *fp; ! 3409: register SY sy; ! 3410: register YT yt; ! 3411: register YP yp; ! 3412: ! 3413: (void) sprintf (file, "%s.ph", mymodule); ! 3414: if (mymoduleid) ! 3415: (void) sprintf (cp = fileoid, "%s.ph", sprintoid(mymoduleid)); ! 3416: else ! 3417: cp = NULLCP; ! 3418: msave = mflag, mflag = 0; ! 3419: if ((fp = open_ph_file (file, cp, "w")) == NULL) ! 3420: myyerror ("unable to write %s", file); ! 3421: mflag = msave; ! 3422: ! 3423: for (sy = mysymbols; sy; sy = sy -> sy_next) { ! 3424: yp = sy -> sy_type; ! 3425: if (yp -> yp_flags & YP_IMPORTED) ! 3426: continue; ! 3427: if (doexternals == 0 && (yp->yp_flags & YP_EXPORTED) == 0) ! 3428: continue; ! 3429: ! 3430: if (is_any_type (yp)) { ! 3431: (void) fprintf (fp, "-1/0/%d: %s", yp -> yp_direction, sy -> sy_name); ! 3432: (void) fprintf (fp, " |%s %s %s\n", yyencpref, yydecpref, yyprfpref); ! 3433: } ! 3434: else ! 3435: if ((yt = lookup_tag (yp)) && yt -> yt_class != PE_CLASS_CONT) { ! 3436: (void) fprintf (fp, "%d/%d/%d: %s", yt -> yt_class, ! 3437: val2int (yt -> yt_value), yp -> yp_direction, ! 3438: sy -> sy_name); ! 3439: (void) fprintf (fp, " |%s %s %s\n", yyencpref, yydecpref, yyprfpref); ! 3440: } ! 3441: } ! 3442: ! 3443: (void) fclose (fp); ! 3444: } ! 3445: ! 3446: /* */ ! 3447: ! 3448: #ifndef PEPSYPATH ! 3449: #define PEPSYPATH "" ! 3450: #endif ! 3451: ! 3452: ! 3453: static FILE *open_ph_file (fn, fnoid, mode) ! 3454: char *fn, ! 3455: *fnoid, ! 3456: *mode; ! 3457: { ! 3458: register char *dst, ! 3459: *path; ! 3460: char fnb[BUFSIZ]; ! 3461: register FILE *fp; ! 3462: static char *pepypath = NULL; ! 3463: ! 3464: if (*fn == '/') ! 3465: return fopen (fn, mode); ! 3466: ! 3467: if (mflag) { /* MOBY HACK */ ! 3468: if (fnoid && (fp = fopen (fnoid, mode)) != NULL) ! 3469: return fp; ! 3470: if ((fp = fopen (fn, mode)) != NULL) ! 3471: return fp; ! 3472: ! 3473: if (fnoid) { ! 3474: (void) sprintf (fnb, "../pepy/%s", fnoid); ! 3475: if ((fp = fopen (fnb, mode)) != NULL) ! 3476: return fp; ! 3477: } ! 3478: (void) sprintf (fnb, "../pepy/%s", fn); ! 3479: if ((fp = fopen (fnb, mode)) != NULL) ! 3480: return fp; ! 3481: ! 3482: if (fnoid) { ! 3483: (void) sprintf (fnb, "../../pepy/%s", fnoid); ! 3484: if ((fp = fopen (fnb, mode)) != NULL) ! 3485: return fp; ! 3486: } ! 3487: (void) sprintf (fnb, "../../pepy/%s", fn); ! 3488: return fopen (fnb, mode); ! 3489: } ! 3490: ! 3491: if (pepypath == NULL && (pepypath = getenv ("PEPSYPATH")) == NULL) ! 3492: pepypath = PEPSYPATH; ! 3493: path = pepypath; ! 3494: ! 3495: do { ! 3496: dst = fnb; ! 3497: while (*path && *path != ':') ! 3498: *dst++ = *path++; ! 3499: if (dst != fnb) ! 3500: *dst++ = '/'; ! 3501: if (fnoid) { ! 3502: (void) strcpy (dst, fnoid); ! 3503: if ((fp = fopen (fnb, mode)) != NULL) ! 3504: break; ! 3505: } ! 3506: (void) strcpy (dst, fn); ! 3507: if ((fp = fopen (fnb, mode)) != NULL) ! 3508: break; ! 3509: } while (*path++); ! 3510: ! 3511: return fp; ! 3512: } ! 3513: ! 3514: YT lookup_tag (yp) ! 3515: register YP yp; ! 3516: { ! 3517: register struct tuple *t; ! 3518: static struct ypt ypts; ! 3519: register YT yt = &ypts; ! 3520: static struct ypv ypvs; ! 3521: register YV yv = &ypvs; ! 3522: register YP z; ! 3523: ! 3524: if (yp -> yp_flags & YP_TAG) ! 3525: return yp -> yp_tag; ! 3526: ! 3527: while (yp -> yp_code == YP_IDEFINED) { ! 3528: if (yp -> yp_module && strcmp (yp -> yp_module, mymodule)) ! 3529: (void) lookup_module (yp -> yp_module, yp -> yp_modid); ! 3530: ! 3531: if (z = lookup_type (yp -> yp_module, yp -> yp_identifier)) { ! 3532: yp = z; ! 3533: ! 3534: if (yp -> yp_flags & YP_TAG) ! 3535: return yp -> yp_tag; ! 3536: ! 3537: continue; ! 3538: } ! 3539: ! 3540: break; ! 3541: } ! 3542: ! 3543: for (t = tuples; t -> t_type != YP_UNDF; t++) ! 3544: if (t -> t_type == yp -> yp_code) { ! 3545: yt -> yt_class = t -> t_classnum; ! 3546: yt -> yt_value = yv; ! 3547: yv -> yv_code = YV_NUMBER; ! 3548: yv -> yv_number = t -> t_idnum; ! 3549: ! 3550: return yt; ! 3551: } ! 3552: ! 3553: return NULLYT; ! 3554: } ! 3555: ! 3556: int is_any_type (yp) ! 3557: register YP yp; ! 3558: { ! 3559: register YP z; ! 3560: ! 3561: while (yp -> yp_code == YP_IDEFINED) { ! 3562: if (yp -> yp_flags & YP_TAG) ! 3563: return 0; ! 3564: ! 3565: if (yp -> yp_module && strcmp (yp -> yp_module, mymodule)) ! 3566: (void) lookup_module (yp -> yp_module, yp -> yp_modid); ! 3567: ! 3568: if (z = lookup_type (yp -> yp_module, yp -> yp_identifier)) { ! 3569: yp = z; ! 3570: ! 3571: continue; ! 3572: } ! 3573: ! 3574: break; ! 3575: } ! 3576: ! 3577: return (yp -> yp_code == YP_ANY && !(yp -> yp_flags & YP_TAG)); ! 3578: } ! 3579: ! 3580: /* ! 3581: * return a string with the leading pathname stripped off ! 3582: */ ! 3583: char * ! 3584: pstrip(p) ! 3585: char *p; ! 3586: { ! 3587: char *p1; ! 3588: ! 3589: if (p1 = rindex(p, '/')) ! 3590: return (p1 + 1); ! 3591: return (p); ! 3592: } ! 3593: ! 3594: ! 3595: /* ! 3596: * produce a #include on the given file descriptor according to what ever ! 3597: * rules are in fashion today. Unfortunately these keep changing so to ! 3598: * minimise the effort involved in keeping up we put all the code to change ! 3599: * in the one place, here. -- amrw ! 3600: * ! 3601: * actually, the rules have never changed, andrew just can't figure them out. ! 3602: * -- mtr ! 3603: */ ! 3604: doincl(fp, file) ! 3605: FILE *fp; /* where #include is to be written to */ ! 3606: char *file[]; /* files to be included */ ! 3607: { ! 3608: char **p; ! 3609: int stflag = 0; /* are there any standard files ? */ ! 3610: ! 3611: /* determine if there are any standard files present */ ! 3612: for (p = file; *p; p++) { ! 3613: if (is_stand(*p)) { ! 3614: stflag = 1; ! 3615: break; ! 3616: } ! 3617: } ! 3618: ! 3619: if (mflag || stflag) { ! 3620: /* PEPYPATH version */ ! 3621: ! 3622: (void) fprintf (fp, "#ifndef PEPYPATH\n"); ! 3623: for (p = file; *p; p++) { ! 3624: if (mflag || is_stand(*p)) ! 3625: (void) fprintf (fp, "#include <isode/%s>\n", *p); ! 3626: } ! 3627: (void) fprintf (fp, "#else\n"); ! 3628: for (p = file; *p; p++) { ! 3629: if (mflag || is_stand(*p)) ! 3630: (void) fprintf (fp, "#include \"%s\"\n", pstrip(*p)); ! 3631: } ! 3632: (void) fprintf (fp, "#endif\n\n"); ! 3633: ! 3634: /* Now the non standard files */ ! 3635: if (!mflag) { ! 3636: for (p = file; *p; p++) { ! 3637: if (!is_stand(*p)) ! 3638: (void) fprintf (fp, "#include \"%s\"\n", pstrip(*p)); ! 3639: } ! 3640: } ! 3641: ! 3642: } else { ! 3643: /* simple include only version */ ! 3644: ! 3645: for (p = file; *p; p++) ! 3646: (void) fprintf (fp, "#include \"%s\"\n", pstrip(*p)); ! 3647: } ! 3648: ! 3649: (void) fprintf (fp, "\n"); ! 3650: } ! 3651: ! 3652: /* standard files - that should be found in the <isode> directory */ ! 3653: static char *stand_f[] = { ! 3654: "psap.h", ! 3655: "pepsy.h", ! 3656: "UNIV-types.h", ! 3657: ! 3658: (char *)0 /* terminating NULL pointer */ ! 3659: }; ! 3660: ! 3661: ! 3662: /* ! 3663: * determine if the given (after stripping any path) file is a standard ! 3664: * include file which should be in the include/isode directory. ! 3665: * return nonzero (true) if it is. ! 3666: */ ! 3667: is_stand(file) ! 3668: char *file; ! 3669: { ! 3670: char **p; ! 3671: ! 3672: for (p = stand_f; *p; p++) { ! 3673: if (strcmp(file, pstrip(*p)) == 0) ! 3674: return (1); ! 3675: } ! 3676: ! 3677: return (0); ! 3678: } ! 3679: ! 3680: /* Number of different external modules that can referenced */ ! 3681: #define EXTMODSIZE 50 ! 3682: ! 3683: /* table of external modules we reference */ ! 3684: static char *extmodtab[EXTMODSIZE]; ! 3685: static int nextmod = 0; /* next free slot in external module table */ ! 3686: ! 3687: /* ! 3688: * build up a list of external modules we have referenced ! 3689: */ ! 3690: addextmod(p) ! 3691: char *p; /* name of external module */ ! 3692: { ! 3693: #if 0 ! 3694: char *s; ! 3695: #endif ! 3696: ! 3697: if (nextmod >= EXTMODSIZE) ! 3698: ferr(1, "Too many external modules reference, table overflow\n"); ! 3699: ! 3700: #if 0 ! 3701: if ((s = (char *)malloc(strlen(p) + 1)) == NULL) ! 3702: ferr(1, "addextmodout of memory\n"); ! 3703: strcpy(s, p); ! 3704: extmodtab[nextmod++] = s; ! 3705: #else ! 3706: extmodtab[nextmod++] = p; ! 3707: #endif ! 3708: } ! 3709: ! 3710: /* ! 3711: * process all the external modules collected to produce the includes ! 3712: * required ! 3713: */ ! 3714: proc_extmod(fp) ! 3715: FILE *fp; ! 3716: { ! 3717: char **p; ! 3718: char *files[EXTMODSIZE + 1]; ! 3719: char *buf; ! 3720: char *tail = "-types.h"; ! 3721: char *prefix = "pepsy/"; ! 3722: int last = 0; ! 3723: ! 3724: if (nextmod <= 0) ! 3725: return; /* no external definitions */ ! 3726: ! 3727: for (p = extmodtab; p < extmodtab + nextmod; p++) { ! 3728: if (last >= EXTMODSIZE) ! 3729: ferr(1, "proc_extmod: too many external modules\n"); ! 3730: ! 3731: buf = concat(*p, tail); ! 3732: if (mflag || is_stand(buf)) /* need to prepend a "pepsy/" */ ! 3733: files[last++] = my_strcat(prefix, buf); ! 3734: else ! 3735: files[last++] = my_new_str(buf); ! 3736: } ! 3737: files[last++] = (char *)0; ! 3738: ! 3739: doincl(fp, files); ! 3740: ! 3741: /* free up this memory */ ! 3742: --last; /* don't free the NULL pointer - can core dump */ ! 3743: while (last > 0) ! 3744: free(files[--last]); ! 3745: ! 3746: } ! 3747:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.