usr/src/cmd/localedef/localedef.c
author Garrett D'Amore <garrett@dey-sys.com>
Tue, 27 Aug 2013 18:16:23 -0700
changeset 14265 8ae0bbd9e7cc
parent 13222 02526851ba75
permissions -rw-r--r--
2408 CJK character width handled incorrectly in terminal emulators 3019 localedef(1) manpage is pretty out of date Reviewed by: Yuri Pankov <[email protected]> Reviewed by: Lauri Tirkkonen <[email protected]> Reviewed by: Andy Stormont <[email protected]> Approved by: Gordon Ross <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     1
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     2
 * This file and its contents are supplied under the terms of the
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     3
 * Common Development and Distribution License ("CDDL"), version 1.0.
13222
02526851ba75 357 fix license on strptime.c
Garrett D'Amore <garrett@nexenta.com>
parents: 13200
diff changeset
     4
 * You may only use this file in accordance with the terms of version
02526851ba75 357 fix license on strptime.c
Garrett D'Amore <garrett@nexenta.com>
parents: 13200
diff changeset
     5
 * 1.0 of the CDDL.
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     6
 *
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     7
 * A full copy of the text of the CDDL should have accompanied this
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     8
 * source.  A copy of the CDDL is also available via the Internet at
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     9
 * http://www.illumos.org/license/CDDL.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    10
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    11
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    12
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    13
 * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
    14
 * Copyright 2013 DEY Storage Systems, Inc.
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    15
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    16
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    17
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    18
 * POSIX localedef.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    19
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    20
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    21
#include <stdio.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    22
#include <stdlib.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    23
#include <errno.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    24
#include <sys/types.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    25
#include <sys/stat.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    26
#include <string.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    27
#include <unistd.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    28
#include <libgen.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    29
#include <stddef.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    30
#include <unistd.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    31
#include <limits.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    32
#include <locale.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    33
#include <dirent.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    34
#include "localedef.h"
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    35
#include "parser.tab.h"
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    36
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    37
#ifndef	TEXT_DOMAIN
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    38
#define	TEXT_DOMAIN	"SYS_TEST"
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    39
#endif
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    40
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    41
int verbose = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    42
int undefok = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    43
int warnok = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    44
static char *locname = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    45
static char locpath[PATH_MAX];
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    46
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    47
const char *
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    48
category_name(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    49
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    50
	switch (get_category()) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    51
	case T_CHARMAP:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    52
		return ("CHARMAP");
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
    53
	case T_WIDTH:
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
    54
		return ("WIDTH");
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    55
	case T_COLLATE:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    56
		return ("LC_COLLATE");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    57
	case T_CTYPE:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    58
		return ("LC_CTYPE");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    59
	case T_MESSAGES:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    60
		return ("LC_MESSAGES");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    61
	case T_MONETARY:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    62
		return ("LC_MONETARY");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    63
	case T_NUMERIC:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    64
		return ("LC_NUMERIC");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    65
	case T_TIME:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    66
		return ("LC_TIME");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    67
	default:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    68
		INTERR;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    69
		return (NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    70
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    71
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    72
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    73
static char *
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    74
category_file(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    75
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    76
	(void) snprintf(locpath, sizeof (locpath), "%s/%s/LCL_DATA",
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    77
	    locname, category_name());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    78
	return (locpath);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    79
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    80
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    81
FILE *
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    82
open_category(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    83
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    84
	FILE *file;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    85
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    86
	if (verbose) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    87
		(void) printf(_("Writing category %s: "), category_name());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    88
		(void) fflush(stdout);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    89
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    90
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    91
	/* make the parent directory */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    92
	(void) mkdirp(dirname(category_file()), 0755);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    93
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    94
	/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    95
	 * note that we have to regenerate the file name, as dirname
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    96
	 * clobbered it.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    97
	 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    98
	file = fopen(category_file(), "w");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    99
	if (file == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   100
		errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   101
		return (NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   102
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   103
	return (file);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   104
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   105
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   106
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   107
close_category(FILE *f)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   108
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   109
	if (fchmod(fileno(f), 0644) < 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   110
		(void) fclose(f);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   111
		(void) unlink(category_file());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   112
		errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   113
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   114
	if (fclose(f) < 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   115
		(void) unlink(category_file());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   116
		errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   117
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   118
	if (verbose) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   119
		(void) fprintf(stdout, _("done.\n"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   120
		(void) fflush(stdout);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   121
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   122
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   123
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   124
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   125
 * This function is used when copying the category from another
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   126
 * locale.  Note that the copy is actually performed using a hard
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   127
 * link for efficiency.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   128
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   129
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   130
copy_category(char *src)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   131
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   132
	char	srcpath[PATH_MAX];
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   133
	int	rv;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   134
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   135
	(void) snprintf(srcpath, sizeof (srcpath), "%s/%s/LCL_DATA",
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   136
	    src, category_name());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   137
	rv = access(srcpath, R_OK);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   138
	if ((rv != 0) && (strchr(srcpath, '/') == NULL)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   139
		/* Maybe we should try the system locale */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   140
		(void) snprintf(srcpath, sizeof (srcpath),
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   141
		    "/usr/lib/locale/%s/%s/LCL_DATA", src, category_name());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   142
		rv = access(srcpath, R_OK);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   143
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   144
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   145
	if (rv != 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   146
		errf(_("source locale data unavailable"), src);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   147
		return;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   148
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   149
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   150
	if (verbose > 1) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   151
		(void) printf(_("Copying category %s from %s: "),
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   152
		    category_name(), src);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   153
		(void) fflush(stdout);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   154
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   155
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   156
	/* make the parent directory */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   157
	(void) mkdirp(dirname(category_file()), 0755);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   158
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   159
	if (link(srcpath, category_file()) != 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   160
		errf(_("unable to copy locale data: %s"), strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   161
		return;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   162
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   163
	if (verbose > 1) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   164
		(void) printf(_("done.\n"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   165
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   166
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   167
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   168
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   169
putl_category(const char *s, FILE *f)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   170
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   171
	if (s && fputs(s, f) == EOF) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   172
		(void) fclose(f);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   173
		(void) unlink(category_file());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   174
		errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   175
		return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   176
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   177
	if (fputc('\n', f) == EOF) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   178
		(void) fclose(f);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   179
		(void) unlink(category_file());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   180
		errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   181
		return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   182
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   183
	return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   184
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   185
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   186
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   187
wr_category(void *buf, size_t sz, FILE *f)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   188
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   189
	if (!sz) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   190
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   191
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   192
	if (fwrite(buf, sz, 1, f) < 1) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   193
		(void) fclose(f);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   194
		(void) unlink(category_file());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   195
		errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   196
		return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   197
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   198
	return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   199
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   201
int yyparse(void);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   202
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   203
static void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   204
usage(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   205
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   206
	(void) fprintf(stderr,
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   207
	    _("Usage: localedef [options] localename\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   208
	(void) fprintf(stderr, ("[options] are:\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   209
	(void) fprintf(stderr, ("  -c          : ignore warnings\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   210
	(void) fprintf(stderr, ("  -v          : verbose output\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   211
	(void) fprintf(stderr, ("  -U          : ignore undefined symbols\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   212
	(void) fprintf(stderr, ("  -f charmap  : use given charmap file\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   213
	(void) fprintf(stderr, ("  -u encoding : assume encoding\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   214
	(void) fprintf(stderr, ("  -w widths   : use screen widths file\n"));
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   215
	(void) fprintf(stderr, ("  -i locsrc   : source file for locale\n"));
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   216
	exit(4);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   217
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   218
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   219
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   220
main(int argc, char **argv)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   221
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   222
	int c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   223
	char *lfname = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   224
	char *cfname = NULL;
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   225
	char *wfname = NULL;
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   226
	DIR *dir;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   227
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   228
	init_charmap();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   229
	init_collate();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   230
	init_ctype();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   231
	init_messages();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   232
	init_monetary();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   233
	init_numeric();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   234
	init_time();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   235
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   236
	yydebug = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   237
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   238
	(void) setlocale(LC_ALL, "");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   239
	(void) textdomain(TEXT_DOMAIN);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   240
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   241
	while ((c = getopt(argc, argv, "w:i:cf:u:vU")) != -1) {
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   242
		switch (c) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   243
		case 'v':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   244
			verbose++;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   245
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   246
		case 'i':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   247
			lfname = optarg;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   248
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   249
		case 'u':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   250
			set_wide_encoding(optarg);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   251
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   252
		case 'f':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   253
			cfname = optarg;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   254
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   255
		case 'U':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   256
			undefok++;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   257
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   258
		case 'c':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   259
			warnok++;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   260
			break;
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   261
		case 'w':
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   262
			wfname = optarg;
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   263
			break;
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   264
		case '?':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   265
			usage();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   266
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   267
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   268
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   269
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   270
	if ((argc - 1) != (optind)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   271
		usage();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   272
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   273
	locname = argv[argc - 1];
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   274
	if (verbose) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   275
		(void) printf(_("Processing locale %s.\n"), locname);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   276
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   277
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   278
	if (cfname) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   279
		if (verbose)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   280
			(void) printf(_("Loading charmap %s.\n"), cfname);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   281
		reset_scanner(cfname);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   282
		(void) yyparse();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   283
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   284
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   285
	if (wfname) {
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   286
		if (verbose)
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   287
			(void) printf(_("Loading widths %s.\n"), wfname);
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   288
		reset_scanner(wfname);
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   289
		(void) yyparse();
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   290
	}
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   291
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   292
	if (verbose) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   293
		(void) printf(_("Loading POSIX portable characters.\n"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   294
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   295
	add_charmap_posix();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   296
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   297
	if (lfname) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   298
		reset_scanner(lfname);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   299
	} else {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   300
		reset_scanner(NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   301
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   302
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   303
	/* make the directory for the locale if not already present */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   304
	while ((dir = opendir(locname)) == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   305
		if ((errno != ENOENT) ||
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   306
		    (mkdir(locname, 0755) <  0)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   307
			errf(strerror(errno));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   308
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   309
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   310
	(void) closedir(dir);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   311
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   312
	(void) mkdirp(dirname(category_file()), 0755);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   313
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   314
	(void) yyparse();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   315
	if (verbose) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   316
		(void) printf(_("All done.\n"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   317
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   318
	return (warnings ? 1 : 0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   319
}