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