asa.c revision 96627
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 96627 2002-05-15 03:10:17Z tjr $"); 4096625Stjr 4196626Stjr#include <err.h> 4296625Stjr#include <stdio.h> 4396625Stjr#include <stdlib.h> 4496625Stjr 4596627Stjrstatic void asa(FILE *); 4696625Stjr 4796625Stjrint 4896627Stjrmain(int argc, char *argv[]) 4996625Stjr{ 5096625Stjr FILE *fp; 5196625Stjr 5296625Stjr /* skip progname */ 5396625Stjr argv++; 5496625Stjr 5596625Stjr fp = stdin; 5696625Stjr do { 5796626Stjr if (*argv != NULL) { 5896626Stjr if ((fp = fopen(*argv, "r")) == NULL) { 5996626Stjr warn("%s", *argv); 6096625Stjr continue; 6196625Stjr } 6296625Stjr } 6396626Stjr asa(fp); 6496625Stjr if (fp != stdin) 6596625Stjr (void)fclose(fp); 6696626Stjr } while (*argv++ != NULL); 6796625Stjr 6896626Stjr exit(0); 6996625Stjr} 7096625Stjr 7196625Stjrstatic void 7296627Stjrasa(FILE *f) 7396625Stjr{ 7496626Stjr size_t len; 7596625Stjr char *buf; 7696625Stjr 7796626Stjr if ((buf = fgetln(f, &len)) != NULL) { 7896625Stjr if (buf[len - 1] == '\n') 7996625Stjr buf[--len] = '\0'; 8096626Stjr /* special case the first line */ 8196625Stjr switch (buf[0]) { 8296625Stjr case '0': 8396626Stjr putchar('\n'); 8496625Stjr break; 8596625Stjr case '1': 8696626Stjr putchar('\f'); 8796625Stjr break; 8896625Stjr } 8996625Stjr 9096626Stjr if (len > 1 && buf[0] && buf[1]) 9196625Stjr printf("%.*s", (int)(len - 1), buf + 1); 9296625Stjr 9396625Stjr while ((buf = fgetln(f, &len)) != NULL) { 9496625Stjr if (buf[len - 1] == '\n') 9596625Stjr buf[--len] = '\0'; 9696625Stjr switch (buf[0]) { 9796625Stjr default: 9896625Stjr case ' ': 9996626Stjr putchar('\n'); 10096625Stjr break; 10196625Stjr case '0': 10296626Stjr putchar('\n'); 10396626Stjr putchar('\n'); 10496625Stjr break; 10596625Stjr case '1': 10696626Stjr putchar('\f'); 10796625Stjr break; 10896625Stjr case '+': 10996626Stjr putchar('\r'); 11096625Stjr break; 11196625Stjr } 11296625Stjr 11396626Stjr if (len > 1 && buf[0] && buf[1]) 11496625Stjr printf("%.*s", (int)(len - 1), buf + 1); 11596625Stjr } 11696625Stjr 11796626Stjr putchar('\n'); 11896625Stjr } 11996625Stjr} 120