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