52static std::vector<Charmap*> charmaps;
58 static const char msg[] =
60 "\tlocaledef - generate a locale environment\n"
63 "\tlocaledef [-c][-w[###]][-f charmap_file][-i locale_defintion]\n"
66 "\tlocaledef -g [-m creation_list]\n"
67 "\t\t[-d output_dir][-r charmap_dir][-s src_dir][--ucs]\n"
70 "\tThe localedef utility sets up the language environment for the\n"
71 "\tnamed locale. localedef reads a locale definition file from\n"
72 "\tstandard input or from locale_definition file and creates a\n"
73 "\tlocale database with the name specified on the command line.\n"
76 "\tThe localedef utility recognizes the following options:\n"
78 "\t-c\tCreate output irrespective of warnings.\n"
81 "\t\tIf the locale definition uses symbolic names use charmap_file.\n"
83 "\t-i locale_definition\n"
84 "\t\tUse locale_definition as input, instead of standard input\n"
87 "\t-g\tGenerate all the locales listed in the creation list.\n"
89 "\t--ucs\tUse UCS for the internal (wchar_t) encoding."
91 "\n\t-m creation_list\n"
92 "\t\tSpecify a file that lists what combinations of charmaps and\n"
93 "\t\tsource files should be used to create a locale.\n"
96 "\t\tSpecify the directory where the character maps are located.\n"
99 "\t\tSpecify the directory where the source files are located.\n"
102 "\t\tSpecify the directory where the generated locale database\n"
103 "\t\tfiles should be placed.\n"
105 "\t-w\tDisable all warning messages.\n"
108 "\t\tDisable warning number ###.\n"
110 "\t--notes\tEnable notes (informational messages).\n"
112 "\t--help\tPrint out this message.\n";
120 std::string std_cmap,
122 std::string std_locale,
123 bool force_output,
bool use_ucs,
124 bool no_position,
bool link_aliases)
127 std::string lname (std_src);
128 std::string cname (std_cmap);
136 if (lname.find(
'.') != std::string::npos)
137 lname = lname.substr(0, lname.find(
'.'));
138 if (cname.find(
'.') != std::string::npos)
139 cname = cname.substr(0, cname.find(
'.'));
148 std::string enc_C_locale;
150#ifdef _RWSTD_NO_ISO_10646_WCHAR_T
158 if (enc_C_locale.empty ()) {
161 std::setlocale (
LC_ALL, enc_C_locale.c_str ());
166 if (std_cmap.empty ())
167 std_cmap =
"ISO-8859-1";
170 std::string utf8_cname(
"UTF-8");
175 bool is_utf8 =
false;
176 StringVector::iterator
pos = utf8_aliases.begin();
177 for (;
pos != utf8_aliases.end ();
pos++)
185 std::vector <Charmap*>::iterator charmaps_it = charmaps.begin();
186 for (; charmaps_it != charmaps.end(); charmaps_it++){
187 if ((*charmaps_it)->get_full_charmap_name() == std_cmap) {
188 charmap_p = *charmaps_it;
194 if (0 == charmap_p) {
197 "processing character set description file %s\n",
200 charmap_p =
new Charmap (enc_C_locale.c_str (),
202 is_utf8,
true,
true, use_ucs);
203 charmaps.push_back (charmap_p);
207 bool def_error =
false;
210 "processing locale definition file %s\n", std_src.c_str ());
212 Def def (std_src.c_str (), (outdir + std_locale).c_str (),
213 *charmap_p, no_position);
217 def.process_input ();
224 std::string locale_dir (outdir + std_locale);
230 def.write_codecvt (locale_dir);
235 if (!force_output && def.warnings_occurred_) {
236 std::cerr <<
"Warnings occurred - No output produced\n";
242 def.write_ctype (locale_dir);
245 def.write_codecvt (locale_dir);
248 def.write_monetary (locale_dir);
251 def.write_numeric (locale_dir);
254 def.write_time (locale_dir);
257 def.write_collate (locale_dir);
262 def.write_messages (locale_dir);
267 if (C_locales.empty ())
270#if !defined (_WIN32) && !defined (__CYGWIN__)
272 if (link_aliases ==
false)
276 StringVector::iterator it = C_locales.begin ();
277 for (; it != C_locales.end (); it++) {
279 if (*it == std_locale)
291generate_locales (
const char* map_name,
const char* ,
292 const char* charmap_dir,
const char* src_dir,
293 const char* output_dir,
bool use_ucs,
294 bool no_position,
bool link_aliases)
296 std::ifstream
f (map_name);
300 "the generation list '%s' "
301 "could not be opened\n", map_name);
311 std::string lname =
s1.substr (0,
s1.find(
'.'));
312 std::string cname =
s2.substr (0,
s2.find(
'.'));
315 std::string std_locale(lname +
"." + cname);
318 std::cout <<
"creating locale " << std_locale <<
'\n';
321 (std::string(charmap_dir) +
s2),
322 std::string (output_dir), std_locale,
323 true, use_ucs, no_position, link_aliases);
326 catch (
const std::ios::failure& error) {
327 std::cerr <<
"I/O exception " <<
error.what() <<
'\n';
330 std::cerr <<
"Unable to create locale " << std_locale
331 <<
" : " <<
e.what () <<
'\n';
334 std::cerr <<
"ERROR: " <<
error.what() <<
'\n';
337 std::cerr <<
"Unable to create locale " << std_locale
367process_command_line (
ProgramOptions *opts,
int argc,
char* argv[])
384 for (
i = 1;
i < argc &&
'-' == argv [
i][0]; ++
i) {
386 switch (argv [
i][1]) {
433 issue_diag (std::atoi (argv [
i] + 2),
false, 0, 0);
443 if (0 == std::strcmp (argv [
i] + 2,
"help")) {
448 if (0 == std::strcmp (argv [
i] + 2,
"ucs")) {
453 else if (0 == std::strcmp (argv [
i] + 2,
"no_position")) {
457 else if (0 == std::strcmp (argv [
i] + 2,
"aliases")) {
461 else if (0 == std::strcmp (argv [
i] + 2,
"notes")) {
480 "option %s requires a string argument\n",
"-m");
485 "option %s requires a string argument\n",
"-r");
490 "option %s requires a string argument\n",
"-s");
495 "option %s requires a string argument\n",
"-d");
509 if (0 == argv [
i] && !opts->
gen) {
517 "extra command line arguments after %s\n", argv [
i]);
528 if (!process_command_line (&opts, argc, argv))
548 std::string std_outdir (
"");
562 std_outdir, std_locale,
575int main (
int argc,
char *argv[])
581 if (1 < argc && 0 == std::strcmp (argv [1],
"--locale-mode")) {
587 for (
int i = 2; argv [
i]; ++
i)
588 argv [
i - 1] = argv [
i];
599 catch (
const std::ios::failure& error) {
600 std::cerr <<
"Error: I/O exception: " << error.what () <<
'\n';
607 std::cerr <<
"Error: " << error.what () <<
'\n';
611 std::cerr <<
"Error: unknown exception\n";
const char *const errors[]
const char * create_locale()
void get_same_encoding_C_locale(const std::string &lname, const std::string &cname, StringVector &libc_locales)
void get_cname_aliases(const std::string &name, StringVector &aliases)
int ci_compare(const char *s1, const char *s2)
std::string get_C_encoding_locale(const std::string &codeset)
std::vector< std::string > StringVector
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
int localedef_main(int argc, char *argv[])
int locale_main(int, char *[])
@ error
throw a parse_error exception in case of a tag
void create_symlink(const std::string &dir, const std::string &xname, const std::string &sname)
int makedir(const char *name)
const char * program_name
const char * charmap_name