Annotation of 43BSDReno/contrib/isode-beta/others/mosy/mosy.c, revision 1.1.1.1

1.1       root        1: /* mosy.c - Managed Object Syntax-compiler (yacc-based) */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/others/mosy/RCS/mosy.c,v 7.1 90/07/01 21:04:36 mrose Exp $";
                      5: #endif
                      6: 
                      7: /*
                      8:  * $Header: /f/osi/others/mosy/RCS/mosy.c,v 7.1 90/07/01 21:04:36 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       mosy.c,v $
                     12:  * Revision 7.1  90/07/01  21:04:36  mrose
                     13:  * pepsy
                     14:  * 
                     15:  * Revision 7.0  89/11/23  22:00:38  mrose
                     16:  * Release 6.0
                     17:  * 
                     18:  */
                     19: 
                     20: /*
                     21:  *                               NOTICE
                     22:  *
                     23:  *    Acquisition, use, and distribution of this module and related
                     24:  *    materials are subject to the restrictions of a license agreement.
                     25:  *    Consult the Preface in the User's Manual for the full terms of
                     26:  *    this agreement.
                     27:  *
                     28:  */
                     29: 
                     30: 
                     31: #include <ctype.h>
                     32: #include <stdio.h>
                     33: #include <varargs.h>
                     34: #include "mosy-defs.h"
                     35: 
                     36: /*    DATA */
                     37: 
                     38: int    Cflag = 0;              /* mosy */
                     39: int    dflag = 0;
                     40: int    Pflag = 0;              /* pepy compat... */
                     41: int    doexternals;
                     42: static int linepos = 0;
                     43: static int mflag = 0;
                     44: static int mosydebug = 0;
                     45: static int sflag = 0;
                     46: 
                     47: static  char *eval = NULLCP;
                     48: 
                     49: char   *mymodule = "";
                     50: OID    mymoduleid;
                     51: 
                     52: int yysection = NULL;
                     53: char *yyencpref = "none";
                     54: char *yydecpref = "none";
                     55: char *yyprfpref = "none";
                     56: char *yyencdflt = "none";
                     57: char *yydecdflt = "none";
                     58: char *yyprfdflt = "none";
                     59: 
                     60: static char *yymode = "";
                     61: 
                     62: static char *classes[] = {
                     63:     "UNIVERSAL ",
                     64:     "APPLICATION ",
                     65:     "",
                     66:     "PRIVATE "
                     67: };
                     68: 
                     69: static char autogen[BUFSIZ];
                     70: 
                     71: char *sysin = NULLCP;
                     72: static char sysout[BUFSIZ];
                     73: 
                     74: /*  */
                     75: 
                     76: typedef struct yot {
                     77:     char   *yo_name;
                     78: 
                     79:     YP     yo_syntax;
                     80:     YV     yo_value;
                     81: 
                     82:     char   *yo_access;
                     83:     char   *yo_status;
                     84: }              yot, *OT;
                     85: #define        NULLOT  ((OT) 0)
                     86: 
                     87: typedef struct yoi {
                     88:     char   *yi_name;
                     89: 
                     90:     YV     yi_value;
                     91: }              yoi, *OI;
                     92: #define        NULLOI  ((OI) 0)
                     93: 
                     94: /*  */
                     95: 
                     96: typedef struct symlist {
                     97:     char   *sy_encpref;
                     98:     char   *sy_decpref;
                     99:     char   *sy_prfpref;
                    100:     char   *sy_module;
                    101:     char   *sy_name;
                    102: 
                    103:     union {
                    104:        OT      sy_un_yo;
                    105: 
                    106:        OI      sy_un_yi;
                    107: 
                    108:        YP      sy_un_yp;
                    109:     }  sy_un;
                    110: #define        sy_yo   sy_un.sy_un_yo
                    111: #define        sy_yi   sy_un.sy_un_yi
                    112: #define        sy_yp   sy_un.sy_un_yp
                    113: 
                    114:     struct symlist *sy_next;
                    115: }              symlist, *SY;
                    116: #define        NULLSY  ((SY) 0)
                    117: 
                    118: static SY      myobjects = NULLSY;
                    119: 
                    120: static SY      myidentifiers = NULLSY;
                    121: 
                    122: static SY      mytypes = NULLSY;
                    123: 
                    124: 
                    125: char   *modsym ();
                    126: SY     new_symbol (), add_symbol ();
                    127: 
                    128: char   *id2str ();
                    129: 
                    130: YP     lookup_type ();
                    131: char   *val2str ();
                    132: 
                    133: /*    MAIN */
                    134: 
                    135: /* ARGSUSED */
                    136: 
                    137: main (argc, argv, envp)
                    138: int    argc;
                    139: char  **argv,
                    140:       **envp;
                    141: {
                    142:     register char  *cp,
                    143:                   *sp;
                    144: 
                    145:     fprintf (stderr, "%s\n", mosyversion);
                    146: 
                    147:     sysout[0] = NULL;
                    148:     for (argc--, argv++; argc > 0; argc--, argv++) {
                    149:        cp = *argv;
                    150: 
                    151:        if (strcmp (cp, "-d") == 0) {
                    152:            dflag++;
                    153:            continue;
                    154:        }
                    155:        if (strcmp (cp, "-m") == 0) {
                    156:            mflag++;
                    157:            continue;
                    158:        }
                    159:        if (strcmp (cp, "-o") == 0) {
                    160:            if (sysout[0]) {
                    161:                fprintf (stderr, "too many output files\n");
                    162:                exit (1);
                    163:            }
                    164:            argc--, argv++;
                    165:            if ((cp = *argv) == NULL || (*cp == '-' && cp[1] != NULL))
                    166:                goto usage;
                    167:            (void) strcpy (sysout, cp);
                    168: 
                    169:            continue;
                    170:        }
                    171:        if (strcmp (cp, "-s") == 0) {
                    172:            sflag++;
                    173:            continue;
                    174:        }
                    175: 
                    176:        if (sysin) {
                    177: usage: ;
                    178:            fprintf (stderr,
                    179:                "usage: mosy [-d] [-o module.defs] [-s] module.my\n");
                    180:            exit (1);
                    181:        }
                    182: 
                    183:        if (*cp == '-') {
                    184:            if (*++cp != NULL)
                    185:                goto usage;
                    186:            sysin = "";
                    187:        }
                    188:        sysin = cp;
                    189: 
                    190:        if (sysout[0])
                    191:            continue;
                    192:        if (sp = rindex (cp, '/'))
                    193:            sp++;
                    194:        if (sp == NULL || *sp == NULL)
                    195:            sp = cp;
                    196:        sp += strlen (cp = sp) - 3;
                    197:        if (sp > cp && strcmp (sp, ".my") == 0)
                    198:            (void) sprintf (sysout, "%.*s.defs", sp - cp, cp);
                    199:        else
                    200:            (void) sprintf (sysout, "%s.defs", cp);
                    201:     }
                    202: 
                    203:     switch (mosydebug = (cp = getenv ("MOSYTEST")) && *cp ? atoi (cp) : 0) {
                    204:        case 2:
                    205:            yydebug++;          /* fall */
                    206:        case 1:
                    207:            sflag++;            /*   .. */
                    208:        case 0:
                    209:            break;
                    210:     }
                    211: 
                    212:     if (sysin == NULLCP)
                    213:        sysin = "";
                    214: 
                    215:     if (*sysin && freopen (sysin, "r", stdin) == NULL) {
                    216:        fprintf (stderr, "unable to read "), perror (sysin);
                    217:        exit (1);
                    218:     }
                    219: 
                    220:     if (strcmp (sysout, "-") == 0)
                    221:        sysout[0] = NULL;
                    222:     if (*sysout && freopen (sysout, "w", stdout) == NULL) {
                    223:        fprintf (stderr, "unable to write "), perror (sysout);
                    224:        exit (1);
                    225:     }
                    226: 
                    227:     if (cp = index (mosyversion, ')'))
                    228:        for (cp++; *cp != ' '; cp++)
                    229:            if (*cp == NULL) {
                    230:                cp = NULL;
                    231:                break;
                    232:            }
                    233:     if (cp == NULL)
                    234:        cp = mosyversion + strlen (mosyversion);
                    235:     (void) sprintf (autogen, "%*.*s", 
                    236:            cp - mosyversion, cp - mosyversion, mosyversion);
                    237:     printf ("-- automatically generated by %s, do not edit!\n\n", autogen);
                    238: 
                    239:     initoidtbl ();
                    240: 
                    241:     exit (yyparse ());         /* NOTREACHED */
                    242: }
                    243: 
                    244: /*    ERRORS */
                    245: 
                    246: yyerror (s)
                    247: register char   *s;
                    248: {
                    249:     yyerror_aux (s);
                    250: 
                    251:     if (*sysout)
                    252:        (void) unlink (sysout);
                    253: 
                    254:     exit (1);
                    255: }
                    256: 
                    257: #ifndef lint
                    258: warning (va_alist)
                    259: va_dcl
                    260: {
                    261:     char       buffer[BUFSIZ];
                    262:     char       buffer2[BUFSIZ];
                    263:     char       *cp;
                    264:     va_list    ap;
                    265: 
                    266:     va_start (ap);
                    267: 
                    268:     _asprintf (buffer, NULLCP, ap);
                    269: 
                    270:     va_end (ap);
                    271: 
                    272:     (void) sprintf (buffer2, "Warning: %s", buffer);
                    273:     yyerror_aux (buffer2);
                    274: }
                    275: 
                    276: #else
                    277: 
                    278: /* VARARGS1 */
                    279: warning (fmt)
                    280: char   *fmt;
                    281: {
                    282:     warning (fmt);
                    283: }
                    284: #endif
                    285: 
                    286: static yyerror_aux (s)
                    287: register char   *s;
                    288: {
                    289:     if (linepos)
                    290:        fprintf (stderr, "\n"), linepos = 0;
                    291: 
                    292:     if (eval)
                    293:        fprintf (stderr, "%s %s: ", yymode, eval);
                    294:     else
                    295:        fprintf (stderr, "line %d: ", yylineno);
                    296:     fprintf (stderr, "%s\n", s);
                    297:     if (!eval)
                    298:        fprintf (stderr, "last token read was \"%s\"\n", yytext);
                    299: }
                    300: 
                    301: /*  */
                    302: 
                    303: #ifndef        lint
                    304: myyerror (va_alist)
                    305: va_dcl
                    306: {
                    307:     char    buffer[BUFSIZ];
                    308:     va_list ap;
                    309: 
                    310:     va_start (ap);
                    311: 
                    312:     _asprintf (buffer, NULLCP, ap);
                    313: 
                    314:     va_end (ap);
                    315: 
                    316:     yyerror (buffer);
                    317: }
                    318: #else
                    319: /* VARARGS */
                    320: 
                    321: myyerror (fmt)
                    322: char   *fmt;
                    323: {
                    324:     myyerror (fmt);
                    325: }
                    326: #endif
                    327: 
                    328: /*  */
                    329: 
                    330: yywrap () {
                    331:     if (linepos)
                    332:        fprintf (stderr, "\n"), linepos = 0;
                    333: 
                    334:     return 1;
                    335: }
                    336: 
                    337: /*  */
                    338: 
                    339: /* ARGSUSED */
                    340: 
                    341: yyprint (s, f, top)
                    342: char   *s;
                    343: int    f,
                    344:        top;
                    345: {
                    346: }
                    347: 
                    348: static  yyprint_aux (s, mode)
                    349: char   *s,
                    350:        *mode;
                    351: {
                    352:     int            len;
                    353:     static int nameoutput = 0;
                    354:     static int outputlinelen = 79;
                    355: 
                    356:     if (sflag)
                    357:        return;
                    358: 
                    359:     if (strcmp (yymode, mode)) {
                    360:        if (linepos)
                    361:            fprintf (stderr, "\n\n");
                    362: 
                    363:        fprintf (stderr, "%s", mymodule);
                    364:        nameoutput = (linepos = strlen (mymodule)) + 1;
                    365: 
                    366:        fprintf (stderr, " %ss", yymode = mode);
                    367:        linepos += strlen (yymode) + 1;
                    368:        fprintf (stderr, ":");
                    369:        linepos += 2;
                    370:     }
                    371: 
                    372:     len = strlen (s);
                    373:     if (linepos != nameoutput)
                    374:        if (len + linepos + 1 > outputlinelen)
                    375:            fprintf (stderr, "\n%*s", linepos = nameoutput, "");
                    376:        else
                    377:            fprintf (stderr, " "), linepos++;
                    378:     fprintf (stderr, "%s", s);
                    379:     linepos += len;
                    380: }
                    381: 
                    382: /*    PASS1 */
                    383: 
                    384: pass1 ()
                    385: {
                    386:     printf ("-- object definitions compiled from %s", mymodule);
                    387:     if (mymoduleid)
                    388:        printf (" %s", oidprint(mymoduleid));
                    389:     printf ("\n\n");
                    390: }
                    391: 
                    392: /*  */
                    393: 
                    394: pass1_oid (mod, id, value)
                    395: char   *mod,
                    396:        *id;
                    397: YV     value;
                    398: {
                    399:     register SY            sy;
                    400:     register OI            yi;
                    401: 
                    402:     if ((yi = (OI) calloc (1, sizeof *yi)) == NULLOI)
                    403:        yyerror ("out of memory");
                    404: 
                    405:     yi -> yi_name = id;
                    406:     yi -> yi_value = value;
                    407: 
                    408:     if (mosydebug) {
                    409:        if (linepos)
                    410:            fprintf (stderr, "\n"), linepos = 0;
                    411: 
                    412:        fprintf (stderr, "%s.%s\n", mod ? mod : mymodule, id);
                    413:        print_yi (yi, 0);
                    414:        fprintf (stderr, "--------\n");
                    415:     }
                    416:     else
                    417:        yyprint_aux (id, "identifier");
                    418: 
                    419:     sy = new_symbol (NULLCP, NULLCP, NULLCP, mod, id);
                    420:     sy -> sy_yi = yi;
                    421:     myidentifiers = add_symbol (myidentifiers, sy);
                    422: }
                    423: 
                    424: /*  */
                    425: 
                    426: pass1_obj (mod, id, syntax, value, aname, sname)
                    427: char   *mod,
                    428:        *id,
                    429:        *aname,
                    430:        *sname;
                    431: YP     syntax;
                    432: YV     value;
                    433: {
                    434:     register SY            sy;
                    435:     register OT            yo;
                    436: 
                    437:     if ((yo = (OT) calloc (1, sizeof *yo)) == NULLOT)
                    438:        yyerror ("out of memory");
                    439: 
                    440:     yo -> yo_name = id;
                    441:     yo -> yo_syntax = syntax;
                    442:     yo -> yo_value = value;
                    443:     yo -> yo_access = aname;
                    444:     yo -> yo_status = sname;
                    445: 
                    446:     if (mosydebug) {
                    447:        if (linepos)
                    448:            fprintf (stderr, "\n"), linepos = 0;
                    449: 
                    450:        fprintf (stderr, "%s.%s\n", mod ? mod : mymodule, id);
                    451:        print_yo (yo, 0);
                    452:        fprintf (stderr, "--------\n");
                    453:     }
                    454:     else
                    455:        yyprint_aux (id, "object");
                    456: 
                    457:     sy = new_symbol (NULLCP, NULLCP, NULLCP, mod, id);
                    458:     sy -> sy_yo = yo;
                    459:     myobjects = add_symbol (myobjects, sy);
                    460: }
                    461: 
                    462: /*  */
                    463: 
                    464: pass1_type (encpref, decpref, prfpref, mod, id, yp)
                    465: register char  *encpref,
                    466:               *decpref,
                    467:               *prfpref,
                    468:               *mod,
                    469:               *id;
                    470: register YP    yp;
                    471: {
                    472:     register SY            sy;
                    473: 
                    474:     if (dflag && lookup_type (mod, id))        /* no duplicate entries, please... */
                    475:        return;
                    476: 
                    477:     if (mosydebug) {
                    478:        if (linepos)
                    479:            fprintf (stderr, "\n"), linepos = 0;
                    480: 
                    481:        fprintf (stderr, "%s.%s\n", mod ? mod : mymodule, id);
                    482:        print_type (yp, 0);
                    483:        fprintf (stderr, "--------\n");
                    484:     }
                    485:     else
                    486:        if (!(yp -> yp_flags & YP_IMPORTED))
                    487:            yyprint_aux (id, "type");
                    488: 
                    489:     sy = new_symbol (encpref, decpref, prfpref, mod, id);
                    490:     sy -> sy_yp = yp;
                    491:     mytypes = add_symbol (mytypes, sy);
                    492: }
                    493: 
                    494: /*    PASS2 */
                    495: 
                    496: pass2 () {
                    497:     register SY            sy;
                    498:     register YP            yp;
                    499: 
                    500:     if (!sflag)
                    501:        (void) fflush (stderr);
                    502: 
                    503:     yymode = "identifiers";
                    504:     for (sy = myidentifiers; sy; sy = sy -> sy_next) {
                    505:        if (sy -> sy_module == NULLCP)
                    506:            yyerror ("no module name associated with symbol");
                    507: 
                    508:        do_id (sy -> sy_yi, eval = sy -> sy_name);
                    509:     }
                    510:     if (myidentifiers)
                    511:        printf ("\n");
                    512: 
                    513:     yymode = "objects";
                    514:     for (sy = myobjects; sy; sy = sy -> sy_next) {
                    515:        if (sy -> sy_module == NULLCP)
                    516:            yyerror ("no module name associated with symbol");
                    517: 
                    518:        do_obj1 (sy -> sy_yo, eval = sy -> sy_name);
                    519:     }
                    520:     if (myobjects)
                    521:        printf ("\n\n");
                    522: 
                    523:     (void) fflush (stdout);
                    524: 
                    525:     if (ferror (stdout))
                    526:        myyerror ("write error - %s", sys_errname (errno));
                    527: }
                    528: 
                    529: /*  */
                    530: 
                    531: /* ARGSUSED */
                    532: 
                    533: static do_id (yi, id)
                    534: register OI    yi;
                    535: char   *id;
                    536: {
                    537:     printf ("%-20s %s\n", yi -> yi_name, id2str (yi -> yi_value));
                    538: }
                    539: 
                    540: /*  */
                    541: 
                    542: /* ARGSUSED */
                    543: 
                    544: static do_obj1 (yo, id)
                    545: register OT    yo;
                    546: char   *id;
                    547: {
                    548:     register YP            yp,
                    549:                    yz;
                    550: 
                    551:     printf ("%-20s %-16s ", yo -> yo_name, id2str (yo -> yo_value));
                    552: 
                    553:     if ((yp = yo -> yo_syntax) == NULLYP)
                    554:        yyerror ("no syntax associated with object type");
                    555:     switch (yp -> yp_code) {
                    556:        case YP_INT:
                    557:        case YP_INTLIST:
                    558:            id = "INTEGER";
                    559:            break;
                    560: 
                    561:        case YP_OCT:
                    562:            id = "OctetString";
                    563:            break;
                    564: 
                    565:        case YP_OID:
                    566:            id = "ObjectID";
                    567:            break;
                    568: 
                    569:        case YP_NULL:
                    570:            id = "NULL";
                    571:            break;
                    572: 
                    573:        default:
                    574: #ifdef notdef
                    575:            yp = new_type (YP_IDEFINED);
                    576:            yp -> yp_identifier = new_string (yo -> yo_name);
                    577:            yp -> yp_identifier[0] = toupper (yp -> yp_identifier[0]);
                    578:            if (lookup_type (mymodule, yp -> yp_identifier))
                    579:                yyerror ("unable to create inline type for object's syntax");
                    580:            pass1_type (yyencpref, yydecpref, yyprfpref, mymodule,
                    581:                        new_string (yp -> yp_identifier),
                    582:                        yo -> yo_syntax = yp);
                    583: #endif
                    584:            id = "Aggregate";
                    585:            break;
                    586: 
                    587:        case YP_IDEFINED:
                    588:            yz = lookup_type (yp -> yp_module, yp -> yp_identifier);
                    589: again: ;
                    590:            switch (yz ? yz -> yp_code : YP_UNDF) {
                    591:                case YP_UNDF:
                    592:                case YP_INT:
                    593:                case YP_INTLIST:
                    594:                case YP_OCT:
                    595:                case YP_OID:
                    596:                case YP_NULL:
                    597:                    id = yp -> yp_identifier;
                    598:                    break;
                    599: 
                    600:                case YP_IDEFINED:
                    601:                    yz = lookup_type (yz -> yp_module, yz -> yp_identifier);
                    602:                    goto again;
                    603: 
                    604:                default:
                    605:                    id = "Aggregate";
                    606:                    break;
                    607:            }
                    608:            break;
                    609:     }
                    610: 
                    611:     printf ("%-15s %-15s %s\n", id, yo -> yo_access, yo -> yo_status);
                    612: }
                    613: 
                    614: /*    IDENTIFIER HANDLING */
                    615: 
                    616: static char *id2str (yv)
                    617: register YV    yv;
                    618: {
                    619:     register char *cp,
                    620:                  *dp;
                    621:     static char buffer[BUFSIZ];
                    622: 
                    623:     if (yv -> yv_code != YV_OIDLIST)
                    624:        yyerror ("need an object identifer");
                    625:        
                    626:     cp = buffer;
                    627:     for (yv = yv -> yv_idlist, dp = ""; yv; yv = yv -> yv_next, dp = ".") {
                    628:        (void) sprintf (cp, "%s%s", dp, val2str (yv));
                    629:        cp += strlen (cp);
                    630:     }
                    631:     *cp = NULL;
                    632: 
                    633:     return buffer;
                    634: }
                    635: 
                    636: /*    TYPE HANDLING */
                    637: 
                    638: static YP  lookup_type (mod, id)
                    639: register char *mod,
                    640:              *id;
                    641: {
                    642:     register SY            sy;
                    643: 
                    644:     for (sy = mytypes; sy; sy = sy -> sy_next) {
                    645:        if (mod) {
                    646:            if (strcmp (sy -> sy_module, mod))
                    647:                continue;
                    648:        }
                    649:        else
                    650:            if (strcmp (sy -> sy_module, mymodule)
                    651:                    && strcmp (sy -> sy_module, "UNIV"))
                    652:                continue;
                    653: 
                    654:        if (strcmp (sy -> sy_name, id) == 0)
                    655:            return sy -> sy_yp;
                    656:     }
                    657: 
                    658:     return NULLYP;
                    659: }
                    660: 
                    661: /*    VALUE HANDLING */
                    662: 
                    663: static char *val2str (yv)
                    664: register YV    yv;
                    665: {
                    666:     static char buffer[BUFSIZ];
                    667: 
                    668:     switch (yv -> yv_code) {
                    669:        case YV_BOOL:
                    670:            yyerror ("need a sub-identifier, not a boolean");
                    671: 
                    672:        case YV_NUMBER:
                    673:            (void) sprintf (buffer, "%d", yv -> yv_number);
                    674:            return buffer;
                    675: 
                    676:        case YV_STRING:
                    677:            yyerror ("need a sub-identifier, not a string");
                    678: 
                    679:        case YV_IDEFINED:
                    680:            return yv -> yv_identifier;
                    681: 
                    682:        case YV_IDLIST:
                    683:            yyerror ("haven't written symbol table for values yet");
                    684: 
                    685:        case YV_VALIST:
                    686:            yyerror ("need a sub-identifier, not a list of values");
                    687: 
                    688:        case YV_OIDLIST:
                    689:            yyerror ("need a sub-identifier, not an object identifier");
                    690: 
                    691:        case YV_NULL:
                    692:            yyerror ("need a sub-identifier, not NULL");
                    693: 
                    694:        default:
                    695:            myyerror ("unknown value: %d", yv -> yv_code);
                    696:     }
                    697: /* NOTREACHED */
                    698: }
                    699: 
                    700: /*  */
                    701: 
                    702: static int  val2int (yv)
                    703: register YV    yv;
                    704: {
                    705:     switch (yv -> yv_code) {
                    706:        case YV_BOOL:
                    707:        case YV_NUMBER:
                    708:            return yv -> yv_number;
                    709: 
                    710:        case YV_STRING:
                    711:            yyerror ("need an integer, not a string");
                    712: 
                    713:        case YV_IDEFINED:
                    714:        case YV_IDLIST:
                    715:            yyerror ("haven't written symbol table for values yet");
                    716: 
                    717:        case YV_VALIST:
                    718:            yyerror ("need an integer, not a list of values");
                    719: 
                    720:        case YV_OIDLIST:
                    721:            yyerror ("need an integer, not an object identifier");
                    722: 
                    723:        case YV_NULL:
                    724:            yyerror ("need an integer, not NULL");
                    725: 
                    726:        default:
                    727:            myyerror ("unknown value: %d", yv -> yv_code);
                    728:     }
                    729: /* NOTREACHED */
                    730: }
                    731: 
                    732: /*  */
                    733: 
                    734: static val2prf (yv, level)
                    735: register YV    yv;
                    736: int    level;
                    737: {
                    738:     register YV    y;
                    739: 
                    740:     if (yv -> yv_flags & YV_ID)
                    741:        printf ("%s ", yv -> yv_id);
                    742: 
                    743: #ifdef notdef
                    744:     if (yv -> yv_flags & YV_TYPE)      /* will this REALLY work??? */
                    745:        do_type (yv -> yv_type, level, NULLCP);
                    746: #endif
                    747: 
                    748:     switch (yv -> yv_code) {
                    749:        case YV_BOOL: 
                    750:            printf (yv -> yv_number ? "TRUE" : "FALSE");
                    751:            break;
                    752: 
                    753:        case YV_NUMBER: 
                    754:            if (yv -> yv_named)
                    755:                printf ("%s", yv -> yv_named);
                    756:            else
                    757:                printf ("%d", yv -> yv_number);
                    758:            break;
                    759: 
                    760:        case YV_STRING: 
                    761:            printf ("\"%s\"", yv -> yv_string);
                    762:            break;
                    763: 
                    764:        case YV_IDEFINED: 
                    765:            if (yv -> yv_module)
                    766:                printf ("%s.", yv -> yv_module);
                    767:            printf ("%s", yv -> yv_identifier);
                    768:            break;
                    769: 
                    770:        case YV_IDLIST: 
                    771:        case YV_VALIST: 
                    772:            printf ("{");
                    773:            for (y = yv -> yv_idlist; y; y = y -> yv_next) {
                    774:                printf (" ");
                    775:                val2prf (y, level + 1);
                    776:                printf (y -> yv_next ? ", " : " ");
                    777:            }
                    778:            printf ("}");
                    779:            break;
                    780: 
                    781:        case YV_OIDLIST: 
                    782:            printf ("{");
                    783:            for (y = yv -> yv_idlist; y; y = y -> yv_next) {
                    784:                printf (" ");
                    785:                val2prf (y, level + 1);
                    786:                printf (" ");
                    787:            }
                    788:            printf ("}");
                    789:            break;
                    790: 
                    791:        case YV_NULL: 
                    792:            printf ("NULL");
                    793:            break;
                    794: 
                    795:        default: 
                    796:            myyerror ("unknown value: %d", yv -> yv_code);
                    797:        /* NOTREACHED */
                    798:     }
                    799: }
                    800: 
                    801: /*    ACTION HANDLING */
                    802: 
                    803: static act2prf (cp, level, e1, e2)
                    804: char   *cp,
                    805:        *e1,
                    806:        *e2;
                    807: int    level;
                    808: {
                    809:     register int    i,
                    810:                     j,
                    811:                     l4;
                    812:     register char  *dp,
                    813:                    *ep,
                    814:                    *fp;
                    815:     char   *gp;
                    816: 
                    817:     if (e1)
                    818:        printf (e1, level * 4, "");
                    819: 
                    820:     if (!(ep = index (dp = cp, '\n'))) {
                    821:        printf ("%s", dp);
                    822:        goto out;
                    823:     }
                    824: 
                    825:     for (;;) {
                    826:        i = expand (dp, ep, &gp);
                    827:        if (gp) {
                    828:            if (i == 0)
                    829:                printf ("%*.*s\n", ep - dp, ep - dp, dp);
                    830:            else
                    831:                break;
                    832:        }
                    833: 
                    834:        if (!(ep = index (dp = ep + 1, '\n'))) {
                    835:            printf ("%s", dp);
                    836:            return;
                    837:        }
                    838:     }
                    839: 
                    840: 
                    841:     printf ("\n");
                    842:     l4 = (level + 1) * 4;
                    843:     for (; *dp; dp = fp) {
                    844:        if (ep = index (dp, '\n'))
                    845:            fp = ep + 1;
                    846:        else
                    847:            fp = ep = dp + strlen (dp);
                    848: 
                    849:        j = expand (dp, ep, &gp);
                    850:        if (gp == NULL) {
                    851:            if (*fp)
                    852:                printf ("\n");
                    853:            continue;
                    854:        }
                    855: 
                    856:        if (j < i)
                    857:            j = i;
                    858:        if (j)
                    859:            printf ("%*s", l4 + j - i, "");
                    860:        printf ("%*.*s\n", ep - gp, ep - gp, gp);
                    861:     }
                    862: 
                    863:     printf ("%*s", level * 4, "");
                    864: out: ;
                    865:     if (e2)
                    866:        printf (e2, level * 4, "");
                    867: }
                    868: 
                    869: 
                    870: static expand (dp, ep, gp)
                    871: register char  *dp,
                    872:               *ep;
                    873: char  **gp;
                    874: {
                    875:     register int    i;
                    876: 
                    877:     *gp = NULL;
                    878:     for (i = 0; dp < ep; dp++) {
                    879:        switch (*dp) {
                    880:            case ' ': 
                    881:                i++;
                    882:                continue;
                    883: 
                    884:            case '\t': 
                    885:                i += 8 - (i % 8);
                    886:                continue;
                    887: 
                    888:            default: 
                    889:                *gp = dp;
                    890:                break;
                    891:        }
                    892:        break;
                    893:     }
                    894: 
                    895:     return i;
                    896: }
                    897: 
                    898: /*    DEBUG */
                    899: 
                    900: static print_yo (yo, level)
                    901: register OT    yo;
                    902: register int   level;
                    903: {
                    904:     if (yo == NULLOT)
                    905:        return;
                    906: 
                    907:     fprintf (stderr, "%*sname=%s\n", level * 4, "", yo -> yo_name);
                    908: 
                    909:     if (yo -> yo_syntax) {
                    910:        fprintf (stderr, "%*ssyntax\n", level * 4, "");
                    911:        print_type (yo -> yo_syntax, level + 1);
                    912:     }
                    913:     if (yo -> yo_value) {
                    914:        fprintf (stderr, "%*svalue\n", level * 4, "");
                    915:        print_value (yo -> yo_value, level + 1);
                    916:     }
                    917: }
                    918: 
                    919: /*  */
                    920: 
                    921: static print_yi (yi, level)
                    922: register OI    yi;
                    923: register int   level;
                    924: {
                    925:     if (yi == NULLOI)
                    926:        return;
                    927: 
                    928:     fprintf (stderr, "%*sname=%s\n", level * 4, "", yi -> yi_name);
                    929: 
                    930:     if (yi -> yi_value) {
                    931:        fprintf (stderr, "%*svalue\n", level * 4, "");
                    932:        print_value (yi -> yi_value, level + 1);
                    933:     }
                    934: }
                    935: 
                    936: /*  */
                    937: 
                    938: static print_type (yp, level)
                    939: register YP    yp;
                    940: register int   level;
                    941: {
                    942:     register YP            y;
                    943:     register YV            yv;
                    944: 
                    945:     if (yp == NULLYP)
                    946:        return;
                    947: 
                    948:     fprintf (stderr, "%*scode=0x%x flags=%s\n", level * 4, "",
                    949:            yp -> yp_code, sprintb (yp -> yp_flags, YPBITS));
                    950:     fprintf (stderr,
                    951:            "%*sintexp=\"%s\" strexp=\"%s\" prfexp=%c declexp=\"%s\" varexp=\"%s\"\n",
                    952:            level * 4, "", yp -> yp_intexp, yp -> yp_strexp, yp -> yp_prfexp,
                    953:            yp -> yp_declexp, yp -> yp_varexp);
                    954:     fprintf(stderr,
                    955:            "%*sstructname=\"%s\" ptrname=\"%s\"\n", level * 4, "",
                    956:            yp -> yp_structname, yp -> yp_ptrname);
                    957: 
                    958:     if (yp -> yp_action0)
                    959:        fprintf (stderr, "%*saction0 at line %d=\"%s\"\n", level * 4, "",
                    960:                yp -> yp_act0_lineno, yp -> yp_action0);
                    961:     if (yp -> yp_action1)
                    962:        fprintf (stderr, "%*saction1 at line %d=\"%s\"\n", level * 4, "",
                    963:                yp -> yp_act1_lineno, yp -> yp_action1);
                    964:     if (yp -> yp_action2)
                    965:        fprintf (stderr, "%*saction2 at line %d=\"%s\"\n", level * 4, "",
                    966:                yp -> yp_act2_lineno, yp -> yp_action2);
                    967:     if (yp -> yp_action3)
                    968:        fprintf (stderr, "%*saction3 at line %d=\"%s\"\n", level * 4, "",
                    969:                yp -> yp_act3_lineno, yp -> yp_action3);
                    970: 
                    971:     if (yp -> yp_flags & YP_TAG) {
                    972:        fprintf (stderr, "%*stag class=0x%x value=0x%x\n", level * 4, "",
                    973:                yp -> yp_tag -> yt_class, yp -> yp_tag -> yt_value);
                    974:        print_value (yp -> yp_tag -> yt_value, level + 1);
                    975:     }
                    976: 
                    977:     if (yp -> yp_flags & YP_DEFAULT) {
                    978:        fprintf (stderr, "%*sdefault=0x%x\n", level * 4, "", yp -> yp_default);
                    979:        print_value (yp -> yp_default, level + 1);
                    980:     }
                    981: 
                    982:     if (yp -> yp_flags & YP_ID)
                    983:        fprintf (stderr, "%*sid=\"%s\"\n", level * 4, "", yp -> yp_id);
                    984: 
                    985:     if (yp -> yp_flags & YP_BOUND)
                    986:        fprintf (stderr, "%*sbound=\"%s\"\n", level * 4, "", yp -> yp_bound);
                    987: 
                    988:     if (yp -> yp_offset)
                    989:        fprintf (stderr, "%*soffset=\"%s\"\n", level * 4, "", yp -> yp_offset);
                    990: 
                    991:     switch (yp -> yp_code) {
                    992:        case YP_INTLIST:
                    993:        case YP_BITLIST:
                    994:            fprintf (stderr, "%*svalue=0x%x\n", level * 4, "", yp -> yp_value);
                    995:            for (yv = yp -> yp_value; yv; yv = yv -> yv_next) {
                    996:                print_value (yv, level + 1);
                    997:                fprintf (stderr, "%*s----\n", (level + 1) * 4, "");
                    998:            }
                    999:            break;
                   1000: 
                   1001:        case YP_SEQTYPE:
                   1002:        case YP_SEQLIST:
                   1003:        case YP_SETTYPE:
                   1004:        case YP_SETLIST:
                   1005:        case YP_CHOICE:
                   1006:            fprintf (stderr, "%*stype=0x%x\n", level * 4, "", yp -> yp_type);
                   1007:            for (y = yp -> yp_type; y; y = y -> yp_next) {
                   1008:                print_type (y, level + 1);
                   1009:                fprintf (stderr, "%*s----\n", (level + 1) * 4, "");
                   1010:            }
                   1011:            break;
                   1012: 
                   1013:        case YP_IDEFINED:
                   1014:            fprintf (stderr, "%*smodule=\"%s\" identifier=\"%s\"\n",
                   1015:                    level * 4, "", yp -> yp_module ? yp -> yp_module : "",
                   1016:                    yp -> yp_identifier);
                   1017:            break;
                   1018: 
                   1019:        default:
                   1020:            break;
                   1021:     }
                   1022: }
                   1023: 
                   1024: /*  */
                   1025: 
                   1026: static print_value (yv, level)
                   1027: register YV    yv;
                   1028: register int   level;
                   1029: {
                   1030:     register YV            y;
                   1031: 
                   1032:     if (yv == NULLYV)
                   1033:        return;
                   1034: 
                   1035:     fprintf (stderr, "%*scode=0x%x flags=%s\n", level * 4, "",
                   1036:            yv -> yv_code, sprintb (yv -> yv_flags, YVBITS));
                   1037: 
                   1038:     if (yv -> yv_action)
                   1039:        fprintf (stderr, "%*saction at line %d=\"%s\"\n", level * 4, "",
                   1040:                yv -> yv_act_lineno, yv -> yv_action);
                   1041: 
                   1042:     if (yv -> yv_flags & YV_ID)
                   1043:        fprintf (stderr, "%*sid=\"%s\"\n", level * 4, "", yv -> yv_id);
                   1044: 
                   1045:     if (yv -> yv_flags & YV_NAMED)
                   1046:        fprintf (stderr, "%*snamed=\"%s\"\n", level * 4, "", yv -> yv_named);
                   1047: 
                   1048:     if (yv -> yv_flags & YV_TYPE) {
                   1049:        fprintf (stderr, "%*stype=0x%x\n", level * 4, "", yv -> yv_type);
                   1050:        print_type (yv -> yv_type, level + 1);
                   1051:     }
                   1052: 
                   1053:     switch (yv -> yv_code) {
                   1054:        case YV_NUMBER:
                   1055:        case YV_BOOL:
                   1056:            fprintf (stderr, "%*snumber=0x%x\n", level * 4, "",
                   1057:                    yv -> yv_number);
                   1058:            break;
                   1059: 
                   1060:        case YV_STRING:
                   1061:            fprintf (stderr, "%*sstring=0x%x\n", level * 4, "",
                   1062:                    yv -> yv_string);
                   1063:            break;
                   1064: 
                   1065:        case YV_IDEFINED:
                   1066:            if (yv -> yv_flags & YV_BOUND)
                   1067:                fprintf (stderr, "%*smodule=\"%s\" identifier=\"%s\"\n",
                   1068:                        level * 4, "", yv -> yv_module, yv -> yv_identifier);
                   1069:            else
                   1070:                fprintf (stderr, "%*sbound identifier=\"%s\"\n",
                   1071:                        level * 4, "", yv -> yv_identifier);
                   1072:            break;
                   1073: 
                   1074:        case YV_IDLIST:
                   1075:        case YV_VALIST:
                   1076:        case YV_OIDLIST:
                   1077:            for (y = yv -> yv_idlist; y; y = y -> yv_next) {
                   1078:                print_value (y, level + 1);
                   1079:                fprintf (stderr, "%*s----\n", (level + 1) * 4, "");
                   1080:            }
                   1081:            break;
                   1082: 
                   1083:        default:
                   1084:            break;
                   1085:     }
                   1086: }
                   1087: 
                   1088: /*    SYMBOLS */
                   1089: 
                   1090: static SY  new_symbol (encpref, decpref, prfpref, mod, id)
                   1091: register char  *encpref,
                   1092:               *decpref,
                   1093:               *prfpref,
                   1094:               *mod,
                   1095:               *id;
                   1096: {
                   1097:     register SY    sy;
                   1098: 
                   1099:     if ((sy = (SY) calloc (1, sizeof *sy)) == NULLSY)
                   1100:        yyerror ("out of memory");
                   1101:     sy -> sy_encpref = encpref;
                   1102:     sy -> sy_decpref = decpref;
                   1103:     sy -> sy_prfpref = prfpref;
                   1104:     sy -> sy_module = mod;
                   1105:     sy -> sy_name = id;
                   1106: 
                   1107:     return sy;
                   1108: }
                   1109: 
                   1110: 
                   1111: static SY  add_symbol (s1, s2)
                   1112: register SY    s1,
                   1113:                s2;
                   1114: {
                   1115:     register SY            sy;
                   1116: 
                   1117:     if (s1 == NULLSY)
                   1118:        return s2;
                   1119: 
                   1120:     for (sy = s1; sy -> sy_next; sy = sy -> sy_next)
                   1121:        continue;
                   1122:     sy -> sy_next = s2;
                   1123: 
                   1124:     return s1;
                   1125: }
                   1126: 
                   1127: /*    TYPES */
                   1128: 
                   1129: YP     new_type (code)
                   1130: int    code;
                   1131: {
                   1132:     register YP    yp;
                   1133: 
                   1134:     if ((yp = (YP) calloc (1, sizeof *yp)) == NULLYP)
                   1135:        yyerror ("out of memory");
                   1136:     yp -> yp_code = code;
                   1137: 
                   1138:     return yp;
                   1139: }
                   1140: 
                   1141: 
                   1142: YP     add_type (y1, y2)
                   1143: register YP    y1,
                   1144:                y2;
                   1145: {
                   1146:     register YP            yp;
                   1147: 
                   1148:     for (yp = y1; yp -> yp_next; yp = yp -> yp_next)
                   1149:        continue;
                   1150:     yp -> yp_next = y2;
                   1151: 
                   1152:     return y1;
                   1153: }
                   1154: 
                   1155: /*    VALUES */
                   1156: 
                   1157: YV     new_value (code)
                   1158: int    code;
                   1159: {
                   1160:     register YV    yv;
                   1161: 
                   1162:     if ((yv = (YV) calloc (1, sizeof *yv)) == NULLYV)
                   1163:        yyerror ("out of memory");
                   1164:     yv -> yv_code = code;
                   1165: 
                   1166:     return yv;
                   1167: }
                   1168: 
                   1169: 
                   1170: YV     add_value (y1, y2)
                   1171: register YV    y1,
                   1172:                y2;
                   1173: {
                   1174:     register YV            yv;
                   1175: 
                   1176:     for (yv = y1; yv -> yv_next; yv = yv -> yv_next)
                   1177:        continue;
                   1178:     yv -> yv_next = y2;
                   1179: 
                   1180:     return y1;
                   1181: }
                   1182: 
                   1183: /*    TAGS */
                   1184: 
                   1185: YT     new_tag (class)
                   1186: PElementClass  class;
                   1187: {
                   1188:     register YT    yt;
                   1189: 
                   1190:     if ((yt = (YT) calloc (1, sizeof *yt)) == NULLYT)
                   1191:        yyerror ("out of memory");
                   1192:     yt -> yt_class = class;
                   1193: 
                   1194:     return yt;
                   1195: }
                   1196: 
                   1197: /*    STRINGS */
                   1198: 
                   1199: char   *new_string (s)
                   1200: register char  *s;
                   1201: {
                   1202:     register char  *p;
                   1203: 
                   1204:     if ((p = malloc ((unsigned) (strlen (s) + 1))) == NULLCP)
                   1205:        yyerror ("out of memory");
                   1206: 
                   1207:     (void) strcpy (p, s);
                   1208:     return p;
                   1209: }
                   1210: 
                   1211: /*    SYMBOLS */
                   1212: 
                   1213: static struct triple {
                   1214:     char          *t_name;
                   1215:     PElementClass   t_class;
                   1216:     PElementID     t_id;
                   1217: }              triples[] = {
                   1218:     "IA5String", PE_CLASS_UNIV,        PE_DEFN_IA5S,
                   1219:     "ISO646String", PE_CLASS_UNIV, PE_DEFN_IA5S,
                   1220:     "NumericString", PE_CLASS_UNIV, PE_DEFN_NUMS,
                   1221:     "PrintableString", PE_CLASS_UNIV, PE_DEFN_PRTS,
                   1222:     "T61String", PE_CLASS_UNIV, PE_DEFN_T61S,
                   1223:     "TeletexString", PE_CLASS_UNIV, PE_DEFN_T61S,
                   1224:     "VideotexString", PE_CLASS_UNIV, PE_DEFN_VTXS,
                   1225:     "GeneralizedTime", PE_CLASS_UNIV, PE_DEFN_GENT,
                   1226:     "GeneralisedTime", PE_CLASS_UNIV, PE_DEFN_GENT,
                   1227:     "UTCTime", PE_CLASS_UNIV, PE_DEFN_UTCT,
                   1228:     "UniversalTime", PE_CLASS_UNIV, PE_DEFN_UTCT,
                   1229:     "GraphicString", PE_CLASS_UNIV, PE_DEFN_GFXS,
                   1230:     "VisibleString", PE_CLASS_UNIV, PE_DEFN_VISS,
                   1231:     "GeneralString", PE_CLASS_UNIV, PE_DEFN_GENS,
                   1232:     "EXTERNAL", PE_CLASS_UNIV, PE_CONS_EXTN,
                   1233:     "ObjectDescriptor", PE_CLASS_UNIV, PE_PRIM_ODE,
                   1234: 
                   1235:     NULL
                   1236: };
                   1237: 
                   1238: /*  */
                   1239: 
                   1240: static char *modsym (module, id, prefix)
                   1241: register char  *module,
                   1242:               *id;
                   1243: char   *prefix;
                   1244: {
                   1245:     char    buf1[BUFSIZ],
                   1246:             buf2[BUFSIZ],
                   1247:             buf3[BUFSIZ];
                   1248:     register struct triple *t;
                   1249:     static char buffer[BUFSIZ];
                   1250: 
                   1251:     if (module == NULLCP)
                   1252:        for (t = triples; t -> t_name; t++)
                   1253:            if (strcmp (t -> t_name, id) == 0) {
                   1254:                module = "UNIV";
                   1255:                break;
                   1256:            }
                   1257: 
                   1258:     if (prefix)
                   1259:        modsym_aux (prefix, buf1);
                   1260:     modsym_aux (module ? module : mymodule, buf2);
                   1261:     modsym_aux (id, buf3);
                   1262:     if (prefix)
                   1263:        (void) sprintf (buffer, "%s_%s_%s", buf1, buf2, buf3);
                   1264:     else
                   1265:        (void) sprintf (buffer, "%s_%s", buf2, buf3);
                   1266: 
                   1267:     return buffer;
                   1268: }
                   1269: 
                   1270: 
                   1271: static modsym_aux (name, bp)
                   1272: register char  *name,
                   1273:               *bp;
                   1274: {
                   1275:     register char   c;
                   1276: 
                   1277:     while (c = *name++)
                   1278:        switch (c) {
                   1279:            case '-':
                   1280:                *bp++ = '_';
                   1281:                *bp++ = '_';
                   1282:                break;
                   1283: 
                   1284:            default:
                   1285:                *bp++ = c;
                   1286:                break;
                   1287:        }
                   1288: 
                   1289:     *bp = NULL;
                   1290: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.