17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
30*2a8bcb4eSToomas Soome /*
317c478bd9Sstevel@tonic-gate * Create message files in a specific format.
327c478bd9Sstevel@tonic-gate * the gettxt message retrieval function must know the format of
337c478bd9Sstevel@tonic-gate * the data file created by this utility.
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * FORMAT OF MESSAGE FILES
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate __________________________
387c478bd9Sstevel@tonic-gate | Number of messages |
397c478bd9Sstevel@tonic-gate --------------------------
407c478bd9Sstevel@tonic-gate | offset to the 1st mesg |
417c478bd9Sstevel@tonic-gate --------------------------
427c478bd9Sstevel@tonic-gate | offset to the 2nd mesg |
437c478bd9Sstevel@tonic-gate --------------------------
447c478bd9Sstevel@tonic-gate | offset to the 3rd mesg |
457c478bd9Sstevel@tonic-gate --------------------------
467c478bd9Sstevel@tonic-gate | . |
477c478bd9Sstevel@tonic-gate | . |
487c478bd9Sstevel@tonic-gate | . |
497c478bd9Sstevel@tonic-gate --------------------------
507c478bd9Sstevel@tonic-gate | offset to the nth mesg |
517c478bd9Sstevel@tonic-gate --------------------------
527c478bd9Sstevel@tonic-gate | message #1
537c478bd9Sstevel@tonic-gate --------------------------
547c478bd9Sstevel@tonic-gate | message #2
557c478bd9Sstevel@tonic-gate --------------------------
567c478bd9Sstevel@tonic-gate | message #3
577c478bd9Sstevel@tonic-gate --------------------------
587c478bd9Sstevel@tonic-gate .
597c478bd9Sstevel@tonic-gate .
607c478bd9Sstevel@tonic-gate .
617c478bd9Sstevel@tonic-gate --------------------------
627c478bd9Sstevel@tonic-gate | message #n
637c478bd9Sstevel@tonic-gate --------------------------
647c478bd9Sstevel@tonic-gate *
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #include <stdio.h>
687c478bd9Sstevel@tonic-gate #include <stdlib.h>
697c478bd9Sstevel@tonic-gate #include <unistd.h>
707c478bd9Sstevel@tonic-gate #include <string.h>
717c478bd9Sstevel@tonic-gate #include <sys/types.h>
727c478bd9Sstevel@tonic-gate #include <sys/stat.h>
737c478bd9Sstevel@tonic-gate #include <signal.h>
747c478bd9Sstevel@tonic-gate #include <errno.h>
757c478bd9Sstevel@tonic-gate #include <libgen.h>
767c478bd9Sstevel@tonic-gate
77*2a8bcb4eSToomas Soome /*
787c478bd9Sstevel@tonic-gate * Definitions
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate #define LINESZ 2048 /* max line in input base */
827c478bd9Sstevel@tonic-gate #define STDERR 2
837c478bd9Sstevel@tonic-gate #define P_locale "/usr/lib/locale/" /* locale info directory */
847c478bd9Sstevel@tonic-gate #define L_locale sizeof(P_locale)
857c478bd9Sstevel@tonic-gate #define MESSAGES "/LC_MESSAGES/" /* messages category */
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate * internal functions
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate static char *syserr(void); /* Returns description of error */
927c478bd9Sstevel@tonic-gate static void usage(void); /* Displays valid invocations */
937c478bd9Sstevel@tonic-gate static int mymkdir(char *); /* Creates sub-directories */
947c478bd9Sstevel@tonic-gate static void clean(int); /* removes work file */
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate * static variables
987c478bd9Sstevel@tonic-gate */
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate static char *cmdname; /* Last qualifier of arg0 */
1017c478bd9Sstevel@tonic-gate static char *workp; /* name of the work file */
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate int
main(argc,argv)1047c478bd9Sstevel@tonic-gate main(argc, argv)
1057c478bd9Sstevel@tonic-gate int argc;
1067c478bd9Sstevel@tonic-gate char *argv[];
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate int c; /* contains option letter */
1097c478bd9Sstevel@tonic-gate char *ifilep; /* input file name */
1107c478bd9Sstevel@tonic-gate char *ofilep; /* output file name */
1117c478bd9Sstevel@tonic-gate char *localep; /* locale name */
1127c478bd9Sstevel@tonic-gate char *localedirp; /* full-path name of parent directory
1137c478bd9Sstevel@tonic-gate * of the output file */
1147c478bd9Sstevel@tonic-gate char *outfilep; /* full-path name of output file */
1157c478bd9Sstevel@tonic-gate FILE *fp_inp; /* input file FILE pointer */
1167c478bd9Sstevel@tonic-gate FILE *fp_outp; /* output file FILE pointer */
1177c478bd9Sstevel@tonic-gate char *bufinp, *bufworkp; /* pointers to input and work areas */
1187c478bd9Sstevel@tonic-gate int *bufoutp; /* pointer to the output area */
1197c478bd9Sstevel@tonic-gate char *msgp; /* pointer to the a message */
1207c478bd9Sstevel@tonic-gate int num_msgs; /* number of messages in input file */
1217c478bd9Sstevel@tonic-gate int iflag; /* -i option was specified */
1227c478bd9Sstevel@tonic-gate int oflag; /* -o option was slecified */
1237c478bd9Sstevel@tonic-gate int nitems; /* number of bytes to write */
1247c478bd9Sstevel@tonic-gate char *pathoutp; /* full-path name of output file */
1257c478bd9Sstevel@tonic-gate struct stat buf; /* buffer to stat the work file */
1267c478bd9Sstevel@tonic-gate unsigned size; /* used for argument to malloc */
127*2a8bcb4eSToomas Soome int i;
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /* Initializations */
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate localep = (char *)NULL;
1327c478bd9Sstevel@tonic-gate num_msgs = 0;
1337c478bd9Sstevel@tonic-gate iflag = 0;
1347c478bd9Sstevel@tonic-gate oflag = 0;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /* Get name of command */
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate if (cmdname = strrchr(argv[0], '/'))
1397c478bd9Sstevel@tonic-gate ++cmdname;
1407c478bd9Sstevel@tonic-gate else
1417c478bd9Sstevel@tonic-gate cmdname = argv[0];
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate /* Check for invalid number of arguments */
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate if (argc < 3 && argc > 6)
1467c478bd9Sstevel@tonic-gate usage();
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate /* Get command line options */
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "oi:")) != EOF) {
1517c478bd9Sstevel@tonic-gate switch (c) {
1527c478bd9Sstevel@tonic-gate case 'o':
1537c478bd9Sstevel@tonic-gate oflag++;
1547c478bd9Sstevel@tonic-gate break;
1557c478bd9Sstevel@tonic-gate case 'i':
1567c478bd9Sstevel@tonic-gate iflag++;
1577c478bd9Sstevel@tonic-gate localep = optarg;
1587c478bd9Sstevel@tonic-gate break;
1597c478bd9Sstevel@tonic-gate case '?':
1607c478bd9Sstevel@tonic-gate usage();
1617c478bd9Sstevel@tonic-gate break;
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate /* Initialize pointers to input and output file names */
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate ifilep = argv[optind];
1687c478bd9Sstevel@tonic-gate ofilep = argv[optind + 1];
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate /* check for invalid invocations */
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate if (iflag && oflag && argc != 6)
1737c478bd9Sstevel@tonic-gate usage();
1747c478bd9Sstevel@tonic-gate if (iflag && ! oflag && argc != 5)
1757c478bd9Sstevel@tonic-gate usage();
1767c478bd9Sstevel@tonic-gate if (! iflag && oflag && argc != 4)
1777c478bd9Sstevel@tonic-gate usage();
1787c478bd9Sstevel@tonic-gate if (! iflag && ! oflag && argc != 3)
1797c478bd9Sstevel@tonic-gate usage();
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate /* Construct a full-path to the output file */
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate if (localep) {
1847c478bd9Sstevel@tonic-gate size = L_locale + strlen(localep) +
1857c478bd9Sstevel@tonic-gate sizeof(MESSAGES) + strlen(ofilep);
1867c478bd9Sstevel@tonic-gate if ((pathoutp = malloc(2 * (size + 1))) == NULL) {
1877c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: malloc error (size = %d)\n",
1887c478bd9Sstevel@tonic-gate cmdname, size);
1897c478bd9Sstevel@tonic-gate exit(1);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate localedirp = pathoutp + size + 1;
1927c478bd9Sstevel@tonic-gate (void)strcpy(pathoutp, P_locale);
1937c478bd9Sstevel@tonic-gate (void)strcpy(&pathoutp[L_locale - 1], localep);
1947c478bd9Sstevel@tonic-gate (void)strcat(pathoutp, MESSAGES);
1957c478bd9Sstevel@tonic-gate (void)strcpy(localedirp, pathoutp);
1967c478bd9Sstevel@tonic-gate (void)strcat(pathoutp, ofilep);
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate /* Check for overwrite error conditions */
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate if (! oflag) {
2027c478bd9Sstevel@tonic-gate if (iflag) {
2037c478bd9Sstevel@tonic-gate if (access(pathoutp, 0) == 0) {
2047c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: Message file \"%s\" already exists;\ndid not overwrite it\n", cmdname, pathoutp);
2057c478bd9Sstevel@tonic-gate if (localep)
2067c478bd9Sstevel@tonic-gate free(pathoutp);
2077c478bd9Sstevel@tonic-gate exit(1);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate }
210*2a8bcb4eSToomas Soome else
2117c478bd9Sstevel@tonic-gate if (access(ofilep, 0) == 0) {
2127c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: Message file \"%s\" already exists;\ndid not overwrite it\n", cmdname, ofilep);
2137c478bd9Sstevel@tonic-gate if (localep)
2147c478bd9Sstevel@tonic-gate free(pathoutp);
2157c478bd9Sstevel@tonic-gate exit(1);
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate }
218*2a8bcb4eSToomas Soome
2197c478bd9Sstevel@tonic-gate /* Open input file */
2207c478bd9Sstevel@tonic-gate if ((fp_inp = fopen(ifilep, "r")) == NULL) {
2217c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n",
2227c478bd9Sstevel@tonic-gate cmdname, ifilep, syserr());
2237c478bd9Sstevel@tonic-gate exit(1);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /* Allocate buffer for input and work areas */
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate if ((bufinp = malloc(2 * LINESZ)) == NULL) {
2297c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: malloc error (size = %d)\n",
2307c478bd9Sstevel@tonic-gate cmdname, 2 * LINESZ);
2317c478bd9Sstevel@tonic-gate exit(1);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate bufworkp = bufinp + LINESZ;
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate if (sigset(SIGINT, SIG_IGN) == SIG_DFL)
2367c478bd9Sstevel@tonic-gate (void)sigset(SIGINT, clean);
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /* Open work file */
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate workp = tempnam(".", "xx");
2417c478bd9Sstevel@tonic-gate if ((fp_outp = fopen(workp, "a+")) == NULL) {
2427c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
2437c478bd9Sstevel@tonic-gate if (localep)
2447c478bd9Sstevel@tonic-gate free(pathoutp);
2457c478bd9Sstevel@tonic-gate free(bufinp);
2467c478bd9Sstevel@tonic-gate exit(1);
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate
249*2a8bcb4eSToomas Soome /* Search for C-escape sequences in input file and
2507c478bd9Sstevel@tonic-gate * replace them by the appropriate characters.
2517c478bd9Sstevel@tonic-gate * The modified lines are copied to the work area
2527c478bd9Sstevel@tonic-gate * and written to the work file */
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate for(;;) {
2557c478bd9Sstevel@tonic-gate if (!fgets(bufinp, LINESZ, fp_inp)) {
2567c478bd9Sstevel@tonic-gate if (!feof(fp_inp)) {
2577c478bd9Sstevel@tonic-gate (void)fprintf(stderr,"%s: %s: %s\n",
2587c478bd9Sstevel@tonic-gate cmdname, ifilep, syserr());
2597c478bd9Sstevel@tonic-gate free(bufinp);
2607c478bd9Sstevel@tonic-gate if (localep)
2617c478bd9Sstevel@tonic-gate free(pathoutp);
2627c478bd9Sstevel@tonic-gate exit(1);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate break;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate if(*(bufinp+strlen(bufinp)-1) != '\n') {
2677c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: data base file: error on line %d\n", cmdname, ifilep, num_msgs);
2687c478bd9Sstevel@tonic-gate free(bufinp);
2697c478bd9Sstevel@tonic-gate exit(1);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate *(bufinp + strlen(bufinp) -1) = (char)0; /* delete newline */
2727c478bd9Sstevel@tonic-gate num_msgs++;
2737c478bd9Sstevel@tonic-gate (void)strccpy(bufworkp, bufinp);
2747c478bd9Sstevel@tonic-gate nitems = strlen(bufworkp) + 1;
2757c478bd9Sstevel@tonic-gate if (fwrite(bufworkp, sizeof(*bufworkp), nitems, fp_outp) != nitems) {
2767c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n",
2777c478bd9Sstevel@tonic-gate cmdname, workp, syserr());
2787c478bd9Sstevel@tonic-gate exit(1);
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate free(bufinp);
2827c478bd9Sstevel@tonic-gate (void)fclose(fp_outp);
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /* Open and stat the work file */
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate if ((fp_outp = fopen(workp, "r")) == NULL) {
2877c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
2887c478bd9Sstevel@tonic-gate exit(1);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate if ((stat(workp, &buf)) != 0) {
2917c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate
294*2a8bcb4eSToomas Soome /* Find the size of the output message file
2957c478bd9Sstevel@tonic-gate * and copy the control information and the messages
2967c478bd9Sstevel@tonic-gate * to the output file */
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate size = sizeof(int) + num_msgs * sizeof(int) + buf.st_size;
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate if ( (bufoutp = (int *)malloc((uint)size)) == NULL ) {
3017c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: malloc error (size = %d)\n",
3027c478bd9Sstevel@tonic-gate cmdname, size);
3037c478bd9Sstevel@tonic-gate exit(1);
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate bufinp = (char *)bufoutp;
3067c478bd9Sstevel@tonic-gate if ( (fread(bufinp + sizeof(int) + num_msgs * sizeof(int), sizeof(*bufinp), buf.st_size, fp_outp)) != buf.st_size ) {
3077c478bd9Sstevel@tonic-gate free(bufinp);
3087c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s: %s\n", cmdname, workp, syserr());
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate (void) fclose(fp_outp);
3117c478bd9Sstevel@tonic-gate (void) unlink(workp);
3127c478bd9Sstevel@tonic-gate free(workp);
3137c478bd9Sstevel@tonic-gate msgp = bufinp + sizeof(int) + num_msgs * sizeof(int);
3147c478bd9Sstevel@tonic-gate *bufoutp = num_msgs;
3157c478bd9Sstevel@tonic-gate *(bufoutp + 1) = (bufinp + sizeof(int) + num_msgs * sizeof(int)) - bufinp;
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate for(i = 2; i <= num_msgs; i++) {
3187c478bd9Sstevel@tonic-gate *(bufoutp + i) = (msgp + strlen(msgp) + 1) - bufinp;
3197c478bd9Sstevel@tonic-gate msgp = msgp + strlen(msgp) + 1;
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
322*2a8bcb4eSToomas Soome if (iflag) {
3237c478bd9Sstevel@tonic-gate outfilep = pathoutp;
3247c478bd9Sstevel@tonic-gate if (mymkdir(localedirp) == 0) {
3257c478bd9Sstevel@tonic-gate free(bufinp);
3267c478bd9Sstevel@tonic-gate if (localep)
3277c478bd9Sstevel@tonic-gate free(pathoutp);
3287c478bd9Sstevel@tonic-gate exit(1);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate else
3327c478bd9Sstevel@tonic-gate outfilep = ofilep;
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate if ((fp_outp = fopen(outfilep, "w")) == NULL) {
3357c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n",
3367c478bd9Sstevel@tonic-gate cmdname, outfilep, syserr());
3377c478bd9Sstevel@tonic-gate free(bufinp);
3387c478bd9Sstevel@tonic-gate if (localep)
3397c478bd9Sstevel@tonic-gate free(pathoutp);
3407c478bd9Sstevel@tonic-gate exit(1);
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate if (fwrite((char *)bufinp, sizeof(*bufinp), size, fp_outp) != size) {
3447c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "%s: %s: %s\n",
3457c478bd9Sstevel@tonic-gate cmdname, ofilep, syserr());
3467c478bd9Sstevel@tonic-gate free(bufinp);
3477c478bd9Sstevel@tonic-gate if (localep)
3487c478bd9Sstevel@tonic-gate free(pathoutp);
3497c478bd9Sstevel@tonic-gate exit(1);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate free(bufinp);
3527c478bd9Sstevel@tonic-gate if (localep)
3537c478bd9Sstevel@tonic-gate free(pathoutp);
3547c478bd9Sstevel@tonic-gate return (0);
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate /*
3587c478bd9Sstevel@tonic-gate * syserr()
3597c478bd9Sstevel@tonic-gate *
3607c478bd9Sstevel@tonic-gate * Return a pointer to a system error message.
3617c478bd9Sstevel@tonic-gate */
3627c478bd9Sstevel@tonic-gate static char *
syserr()3637c478bd9Sstevel@tonic-gate syserr()
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate return (strerror(errno));
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate static void
usage()3697c478bd9Sstevel@tonic-gate usage()
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate (void)fprintf(stderr, "Usage: %s [-o] inputstrings outputmsgs\n",
3727c478bd9Sstevel@tonic-gate cmdname);
3737c478bd9Sstevel@tonic-gate (void)fprintf(stderr, " %s [-o] [-i locale] inputstrings outputmsgs\n", cmdname);
3747c478bd9Sstevel@tonic-gate exit(1);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate static int
mymkdir(localdir)3787c478bd9Sstevel@tonic-gate mymkdir(localdir)
3797c478bd9Sstevel@tonic-gate char *localdir;
3807c478bd9Sstevel@tonic-gate {
3817c478bd9Sstevel@tonic-gate char *dirp;
3827c478bd9Sstevel@tonic-gate char *s1 = localdir;
3837c478bd9Sstevel@tonic-gate char *path;
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate if ((path = malloc(strlen(localdir)+1)) == NULL)
3867c478bd9Sstevel@tonic-gate return(0);
3877c478bd9Sstevel@tonic-gate *path = '\0';
3887c478bd9Sstevel@tonic-gate while( (dirp = strtok(s1, "/")) != NULL ) {
3897c478bd9Sstevel@tonic-gate s1 = (char *)NULL;
3907c478bd9Sstevel@tonic-gate (void)strcat(path, "/");
3917c478bd9Sstevel@tonic-gate (void)strcat(path, dirp);
3927c478bd9Sstevel@tonic-gate if (access(path, 3) == 0)
3937c478bd9Sstevel@tonic-gate continue;
3947c478bd9Sstevel@tonic-gate if (mkdir(path, 0777) == -1) {
395*2a8bcb4eSToomas Soome (void)fprintf(stderr, "%s: %s: %s\n",
3967c478bd9Sstevel@tonic-gate cmdname, path, syserr());
3977c478bd9Sstevel@tonic-gate free(path);
3987c478bd9Sstevel@tonic-gate return(0);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate free(path);
4027c478bd9Sstevel@tonic-gate return(1);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate /* ARGSUSED */
4067c478bd9Sstevel@tonic-gate static void
clean(int sig)4077c478bd9Sstevel@tonic-gate clean(int sig)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate (void)sigset(SIGINT, SIG_IGN);
4107c478bd9Sstevel@tonic-gate if (workp)
4117c478bd9Sstevel@tonic-gate (void) unlink(workp);
4127c478bd9Sstevel@tonic-gate exit(1);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate
415