Annotation of 43BSDReno/contrib/isode-beta/pepy/py_pp.c, revision 1.1

1.1     ! root        1: /* py_pp.c - generic pretty-printer */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/pepy/RCS/py_pp.c,v 7.0 89/11/23 22:12:06 mrose Rel $";
        !             5: #endif
        !             6:     
        !             7: /*
        !             8:  * $Header: /f/osi/pepy/RCS/py_pp.c,v 7.0 89/11/23 22:12:06 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       py_pp.c,v $
        !            12:  * Revision 7.0  89/11/23  22:12:06  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: /* LINTLIBRARY */
        !            29: 
        !            30: #include <stdio.h>
        !            31: #include "psap.h"
        !            32: 
        !            33: #define        ps_advise(ps, f) \
        !            34:        advise (NULLCP, "%s: %s", (f), ps_error ((ps) -> ps_errno))
        !            35: 
        !            36: /*    DATA */
        !            37: 
        !            38: static char *myname = "pp";
        !            39: 
        !            40: static enum { ps2pp, pl2pp } mode = ps2pp;
        !            41: 
        !            42: 
        !            43: void   adios (), advise ();
        !            44: 
        !            45: /*  */
        !            46: 
        !            47: /* ARGSUSED */
        !            48: 
        !            49: int    PY_pp (argc, argv, envp, pfx)
        !            50: int    argc;
        !            51: char  **argv,
        !            52:       **envp;
        !            53: IFP    pfx;
        !            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 = ps2pp;
        !            68:                continue;
        !            69:            }
        !            70:            if (strcmp (cp + 1, "pl") == 0) {
        !            71:                mode = pl2pp;
        !            72:                continue;
        !            73:            }
        !            74:            adios (NULLCP, "usage: %s [ -ps | -pl ] [ files... ]", myname);
        !            75:        }
        !            76:        else
        !            77:            break;
        !            78: 
        !            79:     if (argc == 0)
        !            80:        status = process ("(stdin)", stdin, pfx);
        !            81:     else
        !            82:        while (cp = *argv++) {
        !            83:            if ((fp = fopen (cp, "r")) == NULL) {
        !            84:                advise (cp, "unable to read");
        !            85:                status++;
        !            86:                continue;
        !            87:            }
        !            88:            status += process (cp, fp, pfx);
        !            89:            (void) fclose (fp);
        !            90:        }
        !            91: 
        !            92:     return status;
        !            93: }
        !            94: 
        !            95: /*  */
        !            96: 
        !            97: static int  process (file, fp, pfx)
        !            98: register char *file;
        !            99: register FILE *fp;
        !           100: IFP    pfx;
        !           101: {
        !           102:     register PE            pe;
        !           103:     register PS            ps;
        !           104: 
        !           105:     if ((ps = ps_alloc (std_open)) == NULLPS) {
        !           106:        ps_advise (ps, "ps_alloc");
        !           107:        return 1;
        !           108:     }
        !           109:     if (std_setup (ps, fp) == NOTOK) {
        !           110:        advise (NULLCP, "%s: std_setup loses", file);
        !           111:        return 1;
        !           112:     }
        !           113: 
        !           114:     for (;;) {
        !           115:        switch (mode) {
        !           116:            case ps2pp: 
        !           117:                if ((pe = ps2pe (ps)) == NULLPE)
        !           118:                    if (ps -> ps_errno) {
        !           119:                        ps_advise (ps, "ps2pe");
        !           120:                you_lose: ;
        !           121:                        ps_free (ps);
        !           122:                        return 1;
        !           123:                    }
        !           124:                    else {
        !           125:                done:   ;
        !           126:                        ps_free (ps);
        !           127:                        return 0;
        !           128:                    }
        !           129:                break;
        !           130: 
        !           131:            case pl2pp: 
        !           132:                if ((pe = pl2pe (ps)) == NULLPE)
        !           133:                    if (ps -> ps_errno) {
        !           134:                        ps_advise (ps, "pl2pe");
        !           135:                        goto you_lose;
        !           136:                    }
        !           137:                    else
        !           138:                        goto done;
        !           139:                break;
        !           140:        }
        !           141: 
        !           142:        (void) (*pfx) (pe, 1, NULLIP, NULLVP, NULLCP);
        !           143: 
        !           144:        pe_free (pe);
        !           145:     }
        !           146: }
        !           147: 
        !           148: /*    ERRORS */
        !           149: 
        !           150: #include <varargs.h>
        !           151: 
        !           152: 
        !           153: #ifndef        lint
        !           154: void   _advise ();
        !           155: 
        !           156: 
        !           157: static void  adios (va_alist)
        !           158: va_dcl
        !           159: {
        !           160:     va_list ap;
        !           161: 
        !           162:     va_start (ap);
        !           163: 
        !           164:     _advise (ap);
        !           165: 
        !           166:     va_end (ap);
        !           167: 
        !           168:     _exit (1);
        !           169: }
        !           170: #else
        !           171: /* VARARGS */
        !           172: 
        !           173: static void  adios (what, fmt)
        !           174: char   *what,
        !           175:        *fmt;
        !           176: {
        !           177:     adios (what, fmt);
        !           178: }
        !           179: #endif
        !           180: 
        !           181: 
        !           182: #ifndef        lint
        !           183: static void  advise (va_alist)
        !           184: va_dcl
        !           185: {
        !           186:     va_list ap;
        !           187: 
        !           188:     va_start (ap);
        !           189: 
        !           190:     _advise (ap);
        !           191: 
        !           192:     va_end (ap);
        !           193: }
        !           194: 
        !           195: 
        !           196: static void  _advise (ap)
        !           197: va_list        ap;
        !           198: {
        !           199:     char    buffer[BUFSIZ];
        !           200: 
        !           201:     asprintf (buffer, ap);
        !           202: 
        !           203:     (void) fflush (stdout);
        !           204: 
        !           205:     fprintf (stderr, "%s: ", myname);
        !           206:     (void) fputs (buffer, stderr);
        !           207:     (void) fputc ('\n', stderr);
        !           208: 
        !           209:     (void) fflush (stderr);
        !           210: }
        !           211: #else
        !           212: /* VARARGS */
        !           213: 
        !           214: static void  advise (what, fmt)
        !           215: char   *what,
        !           216:        *fmt;
        !           217: {
        !           218:     advise (what, fmt);
        !           219: }
        !           220: #endif

unix.superglobalmegacorp.com

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