13990fae7STim J. Robbins /* $NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $ */ 23990fae7STim J. Robbins 3*1de7b4b8SPedro F. Giffuni /*- 4*1de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 5*1de7b4b8SPedro F. Giffuni * 63990fae7STim J. Robbins * Copyright (c) 1993,94 Winning Strategies, Inc. 73990fae7STim J. Robbins * All rights reserved. 83990fae7STim J. Robbins * 93990fae7STim J. Robbins * Redistribution and use in source and binary forms, with or without 103990fae7STim J. Robbins * modification, are permitted provided that the following conditions 113990fae7STim J. Robbins * are met: 123990fae7STim J. Robbins * 1. Redistributions of source code must retain the above copyright 133990fae7STim J. Robbins * notice, this list of conditions and the following disclaimer. 143990fae7STim J. Robbins * 2. Redistributions in binary form must reproduce the above copyright 153990fae7STim J. Robbins * notice, this list of conditions and the following disclaimer in the 163990fae7STim J. Robbins * documentation and/or other materials provided with the distribution. 173990fae7STim J. Robbins * 3. All advertising materials mentioning features or use of this software 183990fae7STim J. Robbins * must display the following acknowledgement: 193990fae7STim J. Robbins * This product includes software developed by Winning Strategies, Inc. 203990fae7STim J. Robbins * 4. The name of the author may not be used to endorse or promote products 213990fae7STim J. Robbins * derived from this software without specific prior written permission 223990fae7STim J. Robbins * 233990fae7STim J. Robbins * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 243990fae7STim J. Robbins * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 253990fae7STim J. Robbins * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 263990fae7STim J. Robbins * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 273990fae7STim J. Robbins * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 283990fae7STim J. Robbins * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 293990fae7STim J. Robbins * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 303990fae7STim J. Robbins * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 313990fae7STim J. Robbins * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 323990fae7STim J. Robbins * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 333990fae7STim J. Robbins */ 343990fae7STim J. Robbins 353990fae7STim J. Robbins #include <sys/cdefs.h> 363990fae7STim J. Robbins #if 0 373990fae7STim J. Robbins #ifndef lint 383990fae7STim J. Robbins __RCSID("$NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $"); 393990fae7STim J. Robbins #endif 403990fae7STim J. Robbins #endif 413990fae7STim J. Robbins __FBSDID("$FreeBSD$"); 423990fae7STim J. Robbins 4381c126e7STim J. Robbins #include <err.h> 443990fae7STim J. Robbins #include <stdio.h> 453990fae7STim J. Robbins #include <stdlib.h> 46a3778ff6STim J. Robbins #include <unistd.h> 473990fae7STim J. Robbins 488a99cbd5STim J. Robbins static void asa(FILE *); 4966562e1aSTim J. Robbins static void usage(void); 503990fae7STim J. Robbins 513990fae7STim J. Robbins int 528a99cbd5STim J. Robbins main(int argc, char *argv[]) 533990fae7STim J. Robbins { 5466562e1aSTim J. Robbins int ch, exval; 553990fae7STim J. Robbins FILE *fp; 5666562e1aSTim J. Robbins const char *fn; 573990fae7STim J. Robbins 5866562e1aSTim J. Robbins while ((ch = getopt(argc, argv, "")) != -1) { 5966562e1aSTim J. Robbins switch (ch) { 6066562e1aSTim J. Robbins case '?': 6166562e1aSTim J. Robbins default: 6266562e1aSTim J. Robbins usage(); 6366562e1aSTim J. Robbins /*NOTREACHED*/ 6466562e1aSTim J. Robbins } 6566562e1aSTim J. Robbins } 6666562e1aSTim J. Robbins argc -= optind; 6766562e1aSTim J. Robbins argv += optind; 683990fae7STim J. Robbins 6966562e1aSTim J. Robbins exval = 0; 7066562e1aSTim J. Robbins if (argc == 0) 7166562e1aSTim J. Robbins asa(stdin); 7266562e1aSTim J. Robbins else { 7366562e1aSTim J. Robbins while ((fn = *argv++) != NULL) { 7466562e1aSTim J. Robbins if ((fp = fopen(fn, "r")) == NULL) { 7566562e1aSTim J. Robbins warn("%s", fn); 7666562e1aSTim J. Robbins exval = 1; 773990fae7STim J. Robbins continue; 783990fae7STim J. Robbins } 793990fae7STim J. Robbins asa(fp); 8066562e1aSTim J. Robbins fclose(fp); 8166562e1aSTim J. Robbins } 8266562e1aSTim J. Robbins } 833990fae7STim J. Robbins 8466562e1aSTim J. Robbins exit(exval); 8566562e1aSTim J. Robbins } 8666562e1aSTim J. Robbins 8766562e1aSTim J. Robbins static void 8866562e1aSTim J. Robbins usage(void) 8966562e1aSTim J. Robbins { 9066562e1aSTim J. Robbins 9166562e1aSTim J. Robbins fprintf(stderr, "usage: asa [file ...]\n"); 9266562e1aSTim J. Robbins exit(1); 933990fae7STim J. Robbins } 943990fae7STim J. Robbins 953990fae7STim J. Robbins static void 968a99cbd5STim J. Robbins asa(FILE *f) 973990fae7STim J. Robbins { 983990fae7STim J. Robbins size_t len; 9981c126e7STim J. Robbins char *buf; 1003990fae7STim J. Robbins 1013990fae7STim J. Robbins if ((buf = fgetln(f, &len)) != NULL) { 1023990fae7STim J. Robbins if (buf[len - 1] == '\n') 1033990fae7STim J. Robbins buf[--len] = '\0'; 1043990fae7STim J. Robbins /* special case the first line */ 1053990fae7STim J. Robbins switch (buf[0]) { 1063990fae7STim J. Robbins case '0': 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 } 1133990fae7STim J. Robbins 11481c126e7STim J. Robbins if (len > 1 && buf[0] && buf[1]) 1153990fae7STim J. Robbins printf("%.*s", (int)(len - 1), buf + 1); 1163990fae7STim J. Robbins 1173990fae7STim J. Robbins while ((buf = fgetln(f, &len)) != NULL) { 1183990fae7STim J. Robbins if (buf[len - 1] == '\n') 1193990fae7STim J. Robbins buf[--len] = '\0'; 1203990fae7STim J. Robbins switch (buf[0]) { 1213990fae7STim J. Robbins default: 1223990fae7STim J. Robbins case ' ': 1233990fae7STim J. Robbins putchar('\n'); 1243990fae7STim J. Robbins break; 1253990fae7STim J. Robbins case '0': 1263990fae7STim J. Robbins putchar('\n'); 1273990fae7STim J. Robbins putchar('\n'); 1283990fae7STim J. Robbins break; 1293990fae7STim J. Robbins case '1': 1303990fae7STim J. Robbins putchar('\f'); 1313990fae7STim J. Robbins break; 1323990fae7STim J. Robbins case '+': 1333990fae7STim J. Robbins putchar('\r'); 1343990fae7STim J. Robbins break; 1353990fae7STim J. Robbins } 1363990fae7STim J. Robbins 13781c126e7STim J. Robbins if (len > 1 && buf[0] && buf[1]) 1383990fae7STim J. Robbins printf("%.*s", (int)(len - 1), buf + 1); 1393990fae7STim J. Robbins } 1403990fae7STim J. Robbins 1413990fae7STim J. Robbins putchar('\n'); 1423990fae7STim J. Robbins } 1433990fae7STim J. Robbins } 144