2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
14 * Copyright 2013 DEY Storage Systems, Inc.
24 #include <sys/types.h>
34 #include "localedef.h"
35 #include "parser.tab.h"
38 #define TEXT_DOMAIN "SYS_TEST"
44 static char *locname
= NULL
;
45 static char locpath
[PATH_MAX
];
50 switch (get_category()) {
56 return ("LC_COLLATE");
60 return ("LC_MESSAGES");
62 return ("LC_MONETARY");
64 return ("LC_NUMERIC");
76 (void) snprintf(locpath
, sizeof (locpath
), "%s/%s/LCL_DATA",
77 locname
, category_name());
87 (void) printf(_("Writing category %s: "), category_name());
88 (void) fflush(stdout
);
91 /* make the parent directory */
92 (void) mkdirp(dirname(category_file()), 0755);
95 * note that we have to regenerate the file name, as dirname
98 file
= fopen(category_file(), "w");
100 errf(strerror(errno
));
107 close_category(FILE *f
)
109 if (fchmod(fileno(f
), 0644) < 0) {
111 (void) unlink(category_file());
112 errf(strerror(errno
));
115 (void) unlink(category_file());
116 errf(strerror(errno
));
119 (void) fprintf(stdout
, _("done.\n"));
120 (void) fflush(stdout
);
125 * This function is used when copying the category from another
126 * locale. Note that the copy is actually performed using a hard
127 * link for efficiency.
130 copy_category(char *src
)
132 char srcpath
[PATH_MAX
];
135 (void) snprintf(srcpath
, sizeof (srcpath
), "%s/%s/LCL_DATA",
136 src
, category_name());
137 rv
= access(srcpath
, R_OK
);
138 if ((rv
!= 0) && (strchr(srcpath
, '/') == NULL
)) {
139 /* Maybe we should try the system locale */
140 (void) snprintf(srcpath
, sizeof (srcpath
),
141 "/usr/lib/locale/%s/%s/LCL_DATA", src
, category_name());
142 rv
= access(srcpath
, R_OK
);
146 errf(_("source locale data unavailable"), src
);
151 (void) printf(_("Copying category %s from %s: "),
152 category_name(), src
);
153 (void) fflush(stdout
);
156 /* make the parent directory */
157 (void) mkdirp(dirname(category_file()), 0755);
159 if (link(srcpath
, category_file()) != 0) {
160 errf(_("unable to copy locale data: %s"), strerror(errno
));
164 (void) printf(_("done.\n"));
169 putl_category(const char *s
, FILE *f
)
171 if (s
&& fputs(s
, f
) == EOF
) {
173 (void) unlink(category_file());
174 errf(strerror(errno
));
177 if (fputc('\n', f
) == EOF
) {
179 (void) unlink(category_file());
180 errf(strerror(errno
));
187 wr_category(void *buf
, size_t sz
, FILE *f
)
192 if (fwrite(buf
, sz
, 1, f
) < 1) {
194 (void) unlink(category_file());
195 errf(strerror(errno
));
206 (void) fprintf(stderr
,
207 _("Usage: localedef [options] localename\n"));
208 (void) fprintf(stderr
, ("[options] are:\n"));
209 (void) fprintf(stderr
, (" -c : ignore warnings\n"));
210 (void) fprintf(stderr
, (" -v : verbose output\n"));
211 (void) fprintf(stderr
, (" -U : ignore undefined symbols\n"));
212 (void) fprintf(stderr
, (" -f charmap : use given charmap file\n"));
213 (void) fprintf(stderr
, (" -u encoding : assume encoding\n"));
214 (void) fprintf(stderr
, (" -w widths : use screen widths file\n"));
215 (void) fprintf(stderr
, (" -i locsrc : source file for locale\n"));
220 main(int argc
, char **argv
)
238 (void) setlocale(LC_ALL
, "");
239 (void) textdomain(TEXT_DOMAIN
);
241 while ((c
= getopt(argc
, argv
, "w:i:cf:u:vU")) != -1) {
250 set_wide_encoding(optarg
);
270 if ((argc
- 1) != (optind
)) {
273 locname
= argv
[argc
- 1];
275 (void) printf(_("Processing locale %s.\n"), locname
);
280 (void) printf(_("Loading charmap %s.\n"), cfname
);
281 reset_scanner(cfname
);
287 (void) printf(_("Loading widths %s.\n"), wfname
);
288 reset_scanner(wfname
);
293 (void) printf(_("Loading POSIX portable characters.\n"));
298 reset_scanner(lfname
);
303 /* make the directory for the locale if not already present */
304 while ((dir
= opendir(locname
)) == NULL
) {
305 if ((errno
!= ENOENT
) ||
306 (mkdir(locname
, 0755) < 0)) {
307 errf(strerror(errno
));
310 (void) closedir(dir
);
312 (void) mkdirp(dirname(category_file()), 0755);
316 (void) printf(_("All done.\n"));
318 return (warnings
? 1 : 0);