[BACK]Return to asa.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / asa

Annotation of src/usr.bin/asa/asa.c, Revision 1.3

1.3     ! deraadt     1: /*     $OpenBSD: asa.c,v 1.2 1996/06/26 05:31:25 deraadt Exp $ */
1.1       deraadt     2: /*     $NetBSD: asa.c,v 1.10 1995/04/21 03:01:41 cgd Exp $     */
                      3:
                      4: /*
                      5:  * Copyright (c) 1993,94 Winning Strategies, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *      This product includes software developed by Winning Strategies, Inc.
                     19:  * 4. The name of the author may not be used to endorse or promote products
                     20:  *    derived from this software without specific prior written permission
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     23:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     24:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     25:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     26:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     27:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     28:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     29:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     30:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     31:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     32:  */
                     33:
                     34: #ifndef lint
1.3     ! deraadt    35: static char rcsid[] = "$OpenBSD: asa.c,v 1.2 1996/06/26 05:31:25 deraadt Exp $";
1.1       deraadt    36: #endif
                     37:
                     38: #include <stdio.h>
                     39: #include <stdlib.h>
                     40: #include <err.h>
                     41:
                     42: static void asa();
                     43:
                     44: int
                     45: main (argc, argv)
                     46:        int argc;
                     47:        char **argv;
                     48: {
                     49:        FILE *fp;
                     50:
                     51:        /* skip progname */
                     52:        argv++;
                     53:
1.3     ! deraadt    54:        fp = stdin;
        !            55:        do {
        !            56:                if (*argv) {
        !            57:                        if (!(fp = fopen(*argv, "r"))) {
1.1       deraadt    58:                                warn ("%s", *argv);
                     59:                                continue;
1.3     ! deraadt    60:                        }
        !            61:                }
        !            62:                if (fp)
        !            63:                        asa (fp);
        !            64:                if (fp && fp != stdin)
        !            65:                        (void)fclose(fp);
        !            66:        } while (*argv++);
1.1       deraadt    67:
                     68:        exit (0);
                     69: }
                     70:
                     71: static void
                     72: asa(f)
                     73:        FILE *f;
                     74: {
                     75:        char *buf;
                     76:        size_t len;
                     77:
                     78:        if ((buf = fgetln (f, &len)) != NULL) {
                     79:                buf[len - 1] = '\0';
                     80:                /* special case the first line  */
                     81:                switch (buf[0]) {
                     82:                case '0':
                     83:                        putchar ('\n');
                     84:                        break;
                     85:                case '1':
                     86:                        putchar ('\f');
                     87:                        break;
                     88:                }
                     89:
                     90:                if (buf[0] && buf[1]) {
                     91:                        fputs (&buf[1], stdout);
                     92:                }
                     93:
                     94:                while ((buf = fgetln(f, &len)) != NULL) {
                     95:                        buf[len - 1] = '\0';
                     96:                        switch (buf[0]) {
                     97:                        default:
                     98:                        case ' ':
                     99:                                putchar ('\n');
                    100:                                break;
                    101:                        case '0':
                    102:                                putchar ('\n');
                    103:                                putchar ('\n');
                    104:                                break;
                    105:                        case '1':
                    106:                                putchar ('\f');
                    107:                                break;
                    108:                        case '+':
                    109:                                putchar ('\r');
                    110:                                break;
                    111:                        }
                    112:
                    113:                        if (buf[0] && buf[1]) {
                    114:                                fputs (&buf[1], stdout);
                    115:                        }
                    116:                }
                    117:
                    118:                putchar ('\n');
                    119:        }
                    120: }