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