Annotation of 43BSDReno/contrib/isode-beta/pepy/test/A/A.py, revision 1.1

1.1     ! root        1:     A DEFINITIONS ::=
        !             2: %{
        !             3: 
        !             4: #define        DEBUG
        !             5: 
        !             6: #include <stdio.h>
        !             7: 
        !             8: /*    DATA */
        !             9: 
        !            10: #define        ps_advise(ps, f) \
        !            11:        advise (NULLCP, "%s: %s", (f), ps_error ((ps) -> ps_errno))
        !            12: 
        !            13: 
        !            14: static char *myname = "integertest";
        !            15: 
        !            16: static enum { ps2test, pl2test } mode = ps2test;
        !            17: 
        !            18: 
        !            19: void   adios ();
        !            20: 
        !            21: /*    MAIN */
        !            22: 
        !            23: /* ARGSUSED */
        !            24: 
        !            25: main (argc, argv, envp)
        !            26: int    argc;
        !            27: char  **argv,
        !            28:       **envp;
        !            29: {
        !            30:     register int    status = 0;
        !            31:     register char  *cp;
        !            32:     register    FILE * fp;
        !            33: 
        !            34:     myname = *argv;
        !            35:     for (argc--, argv++; cp = *argv; argc--, argv++)
        !            36:        if (*cp == '-') {
        !            37:            if (strcmp (cp + 1, "ps") == 0) {
        !            38:                mode = ps2test;
        !            39:                continue;
        !            40:            }
        !            41:            if (strcmp (cp + 1, "pl") == 0) {
        !            42:                mode = pl2test;
        !            43:                continue;
        !            44:            }
        !            45:            adios (NULLCP, "usage: %s [ -ps | -pl ] [ files... ]",
        !            46:                    myname);
        !            47:        }
        !            48:        else
        !            49:            break;
        !            50: 
        !            51:     if (argc == 0)
        !            52:        status = process ("(stdin)", stdin);
        !            53:     else
        !            54:        while (cp = *argv++) {
        !            55:            if ((fp = fopen (cp, "r")) == NULL) {
        !            56:                advise (cp, "unable to read");
        !            57:                status++;
        !            58:                continue;
        !            59:            }
        !            60:            status += process (cp, fp);
        !            61:            (void) fclose (fp);
        !            62:        }
        !            63: 
        !            64:     exit (status);
        !            65: }
        !            66: 
        !            67: /*  */
        !            68: 
        !            69: static int  process (file, fp)
        !            70: register char *file;
        !            71: register FILE *fp;
        !            72: {
        !            73:     register PE            pe;
        !            74:     register PS            ps;
        !            75: 
        !            76:     if ((ps = ps_alloc (std_open)) == NULLPS) {
        !            77:        ps_advise (ps, "ps_alloc");
        !            78:        return 1;
        !            79:     }
        !            80:     if (std_setup (ps, fp) == NOTOK) {
        !            81:        advise (NULLCP, "%s: std_setup loses", file);
        !            82:        return 1;
        !            83:     }
        !            84: 
        !            85:     for (;;) {
        !            86:        switch (mode) {
        !            87:            case ps2test: 
        !            88:                if ((pe = ps2pe (ps)) == NULLPE)
        !            89:                    if (ps -> ps_errno) {
        !            90:                        ps_advise (ps, "ps2pe");
        !            91:                you_lose: ;
        !            92:                        ps_free (ps);
        !            93:                        return 1;
        !            94:                    }
        !            95:                    else {
        !            96:                done:   ;
        !            97:                        ps_free (ps);
        !            98:                        return 0;
        !            99:                    }
        !           100:                break;
        !           101: 
        !           102:            case pl2test: 
        !           103:                if ((pe = pl2pe (ps)) == NULLPE)
        !           104:                    if (ps -> ps_errno) {
        !           105:                        ps_advise (ps, "pl2pe");
        !           106:                        goto you_lose;
        !           107:                    }
        !           108:                    else
        !           109:                        goto done;
        !           110:                break;
        !           111:        }
        !           112: 
        !           113:        (void) do_A_A (pe, 1);
        !           114: 
        !           115:        pe_free (pe);
        !           116:     }
        !           117: }
        !           118: 
        !           119: /*  */
        !           120: 
        !           121: %}
        !           122: 
        !           123:     BEGIN
        !           124: 
        !           125:     A ::= CHOICE { B, C }
        !           126: 
        !           127:     B ::= INTEGER
        !           128:        %{ fprintf(stderr, "INTEGER = %d (0x%x)\n", $$, $$); %}
        !           129: 
        !           130:     C ::= NumericString
        !           131:          %{
        !           132:              int   len;
        !           133:              char *s = prim2str ($$, &len);
        !           134:              fprintf (stderr, "NumericString = %s (len %d)\n", s, len);
        !           135:              free (s);
        !           136:          %}
        !           137: 
        !           138:     END
        !           139: 
        !           140: 
        !           141: 
        !           142: %{
        !           143: /*    DEBUG */
        !           144: 
        !           145: #ifdef DEBUG
        !           146: char   *getenv ();
        !           147: 
        !           148: testdebug (pe, s)
        !           149: register PE pe;
        !           150: register char *s;
        !           151: {
        !           152:     static int  debug = OK;
        !           153:     char   *cp;
        !           154:     register PS            ps;
        !           155: 
        !           156:     switch (debug) {
        !           157:        case NOTOK: 
        !           158:            break;
        !           159: 
        !           160:        case OK: 
        !           161:            if ((debug = (cp = getenv ("PEPYDEBUG")) && *cp ? atoi (cp)
        !           162:                        : NOTOK) == NOTOK)
        !           163:                break;
        !           164:            fprintf (stderr, "%s made with %s\n", myname, pepyid);
        !           165: 
        !           166:        default: 
        !           167:            fprintf (stderr, "%s\n", s);
        !           168: 
        !           169:            if ((ps = ps_alloc (std_open)) == NULLPS)
        !           170:                return;
        !           171:            if (std_setup (ps, stderr) != NOTOK)
        !           172:                (void) pe2pl (ps, pe);
        !           173:            fprintf (stderr, "--------\n");
        !           174:            ps_free (ps);
        !           175:            break;
        !           176:     }
        !           177: }
        !           178: #endif
        !           179: 
        !           180: /*    ERRORS */
        !           181: 
        !           182: /* VARARGS2 */
        !           183: 
        !           184: void   adios (what, fmt, a, b, c, d, e, f, g, h, i, j)
        !           185: char   *what,
        !           186:        *fmt,
        !           187:        *a,
        !           188:        *b,
        !           189:        *c,
        !           190:        *d,
        !           191:        *e,
        !           192:        *f,
        !           193:        *g,
        !           194:        *h,
        !           195:        *i,
        !           196:        *j;
        !           197: {
        !           198:     advise (what, fmt, a, b, c, d, e, f, g, h, i, j);
        !           199:     _exit (1);
        !           200: }
        !           201: 
        !           202: /*  */
        !           203: 
        !           204: /* VARARGS2 */
        !           205: 
        !           206: void   advise (what, fmt, a, b, c, d, e, f, g, h, i, j)
        !           207: char   *what,
        !           208:        *fmt,
        !           209:        *a,
        !           210:        *b,
        !           211:        *c,
        !           212:        *d,
        !           213:        *e,
        !           214:        *f,
        !           215:        *g,
        !           216:        *h,
        !           217:        *i,
        !           218:        *j;
        !           219: {
        !           220:     (void) fflush (stdout);
        !           221: 
        !           222:     fprintf (stderr, "%s: ", myname);
        !           223:     fprintf (stderr, fmt, a, b, c, d, e, f, g, h, i, j);
        !           224:     if (what)
        !           225:        (void) fputc (' ', stderr), perror (what);
        !           226:     else
        !           227:        (void) fputc ('\n', stderr);
        !           228:     (void) fflush (stderr);
        !           229: }
        !           230: 
        !           231: %}

unix.superglobalmegacorp.com

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