Annotation of src/usr.bin/asa/asa.c, Revision 1.4
1.4 ! deraadt 1: /* $OpenBSD: asa.c,v 1.3 1998/07/20 19:57:17 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.4 ! deraadt 35: static char rcsid[] = "$OpenBSD: asa.c,v 1.3 1998/07/20 19:57:17 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
1.4 ! deraadt 45: main(int argc, char *argv[])
1.1 deraadt 46: {
47: FILE *fp;
48:
49: /* skip progname */
50: argv++;
51:
1.3 deraadt 52: fp = stdin;
53: do {
54: if (*argv) {
55: if (!(fp = fopen(*argv, "r"))) {
1.1 deraadt 56: warn ("%s", *argv);
57: continue;
1.3 deraadt 58: }
59: }
60: if (fp)
61: asa (fp);
62: if (fp && fp != stdin)
63: (void)fclose(fp);
64: } while (*argv++);
1.1 deraadt 65:
66: exit (0);
67: }
68:
69: static void
1.4 ! deraadt 70: asa(FILE *f)
1.1 deraadt 71: {
72: char *buf;
73: size_t len;
74:
75: if ((buf = fgetln (f, &len)) != NULL) {
76: buf[len - 1] = '\0';
77: /* special case the first line */
78: switch (buf[0]) {
79: case '0':
80: putchar ('\n');
81: break;
82: case '1':
83: putchar ('\f');
84: break;
85: }
86:
87: if (buf[0] && buf[1]) {
88: fputs (&buf[1], stdout);
89: }
90:
91: while ((buf = fgetln(f, &len)) != NULL) {
92: buf[len - 1] = '\0';
93: switch (buf[0]) {
94: default:
95: case ' ':
96: putchar ('\n');
97: break;
98: case '0':
99: putchar ('\n');
100: putchar ('\n');
101: break;
102: case '1':
103: putchar ('\f');
104: break;
105: case '+':
106: putchar ('\r');
107: break;
108: }
109:
110: if (buf[0] && buf[1]) {
111: fputs (&buf[1], stdout);
112: }
113: }
114:
115: putchar ('\n');
116: }
117: }