4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
44 static void usage(void);
45 static void disp_file(FILE *f
, char *filename
);
46 static FILE *get_next_file(int, char *, char *[], int);
47 static void finish(int need_a_newline
);
49 int estatus
= 0; /* exit status */
50 int i
; /* argv index */
53 main(int argc
, char *argv
[])
57 int need_a_newline
= 0;
58 char *filename
= NULL
;
61 (void) setlocale(LC_ALL
, "");
62 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
63 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it were not */
66 (void) textdomain(TEXT_DOMAIN
);
68 while ((c
= getopt(argc
, argv
, "f")) != EOF
) {
84 f
= get_next_file(need_a_newline
, filename
, argv
, argc
);
89 /* interpret the first character in the line */
94 disp_file(f
, filename
);
97 finish(need_a_newline
);
99 f
= get_next_file(need_a_newline
, filename
, argv
, argc
);
101 if (need_a_newline
) {
119 (void) putchar('\r');
148 } else if (c
== EOF
) {
149 disp_file(f
, filename
);
152 finish(need_a_newline
);
154 f
= get_next_file(need_a_newline
, filename
,
175 (void) fprintf(stderr
, gettext("usage: asa [-f] [-|file...]\n"));
181 disp_file(FILE *f
, char *filename
)
187 (void) fprintf(stderr
, gettext(
188 "asa: read error on file %s\n"), filename
);
190 (void) fprintf(stderr
, gettext(
191 "asa: read error on standard input\n"));
203 get_next_file(int need_a_newline
, char *filename
, char *argv
[], int argc
)
206 if (strcmp(argv
[i
], "-") == 0) {
211 * Process each file operand. If unsuccessful, affect the
212 * exit status and continue processing the next operand.
215 while ((f
= fopen(filename
, "r")) == NULL
) {
217 (void) fprintf(stderr
,
218 gettext("asa: cannot open %s:"), filename
);
223 if (strcmp(argv
[i
], "-") == 0) {
231 finish(need_a_newline
);
240 finish(int need_a_newline
)