xref: /netbsd-src/usr.bin/asa/asa.c (revision 39bbc68a3b8731308f39852383f5430560168a91)
1*39bbc68aSsevan /*	$NetBSD: asa.c,v 1.17 2016/09/05 00:40:28 sevan Exp $	*/
25c84ea4dSglass 
3b2be4a77Sjtc /*
4690434f0Sjtc  * Copyright (c) 1993,94 Winning Strategies, Inc.
5b2be4a77Sjtc  * All rights reserved.
6b2be4a77Sjtc  *
7b2be4a77Sjtc  * Redistribution and use in source and binary forms, with or without
8b2be4a77Sjtc  * modification, are permitted provided that the following conditions
9b2be4a77Sjtc  * are met:
10b2be4a77Sjtc  * 1. Redistributions of source code must retain the above copyright
11b2be4a77Sjtc  *    notice, this list of conditions and the following disclaimer.
12b2be4a77Sjtc  * 2. Redistributions in binary form must reproduce the above copyright
13b2be4a77Sjtc  *    notice, this list of conditions and the following disclaimer in the
14b2be4a77Sjtc  *    documentation and/or other materials provided with the distribution.
15b2be4a77Sjtc  * 3. All advertising materials mentioning features or use of this software
16b2be4a77Sjtc  *    must display the following acknowledgement:
17b2be4a77Sjtc  *      This product includes software developed by Winning Strategies, Inc.
18b2be4a77Sjtc  * 4. The name of the author may not be used to endorse or promote products
1942f840d2Sjtc  *    derived from this software without specific prior written permission
20b2be4a77Sjtc  *
21b2be4a77Sjtc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22b2be4a77Sjtc  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23b2be4a77Sjtc  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24b2be4a77Sjtc  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25b2be4a77Sjtc  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26b2be4a77Sjtc  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27b2be4a77Sjtc  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28b2be4a77Sjtc  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29b2be4a77Sjtc  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30b2be4a77Sjtc  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31b2be4a77Sjtc  */
32b2be4a77Sjtc 
33b0f016eaSlukem #include <sys/cdefs.h>
34b2be4a77Sjtc #ifndef lint
35*39bbc68aSsevan __RCSID("$NetBSD: asa.c,v 1.17 2016/09/05 00:40:28 sevan Exp $");
36b2be4a77Sjtc #endif
37b2be4a77Sjtc 
3866af1d24Swiz #include <err.h>
39b2be4a77Sjtc #include <stdio.h>
40b2be4a77Sjtc #include <stdlib.h>
41b2be4a77Sjtc 
4266af1d24Swiz static void asa(FILE *);
43b2be4a77Sjtc 
44b2be4a77Sjtc int
45a45a783fSchristos /*ARGSUSED*/
main(int argc,char * argv[])4666af1d24Swiz main (int argc, char *argv[])
47b2be4a77Sjtc {
48b2be4a77Sjtc 	FILE *fp;
49b2be4a77Sjtc 
50690434f0Sjtc 	/* skip progname */
51b2be4a77Sjtc 	argv++;
52b2be4a77Sjtc 
530e0aff06Senami 	if (*argv == NULL)
540e0aff06Senami 		asa(stdin);
550e0aff06Senami 	else
56b2be4a77Sjtc         	do {
570e0aff06Senami 			if ((fp = fopen(*argv, "r")) == NULL) {
58b2be4a77Sjtc 				warn("%s", *argv);
59b2be4a77Sjtc 				continue;
60b2be4a77Sjtc 			}
61b2be4a77Sjtc 			asa(fp);
62b2be4a77Sjtc 			(void)fclose(fp);
630e0aff06Senami         	} while (*++argv != NULL);
64b2be4a77Sjtc 
65a45a783fSchristos 	return 0;
66b2be4a77Sjtc }
67b2be4a77Sjtc 
68b2be4a77Sjtc static void
asa(FILE * f)6966af1d24Swiz asa(FILE *f)
70b2be4a77Sjtc {
71b2be4a77Sjtc 	char *buf;
7275c71616Scgd 	size_t len;
73b2be4a77Sjtc 
7402254e0cScgd 	if ((buf = fgetln(f, &len)) != NULL) {
75a45a783fSchristos 		if (len > 0 && buf[len - 1] == '\n')
76b0f016eaSlukem 			buf[--len] = '\0';
77b2be4a77Sjtc 		/* special case the first line */
78b2be4a77Sjtc 		switch (buf[0]) {
79b2be4a77Sjtc 		case '0':
80a45a783fSchristos 			(void)putchar('\n');
81b2be4a77Sjtc 			break;
82b2be4a77Sjtc 		case '1':
83a45a783fSchristos 			(void)putchar('\f');
84b2be4a77Sjtc 			break;
85b2be4a77Sjtc 		}
86b2be4a77Sjtc 
87a45a783fSchristos 		if (len > 1 && buf[0] && buf[1])
88a45a783fSchristos 			(void)fwrite(buf + 1, 1, len - 1, stdout);
89b2be4a77Sjtc 
9002254e0cScgd 		while ((buf = fgetln(f, &len)) != NULL) {
91a45a783fSchristos 			if (len > 0 && buf[len - 1] == '\n')
92b0f016eaSlukem 				buf[--len] = '\0';
93b2be4a77Sjtc 			switch (buf[0]) {
94b2be4a77Sjtc 			default:
95b2be4a77Sjtc 			case ' ':
96a45a783fSchristos 				(void)putchar('\n');
97b2be4a77Sjtc 				break;
98b2be4a77Sjtc 			case '0':
99a45a783fSchristos 				(void)putchar('\n');
100a45a783fSchristos 				(void)putchar('\n');
101b2be4a77Sjtc 				break;
102b2be4a77Sjtc 			case '1':
103a45a783fSchristos 				(void)putchar('\f');
104b2be4a77Sjtc 				break;
105b2be4a77Sjtc 			case '+':
106a45a783fSchristos 				(void)putchar('\r');
107b2be4a77Sjtc 				break;
108b2be4a77Sjtc 			}
109b2be4a77Sjtc 
110a45a783fSchristos 			if (len > 1 && buf[0] && buf[1])
111a45a783fSchristos 				(void)fwrite(buf + 1, 1, len - 1, stdout);
112550dfe1aSjtc 		}
113b2be4a77Sjtc 
114a45a783fSchristos 		(void)putchar('\n');
115b2be4a77Sjtc 	}
116b2be4a77Sjtc }
117