xref: /freebsd/usr.bin/asa/asa.c (revision 81c126e7d398cfef6df681216a8a05a335000077)
13990fae7STim J. Robbins /*	$NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $	*/
23990fae7STim J. Robbins 
33990fae7STim J. Robbins /*
43990fae7STim J. Robbins  * Copyright (c) 1993,94 Winning Strategies, Inc.
53990fae7STim J. Robbins  * All rights reserved.
63990fae7STim J. Robbins  *
73990fae7STim J. Robbins  * Redistribution and use in source and binary forms, with or without
83990fae7STim J. Robbins  * modification, are permitted provided that the following conditions
93990fae7STim J. Robbins  * are met:
103990fae7STim J. Robbins  * 1. Redistributions of source code must retain the above copyright
113990fae7STim J. Robbins  *    notice, this list of conditions and the following disclaimer.
123990fae7STim J. Robbins  * 2. Redistributions in binary form must reproduce the above copyright
133990fae7STim J. Robbins  *    notice, this list of conditions and the following disclaimer in the
143990fae7STim J. Robbins  *    documentation and/or other materials provided with the distribution.
153990fae7STim J. Robbins  * 3. All advertising materials mentioning features or use of this software
163990fae7STim J. Robbins  *    must display the following acknowledgement:
173990fae7STim J. Robbins  *      This product includes software developed by Winning Strategies, Inc.
183990fae7STim J. Robbins  * 4. The name of the author may not be used to endorse or promote products
193990fae7STim J. Robbins  *    derived from this software without specific prior written permission
203990fae7STim J. Robbins  *
213990fae7STim J. Robbins  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223990fae7STim J. Robbins  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
233990fae7STim J. Robbins  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
243990fae7STim J. Robbins  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
253990fae7STim J. Robbins  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
263990fae7STim J. Robbins  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
273990fae7STim J. Robbins  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
283990fae7STim J. Robbins  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
293990fae7STim J. Robbins  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
303990fae7STim J. Robbins  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
313990fae7STim J. Robbins  */
323990fae7STim J. Robbins 
333990fae7STim J. Robbins #include <sys/cdefs.h>
343990fae7STim J. Robbins #if 0
353990fae7STim J. Robbins #ifndef lint
363990fae7STim J. Robbins __RCSID("$NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $");
373990fae7STim J. Robbins #endif
383990fae7STim J. Robbins #endif
393990fae7STim J. Robbins __FBSDID("$FreeBSD$");
403990fae7STim J. Robbins 
4181c126e7STim J. Robbins #include <err.h>
423990fae7STim J. Robbins #include <stdio.h>
433990fae7STim J. Robbins #include <stdlib.h>
443990fae7STim J. Robbins 
453990fae7STim J. Robbins static void asa __P((FILE *));
463990fae7STim J. Robbins int main __P((int, char *[]));
473990fae7STim J. Robbins 
483990fae7STim J. Robbins int
493990fae7STim J. Robbins main(argc, argv)
503990fae7STim J. Robbins 	int argc;
513990fae7STim J. Robbins 	char **argv;
523990fae7STim J. Robbins {
533990fae7STim J. Robbins 	FILE *fp;
543990fae7STim J. Robbins 
553990fae7STim J. Robbins 	/* skip progname */
563990fae7STim J. Robbins 	argv++;
573990fae7STim J. Robbins 
583990fae7STim J. Robbins         fp = stdin;
593990fae7STim J. Robbins         do {
6081c126e7STim J. Robbins                 if (*argv != NULL) {
6181c126e7STim J. Robbins                         if ((fp = fopen(*argv, "r")) == NULL) {
623990fae7STim J. Robbins 				warn("%s", *argv);
633990fae7STim J. Robbins 				continue;
643990fae7STim J. Robbins                         }
653990fae7STim J. Robbins                 }
663990fae7STim J. Robbins                 asa(fp);
673990fae7STim J. Robbins                 if (fp != stdin)
683990fae7STim J. Robbins                         (void)fclose(fp);
6981c126e7STim J. Robbins         } while (*argv++ != NULL);
703990fae7STim J. Robbins 
713990fae7STim J. Robbins 	exit(0);
723990fae7STim J. Robbins }
733990fae7STim J. Robbins 
743990fae7STim J. Robbins static void
753990fae7STim J. Robbins asa(f)
763990fae7STim J. Robbins 	FILE *f;
773990fae7STim J. Robbins {
783990fae7STim J. Robbins 	size_t len;
7981c126e7STim J. Robbins 	char *buf;
803990fae7STim J. Robbins 
813990fae7STim J. Robbins 	if ((buf = fgetln(f, &len)) != NULL) {
823990fae7STim J. Robbins 		if (buf[len - 1] == '\n')
833990fae7STim J. Robbins 			buf[--len] = '\0';
843990fae7STim J. Robbins 		/* special case the first line */
853990fae7STim J. Robbins 		switch (buf[0]) {
863990fae7STim J. Robbins 		case '0':
873990fae7STim J. Robbins 			putchar('\n');
883990fae7STim J. Robbins 			break;
893990fae7STim J. Robbins 		case '1':
903990fae7STim J. Robbins 			putchar('\f');
913990fae7STim J. Robbins 			break;
923990fae7STim J. Robbins 		}
933990fae7STim J. Robbins 
9481c126e7STim J. Robbins 		if (len > 1 && buf[0] && buf[1])
953990fae7STim J. Robbins 			printf("%.*s", (int)(len - 1), buf + 1);
963990fae7STim J. Robbins 
973990fae7STim J. Robbins 		while ((buf = fgetln(f, &len)) != NULL) {
983990fae7STim J. Robbins 			if (buf[len - 1] == '\n')
993990fae7STim J. Robbins 				buf[--len] = '\0';
1003990fae7STim J. Robbins 			switch (buf[0]) {
1013990fae7STim J. Robbins 			default:
1023990fae7STim J. Robbins 			case ' ':
1033990fae7STim J. Robbins 				putchar('\n');
1043990fae7STim J. Robbins 				break;
1053990fae7STim J. Robbins 			case '0':
1063990fae7STim J. Robbins 				putchar('\n');
1073990fae7STim J. Robbins 				putchar('\n');
1083990fae7STim J. Robbins 				break;
1093990fae7STim J. Robbins 			case '1':
1103990fae7STim J. Robbins 				putchar('\f');
1113990fae7STim J. Robbins 				break;
1123990fae7STim J. Robbins 			case '+':
1133990fae7STim J. Robbins 				putchar('\r');
1143990fae7STim J. Robbins 				break;
1153990fae7STim J. Robbins 			}
1163990fae7STim J. Robbins 
11781c126e7STim J. Robbins 			if (len > 1 && buf[0] && buf[1])
1183990fae7STim J. Robbins 				printf("%.*s", (int)(len - 1), buf + 1);
1193990fae7STim J. Robbins 		}
1203990fae7STim J. Robbins 
1213990fae7STim J. Robbins 		putchar('\n');
1223990fae7STim J. Robbins 	}
1233990fae7STim J. Robbins }
124