asa.c revision 96625
196625Stjr/*	$NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $	*/
296625Stjr
396625Stjr/*
496625Stjr * Copyright (c) 1993,94 Winning Strategies, Inc.
596625Stjr * All rights reserved.
696625Stjr *
796625Stjr * Redistribution and use in source and binary forms, with or without
896625Stjr * modification, are permitted provided that the following conditions
996625Stjr * are met:
1096625Stjr * 1. Redistributions of source code must retain the above copyright
1196625Stjr *    notice, this list of conditions and the following disclaimer.
1296625Stjr * 2. Redistributions in binary form must reproduce the above copyright
1396625Stjr *    notice, this list of conditions and the following disclaimer in the
1496625Stjr *    documentation and/or other materials provided with the distribution.
1596625Stjr * 3. All advertising materials mentioning features or use of this software
1696625Stjr *    must display the following acknowledgement:
1796625Stjr *      This product includes software developed by Winning Strategies, Inc.
1896625Stjr * 4. The name of the author may not be used to endorse or promote products
1996625Stjr *    derived from this software without specific prior written permission
2096625Stjr *
2196625Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2296625Stjr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2396625Stjr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2496625Stjr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2596625Stjr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2696625Stjr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2796625Stjr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2896625Stjr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2996625Stjr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3096625Stjr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3196625Stjr */
3296625Stjr
3396625Stjr#include <sys/cdefs.h>
3496625Stjr#if 0
3596625Stjr#ifndef lint
3696625Stjr__RCSID("$NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $");
3796625Stjr#endif
3896625Stjr#endif
3996625Stjr__FBSDID("$FreeBSD: head/usr.bin/asa/asa.c 96625 2002-05-15 02:40:57Z tjr $");
4096625Stjr
4196625Stjr#include <stdio.h>
4296625Stjr#include <stdlib.h>
4396625Stjr#include <err.h>
4496625Stjr
4596625Stjrstatic void asa __P((FILE *));
4696625Stjrint main __P((int, char *[]));
4796625Stjr
4896625Stjrint
4996625Stjrmain (argc, argv)
5096625Stjr	int argc;
5196625Stjr	char **argv;
5296625Stjr{
5396625Stjr	FILE *fp;
5496625Stjr
5596625Stjr	/* skip progname */
5696625Stjr	argv++;
5796625Stjr
5896625Stjr        fp = stdin;
5996625Stjr        do {
6096625Stjr                if (*argv) {
6196625Stjr                        if (!(fp = fopen(*argv, "r"))) {
6296625Stjr				warn ("%s", *argv);
6396625Stjr				continue;
6496625Stjr                        }
6596625Stjr                }
6696625Stjr                asa (fp);
6796625Stjr                if (fp != stdin)
6896625Stjr                        (void)fclose(fp);
6996625Stjr        } while (*argv++);
7096625Stjr
7196625Stjr	exit (0);
7296625Stjr}
7396625Stjr
7496625Stjrstatic void
7596625Stjrasa(f)
7696625Stjr	FILE *f;
7796625Stjr{
7896625Stjr	char *buf;
7996625Stjr	size_t len;
8096625Stjr
8196625Stjr	if ((buf = fgetln (f, &len)) != NULL) {
8296625Stjr		if (buf[len - 1] == '\n')
8396625Stjr			buf[--len] = '\0';
8496625Stjr		/* special case the first line  */
8596625Stjr		switch (buf[0]) {
8696625Stjr		case '0':
8796625Stjr			putchar ('\n');
8896625Stjr			break;
8996625Stjr		case '1':
9096625Stjr			putchar ('\f');
9196625Stjr			break;
9296625Stjr		}
9396625Stjr
9496625Stjr		if (len > 1 && buf[0] && buf[1]) {
9596625Stjr			printf("%.*s", (int)(len - 1), buf + 1);
9696625Stjr		}
9796625Stjr
9896625Stjr		while ((buf = fgetln(f, &len)) != NULL) {
9996625Stjr			if (buf[len - 1] == '\n')
10096625Stjr				buf[--len] = '\0';
10196625Stjr			switch (buf[0]) {
10296625Stjr			default:
10396625Stjr			case ' ':
10496625Stjr				putchar ('\n');
10596625Stjr				break;
10696625Stjr			case '0':
10796625Stjr				putchar ('\n');
10896625Stjr				putchar ('\n');
10996625Stjr				break;
11096625Stjr			case '1':
11196625Stjr				putchar ('\f');
11296625Stjr				break;
11396625Stjr			case '+':
11496625Stjr				putchar ('\r');
11596625Stjr				break;
11696625Stjr			}
11796625Stjr
11896625Stjr			if (len > 1 && buf[0] && buf[1]) {
11996625Stjr				printf("%.*s", (int)(len - 1), buf + 1);
12096625Stjr			}
12196625Stjr		}
12296625Stjr
12396625Stjr		putchar ('\n');
12496625Stjr	}
12596625Stjr}
126