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

1.1     ! root        1: -- mpp.py - test out PEPY
        !             2: 
        !             3: -- $Header: /f/osi/pepy/RCS/mpp.py,v 7.0 89/11/23 22:11:43 mrose Rel $
        !             4: --
        !             5: --
        !             6: -- $Log:       mpp.py,v $
        !             7: -- Revision 7.0  89/11/23  22:11:43  mrose
        !             8: -- Release 6.0
        !             9: -- 
        !            10: 
        !            11: --
        !            12: --                               NOTICE
        !            13: --
        !            14: --    Acquisition, use, and distribution of this module and related
        !            15: --    materials are subject to the restrictions of a license agreement.
        !            16: --    Consult the Preface in the User's Manual for the full terms of
        !            17: --    this agreement.
        !            18: --
        !            19: --
        !            20: 
        !            21: 
        !            22: MPP DEFINITIONS   ::=
        !            23: 
        !            24: %{
        !            25: #ifndef        lint
        !            26: static char *rcsid = "$Header: /f/osi/pepy/RCS/mpp.py,v 7.0 89/11/23 22:11:43 mrose Rel $";
        !            27: #endif
        !            28: 
        !            29: #include <stdio.h>
        !            30: 
        !            31: 
        !            32: #define        ps_advise(ps, f) \
        !            33:        advise (NULLCP, "%s: %s", (f), ps_error ((ps) -> ps_errno))
        !            34: 
        !            35: /*    DATA */
        !            36: 
        !            37: static char *myname = "mpp";
        !            38: 
        !            39: static enum { ps2mpp, pl2mpp } mode = ps2mpp;
        !            40: 
        !            41: static enum format { p1, p2, sfd, ean, eanp2 } topfmt = ean;
        !            42: 
        !            43: 
        !            44: void   adios ();
        !            45: 
        !            46: /*    MAIN */
        !            47: 
        !            48: /* ARGSUSED */
        !            49: 
        !            50: main (argc, argv, envp)
        !            51: int    argc;
        !            52: char  **argv,
        !            53:       **envp;
        !            54: {
        !            55:     register int    status = 0;
        !            56:     register char  *cp;
        !            57:     register FILE  *fp;
        !            58: 
        !            59:     if (myname = rindex (argv[0], '/'))
        !            60:        myname++;
        !            61:     if (myname == NULL || *myname == NULL)
        !            62:        myname = argv[0];
        !            63: 
        !            64:     for (argc--, argv++; cp = *argv; argc--, argv++)
        !            65:        if (*cp == '-') {
        !            66:            if (strcmp (cp + 1, "ps") == 0) {
        !            67:                mode = ps2mpp;
        !            68:                continue;
        !            69:            }
        !            70:            if (strcmp (cp + 1, "pl") == 0) {
        !            71:                mode = pl2mpp;
        !            72:                continue;
        !            73:            }
        !            74:            if (strcmp (cp + 1, "p1") == 0) {
        !            75:                topfmt = p1;
        !            76:                continue;
        !            77:            }
        !            78:            if (strcmp (cp + 1, "p2") == 0) {
        !            79:                topfmt = p2;
        !            80:                continue;
        !            81:            }
        !            82:            if (strcmp (cp + 1, "sfd") == 0) {
        !            83:                topfmt = sfd;
        !            84:                continue;
        !            85:            }
        !            86:            if (strcmp (cp + 1, "ean") == 0) {
        !            87:                topfmt = ean;
        !            88:                continue;
        !            89:            }
        !            90:            adios (NULLCP, "usage: %s [ -ps | -pl ] [-p1 | -p2 | -sfd | -ean ] [ files... ]",
        !            91:                    myname);
        !            92:        }
        !            93:        else
        !            94:            break;
        !            95: 
        !            96:     if (argc == 0)
        !            97:        status = process ("(stdin)", stdin);
        !            98:     else
        !            99:        while (cp = *argv++) {
        !           100:            if ((fp = fopen (cp, "r")) == NULL) {
        !           101:                advise (cp, "unable to read");
        !           102:                status++;
        !           103:                continue;
        !           104:            }
        !           105:            status += process (cp, fp);
        !           106:            (void) fclose (fp);
        !           107:        }
        !           108: 
        !           109:     exit (status);             /* NOTREACHED */
        !           110: }
        !           111: 
        !           112: /*  */
        !           113: 
        !           114: static int  process (file, fp)
        !           115: register char *file;
        !           116: register FILE *fp;
        !           117: {
        !           118:     enum format curfmt = topfmt;
        !           119:     register PE            pe;
        !           120:     register PS            ps;
        !           121: 
        !           122:     if ((ps = ps_alloc (std_open)) == NULLPS) {
        !           123:        ps_advise (ps, "ps_alloc");
        !           124:        return 1;
        !           125:     }
        !           126:     if (std_setup (ps, fp) == NOTOK) {
        !           127:        advise (NULLCP, "%s: std_setup loses", file);
        !           128:        return 1;
        !           129:     }
        !           130: 
        !           131:     for (;;) {
        !           132:        switch (mode) {
        !           133:            case ps2mpp: 
        !           134:                if ((pe = ps2pe (ps)) == NULLPE)
        !           135:                    if (ps -> ps_errno) {
        !           136:                        ps_advise (ps, "ps2pe");
        !           137:                you_lose: ;
        !           138:                        ps_free (ps);
        !           139:                        return 1;
        !           140:                    }
        !           141:                    else {
        !           142:                done:   ;
        !           143:                        ps_free (ps);
        !           144:                        return 0;
        !           145:                    }
        !           146:                break;
        !           147: 
        !           148:            case pl2mpp: 
        !           149:                if ((pe = pl2pe (ps)) == NULLPE)
        !           150:                    if (ps -> ps_errno) {
        !           151:                        ps_advise (ps, "pl2pe");
        !           152:                        goto you_lose;
        !           153:                    }
        !           154:                    else
        !           155:                        goto done;
        !           156:                break;
        !           157:        }
        !           158: 
        !           159:        switch (curfmt) {
        !           160:            case p1:
        !           161:            default:
        !           162:                (void) print_P1_MPDU (pe, 1, NULLIP, NULLVP, NULLCP);
        !           163:                break;
        !           164: 
        !           165:            case p2:
        !           166:                (void) print_P2_UAPDU (pe, 1, NULLIP, NULLVP, NULLCP);
        !           167:                break;
        !           168: 
        !           169:            case sfd:
        !           170:                (void) print_SFD_Document (pe, 1, NULLIP, NULLVP, NULLCP);
        !           171:                break;
        !           172: 
        !           173:            case ean:
        !           174:                (void) print_EAN_MPDU (pe, 1, NULLIP, NULLVP, NULLCP);
        !           175:                curfmt = eanp2;
        !           176:                break;
        !           177: 
        !           178:            case eanp2:
        !           179:                (void) print_EAN_UAPDU (pe, 1, NULLIP, NULLVP, NULLCP);
        !           180:                curfmt = ean;
        !           181:                break;
        !           182:        }
        !           183: 
        !           184:        pe_free (pe);
        !           185:     }
        !           186: }
        !           187: 
        !           188: /*  */
        !           189: 
        !           190: %}
        !           191: 
        !           192: BEGIN
        !           193: 
        !           194: END
        !           195: 
        !           196: %{
        !           197: 
        !           198: /*    ERRORS */
        !           199: 
        !           200: #include <varargs.h>
        !           201: 
        !           202: 
        !           203: #ifndef        lint
        !           204: void   _advise ();
        !           205: 
        !           206: 
        !           207: void   adios (va_alist)
        !           208: va_dcl
        !           209: {
        !           210:     va_list ap;
        !           211: 
        !           212:     va_start (ap);
        !           213: 
        !           214:     _advise (ap);
        !           215: 
        !           216:     va_end (ap);
        !           217: 
        !           218:     _exit (1);
        !           219: }
        !           220: #else
        !           221: /* VARARGS */
        !           222: 
        !           223: void   adios (what, fmt)
        !           224: char   *what,
        !           225:        *fmt;
        !           226: {
        !           227:     adios (what, fmt);
        !           228: }
        !           229: #endif
        !           230: 
        !           231: 
        !           232: #ifndef        lint
        !           233: static void  advise (va_alist)
        !           234: va_dcl
        !           235: {
        !           236:     va_list ap;
        !           237: 
        !           238:     va_start (ap);
        !           239: 
        !           240:     _advise (ap);
        !           241: 
        !           242:     va_end (ap);
        !           243: }
        !           244: 
        !           245: 
        !           246: static void  _advise (ap)
        !           247: va_list        ap;
        !           248: {
        !           249:     char    buffer[BUFSIZ];
        !           250: 
        !           251:     asprintf (buffer, ap);
        !           252: 
        !           253:     (void) fflush (stdout);
        !           254: 
        !           255:     fprintf (stderr, "%s: ", myname);
        !           256:     (void) fputs (buffer, stderr);
        !           257:     (void) fputc ('\n', stderr);
        !           258: 
        !           259:     (void) fflush (stderr);
        !           260: }
        !           261: #else
        !           262: /* VARARGS */
        !           263: 
        !           264: static void  advise (what, fmt)
        !           265: char   *what,
        !           266:        *fmt;
        !           267: {
        !           268:     advise (what, fmt);
        !           269: }
        !           270: #endif
        !           271: 
        !           272: %}

unix.superglobalmegacorp.com

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