asa.c (96627) | asa.c (96628) |
---|---|
1/* $NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $ */ 2 3/* 4 * Copyright (c) 1993,94 Winning Strategies, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 22 unchanged lines hidden (view full) --- 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 | 1/* $NetBSD: asa.c,v 1.11 1997/09/20 14:55:00 lukem Exp $ */ 2 3/* 4 * Copyright (c) 1993,94 Winning Strategies, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 22 unchanged lines hidden (view full) --- 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 96627 2002-05-15 03:10:17Z tjr $"); | 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 *); | 40 41#include <err.h> 42#include <stdio.h> 43#include <stdlib.h> 44 45static void asa(FILE *); |
46static void usage(void); |
|
46 47int 48main(int argc, char *argv[]) 49{ | 47 48int 49main(int argc, char *argv[]) 50{ |
51 int ch, exval; |
|
50 FILE *fp; | 52 FILE *fp; |
53 const char *fn; |
|
51 | 54 |
52 /* skip progname */ 53 argv++; | 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; |
54 | 65 |
55 fp = stdin; 56 do { 57 if (*argv != NULL) { 58 if ((fp = fopen(*argv, "r")) == NULL) { 59 warn("%s", *argv); | 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; |
60 continue; 61 } | 74 continue; 75 } |
62 } 63 asa(fp); 64 if (fp != stdin) 65 (void)fclose(fp); 66 } while (*argv++ != NULL); | 76 asa(fp); 77 fclose(fp); 78 } 79 } |
67 | 80 |
68 exit(0); | 81 exit(exval); |
69} 70 71static void | 82} 83 84static void |
85usage(void) 86{ 87 88 fprintf(stderr, "usage: asa [file...]\n"); 89 exit(1); 90} 91 92static void |
|
72asa(FILE *f) 73{ 74 size_t len; 75 char *buf; 76 77 if ((buf = fgetln(f, &len)) != NULL) { 78 if (buf[len - 1] == '\n') 79 buf[--len] = '\0'; --- 40 unchanged lines hidden --- | 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'; --- 40 unchanged lines hidden --- |