Annotation of 43BSDReno/usr.bin/unvis/unvis.c, revision 1.1

1.1     ! root        1: /*-
        !             2:  * Copyright (c) 1989 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted provided
        !             6:  * that: (1) source distributions retain this entire copyright notice and
        !             7:  * comment, and (2) distributions including binaries display the following
        !             8:  * acknowledgement:  ``This product includes software developed by the
        !             9:  * University of California, Berkeley and its contributors'' in the
        !            10:  * documentation or other materials provided with the distribution and in
        !            11:  * all advertising materials mentioning features or use of this software.
        !            12:  * Neither the name of the University nor the names of its contributors may
        !            13:  * be used to endorse or promote products derived from this software without
        !            14:  * specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: char copyright[] =
        !            22: "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)unvis.c    5.1 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: #include <stdio.h>
        !            31: #include <vis.h>
        !            32: 
        !            33: char   *Program;
        !            34: #define usage()        fprintf(stderr, "usage: %s %s\n", Program, USAGE)
        !            35: #define USAGE "[file...]"
        !            36: 
        !            37: main(argc, argv)
        !            38:        char *argv[];
        !            39: {
        !            40:        FILE *fp;
        !            41:        extern char *optarg;
        !            42:        extern int optind;
        !            43:        int ch;
        !            44: 
        !            45:        Program = argv[0];
        !            46:        while ((ch = getopt(argc, argv, "")) != EOF)
        !            47:                switch((char)ch) {
        !            48:                case '?':
        !            49:                default:
        !            50:                        usage();
        !            51:                        exit(1);
        !            52:                }
        !            53:        argc -= optind;
        !            54:        argv += optind;
        !            55: 
        !            56:        if (*argv)
        !            57:                while (*argv) {
        !            58:                        if ((fp=fopen(*argv, "r")) != NULL)
        !            59:                                process(fp, *argv);
        !            60:                        else
        !            61:                                syserror("%s", *argv);
        !            62:                        argv++;
        !            63:                }
        !            64:        else
        !            65:                process(stdin, "<stdin>");
        !            66:        exit(0);
        !            67: }
        !            68: 
        !            69: process(fp, filename)
        !            70:        FILE *fp;
        !            71:        char *filename;
        !            72: {
        !            73:        register int offset = 0, c, ret;
        !            74:        int state = 0;
        !            75:        char outc;
        !            76: 
        !            77:        while ((c = getc(fp)) != EOF) {
        !            78:                offset++;
        !            79:        again:
        !            80:                switch(ret = unvis(&outc, (char)c, &state, 0)) {
        !            81:                case UNVIS_VALID:
        !            82:                        putchar(outc);
        !            83:                        break;
        !            84:                case UNVIS_VALIDPUSH:
        !            85:                        putchar(outc);
        !            86:                        goto again;
        !            87:                case UNVIS_SYNBAD:
        !            88:                        error("%s: offset: %d: can't decode", filename, offset);
        !            89:                        state = 0;
        !            90:                        break;
        !            91:                case 0:
        !            92:                case UNVIS_NOCHAR:
        !            93:                        break;
        !            94:                default:
        !            95:                        error("bad return value (%d), can't happen", ret);
        !            96:                        exit(1);
        !            97:                }
        !            98:        }
        !            99:        if (unvis(&outc, (char)0, &state, UNVIS_END) == UNVIS_VALID)
        !           100:                putchar(outc);
        !           101: }
        !           102: 
        !           103: #include <varargs.h>
        !           104: 
        !           105: error(va_alist)
        !           106:        va_dcl
        !           107: {
        !           108:        char *fmt;
        !           109:        va_list ap;
        !           110:        extern errno;
        !           111: 
        !           112:        fprintf(stderr, "%s: ", Program);
        !           113:        va_start(ap);
        !           114:        fmt = va_arg(ap, char *);
        !           115:        (void) vfprintf(stderr, fmt, ap);
        !           116:        va_end(ap);
        !           117:        fprintf(stderr, "\n");
        !           118: }
        !           119: 
        !           120: syserror(va_alist)
        !           121:        va_dcl
        !           122: {
        !           123:        char *fmt;
        !           124:        va_list ap;
        !           125:        extern errno;
        !           126: 
        !           127:        fprintf(stderr, "%s: ", Program);
        !           128:        va_start(ap);
        !           129:        fmt = va_arg(ap, char *);
        !           130:        (void) vfprintf(stderr, fmt, ap);
        !           131:        va_end(ap);
        !           132:        fprintf(stderr, ": %s\n", strerror(errno));
        !           133: }

unix.superglobalmegacorp.com

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