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 2017 Nexenta Systems, Inc.
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 delete_category(FILE *f
)
110 (void) unlink(category_file());
114 close_category(FILE *f
)
116 if (fchmod(fileno(f
), 0644) < 0 ||
118 errf(strerror(errno
));
122 (void) fprintf(stdout
, _("done.\n"));
123 (void) fflush(stdout
);
128 * This function is used when copying the category from another
129 * locale. Note that the copy is actually performed using a hard
130 * link for efficiency.
133 copy_category(char *src
)
135 char srcpath
[PATH_MAX
];
138 (void) snprintf(srcpath
, sizeof (srcpath
), "%s/%s/LCL_DATA",
139 src
, category_name());
140 rv
= access(srcpath
, R_OK
);
141 if ((rv
!= 0) && (strchr(srcpath
, '/') == NULL
)) {
142 /* Maybe we should try the system locale */
143 (void) snprintf(srcpath
, sizeof (srcpath
),
144 "/usr/lib/locale/%s/%s/LCL_DATA", src
, category_name());
145 rv
= access(srcpath
, R_OK
);
149 errf(_("source locale data unavailable"), src
);
154 (void) printf(_("Copying category %s from %s: "),
155 category_name(), src
);
156 (void) fflush(stdout
);
159 /* make the parent directory */
160 (void) mkdirp(dirname(category_file()), 0755);
162 if (link(srcpath
, category_file()) != 0) {
163 errf(_("unable to copy locale data: %s"), strerror(errno
));
167 (void) printf(_("done.\n"));
172 putl_category(const char *s
, FILE *f
)
174 if (s
&& fputs(s
, f
) == EOF
) {
175 errf(strerror(errno
));
179 if (fputc('\n', f
) == EOF
) {
180 errf(strerror(errno
));
188 wr_category(void *buf
, size_t sz
, FILE *f
)
193 if (fwrite(buf
, sz
, 1, f
) < 1) {
194 errf(strerror(errno
));
205 (void) fprintf(stderr
,
206 _("Usage: localedef [options] localename\n"));
207 (void) fprintf(stderr
, ("[options] are:\n"));
208 (void) fprintf(stderr
, (" -c : ignore warnings\n"));
209 (void) fprintf(stderr
, (" -v : verbose output\n"));
210 (void) fprintf(stderr
, (" -U : ignore undefined symbols\n"));
211 (void) fprintf(stderr
, (" -f charmap : use given charmap file\n"));
212 (void) fprintf(stderr
, (" -u encoding : assume encoding\n"));
213 (void) fprintf(stderr
, (" -w widths : use screen widths file\n"));
214 (void) fprintf(stderr
, (" -i locsrc : source file for locale\n"));
219 main(int argc
, char **argv
)
237 (void) setlocale(LC_ALL
, "");
238 (void) textdomain(TEXT_DOMAIN
);
240 while ((c
= getopt(argc
, argv
, "w:i:cf:u:vU")) != -1) {
249 set_wide_encoding(optarg
);
269 if ((argc
- 1) != (optind
)) {
272 locname
= argv
[argc
- 1];
274 (void) printf(_("Processing locale %s.\n"), locname
);
279 (void) printf(_("Loading charmap %s.\n"), cfname
);
280 reset_scanner(cfname
);
286 (void) printf(_("Loading widths %s.\n"), wfname
);
287 reset_scanner(wfname
);
292 (void) printf(_("Loading POSIX portable characters.\n"));
297 reset_scanner(lfname
);
302 /* make the directory for the locale if not already present */
303 while ((dir
= opendir(locname
)) == NULL
) {
304 if ((errno
!= ENOENT
) ||
305 (mkdir(locname
, 0755) < 0)) {
306 errf(strerror(errno
));
309 (void) closedir(dir
);
311 (void) mkdirp(dirname(category_file()), 0755);
315 (void) printf(_("All done.\n"));
317 return (warnings
? 1 : 0);