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