xref: /onnv-gate/usr/src/cmd/mkmsgs/mkmsgs.c (revision 0:68f95e015346)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate  * Create message files in a specific format.
35*0Sstevel@tonic-gate  * the gettxt message retrieval function must know the format of
36*0Sstevel@tonic-gate  * the data file created by this utility.
37*0Sstevel@tonic-gate  *
38*0Sstevel@tonic-gate  * 	FORMAT OF MESSAGE FILES
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate 	 __________________________
41*0Sstevel@tonic-gate 	|  Number of messages      |
42*0Sstevel@tonic-gate 	 --------------------------
43*0Sstevel@tonic-gate 	|  offset to the 1st mesg  |
44*0Sstevel@tonic-gate 	 --------------------------
45*0Sstevel@tonic-gate 	|  offset to the 2nd mesg  |
46*0Sstevel@tonic-gate 	 --------------------------
47*0Sstevel@tonic-gate 	|  offset to the 3rd mesg  |
48*0Sstevel@tonic-gate 	 --------------------------
49*0Sstevel@tonic-gate 	|          .		   |
50*0Sstevel@tonic-gate 	|	   .	           |
51*0Sstevel@tonic-gate 	|	   .		   |
52*0Sstevel@tonic-gate 	 --------------------------
53*0Sstevel@tonic-gate 	|  offset to the nth mesg  |
54*0Sstevel@tonic-gate 	 --------------------------
55*0Sstevel@tonic-gate 	|    message #1
56*0Sstevel@tonic-gate 	 --------------------------
57*0Sstevel@tonic-gate 	|    message #2
58*0Sstevel@tonic-gate 	 --------------------------
59*0Sstevel@tonic-gate 	|    message #3
60*0Sstevel@tonic-gate 	 --------------------------
61*0Sstevel@tonic-gate 		   .
62*0Sstevel@tonic-gate 		   .
63*0Sstevel@tonic-gate 		   .
64*0Sstevel@tonic-gate 	 --------------------------
65*0Sstevel@tonic-gate 	|    message #n
66*0Sstevel@tonic-gate 	 --------------------------
67*0Sstevel@tonic-gate *
68*0Sstevel@tonic-gate */
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate #include <stdio.h>
71*0Sstevel@tonic-gate #include <stdlib.h>
72*0Sstevel@tonic-gate #include <unistd.h>
73*0Sstevel@tonic-gate #include <string.h>
74*0Sstevel@tonic-gate #include <sys/types.h>
75*0Sstevel@tonic-gate #include <sys/stat.h>
76*0Sstevel@tonic-gate #include <signal.h>
77*0Sstevel@tonic-gate #include <errno.h>
78*0Sstevel@tonic-gate #include <libgen.h>
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate /*
81*0Sstevel@tonic-gate  * Definitions
82*0Sstevel@tonic-gate  */
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate #define	LINESZ	2048	/* max line in input base */
85*0Sstevel@tonic-gate #define STDERR  2
86*0Sstevel@tonic-gate #define P_locale	"/usr/lib/locale/"	/* locale info directory */
87*0Sstevel@tonic-gate #define L_locale	sizeof(P_locale)
88*0Sstevel@tonic-gate #define MESSAGES	"/LC_MESSAGES/"		/* messages category */
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate  * internal functions
92*0Sstevel@tonic-gate  */
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate static	char	*syserr(void);		/* Returns description of error */
95*0Sstevel@tonic-gate static	void	usage(void);		/* Displays valid invocations */
96*0Sstevel@tonic-gate static	int	mymkdir(char *);	/* Creates sub-directories */
97*0Sstevel@tonic-gate static	void	clean(int);		/* removes work file */
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate /*
100*0Sstevel@tonic-gate  * static variables
101*0Sstevel@tonic-gate  */
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate static	char	*cmdname;	/* Last qualifier of arg0 */
104*0Sstevel@tonic-gate static	char    *workp;		/* name of the work file */
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate int
main(argc,argv)107*0Sstevel@tonic-gate main(argc, argv)
108*0Sstevel@tonic-gate int argc;
109*0Sstevel@tonic-gate char *argv[];
110*0Sstevel@tonic-gate {
111*0Sstevel@tonic-gate 	int c;				/* contains option letter */
112*0Sstevel@tonic-gate 	char	*ifilep;		/* input file name */
113*0Sstevel@tonic-gate 	char	*ofilep;		/* output file name */
114*0Sstevel@tonic-gate 	char	*localep; 		/* locale name */
115*0Sstevel@tonic-gate 	char	*localedirp;    	/* full-path name of parent directory
116*0Sstevel@tonic-gate 				 	 * of the output file */
117*0Sstevel@tonic-gate 	char	*outfilep;		/* full-path name of output file */
118*0Sstevel@tonic-gate 	FILE *fp_inp; 			/* input file FILE pointer */
119*0Sstevel@tonic-gate 	FILE *fp_outp;			/* output file FILE pointer */
120*0Sstevel@tonic-gate 	char *bufinp, *bufworkp;	/* pointers to input and work areas */
121*0Sstevel@tonic-gate 	int  *bufoutp;			/* pointer to the output area */
122*0Sstevel@tonic-gate 	char *msgp;			/* pointer to the a message */
123*0Sstevel@tonic-gate 	int num_msgs;			/* number of messages in input file */
124*0Sstevel@tonic-gate 	int iflag;			/* -i option was specified */
125*0Sstevel@tonic-gate 	int oflag;			/* -o option was slecified */
126*0Sstevel@tonic-gate 	int nitems;			/* number of bytes to write */
127*0Sstevel@tonic-gate 	char *pathoutp;			/* full-path name of output file */
128*0Sstevel@tonic-gate 	struct stat buf;		/* buffer to stat the work file */
129*0Sstevel@tonic-gate 	unsigned size;			/* used for argument to malloc */
130*0Sstevel@tonic-gate 	int i;
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	/* Initializations */
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 	localep = (char *)NULL;
135*0Sstevel@tonic-gate 	num_msgs = 0;
136*0Sstevel@tonic-gate 	iflag   = 0;
137*0Sstevel@tonic-gate 	oflag   = 0;
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate 	/* Get name of command */
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate 	if (cmdname = strrchr(argv[0], '/'))
142*0Sstevel@tonic-gate 		++cmdname;
143*0Sstevel@tonic-gate 	else
144*0Sstevel@tonic-gate 		cmdname = argv[0];
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate 	/* Check for invalid number of arguments */
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate 	if (argc < 3 && argc > 6)
149*0Sstevel@tonic-gate 		usage();
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate 	/* Get command line options */
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "oi:")) != EOF) {
154*0Sstevel@tonic-gate 		switch (c) {
155*0Sstevel@tonic-gate 		case 'o':
156*0Sstevel@tonic-gate 			oflag++;
157*0Sstevel@tonic-gate 			break;
158*0Sstevel@tonic-gate 		case 'i':
159*0Sstevel@tonic-gate 			iflag++;
160*0Sstevel@tonic-gate 			localep = optarg;
161*0Sstevel@tonic-gate 			break;
162*0Sstevel@tonic-gate 		case '?':
163*0Sstevel@tonic-gate 			usage();
164*0Sstevel@tonic-gate 			break;
165*0Sstevel@tonic-gate 		}
166*0Sstevel@tonic-gate 	}
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate 	/* Initialize pointers to input and output file names */
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	ifilep = argv[optind];
171*0Sstevel@tonic-gate 	ofilep = argv[optind + 1];
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate 	/* check for invalid invocations */
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	if (iflag && oflag && argc != 6)
176*0Sstevel@tonic-gate 		usage();
177*0Sstevel@tonic-gate 	if (iflag && ! oflag && argc != 5)
178*0Sstevel@tonic-gate 		usage();
179*0Sstevel@tonic-gate 	if (! iflag && oflag && argc != 4)
180*0Sstevel@tonic-gate 		usage();
181*0Sstevel@tonic-gate 	if (! iflag && ! oflag && argc != 3)
182*0Sstevel@tonic-gate 		usage();
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate 	/* Construct a  full-path to the output file */
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	if (localep) {
187*0Sstevel@tonic-gate 		size = L_locale + strlen(localep) +
188*0Sstevel@tonic-gate 			 sizeof(MESSAGES) + strlen(ofilep);
189*0Sstevel@tonic-gate 		if ((pathoutp = malloc(2 * (size + 1))) == NULL) {
190*0Sstevel@tonic-gate 			(void)fprintf(stderr, "%s: malloc error (size = %d)\n",
191*0Sstevel@tonic-gate 					cmdname, size);
192*0Sstevel@tonic-gate 			exit(1);
193*0Sstevel@tonic-gate 		}
194*0Sstevel@tonic-gate 		localedirp = pathoutp + size + 1;
195*0Sstevel@tonic-gate 		(void)strcpy(pathoutp, P_locale);
196*0Sstevel@tonic-gate 		(void)strcpy(&pathoutp[L_locale - 1], localep);
197*0Sstevel@tonic-gate 		(void)strcat(pathoutp, MESSAGES);
198*0Sstevel@tonic-gate 		(void)strcpy(localedirp, pathoutp);
199*0Sstevel@tonic-gate 		(void)strcat(pathoutp, ofilep);
200*0Sstevel@tonic-gate 	}
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate 	/* Check for overwrite error conditions */
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate 	if (! oflag) {
205*0Sstevel@tonic-gate 		if (iflag) {
206*0Sstevel@tonic-gate 			if (access(pathoutp, 0) == 0) {
207*0Sstevel@tonic-gate 				(void)fprintf(stderr, "%s: Message file \"%s\" already exists;\ndid not overwrite it\n", cmdname, pathoutp);
208*0Sstevel@tonic-gate 				if (localep)
209*0Sstevel@tonic-gate 					free(pathoutp);
210*0Sstevel@tonic-gate 				exit(1);
211*0Sstevel@tonic-gate 			}
212*0Sstevel@tonic-gate 		}
213*0Sstevel@tonic-gate 		else
214*0Sstevel@tonic-gate 			if (access(ofilep, 0) == 0) {
215*0Sstevel@tonic-gate 				(void)fprintf(stderr, "%s: Message file \"%s\" already exists;\ndid not overwrite it\n", cmdname, ofilep);
216*0Sstevel@tonic-gate 				if (localep)
217*0Sstevel@tonic-gate 					free(pathoutp);
218*0Sstevel@tonic-gate 				exit(1);
219*0Sstevel@tonic-gate 			}
220*0Sstevel@tonic-gate 	}
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 	/* Open input file */
223*0Sstevel@tonic-gate 	if ((fp_inp = fopen(ifilep, "r")) == NULL) {
224*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: %s: %s\n",
225*0Sstevel@tonic-gate 			cmdname, ifilep, syserr());
226*0Sstevel@tonic-gate 		exit(1);
227*0Sstevel@tonic-gate 	}
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate 	/* Allocate buffer for input and work areas */
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate 	if ((bufinp = malloc(2 * LINESZ)) == NULL) {
232*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: malloc error (size = %d)\n",
233*0Sstevel@tonic-gate 					cmdname, 2 * LINESZ);
234*0Sstevel@tonic-gate 		exit(1);
235*0Sstevel@tonic-gate 	}
236*0Sstevel@tonic-gate 	bufworkp = bufinp + LINESZ;
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate 	if (sigset(SIGINT, SIG_IGN) == SIG_DFL)
239*0Sstevel@tonic-gate 		(void)sigset(SIGINT, clean);
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate 	/* Open work file */
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	workp = tempnam(".", "xx");
244*0Sstevel@tonic-gate 	if ((fp_outp = fopen(workp, "a+")) == NULL) {
245*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
246*0Sstevel@tonic-gate 		if (localep)
247*0Sstevel@tonic-gate 			free(pathoutp);
248*0Sstevel@tonic-gate 		free(bufinp);
249*0Sstevel@tonic-gate 		exit(1);
250*0Sstevel@tonic-gate 	}
251*0Sstevel@tonic-gate 
252*0Sstevel@tonic-gate 	/* Search for C-escape sequences in input file and
253*0Sstevel@tonic-gate 	 * replace them by the appropriate characters.
254*0Sstevel@tonic-gate 	 * The modified lines are copied to the work area
255*0Sstevel@tonic-gate 	 * and written to the work file */
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate 	for(;;) {
258*0Sstevel@tonic-gate 		if (!fgets(bufinp, LINESZ, fp_inp)) {
259*0Sstevel@tonic-gate 			if (!feof(fp_inp)) {
260*0Sstevel@tonic-gate 				(void)fprintf(stderr,"%s: %s: %s\n",
261*0Sstevel@tonic-gate 					cmdname, ifilep, syserr());
262*0Sstevel@tonic-gate 				free(bufinp);
263*0Sstevel@tonic-gate 				if (localep)
264*0Sstevel@tonic-gate 					free(pathoutp);
265*0Sstevel@tonic-gate 				exit(1);
266*0Sstevel@tonic-gate 			}
267*0Sstevel@tonic-gate 			break;
268*0Sstevel@tonic-gate 		}
269*0Sstevel@tonic-gate 		if(*(bufinp+strlen(bufinp)-1)  != '\n') {
270*0Sstevel@tonic-gate 			(void)fprintf(stderr, "%s: %s: data base file: error on line %d\n", cmdname, ifilep, num_msgs);
271*0Sstevel@tonic-gate 			free(bufinp);
272*0Sstevel@tonic-gate 			exit(1);
273*0Sstevel@tonic-gate 		}
274*0Sstevel@tonic-gate 		*(bufinp + strlen(bufinp) -1) = (char)0; /* delete newline */
275*0Sstevel@tonic-gate 		num_msgs++;
276*0Sstevel@tonic-gate 		(void)strccpy(bufworkp, bufinp);
277*0Sstevel@tonic-gate 		nitems = strlen(bufworkp) + 1;
278*0Sstevel@tonic-gate 		if (fwrite(bufworkp, sizeof(*bufworkp), nitems, fp_outp) != nitems) {
279*0Sstevel@tonic-gate 			(void)fprintf(stderr, "%s: %s: %s\n",
280*0Sstevel@tonic-gate 				cmdname, workp, syserr());
281*0Sstevel@tonic-gate 			exit(1);
282*0Sstevel@tonic-gate 		}
283*0Sstevel@tonic-gate 	}
284*0Sstevel@tonic-gate 	free(bufinp);
285*0Sstevel@tonic-gate 	(void)fclose(fp_outp);
286*0Sstevel@tonic-gate 
287*0Sstevel@tonic-gate 	/* Open and stat the work file */
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 	if ((fp_outp = fopen(workp, "r")) == NULL) {
290*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
291*0Sstevel@tonic-gate 		exit(1);
292*0Sstevel@tonic-gate 	}
293*0Sstevel@tonic-gate 	if ((stat(workp, &buf)) != 0) {
294*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
295*0Sstevel@tonic-gate 	}
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	/* Find the size of the output message file
298*0Sstevel@tonic-gate 	 * and copy the control information and the messages
299*0Sstevel@tonic-gate 	 * to the output file */
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate 	size = sizeof(int) + num_msgs * sizeof(int) + buf.st_size;
302*0Sstevel@tonic-gate 
303*0Sstevel@tonic-gate 	if ( (bufoutp = (int *)malloc((uint)size)) == NULL ) {
304*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: malloc error (size = %d)\n",
305*0Sstevel@tonic-gate 				cmdname, size);
306*0Sstevel@tonic-gate 		exit(1);
307*0Sstevel@tonic-gate 	}
308*0Sstevel@tonic-gate 	bufinp = (char *)bufoutp;
309*0Sstevel@tonic-gate 	if ( (fread(bufinp + sizeof(int) + num_msgs * sizeof(int), sizeof(*bufinp), buf.st_size, fp_outp)) != buf.st_size ) {
310*0Sstevel@tonic-gate 		free(bufinp);
311*0Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
312*0Sstevel@tonic-gate 	}
313*0Sstevel@tonic-gate 	(void) fclose(fp_outp);
314*0Sstevel@tonic-gate 	(void) unlink(workp);
315*0Sstevel@tonic-gate 	free(workp);
316*0Sstevel@tonic-gate 	msgp = bufinp + sizeof(int) + num_msgs * sizeof(int);
317*0Sstevel@tonic-gate 	*bufoutp = num_msgs;
318*0Sstevel@tonic-gate 	*(bufoutp + 1) = (bufinp + sizeof(int) + num_msgs * sizeof(int)) - bufinp;
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 	for(i = 2; i <= num_msgs; i++) {
321*0Sstevel@tonic-gate 		*(bufoutp + i) = (msgp + strlen(msgp) + 1) - bufinp;
322*0Sstevel@tonic-gate 		msgp = msgp + strlen(msgp) + 1;
323*0Sstevel@tonic-gate 	}
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate 	if (iflag) {
326*0Sstevel@tonic-gate 		outfilep = pathoutp;
327*0Sstevel@tonic-gate 		if (mymkdir(localedirp) == 0) {
328*0Sstevel@tonic-gate 			free(bufinp);
329*0Sstevel@tonic-gate 			if (localep)
330*0Sstevel@tonic-gate 				free(pathoutp);
331*0Sstevel@tonic-gate 			exit(1);
332*0Sstevel@tonic-gate 		}
333*0Sstevel@tonic-gate 	}
334*0Sstevel@tonic-gate 	else
335*0Sstevel@tonic-gate 		outfilep = ofilep;
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate 	if ((fp_outp = fopen(outfilep, "w")) == NULL) {
338*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: %s: %s\n",
339*0Sstevel@tonic-gate 				cmdname, outfilep, syserr());
340*0Sstevel@tonic-gate 		free(bufinp);
341*0Sstevel@tonic-gate 		if (localep)
342*0Sstevel@tonic-gate 			free(pathoutp);
343*0Sstevel@tonic-gate 		exit(1);
344*0Sstevel@tonic-gate 	}
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate 	if (fwrite((char *)bufinp, sizeof(*bufinp), size, fp_outp) != size) {
347*0Sstevel@tonic-gate 		(void)fprintf(stderr, "%s: %s: %s\n",
348*0Sstevel@tonic-gate 				cmdname, ofilep, syserr());
349*0Sstevel@tonic-gate 		free(bufinp);
350*0Sstevel@tonic-gate 		if (localep)
351*0Sstevel@tonic-gate 			free(pathoutp);
352*0Sstevel@tonic-gate 		exit(1);
353*0Sstevel@tonic-gate 	}
354*0Sstevel@tonic-gate 	free(bufinp);
355*0Sstevel@tonic-gate 	if (localep)
356*0Sstevel@tonic-gate 		free(pathoutp);
357*0Sstevel@tonic-gate 	return (0);
358*0Sstevel@tonic-gate }
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate /*
361*0Sstevel@tonic-gate  * syserr()
362*0Sstevel@tonic-gate  *
363*0Sstevel@tonic-gate  * Return a pointer to a system error message.
364*0Sstevel@tonic-gate  */
365*0Sstevel@tonic-gate static char *
syserr()366*0Sstevel@tonic-gate syserr()
367*0Sstevel@tonic-gate {
368*0Sstevel@tonic-gate 	return (strerror(errno));
369*0Sstevel@tonic-gate }
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate static void
usage()372*0Sstevel@tonic-gate usage()
373*0Sstevel@tonic-gate {
374*0Sstevel@tonic-gate 	(void)fprintf(stderr, "Usage: %s [-o] inputstrings outputmsgs\n",
375*0Sstevel@tonic-gate 				cmdname);
376*0Sstevel@tonic-gate 	(void)fprintf(stderr, "       %s [-o] [-i locale] inputstrings outputmsgs\n", cmdname);
377*0Sstevel@tonic-gate 	exit(1);
378*0Sstevel@tonic-gate }
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate static int
mymkdir(localdir)381*0Sstevel@tonic-gate mymkdir(localdir)
382*0Sstevel@tonic-gate char	*localdir;
383*0Sstevel@tonic-gate {
384*0Sstevel@tonic-gate 	char	*dirp;
385*0Sstevel@tonic-gate 	char	*s1 = localdir;
386*0Sstevel@tonic-gate 	char	*path;
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate 	if ((path = malloc(strlen(localdir)+1)) == NULL)
389*0Sstevel@tonic-gate 		return(0);
390*0Sstevel@tonic-gate 	*path = '\0';
391*0Sstevel@tonic-gate 	while( (dirp = strtok(s1, "/")) != NULL ) {
392*0Sstevel@tonic-gate 		s1 = (char *)NULL;
393*0Sstevel@tonic-gate 		(void)strcat(path, "/");
394*0Sstevel@tonic-gate 		(void)strcat(path, dirp);
395*0Sstevel@tonic-gate 		if (access(path, 3) == 0)
396*0Sstevel@tonic-gate 			continue;
397*0Sstevel@tonic-gate 		if (mkdir(path, 0777) == -1) {
398*0Sstevel@tonic-gate 			(void)fprintf(stderr, "%s: %s: %s\n",
399*0Sstevel@tonic-gate 					cmdname, path, syserr());
400*0Sstevel@tonic-gate 			free(path);
401*0Sstevel@tonic-gate 			return(0);
402*0Sstevel@tonic-gate 		}
403*0Sstevel@tonic-gate 	}
404*0Sstevel@tonic-gate 	free(path);
405*0Sstevel@tonic-gate 	return(1);
406*0Sstevel@tonic-gate }
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate /* ARGSUSED */
409*0Sstevel@tonic-gate static void
clean(int sig)410*0Sstevel@tonic-gate clean(int sig)
411*0Sstevel@tonic-gate {
412*0Sstevel@tonic-gate 	(void)sigset(SIGINT, SIG_IGN);
413*0Sstevel@tonic-gate 	if (workp)
414*0Sstevel@tonic-gate 		(void) unlink(workp);
415*0Sstevel@tonic-gate 	exit(1);
416*0Sstevel@tonic-gate }
417*0Sstevel@tonic-gate 
418