1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate #include <unistd.h>
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/stat.h>
31*0Sstevel@tonic-gate #include <fcntl.h>
32*0Sstevel@tonic-gate #include <sys/mman.h>
33*0Sstevel@tonic-gate #include <stdio.h>
34*0Sstevel@tonic-gate #include <stdarg.h>
35*0Sstevel@tonic-gate #include <string.h>
36*0Sstevel@tonic-gate #include <tnf/tnf.h>
37*0Sstevel@tonic-gate #include <errno.h>
38*0Sstevel@tonic-gate #include <stdlib.h>
39*0Sstevel@tonic-gate #include <libintl.h>
40*0Sstevel@tonic-gate #include <locale.h>
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate #include "state.h"
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate static caddr_t g_file_base; /* base address of file */
45*0Sstevel@tonic-gate static char *g_cmdname; /* name of this command */
46*0Sstevel@tonic-gate static int g_raw = B_FALSE; /* output format */
47*0Sstevel@tonic-gate static int g_status = EXIT_SUCCESS; /* exit status (from stdlib.h) */
48*0Sstevel@tonic-gate static const char *print_unsigned = "%u";
49*0Sstevel@tonic-gate static const char *print_unsigned64 = "%llu";
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate #define OFF(p) (p - g_file_base)
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate static void describe_array (tnf_datum_t);
54*0Sstevel@tonic-gate static void describe_brief (tnf_datum_t);
55*0Sstevel@tonic-gate static void describe_record (tnf_datum_t);
56*0Sstevel@tonic-gate static void describe_struct (tnf_datum_t);
57*0Sstevel@tonic-gate static void describe_type (tnf_datum_t);
58*0Sstevel@tonic-gate static void read_tnf_file (int, char *);
59*0Sstevel@tonic-gate static void usage (void);
60*0Sstevel@tonic-gate static void scanargs (int, char **, int *, char ***);
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate int
main(int ac,char * av[])63*0Sstevel@tonic-gate main(int ac, char *av[])
64*0Sstevel@tonic-gate {
65*0Sstevel@tonic-gate int numfiles; /* number of files to be printed */
66*0Sstevel@tonic-gate char **filenames; /* start of file names list */
67*0Sstevel@tonic-gate int i;
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate /* internationalization stuff */
70*0Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
71*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
72*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
73*0Sstevel@tonic-gate #endif
74*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate g_cmdname = av[0];
77*0Sstevel@tonic-gate scanargs(ac, av, &numfiles, &filenames);
78*0Sstevel@tonic-gate for (i = 0; i < numfiles; i++) {
79*0Sstevel@tonic-gate read_tnf_file(g_raw, filenames[i]);
80*0Sstevel@tonic-gate }
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate if (!g_raw) {
83*0Sstevel@tonic-gate if (table_get_num_elements() > 0) {
84*0Sstevel@tonic-gate print_c_header();
85*0Sstevel@tonic-gate print_sorted_events();
86*0Sstevel@tonic-gate }
87*0Sstevel@tonic-gate }
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate exit(g_status);
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate return (0);
92*0Sstevel@tonic-gate }
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate static void
scanargs(int argc,char ** argv,int * nfiles,char *** files)95*0Sstevel@tonic-gate scanargs(int argc, char **argv, int *nfiles, char ***files)
96*0Sstevel@tonic-gate {
97*0Sstevel@tonic-gate int c;
98*0Sstevel@tonic-gate int errflg = B_FALSE;
99*0Sstevel@tonic-gate char *optstr = "rx";
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate while ((c = getopt(argc, argv, optstr)) != EOF) {
102*0Sstevel@tonic-gate switch (c) {
103*0Sstevel@tonic-gate case 'r':
104*0Sstevel@tonic-gate g_raw = B_TRUE;
105*0Sstevel@tonic-gate break;
106*0Sstevel@tonic-gate case 'x':
107*0Sstevel@tonic-gate print_unsigned = "0x%x";
108*0Sstevel@tonic-gate print_unsigned64 = "0x%llx";
109*0Sstevel@tonic-gate break;
110*0Sstevel@tonic-gate case '?':
111*0Sstevel@tonic-gate errflg = B_TRUE;
112*0Sstevel@tonic-gate break;
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate }
115*0Sstevel@tonic-gate *files = &argv[optind];
116*0Sstevel@tonic-gate *nfiles = argc - optind;
117*0Sstevel@tonic-gate if (*nfiles <= 0) {
118*0Sstevel@tonic-gate errflg = B_TRUE;
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate if (errflg) {
121*0Sstevel@tonic-gate usage();
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate static void
read_tnf_file(int raw,char * path)127*0Sstevel@tonic-gate read_tnf_file(int raw, char *path)
128*0Sstevel@tonic-gate {
129*0Sstevel@tonic-gate int fd;
130*0Sstevel@tonic-gate struct stat st;
131*0Sstevel@tonic-gate caddr_t p, curr_p, end_p;
132*0Sstevel@tonic-gate TNF *tnf;
133*0Sstevel@tonic-gate tnf_errcode_t err;
134*0Sstevel@tonic-gate tnf_datum_t record;
135*0Sstevel@tonic-gate void (*desc_func)(tnf_datum_t) = describe_c_record;
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate if ((fd = open(path, O_RDONLY, 0777)) == -1) {
138*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: cannot open %s\n"),
139*0Sstevel@tonic-gate g_cmdname, path);
140*0Sstevel@tonic-gate g_status = EXIT_FAILURE;
141*0Sstevel@tonic-gate return;
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate if (fstat(fd, &st) != 0) {
144*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: fstat error on %s\n"),
145*0Sstevel@tonic-gate g_cmdname, path);
146*0Sstevel@tonic-gate (void) close(fd);
147*0Sstevel@tonic-gate g_status = EXIT_FAILURE;
148*0Sstevel@tonic-gate return;
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate if (st.st_size == 0) {
151*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: %s is empty\n"),
152*0Sstevel@tonic-gate g_cmdname, path);
153*0Sstevel@tonic-gate (void) close(fd);
154*0Sstevel@tonic-gate g_status = EXIT_FAILURE;
155*0Sstevel@tonic-gate return;
156*0Sstevel@tonic-gate }
157*0Sstevel@tonic-gate if ((p = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))
158*0Sstevel@tonic-gate == (caddr_t)-1) {
159*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: mmap error on %s\n"),
160*0Sstevel@tonic-gate g_cmdname, path);
161*0Sstevel@tonic-gate (void) close(fd);
162*0Sstevel@tonic-gate g_status = EXIT_FAILURE;
163*0Sstevel@tonic-gate return;
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate if (raw)
167*0Sstevel@tonic-gate g_file_base = p; /* for OFF() */
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate if (*p == 0) {
170*0Sstevel@tonic-gate /*
171*0Sstevel@tonic-gate * magic word is 0 - catch the error if entire file is zero.
172*0Sstevel@tonic-gate * tnf_reader_begin() will catch the "not a TNF file" error.
173*0Sstevel@tonic-gate */
174*0Sstevel@tonic-gate curr_p = p;
175*0Sstevel@tonic-gate end_p = p + st.st_size;
176*0Sstevel@tonic-gate while ((curr_p < end_p) && (*curr_p == 0))
177*0Sstevel@tonic-gate curr_p++;
178*0Sstevel@tonic-gate if (curr_p == end_p) {
179*0Sstevel@tonic-gate (void) fprintf(stderr,
180*0Sstevel@tonic-gate gettext("%s: %s is an empty TNF file\n"),
181*0Sstevel@tonic-gate g_cmdname, path);
182*0Sstevel@tonic-gate (void) munmap(p, st.st_size);
183*0Sstevel@tonic-gate (void) close(fd);
184*0Sstevel@tonic-gate return;
185*0Sstevel@tonic-gate }
186*0Sstevel@tonic-gate }
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gate if ((err = tnf_reader_begin(p, st.st_size, &tnf)) != TNF_ERR_NONE) {
189*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: error in %s: %s\n"),
190*0Sstevel@tonic-gate g_cmdname, path, tnf_error_message(err));
191*0Sstevel@tonic-gate (void) munmap(p, st.st_size);
192*0Sstevel@tonic-gate (void) close(fd);
193*0Sstevel@tonic-gate g_status = EXIT_FAILURE;
194*0Sstevel@tonic-gate return;
195*0Sstevel@tonic-gate }
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gate /* Describe file header */
198*0Sstevel@tonic-gate record = tnf_get_file_header(tnf);
199*0Sstevel@tonic-gate if (raw) {
200*0Sstevel@tonic-gate describe_record(record);
201*0Sstevel@tonic-gate desc_func = describe_record;
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gate /* Describe all other records */
205*0Sstevel@tonic-gate while ((record = tnf_get_next_record(record)) != TNF_DATUM_NULL)
206*0Sstevel@tonic-gate desc_func(record);
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate /* Don't munmap for cooked output because we access records later */
209*0Sstevel@tonic-gate if (raw)
210*0Sstevel@tonic-gate (void) munmap(p, st.st_size);
211*0Sstevel@tonic-gate (void) close(fd);
212*0Sstevel@tonic-gate }
213*0Sstevel@tonic-gate
214*0Sstevel@tonic-gate static void
describe_record(tnf_datum_t datum)215*0Sstevel@tonic-gate describe_record(tnf_datum_t datum)
216*0Sstevel@tonic-gate {
217*0Sstevel@tonic-gate (void) printf("0x%-8x: {\n", OFF(tnf_get_raw(datum)));
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate switch (tnf_get_kind(datum)) {
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate case TNF_K_STRUCT:
222*0Sstevel@tonic-gate describe_struct(datum);
223*0Sstevel@tonic-gate break;
224*0Sstevel@tonic-gate case TNF_K_STRING:
225*0Sstevel@tonic-gate case TNF_K_ARRAY:
226*0Sstevel@tonic-gate describe_array(datum);
227*0Sstevel@tonic-gate break;
228*0Sstevel@tonic-gate case TNF_K_TYPE:
229*0Sstevel@tonic-gate describe_type(datum);
230*0Sstevel@tonic-gate break;
231*0Sstevel@tonic-gate default:
232*0Sstevel@tonic-gate fail(0, gettext("illegal record at %x (%d)"),
233*0Sstevel@tonic-gate tnf_get_raw(datum), tnf_get_kind(datum));
234*0Sstevel@tonic-gate break;
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate (void) printf("\t}\n");
238*0Sstevel@tonic-gate }
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate void
describe_scalar(tnf_datum_t datum)241*0Sstevel@tonic-gate describe_scalar(tnf_datum_t datum)
242*0Sstevel@tonic-gate {
243*0Sstevel@tonic-gate switch (tnf_get_kind(datum)) {
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate case TNF_K_CHAR:
246*0Sstevel@tonic-gate (void) printf("%c", tnf_get_char(datum));
247*0Sstevel@tonic-gate break;
248*0Sstevel@tonic-gate case TNF_K_INT8:
249*0Sstevel@tonic-gate (void) printf("%d", tnf_get_int8(datum));
250*0Sstevel@tonic-gate break;
251*0Sstevel@tonic-gate case TNF_K_UINT8:
252*0Sstevel@tonic-gate (void) printf(print_unsigned, (tnf_uint8_t)tnf_get_int8(datum));
253*0Sstevel@tonic-gate break;
254*0Sstevel@tonic-gate case TNF_K_INT16:
255*0Sstevel@tonic-gate (void) printf("%d", tnf_get_int16(datum));
256*0Sstevel@tonic-gate break;
257*0Sstevel@tonic-gate case TNF_K_UINT16:
258*0Sstevel@tonic-gate (void) printf(print_unsigned,
259*0Sstevel@tonic-gate (tnf_uint16_t)tnf_get_int16(datum));
260*0Sstevel@tonic-gate break;
261*0Sstevel@tonic-gate case TNF_K_INT32:
262*0Sstevel@tonic-gate (void) printf("%d", (int)tnf_get_int32(datum));
263*0Sstevel@tonic-gate break;
264*0Sstevel@tonic-gate case TNF_K_UINT32:
265*0Sstevel@tonic-gate if ((tnf_type_get_property(tnf_get_type(datum), TNF_N_OPAQUE))
266*0Sstevel@tonic-gate != TNF_DATUM_NULL) {
267*0Sstevel@tonic-gate /* XXX */
268*0Sstevel@tonic-gate (void) printf("0x%x",
269*0Sstevel@tonic-gate (tnf_uint32_t)tnf_get_int32(datum));
270*0Sstevel@tonic-gate } else {
271*0Sstevel@tonic-gate (void) printf(print_unsigned,
272*0Sstevel@tonic-gate (tnf_uint32_t)tnf_get_int32(datum));
273*0Sstevel@tonic-gate }
274*0Sstevel@tonic-gate break;
275*0Sstevel@tonic-gate case TNF_K_INT64:
276*0Sstevel@tonic-gate /* lint not updated, it complains: malformed format string */
277*0Sstevel@tonic-gate (void) printf("%lld", tnf_get_int64(datum));
278*0Sstevel@tonic-gate break;
279*0Sstevel@tonic-gate case TNF_K_UINT64:
280*0Sstevel@tonic-gate if ((tnf_type_get_property(tnf_get_type(datum), TNF_N_OPAQUE))
281*0Sstevel@tonic-gate != TNF_DATUM_NULL) {
282*0Sstevel@tonic-gate (void) printf("0x%llx",
283*0Sstevel@tonic-gate (tnf_uint64_t)tnf_get_int64(datum));
284*0Sstevel@tonic-gate } else {
285*0Sstevel@tonic-gate /* lint not updated, it complains: malformed format string */
286*0Sstevel@tonic-gate (void) printf(print_unsigned64,
287*0Sstevel@tonic-gate (tnf_uint64_t)tnf_get_int64(datum));
288*0Sstevel@tonic-gate }
289*0Sstevel@tonic-gate break;
290*0Sstevel@tonic-gate case TNF_K_FLOAT32:
291*0Sstevel@tonic-gate (void) printf("%f", tnf_get_float32(datum));
292*0Sstevel@tonic-gate break;
293*0Sstevel@tonic-gate case TNF_K_FLOAT64:
294*0Sstevel@tonic-gate (void) printf("%f", tnf_get_float64(datum));
295*0Sstevel@tonic-gate break;
296*0Sstevel@tonic-gate case TNF_K_SCALAR:
297*0Sstevel@tonic-gate (void) printf("unhandled scalar");
298*0Sstevel@tonic-gate break;
299*0Sstevel@tonic-gate default:
300*0Sstevel@tonic-gate fail(0, gettext("not a scalar"));
301*0Sstevel@tonic-gate break;
302*0Sstevel@tonic-gate }
303*0Sstevel@tonic-gate }
304*0Sstevel@tonic-gate
305*0Sstevel@tonic-gate static void
describe_struct(tnf_datum_t datum)306*0Sstevel@tonic-gate describe_struct(tnf_datum_t datum)
307*0Sstevel@tonic-gate {
308*0Sstevel@tonic-gate unsigned n, i;
309*0Sstevel@tonic-gate char *slotname;
310*0Sstevel@tonic-gate
311*0Sstevel@tonic-gate n = tnf_get_slot_count(datum);
312*0Sstevel@tonic-gate for (i = 0; i < n; i++) {
313*0Sstevel@tonic-gate slotname = tnf_get_slot_name(datum, i);
314*0Sstevel@tonic-gate (void) printf("%24s ", slotname);
315*0Sstevel@tonic-gate describe_brief(tnf_get_slot_indexed(datum, i));
316*0Sstevel@tonic-gate (void) printf("\n");
317*0Sstevel@tonic-gate /* tag_arg heuristic */
318*0Sstevel@tonic-gate if ((i == 0) && tnf_is_record(datum)) {
319*0Sstevel@tonic-gate tnf_datum_t tag_arg;
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gate if ((tag_arg = tnf_get_tag_arg(datum))
322*0Sstevel@tonic-gate != TNF_DATUM_NULL) {
323*0Sstevel@tonic-gate (void) printf("%24s ", TNF_N_TAG_ARG);
324*0Sstevel@tonic-gate describe_brief(tag_arg);
325*0Sstevel@tonic-gate (void) printf("\n");
326*0Sstevel@tonic-gate }
327*0Sstevel@tonic-gate }
328*0Sstevel@tonic-gate }
329*0Sstevel@tonic-gate }
330*0Sstevel@tonic-gate
331*0Sstevel@tonic-gate static void
describe_array(tnf_datum_t datum)332*0Sstevel@tonic-gate describe_array(tnf_datum_t datum)
333*0Sstevel@tonic-gate {
334*0Sstevel@tonic-gate unsigned n, i;
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate describe_struct(datum); /* XXX */
337*0Sstevel@tonic-gate
338*0Sstevel@tonic-gate if (tnf_is_string(datum))
339*0Sstevel@tonic-gate (void) printf("%24s \"%s\"\n", "chars", tnf_get_chars(datum));
340*0Sstevel@tonic-gate else {
341*0Sstevel@tonic-gate n = tnf_get_element_count(datum);
342*0Sstevel@tonic-gate for (i = 0; i < n; i++) {
343*0Sstevel@tonic-gate (void) printf("%24d ", i);
344*0Sstevel@tonic-gate describe_brief(tnf_get_element(datum, i));
345*0Sstevel@tonic-gate (void) printf("\n");
346*0Sstevel@tonic-gate }
347*0Sstevel@tonic-gate }
348*0Sstevel@tonic-gate }
349*0Sstevel@tonic-gate
350*0Sstevel@tonic-gate static void
describe_type(tnf_datum_t datum)351*0Sstevel@tonic-gate describe_type(tnf_datum_t datum)
352*0Sstevel@tonic-gate {
353*0Sstevel@tonic-gate describe_struct(datum);
354*0Sstevel@tonic-gate }
355*0Sstevel@tonic-gate
356*0Sstevel@tonic-gate static void
describe_brief(tnf_datum_t datum)357*0Sstevel@tonic-gate describe_brief(tnf_datum_t datum)
358*0Sstevel@tonic-gate {
359*0Sstevel@tonic-gate if (datum == TNF_DATUM_NULL) /* allowed */
360*0Sstevel@tonic-gate (void) printf("0x%-8x <NULL>", 0);
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate else if (tnf_is_scalar(datum))
363*0Sstevel@tonic-gate describe_scalar(datum);
364*0Sstevel@tonic-gate
365*0Sstevel@tonic-gate else if (tnf_is_record(datum)) {
366*0Sstevel@tonic-gate
367*0Sstevel@tonic-gate (void) printf("0x%-8x ",
368*0Sstevel@tonic-gate OFF(tnf_get_raw(datum))); /* common */
369*0Sstevel@tonic-gate
370*0Sstevel@tonic-gate switch (tnf_get_kind(datum)) {
371*0Sstevel@tonic-gate case TNF_K_TYPE:
372*0Sstevel@tonic-gate (void) printf("%s", tnf_type_get_name(datum));
373*0Sstevel@tonic-gate break;
374*0Sstevel@tonic-gate case TNF_K_STRING:
375*0Sstevel@tonic-gate (void) printf("\"%s\"", tnf_get_chars(datum));
376*0Sstevel@tonic-gate break;
377*0Sstevel@tonic-gate default:
378*0Sstevel@tonic-gate (void) printf("<%s>", tnf_get_type_name(datum));
379*0Sstevel@tonic-gate }
380*0Sstevel@tonic-gate } else
381*0Sstevel@tonic-gate fail(0, gettext("inline aggregate slots/elements unhandled"));
382*0Sstevel@tonic-gate }
383*0Sstevel@tonic-gate
384*0Sstevel@tonic-gate void
fail(int do_perror,char * message,...)385*0Sstevel@tonic-gate fail(int do_perror, char *message, ...)
386*0Sstevel@tonic-gate {
387*0Sstevel@tonic-gate va_list args;
388*0Sstevel@tonic-gate
389*0Sstevel@tonic-gate va_start(args, message);
390*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: "), g_cmdname);
391*0Sstevel@tonic-gate (void) vfprintf(stderr, message, args);
392*0Sstevel@tonic-gate va_end(args);
393*0Sstevel@tonic-gate if (do_perror)
394*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(": %s"), strerror(errno));
395*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("\n"));
396*0Sstevel@tonic-gate exit(EXIT_FAILURE);
397*0Sstevel@tonic-gate }
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate static void
usage(void)400*0Sstevel@tonic-gate usage(void)
401*0Sstevel@tonic-gate {
402*0Sstevel@tonic-gate (void) fprintf(stderr,
403*0Sstevel@tonic-gate gettext("Usage: %s [-r] <tnf_file> [<tnf_file> ...]\n"),
404*0Sstevel@tonic-gate g_cmdname);
405*0Sstevel@tonic-gate exit(EXIT_FAILURE);
406*0Sstevel@tonic-gate }
407