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