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