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