31#if defined (__linux__) && !defined (_XOPEN_SOURCE)
33# define _XOPEN_SOURCE 500
40# pragma diag_suppress 450
43#include _RWSTD_SYS_TYPES_H
45#if _RWSTD_PATH_SEP == '/'
50# define LS_1 "dir /B /A:D "
56# ifndef _RWSTD_NO_ICONV
59# ifndef _RWSTD_NO_NL_LANGINFO
96# ifdef _RWSTD_LC_MESSAGES
97# define LC_MESSAGES _RWSTD_LC_MESSAGES
99# define LC_MESSAGES -1
107static bool print_sect_names =
false;
112static bool print_keywords =
false;
117static bool decode =
false;
122static bool posix_output =
true;
127static bool use_pcs =
false;
129static bool is_utf8 =
true;
132static const _RW::__rw_codecvt_t* codecvt_st = 0;
133static const _RW::__rw_collate_t* collate_st = 0;
134static const _RW::__rw_ctype_t* ctype_st = 0;
135static const _RW::__rw_time_t* time_st = 0;
136static const _RW::__rw_num_t* num_st = 0;
137static const _RW::__rw_mon_t* mon_st = 0;
138static const _RW::__rw_punct_t* num_punct_st = 0;
139static const _RW::__rw_punct_t* mon_punct_st = 0;
140static const _RW::__rw_messages_t* messages_st = 0;
143static const char sect_lc_all[] =
"LC_ALL";
144static const char sect_lc_collate[] =
"LC_COLLATE";
145static const char sect_lc_ctype[] =
"LC_CTYPE";
146static const char sect_lc_messages[] =
"LC_MESSAGES";
147static const char sect_lc_monetary[] =
"LC_MONETARY";
148static const char sect_lc_numeric[] =
"LC_NUMERIC";
149static const char sect_lc_time[] =
"LC_TIME";
152#define MAX_LINE_LEN 50
163 if (nbytes !=
size) {
166 "invalid size at address %p: %u, expected %u\n",
170 "invalid address: %p (%u bytes)\n",
addr, nbytes);
183 const std::size_t first_byte =
memchk (
str, 1);
187 "invalid string address: %p\n",
str);
190 "invalid string at %p: no terminating NUL\n",
str);
207 const char *cat_name,
const char *codeset_name)
211 static const char*
const all_val = std::getenv (
"LC_ALL");
212 static const char* lang_val = std::getenv (
"LANG");
219 const char* env_val = all_val;
220 if (!all_val ||
'\0' == *all_val) {
221 env_val = cat_name ? std::getenv (cat_name) :
"";
228 if (std::strcmp (env_val,
"C") && std::strcmp (env_val,
"POSIX")) {
231 std::string loc_path;
240 loc_path = loc_path_root;
244 loc_path = std::string (env_val, slash - env_val);
252 const int fd =
open (loc_path.c_str (), O_RDONLY);
255 if (fd != -1 && 0 == fstat (fd, &st)) {
260 void*
const ret = mmap (0, st.st_size, PROT_READ | PROT_WRITE,
266 HANDLE file = CreateFile (loc_path.c_str (), GENERIC_READ,
268 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
271 HANDLE mapping = CreateFileMapping (file, 0, PAGE_READONLY,
274 void*
const ret = MapViewOfFile (mapping, FILE_MAP_READ, 0,
287template <
class FacetData>
290 const char *cat_name,
const char *codeset_name,
293 const void*
const ptr =
294 init_struct (loc_path_root, cat_name, codeset_name);
297 return static_cast<const FacetData*
>(
ptr);
306 std::string loc_path_root;
310 const char*
const root = std::getenv (
"RWSTD_LOCALE_ROOT");
312 loc_path_root = root ? root :
".";
317 const char *codeset = 0;
326 const char *section = 0;
329 collate_st =
init_section (loc_path_root, sect_lc_collate, 0,
330 (_RW::__rw_collate_t*)0);
333 validate (collate_st->codeset_name ());
335 codeset = collate_st->codeset_name ();
336 section = sect_lc_collate;
340 ctype_st =
init_section (loc_path_root, sect_lc_ctype, 0,
341 (_RW::__rw_ctype_t*)0);
344 validate (ctype_st->codeset_name ());
347 if (std::strcmp (codeset, ctype_st->codeset_name ()))
351 codeset = ctype_st->codeset_name ();
352 section = sect_lc_ctype;
357 mon_punct_st =
init_section (loc_path_root, sect_lc_monetary, 0,
358 (_RW::__rw_punct_t*)0);
360 if (0 != mon_punct_st) {
362 mon_punct_st->get_ext());
370 if (std::strcmp (codeset, mon_st->codeset_name ()))
374 codeset = mon_st->codeset_name ();
375 section = sect_lc_monetary;
380 num_punct_st =
init_section (loc_path_root, sect_lc_numeric, 0,
381 (_RW::__rw_punct_t*)0);
382 if (0 != num_punct_st) {
384 num_punct_st->get_ext());
392 if (std::strcmp (codeset, num_st->codeset_name ()))
396 codeset = num_st->codeset_name ();
397 section = sect_lc_numeric;
403 (_RW::__rw_time_t*)0);
405 validate (time_st->codeset_name ());
408 if (std::strcmp (codeset, time_st->codeset_name ()))
412 codeset = time_st->codeset_name ();
413 section = sect_lc_time;
418 messages_st =
init_section (loc_path_root, sect_lc_messages, 0,
419 (_RW::__rw_messages_t*)0);
422 validate (messages_st->codeset_name ());
425 if (std::strcmp (codeset, messages_st->codeset_name ()))
429 codeset = messages_st->codeset_name ();
430 section = sect_lc_messages;
436 codecvt_st =
init_section (loc_path_root, section, codeset,
437 (_RW::__rw_codecvt_t*)0);
443set_locale (
int lc_cat,
const char *locname,
const std::string &charmap_name)
449 locname = std::setlocale (lc_cat, locname);
454 std::string encoding (charmap_name.substr (0, charmap_name.rfind (
'.')));
456 std::vector<std::string> aliases;
459 std::vector<std::string>::iterator
pos;
461 for (
pos = aliases.begin(); !is_utf8 &&
pos != aliases.end();
pos++)
467 for (; *names; names += std::strlen (names) + 1) {
469 if (0 != std::setlocale (
LC_CTYPE, names)) {
471 const char*
const codeset = nl_langinfo (CODESET);
473 for (
pos = aliases.begin ();
pos != aliases.end (); ++
pos)
488get_charmap (
int lc_cat)
493 static const char*
const lang = std::getenv (
"LANG");
494 static const char*
const lc_all = std::getenv (sect_lc_all);
495 static const char*
const lc_collate = std::getenv (sect_lc_collate);
496 static const char*
const lc_ctype = std::getenv (sect_lc_ctype);
497 static const char*
const lc_messages = std::getenv (sect_lc_messages);
498 static const char*
const lc_monetary = std::getenv (sect_lc_monetary);
499 static const char*
const lc_numeric = std::getenv (sect_lc_numeric);
500 static const char*
const lc_time = std::getenv (sect_lc_time);
502 static const Charmap* cmaps [6];
503 static bool cmaps_tried [
sizeof cmaps /
sizeof *cmaps];
505 const char* charmap = 0;
506 const char* locale = 0;
513 charmap = collate_st ? collate_st->charmap_name () :
"";
519 charmap = ctype_st ? ctype_st->charmap_name () :
"";
525 charmap = messages_st ? messages_st->charmap_name () :
"";
526 locale = lc_messages;
531 charmap = mon_st ? mon_st->charmap_name () :
"";
532 locale = lc_monetary;
537 charmap = num_st ? num_st->charmap_name () :
"";
543 charmap = time_st ? time_st->charmap_name () :
"";
548 default:
assert (!
"bad LC_XXX constant");
554 if (*cmap && (*cmap)->get_charmap_name () == charmap)
557 if (cmaps_tried [cmap - cmaps])
560 cmaps_tried [cmap - cmaps] =
true;
563 if (lc_all && *lc_all)
568 locale = lang ? lang :
"POSIX";
570 set_locale (lc_cat, locale, charmap);
573 static const char*
const src_root = std::getenv (
"RWSTD_SRC_ROOT");
576 static int warning_issued = 0;
577 if (0 == warning_issued++)
580 else if (
'\0' == *charmap) {
581 static int warning_issued = 0;
582 if (0 == warning_issued++)
586 std::string charmap_path = src_root;
589 charmap_path +=
"charmaps";
591 charmap_path += charmap;
594 std::string std_encoding (charmap);
596# if !defined (_WIN32)
599 std::string C_locale (
"");
602 *cmap =
new Charmap (C_locale.c_str (), charmap_path.c_str(),
603 0 == std::strcmp (
"utf8.cm", charmap),
607 return cmap ? *cmap : 0;
612escape_value (
unsigned val,
bool always =
false)
615 static const char printable [] = {
628 static const char hexdigit[] =
"0123456789abcdef";
637 else if ( use_pcs &&
val <=
UChar (
'~')
642 else if (
val <
sizeof printable - 1 &&
' ' != printable [
val] && !always) {
644 ret += printable [
val];
646 else if (
UChar (
' ') ==
val && !always) {
659 const unsigned mask = 0xffU << (
sizeof mask - 1) * 8;
661 while (
val && 0 == (
val & mask))
667 *pbuf++ = hexdigit [
val >> (
sizeof val * 8 - 4)];
669 *pbuf++ = hexdigit [
val >> (
sizeof val * 8 - 4)];
685create_str (
const char*
str,
const wchar_t* wstr,
const Charmap *charmap)
702 typedef std::map <UChar, std::string>::const_iterator rn_cmap_iter;
703 typedef std::map <wchar_t, std::string>::const_iterator rw_cmap_iter;
705 if (0 == ctype_st || 1 == ctype_st->mb_cur_max) {
713 for (; *
str !=
'\0'; ++
str) {
715 const rn_cmap_iter it = charmap->
get_rn_cmap ().find (uc);
717 ret += (it ==
end) ? escape_value (uc) : it->second;
726 for ( ; *wstr !=
'\0'; ++wstr) {
728 const unsigned uc = unsigned (*wstr);
730 const rw_cmap_iter it = charmap->
get_rw_cmap ().find (uc);
732 ret += (it ==
end) ? escape_value (uc) : it->second;
742create_str (
unsigned ch,
const Charmap *charmap)
744 typedef std::map <wchar_t, std::string>::const_iterator rw_cmap_iter;
750 const rw_cmap_iter ch_pos = charmap->
get_rw_cmap ().find (ch);
755 "not found in character map\n", ch);
758 return ch_pos->second;
761 return escape_value (ch);
766print_section (
const char*
name,
bool end =
false)
770 if (print_sect_names)
771 std::cout << (
end ?
"END " :
"") <<
name <<
'\n';
776print_keyword (
const char*
str)
781 std::cout <<
str << (posix_output ?
'=' :
' ');
796get_wchar_from_offset(
unsigned int offset,
797 const unsigned int* wchar_map,
798 unsigned int num_wchars) {
799 unsigned int beg = 0;
800 unsigned int end = num_wchars;
802 unsigned int cur = (beg +
end) / 2;
803 if (*(wchar_map +
cur * 2 + 1) ==
offset) {
804 return *(
const wchar_t*)(wchar_map +
cur * 2);
816print_weight (
const unsigned int* weightp,
817 unsigned int num_weights,
818 unsigned int longest_weight)
823 for (
unsigned k = 0;
k != num_weights; ++
k) {
825 for (
unsigned x = 0;
x != longest_weight; ++
x, ++weightp) {
829 std::cout <<
"IGNORE;";
831 std::cout << escape_value (*weightp,
true) <<
';';
841write_coll_info (
const std::string &ch,
unsigned int idx,
842 unsigned int tab_num)
844 if (collate_st->num_elms > 1) {
847 typedef std::map <std::string, wchar_t>::const_iterator n_cmap2_iter;
848 const unsigned int* tab = collate_st->get_n_tab (tab_num);
849 unsigned int first = collate_st->get_first_char_in_n_tab(tab_num);
851 std::string new_ch = ch;
854 if (tab[
i - first] & 0x80000000) {
856 write_coll_info (new_ch, idx + 1,
857 tab[
i - first] &~ 0x80000000);
863 n_cmap2_iter n_cmap2_it =
867 n_cmap2_it->second)->second;
870 for (
unsigned int j = 0;
j < idx;
j++) {
873 std::cout <<
"\\d" << int (uc);
880 print_weight (collate_st->get_weight (tab[
i - first]),
881 collate_st->num_weights,
882 collate_st->longest_weight);
892print_ce_info (
unsigned tab_num,
893 const std::string &mb_str,
894 std::map<std::string, unsigned int> &ce_map)
896 static unsigned ce_num = 0;
898 const unsigned*
const tab = collate_st->get_n_ce_tab (tab_num);
900 const unsigned first = collate_st->get_first_char_in_n_ce_tab (tab_num);
901 const unsigned last = collate_st->get_last_char_in_n_ce_tab (tab_num);
907 for (
unsigned i = first;
i <=
last; ++
i) {
912 const unsigned elem = tab [
i - first];
916 if (elem & 0x80000000) {
920 print_ce_info (elem &~ 0x80000000, mbchar, ce_map);
931 std::sprintf (sym,
"<RW_CE_%u>", ce_num++);
933 ce_map.insert (std::make_pair (sym, elem));
934 std::cout <<
"collating-element " << sym <<
" from \"";
937 std::cout << mbchar <<
"\"\n";
939 const std::map<std::string, wchar_t> &cm =
944 for (
unsigned j = 1;
j <= mbchar.size (); ++
j) {
945 const std::map<std::string, wchar_t>::const_iterator
946 it = cm.find (mbchar.substr (ch,
j));
948 if (it != cm.end ()) {
950 (it->second))->second;
964print_lc_collate (
const char *section,
int)
966 print_section (section);
973 std::cout <<
"# collate data:"
975 << collate_st->codeset_name ()
976 <<
"\"\n# charmap: \""
977 << collate_st->charmap_name ()
978 <<
"\"\n# codeset_off: "
979 << collate_st->codeset_off
980 <<
"\n# charmap_off: "
981 << collate_st->charmap_off
983 << collate_st->elm_size
985 << collate_st->num_elms
986 <<
"\n# num_wchars: "
987 << collate_st->num_wchars
988 <<
"\n# longest_weight: "
989 << int (collate_st->longest_weight)
990 <<
"\n# num_weights: "
991 << int (collate_st->num_weights)
992 <<
"\n# largest_ce: "
993 << int (collate_st->largest_ce)
997 std::map<std::string, unsigned int> ce_map;
998 typedef std::map<std::string, unsigned int>::iterator ce_map_iter;
1000 if (collate_st->largest_ce > 1) {
1001 print_ce_info (0,
"", ce_map);
1004 std::cout <<
"\norder_start ";
1008 for (
int i = 0;
i < collate_st->num_weights;
i++) {
1009 switch (collate_st->weight_type[
i]) {
1011 std::cout <<
"forward";
1014 std::cout <<
"backward";
1017 std::cout <<
"forward,position";
1020 std::cout <<
"backward,position";
1023 issue_diag (502,
true, 0,
"invalid order type found "
1024 "in collate definition\n");
1026 if (
i == collate_st->num_weights - 1)
1037 for (ce_map_iter it = ce_map.begin (); it != ce_map.end (); ++it) {
1038 std::cout << it->first <<
" ";
1040 print_weight (collate_st->get_weight (it->second),
1041 collate_st->num_weights,
1042 collate_st->longest_weight);
1045 write_coll_info (
"", 0, 0);
1047 if (collate_st->undefined_optimization) {
1048 std::cout <<
"UNDEFINED ";
1050 const unsigned idx = collate_st->undefined_weight_idx;
1052 print_weight (collate_st->get_weight (idx),
1053 collate_st->num_weights,
1054 collate_st->longest_weight);
1057 std::cout <<
"\norder_end\n";
1060 print_section (section,
true);
1071print_mask (
const char *section,
int mask)
1076 print_section (section);
1078 const char *keyword = 0;
1081 case std::ctype_base::upper: keyword =
"upper";
break;
1082 case std::ctype_base::lower: keyword =
"lower";
break;
1083 case std::ctype_base::space: keyword =
"space";
break;
1084 case std::ctype_base::print: keyword =
"print";
break;
1085 case std::ctype_base::alpha: keyword =
"alpha";
break;
1086 case std::ctype_base::cntrl: keyword =
"cntrl";
break;
1087 case std::ctype_base::punct: keyword =
"punct";
break;
1088 case std::ctype_base::graph: keyword =
"graph";
break;
1089 case std::ctype_base::digit: keyword =
"digit";
break;
1090 case std::ctype_base::xdigit: keyword =
"xdigit";
break;
1095 print_keyword (keyword);
1099 if (0 != ctype_st) {
1108 for (std::size_t
i = 0;
i != ctype_st->wmask_s; ++
i) {
1110 if (ctype_st->wmask_tab (
i).mask & mask) {
1115 std::cout << create_str (ctype_st->wmask_tab (
i).ch, cmap);
1117 if (
i + 1 < ctype_st->wmask_s)
1123 for (std::size_t
k = 0;
k < ctype_st->wmask_s; ++
k) {
1125 if (ctype_st->wmask_tab (
k).mask & mask) {
1128 out += create_str (ctype_st->wmask_tab (
k).ch, cmap);
1132 for (std::size_t
j =
k + 1;
j < ctype_st->wmask_s; ++
j) {
1134 if (ctype_st->wmask_tab (
j).mask & mask) {
1149 std::cout <<
out <<
'\n';
1167print_toupper (
const char *keyword,
int print_cat)
1170 print_section (sect_lc_ctype);
1172 print_keyword (keyword);
1179 if (0 != ctype_st) {
1183 const std::size_t
count = ctype_st->wtoupper_s ();
1189 for (std::size_t
j = 0;
j <
count; ++
j) {
1191 out += create_str (ctype_st->wtoupper_tab (
j).lower, cmap);
1193 out += create_str (ctype_st->wtoupper_tab (
j).upper, cmap);
1204 std::cout <<
out <<
'\n';
1219print_tolower (
const char *keyword,
int print_cat)
1222 print_section (sect_lc_ctype);
1224 print_keyword (keyword);
1231 if (0 != ctype_st) {
1235 const std::size_t
count = ctype_st->wtolower_s ();
1239 for (std::size_t
j = 0;
j <
count; ++
j) {
1241 out += create_str (ctype_st->wtolower_tab (
j).upper, cmap);
1243 out += create_str (ctype_st->wtolower_tab (
j).lower, cmap);
1253 std::cout <<
out <<
'\n';
1267print_lc_ctype (
const char *section,
int)
1269 print_section (section);
1271 if (0 != ctype_st && decode) {
1274 std::cout <<
"# ctype data:"
1275 <<
"\n# codeset: \""
1276 << ctype_st->codeset_name ()
1277 <<
"\"\n# charmap: \""
1278 << ctype_st->charmap_name ()
1279 <<
"\"\n# codeset_off: "
1280 << ctype_st->codeset_off
1281 <<
"\n# charmap_off: "
1282 << ctype_st->charmap_off
1284 << ctype_st->wmask_s
1285 <<
"\n# wtoupper_off: "
1286 << ctype_st->wtoupper_off
1287 <<
"\n# wtolower_off: "
1288 << ctype_st->wtolower_off
1289 <<
"\n# wmask_off: "
1290 << ctype_st->wmask_off
1291 <<
"\n# ctype_ext_off: "
1292 << ctype_st->ctype_ext_off
1293 <<
"\n# mb_cur_max: "
1294 << unsigned (ctype_st->mb_cur_max)
1298 const std::size_t nupper = print_mask (0, std::ctype_base::upper);
1299 const std::size_t nlower = print_mask (0, std::ctype_base::lower);
1300 const std::size_t nspace = print_mask (0, std::ctype_base::space);
1301 const std::size_t nprint = print_mask (0, std::ctype_base::print);
1302 const std::size_t ncntrl = print_mask (0, std::ctype_base::cntrl);
1303 const std::size_t nalpha = print_mask (0, std::ctype_base::alpha);
1304 const std::size_t ndigit = print_mask (0, std::ctype_base::digit);
1305 const std::size_t npunct = print_mask (0, std::ctype_base::punct);
1306 const std::size_t ngraph = print_mask (0, std::ctype_base::graph);
1307 const std::size_t nxdigit = print_mask (0, std::ctype_base::xdigit);
1309 const int all_masks =
1310 std::ctype_base::upper | std::ctype_base::lower
1311 | std::ctype_base::space | std::ctype_base::print
1312 | std::ctype_base::cntrl | std::ctype_base::alpha
1313 | std::ctype_base::digit | std::ctype_base::punct
1314 | std::ctype_base::graph | std::ctype_base::xdigit;
1317 const std::size_t nall = print_mask (0, -1);
1321 const std::size_t nother = print_mask (0, ~all_masks);
1323 const std::size_t ntoupper = print_toupper (
"toupper", 0);
1324 const std::size_t ntolower = print_tolower (
"tolower", 0);
1326 if (0 != ctype_st && decode) {
1327 std::cout <<
"\n# ctype stats:"
1328 <<
"\n# total characters: " << nall
1329 <<
"\n# upper characters: " << nupper
1330 <<
"\n# lower characters: " << nlower
1331 <<
"\n# space characters: " << nspace
1332 <<
"\n# print characters: " << nprint
1333 <<
"\n# cntrl characters: " << ncntrl
1334 <<
"\n# alpha characters: " << nalpha
1335 <<
"\n# digit characters: " << ndigit
1336 <<
"\n# punct characters: " << npunct
1337 <<
"\n# graph characters: " << ngraph
1338 <<
"\n# xdigit characters: " << nxdigit
1339 <<
"\n# unclassified: " << nother
1340 <<
"\n# tolower pairs: " << ntolower
1341 <<
"\n# toupper pairs: " << ntoupper
1345 print_section (section,
true);
1353print_decimal_point (
const char *keyword,
int print_cat)
1356 print_section (sect_lc_numeric);
1358 print_keyword (keyword);
1361 std::cout <<
'"' << create_str (
".", 0, 0) <<
"\"\n";
1363 const char*
const dp =
1366 const wchar_t*
const wdp =
1371 std::cout <<
'"' << create_str (dp, wdp, cmap) <<
"\"\n";
1379print_thousands_sep (
const char *keyword,
int print_cat)
1382 print_section (sect_lc_numeric);
1384 print_keyword (keyword);
1387 std::cout <<
"\"\"\n";
1389 const char*
const ts =
1392 const wchar_t*
const wts =
1397 std::cout <<
'"' << create_str (ts, wts, cmap) <<
"\"\n";
1405print_grouping (
const char *keyword,
int print_cat)
1408 print_section (sect_lc_numeric);
1410 print_keyword (keyword);
1413 std::cout <<
"-1\n";
1417 i < num_punct_st->punct_ext_off - num_punct_st->grouping_off - 2;
1419 std::cout << (
int)((
const char*)num_punct_st->grouping())[
i]
1421 std::cout << (int)((
const char*)num_punct_st->grouping())[
i]
1430print_lc_numeric (
const char *section,
int)
1432 print_section (section);
1434 if (0 != num_st && decode) {
1437 std::cout <<
"# numeric data:"
1438 <<
"\n# codeset: \""
1439 << num_st->codeset_name ()
1440 <<
"\"\n# charmap: \""
1441 << num_st->charmap_name ()
1442 <<
"\"\n# codeset_off: "
1443 << num_st->codeset_off
1444 <<
"\n# charmap_off: "
1445 << num_st->charmap_off
1450 print_decimal_point (
"decimal_point", 0);
1451 print_thousands_sep (
"thousands_sep", 0);
1452 print_grouping (
"grouping", 0);
1454 print_section (section,
true);
1462print_int_curr_symbol (
const char *keyword,
int print_cat)
1465 print_section (sect_lc_monetary);
1467 print_keyword (keyword);
1470 std::cout <<
"\"\"\n";
1472 const char*
const cs =
1475 const wchar_t*
const wcs =
1480 std::cout <<
'"' << create_str (cs, wcs, cmap) <<
"\"\n";
1488print_currency_symbol (
const char *keyword,
int print_cat)
1491 print_section (sect_lc_monetary);
1493 print_keyword (keyword);
1496 std::cout <<
"\"\"\n";
1498 const char*
const cs =
1501 const wchar_t*
const wcs =
1506 std::cout <<
'"' << create_str (cs, wcs, cmap) <<
"\"\n";
1514print_mon_decimal_point (
const char *keyword,
int print_cat)
1517 print_section (sect_lc_monetary);
1519 print_keyword (keyword);
1522 std::cout <<
"\"\"\n";
1524 const char*
const dp =
1527 const wchar_t*
const wdp =
1532 std::cout <<
'"' << create_str (dp, wdp, cmap) <<
"\"\n";
1540print_mon_thousands_sep (
const char *keyword,
int print_cat)
1543 print_section (sect_lc_monetary);
1545 print_keyword (keyword);
1548 std::cout <<
"\"\"\n";
1550 const char*
const ts =
1553 const wchar_t*
const wts =
1558 std::cout <<
'"' << create_str (ts, wts, cmap) <<
"\"\n";
1566print_mon_grouping (
const char *keyword,
int print_cat)
1569 print_section (sect_lc_monetary);
1571 print_keyword (keyword);
1574 std::cout <<
"-1\n";
1578 i < mon_punct_st->punct_ext_off - mon_punct_st->grouping_off - 2;
1580 std::cout << (
int)((
const char*)mon_punct_st->grouping())[
i] <<
";";
1581 std::cout << (int)((
const char*)mon_punct_st->grouping())[
i]
1590print_positive_sign (
const char *keyword,
int print_cat)
1593 print_section (sect_lc_monetary);
1595 print_keyword (keyword);
1598 std::cout <<
"\"\"\n";
1600 const char*
const ps =
1603 const wchar_t*
const wps =
1608 std::cout <<
'"' << create_str (ps, wps, cmap) <<
"\"\n";
1616print_negative_sign (
const char *keyword,
int print_cat)
1619 print_section (sect_lc_monetary);
1621 print_keyword (keyword);
1624 std::cout <<
"\"\"\n";
1626 const char*
const ns =
1629 const wchar_t*
const wns =
1634 std::cout <<
'"' << create_str (ns, wns, cmap) <<
"\"\n";
1642print_int (
const char *keyword,
int val,
int print_cat)
1645 print_section (sect_lc_monetary);
1647 print_keyword (keyword);
1649 std::cout <<
val <<
'\n';
1653#define MON_INT(member) \
1654 (mon_st && CHAR_MAX != (mon_st->member) ? int (UChar (mon_st->member)) : -1)
1657print_int_frac_digits (
const char *keyword,
int print_cat)
1659 print_int (keyword,
MON_INT (frac_digits [1]), print_cat);
1667print_frac_digits (
const char *keyword,
int print_cat)
1669 print_int (keyword,
MON_INT (frac_digits [0]), print_cat);
1676print_p_cs_precedes (
const char *keyword,
int print_cat)
1678 print_int (keyword,
MON_INT (p_cs_precedes [0]), print_cat);
1685print_n_sep_by_space (
const char *keyword,
int print_cat)
1687 print_int (keyword,
MON_INT (n_sep_by_space [0]), print_cat);
1694print_p_sep_by_space (
const char *keyword,
int print_cat)
1696 print_int (keyword,
MON_INT (p_sep_by_space [0]), print_cat);
1703print_n_cs_precedes (
const char *keyword,
int print_cat)
1705 print_int (keyword,
MON_INT (n_cs_precedes [0]), print_cat);
1712print_p_sign_posn (
const char *keyword,
int print_cat)
1714 print_int (keyword,
MON_INT (p_sign_posn [0]), print_cat);
1721print_n_sign_posn (
const char *keyword,
int print_cat)
1723 print_int (keyword,
MON_INT (n_sign_posn [0]), print_cat);
1730print_int_p_cs_precedes (
const char *keyword,
int print_cat)
1732 print_int (keyword,
MON_INT (p_cs_precedes [1]), print_cat);
1739print_int_n_sep_by_space (
const char *keyword,
int print_cat)
1741 print_int (keyword,
MON_INT (n_sep_by_space [1]), print_cat);
1748print_int_p_sep_by_space (
const char *keyword,
int print_cat)
1750 print_int (keyword,
MON_INT (p_sep_by_space [1]), print_cat);
1757print_int_n_cs_precedes (
const char *keyword,
int print_cat)
1759 print_int (keyword,
MON_INT (n_cs_precedes [1]), print_cat);
1766print_int_p_sign_posn (
const char *keyword,
int print_cat)
1768 print_int (keyword,
MON_INT (p_sign_posn [1]), print_cat);
1775print_int_n_sign_posn (
const char *keyword,
int print_cat)
1777 print_int (keyword,
MON_INT (n_sign_posn [1]), print_cat);
1784print_lc_monetary (
const char *section,
int)
1786 print_section (section);
1788 if (mon_st && decode) {
1791 std::cout <<
"# monetary data:"
1792 <<
"\n# codeset: \""
1793 << mon_st->codeset_name ()
1794 <<
"\"\n# charmap: \""
1795 << mon_st->charmap_name ()
1796 <<
"\"\n# codeset_off: "
1797 << mon_st->codeset_off
1798 <<
"\n# charmap_off: "
1799 << mon_st->charmap_off
1804 print_int_curr_symbol (
"int_curr_symbol", 0);
1805 print_currency_symbol (
"currency_symbol", 0);
1806 print_mon_decimal_point (
"mon_decimal_point", 0);
1807 print_mon_thousands_sep (
"mon_thousands_sep", 0);
1808 print_mon_grouping (
"mon_grouping", 0);
1809 print_positive_sign (
"positive_sign", 0);
1810 print_negative_sign (
"negative_sign", 0);
1812 print_int_frac_digits (
"int_frac_digits", 0);
1813 print_frac_digits (
"frac_digits", 0);
1815 print_p_cs_precedes (
"p_cs_precedes", 0);
1816 print_p_sep_by_space (
"p_sep_by_space", 0);
1817 print_n_cs_precedes (
"n_cs_precedes", 0);
1818 print_n_sep_by_space (
"n_sep_by_space", 0);
1819 print_p_sign_posn (
"p_sign_posn", 0);
1820 print_n_sign_posn (
"n_sign_posn", 0);
1822 print_int_p_cs_precedes (
"int_p_cs_precedes", 0);
1823 print_int_p_sep_by_space (
"int_p_sep_by_space", 0);
1824 print_int_n_cs_precedes (
"int_n_cs_precedes", 0);
1825 print_int_n_sep_by_space (
"int_n_sep_by_space", 0);
1826 print_int_p_sign_posn (
"int_p_sign_posn", 0);
1827 print_int_n_sign_posn (
"int_n_sign_posn", 0);
1829 print_section (section,
true);
1837print_time_keyword (
const char *keyword,
int print_cat,
1838 const void *vstr,
const void *vwstr)
1841 print_section (sect_lc_monetary);
1844 print_keyword (keyword);
1851 std::cout <<
'"' << create_str (
str, wstr, cmap) <<
"\"";
1856print_abday (
const char *keyword,
int print_cat)
1858 static const char str[][4] = {
1859 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
1862 for (std::size_t
i = 0; ; ) {
1864 print_time_keyword (keyword, print_cat,
1865 time_st ? time_st->abday (
i, 0) :
str [
i],
1866 time_st ? time_st->abday (
i, 1) : 0);
1871 if (
sizeof str /
sizeof *
str == ++
i)
1884print_day (
const char *keyword,
int print_cat)
1886 static const char str[][10] = {
1887 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
1888 "Thursday",
"Friday",
"Saturday"
1891 for (std::size_t
i = 0; ; ) {
1893 print_time_keyword (keyword, print_cat,
1894 time_st ? time_st->day (
i, 0) :
str [
i],
1895 time_st ? time_st->day (
i, 1) : 0);
1900 if (
sizeof str /
sizeof *
str == ++
i)
1913print_abmon (
const char *keyword,
int print_cat)
1915 static const char str[][4] = {
1916 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
1917 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
1920 for (std::size_t
i = 0; ; ) {
1922 print_time_keyword (keyword, print_cat,
1923 time_st ? time_st->abmon (
i, 0) :
str [
i],
1924 time_st ? time_st->abmon (
i, 1) : 0);
1929 if (
sizeof str /
sizeof *
str == ++
i)
1942print_mon (
const char *keyword,
int print_cat)
1944 static const char str[][10] = {
1945 "January",
"February",
"March",
"April",
"May",
"June",
1946 "July",
"August",
"September",
"October",
"November",
"December"
1949 for (std::size_t
i = 0; ; ) {
1951 print_time_keyword (keyword, print_cat,
1952 time_st ? time_st->mon (
i, 0) :
str [
i],
1953 time_st ? time_st->mon (
i, 1) : 0);
1958 if (
sizeof str /
sizeof *
str == ++
i)
1971print_am_pm (
const char *keyword,
int print_cat)
1973 static const char str[][3] = {
"AM",
"PM" };
1975 print_time_keyword (keyword, print_cat,
1976 time_st ? time_st->am_pm (0, 0) :
str [0],
1977 time_st ? time_st->am_pm (0, 1) :
str [1]);
1981 print_time_keyword (0, 0,
1982 time_st ? time_st->am_pm (1, 0) :
str [0],
1983 time_st ? time_st->am_pm (1, 1) :
str [1]);
1992print_era (
const char *keyword,
int print_cat)
1995 print_section (sect_lc_monetary);
1997 print_keyword (keyword);
2000 std::cout <<
'"' << create_str (
"", 0, 0)
2002 else if (0 == time_st->era_count ()) {
2004 std::cout <<
"\"\"\n";
2011 for (
unsigned int i = 0;
i < time_st->era_count();
i++) {
2012 const _RW::__rw_time_t::era_t *era_p = time_st->era (
i);
2014 if (era_p->offset >= 0)
2015 std::cout <<
"\"+:" << era_p->offset <<
":";
2017 std::cout <<
"\"-:" << era_p->offset * -1 <<
":";
2021 if (era_p->year[0] < 0)
2022 std::cout <<
'-' << std::setw(4) << std::setfill (
'0')
2023 << era_p->year[0] * -1;
2025 std::cout << std::setw(4) << std::setfill (
'0')
2031 << std::setw(2) << int(era_p->day[0]) <<
":";
2035 if (era_p->year[1] ==
INT_MIN)
2037 else if (era_p->year[1] ==
INT_MAX)
2040 if (era_p->year[1] < 0)
2041 std::cout <<
'-' << std::setw(4) << era_p->year[1] * -1;
2043 std::cout << std::setw(4) << era_p->year[1];
2048 << std::setw(2) << int(era_p->day[1]) <<
":";
2051 const char*
const era =
2054 const wchar_t*
const wera =
2057 const char*
const fmt =
2060 const wchar_t*
const wfmt =
2063 std::cout << create_str (era, wera, cmap) <<
":"
2064 << create_str (fmt, wfmt, cmap);
2066 if (
i != time_st->era_count () - 1)
2069 std::cout <<
"\"\n";
2078print_d_t_fmt (
const char *keyword,
int print_cat)
2080 static const char str[] =
"%a %b %e %H:%M:%S %Y";
2082 print_time_keyword (keyword, print_cat,
2083 time_st ? time_st->d_t_fmt (0) :
str,
2084 time_st ? time_st->d_t_fmt (1) : 0);
2093print_era_d_t_fmt (
const char *keyword,
int print_cat)
2095 print_time_keyword (keyword, print_cat,
2096 time_st ? time_st->era_d_t_fmt (0) : 0,
2097 time_st ? time_st->era_d_t_fmt (1) : 0);
2106print_d_fmt (
const char *keyword,
int print_cat)
2108 static const char str[] =
"%m/%d/%y";
2110 print_time_keyword (keyword, print_cat,
2111 time_st ? time_st->d_fmt (0) :
str,
2112 time_st ? time_st->d_fmt (1) : 0);
2121print_era_d_fmt (
const char *keyword,
int print_cat)
2123 print_time_keyword (keyword, print_cat,
2124 time_st ? time_st->era_d_fmt (0) : 0,
2125 time_st ? time_st->era_d_fmt (1) : 0);
2134print_t_fmt (
const char *keyword,
int print_cat)
2136 static const char str[] =
"%H:%M:%S";
2138 print_time_keyword (keyword, print_cat,
2139 time_st ? time_st->t_fmt (0) :
str,
2140 time_st ? time_st->t_fmt (1) : 0);
2149print_era_t_fmt (
const char *keyword,
int print_cat)
2151 print_time_keyword (keyword, print_cat,
2152 time_st ? time_st->era_t_fmt (0) : 0,
2153 time_st ? time_st->era_t_fmt (1) : 0);
2162print_t_fmt_ampm (
const char *keyword,
int print_cat)
2164 static const char str[] =
"%I:%M:%S %p";
2166 print_time_keyword (keyword, print_cat,
2167 time_st ? time_st->t_fmt_ampm (0) :
str,
2168 time_st ? time_st->t_fmt_ampm (1) : 0);
2177print_alt_digits (
const char *keyword,
int print_cat)
2180 const unsigned ndigits = time_st->alt_digits_count ();
2182 for (
unsigned i = 0; ; ) {
2184 print_time_keyword (keyword, print_cat,
2185 i < ndigits ? time_st->alt_digits (
i, 0) : 0,
2186 i < ndigits ? time_st->alt_digits (
i, 1) : 0);
2200 print_time_keyword (keyword, print_cat, 0, 0);
2208print_lc_time (
const char *section,
int)
2210 print_section (section);
2212 if (time_st && decode) {
2215 std::cout <<
"# time data:"
2216 <<
"\n# codeset: \""
2217 << time_st->codeset_name ()
2218 <<
"\"\n# charmap: \""
2219 << time_st->charmap_name ()
2220 <<
"\"\n# codeset_off: "
2221 << time_st->codeset_off
2222 <<
"\n# charmap_off: "
2223 << time_st->charmap_off
2227 print_abday (
"abday", 0);
2228 print_day (
"day", 0);
2229 print_abmon (
"abmon", 0);
2230 print_mon (
"mon", 0);
2231 print_am_pm (
"am_pm", 0);
2232 print_d_t_fmt (
"d_t_fmt", 0);
2233 print_d_fmt (
"d_fmt", 0);
2234 print_t_fmt (
"t_fmt", 0);
2235 print_t_fmt_ampm (
"t_fmt_ampm", 0);
2236 print_era (
"era", 0);
2237 print_era_d_t_fmt (
"era_d_t_fmt", 0);
2238 print_era_d_fmt (
"era_d_fmt", 0);
2239 print_era_t_fmt (
"era_t_fmt", 0);
2240 print_alt_digits (
"alt_digits", 0);
2242 print_section (section,
true);
2250print_noexpr (
const char *keyword,
int print_cat)
2253 print_section (sect_lc_messages);
2255 print_keyword (keyword);
2257 if (0 == messages_st)
2258 std::cout <<
'"' << create_str (
"^[nN]", 0, 0) <<
"\"\n";
2260 const char*
const no
2263 const wchar_t*
const wno
2268 std::cout <<
'"' << create_str (no, wno, cmap) <<
"\"\n";
2276print_yesexpr (
const char *keyword,
int print_cat)
2279 print_section (sect_lc_messages);
2281 print_keyword (keyword);
2283 if (0 == messages_st)
2284 std::cout <<
'"' << create_str (
"^[yY]", 0, 0) <<
"\"\n";
2286 const char*
const yes
2289 const wchar_t*
const wyes
2294 std::cout <<
'"' << create_str (yes, wyes, cmap) <<
"\"\n";
2302print_lc_messages (
const char *section,
int)
2304 print_section (section);
2306 if (messages_st && decode) {
2309 std::cout <<
"# messages data:"
2310 <<
"\n# codeset: \""
2311 << messages_st->codeset_name ()
2312 <<
"\"\n# charmap: \""
2313 << messages_st->charmap_name ()
2314 <<
"\"\n# codeset_off: "
2315 << messages_st->codeset_off
2316 <<
"\n# charmap_off: "
2317 << messages_st->charmap_off
2321 print_yesexpr (
"yesexpr", 0);
2322 print_noexpr (
"noexpr", 0);
2324 print_section (section,
true);
2332print_lc_all (
const char*,
int)
2334 print_lc_collate (sect_lc_collate, 0);
2337 print_lc_ctype (sect_lc_ctype, 0);
2340 print_lc_monetary (sect_lc_monetary, 0);
2343 print_lc_numeric (sect_lc_numeric, 0);
2346 print_lc_time (sect_lc_time, 0);
2349 print_lc_messages (sect_lc_messages, 0);
2357print_charmap_name (
const char *section,
int)
2359 if (0 != ctype_st) {
2360 print_section (section);
2362 print_keyword (
"charmap");
2363 std::cout <<
'"'<< ctype_st->charmap_name () <<
"\"\n";
2372EnumLocales (
char* locale_id)
2374 const LCID lcid = std::strtoul (locale_id, 0, 16);
2377 const int bufsize =
sizeof (
buf) /
sizeof (*
buf);
2381 if (GetLocaleInfo (lcid, LOCALE_SENGLANGUAGE,
buf, bufsize))
2384 if (GetLocaleInfo (lcid, LOCALE_SENGCOUNTRY,
buf, bufsize)) {
2389 if ( GetLocaleInfo (lcid, LOCALE_IDEFAULTANSICODEPAGE ,
buf, bufsize)
2390 && std::strtoul (
buf, 0, 10)) {
2395 if (
const char* locname = std::setlocale (
LC_ALL,
name.c_str ()))
2396 std::cout << locname <<
'\n';
2404print_locale_names ()
2408 const char*
const locale_root = std::getenv (
"RWSTD_LOCALE_ROOT");
2413 std::system (cmd.c_str ());
2417 std::system (
"/usr/bin/locale -a");
2419 EnumSystemLocales (EnumLocales, LCID_INSTALLED);
2427print_charmap_names ()
2429 const char*
const locale_root = std::getenv (
"RWSTD_SRC_ROOT");
2432 const std::string cmd =
2435 std::system (cmd.c_str());
2444 static const char*
msg =
2445 "NAME\n\tlocale - get locale-specific information\n\n"
2447 "\tlocale [-a | -m | -? | --help | --charmap]\n\n"
2448 "\tlocale [-ckhlw] name ...\n\n"
2450 "\tThe locale utility writes information about the current\n"
2451 "\tlocale environment, or all public locales, to the standard\n"
2452 "\toutput. For the purposes of this section, a public locale is\n"
2453 "\tone provided by the implementation that is accessible to the\n"
2454 "\tapplication.\n\n"
2455 "\tWhen locale is invoked without any arguments, it summarizes\n"
2456 "\tthe current locale environment for each locale category as\n"
2457 "\tdetermined by the settings of the environment variables.\n\n"
2458 "\tWhen invoked with operands, it writes values that have been\n"
2459 "\tassigned to the keywords in the locale categories.\n\n"
2461 "\tThe following options are supported:\n\n"
2462 "\t-a\tWrite information about all available public locales.\n"
2463 "\t\tThe available locales include C, representing the\n"
2464 "\t\tPOSIX locale.\n\n"
2465 "\t-c\tWrite the names of selected locale categories.\n\n"
2466 "\t-k\tWrite the names and values of selected keywords.\n\n"
2467 "\t-m\tWrite names of available charmaps.\n\n"
2468 "\t-h\tIf available, use the original character map and \n"
2469 "\t\twrite the symbolic names instead of the character values\n\n"
2470 "\t-l\tWrite the locale information in a format readable by\n"
2471 "\t\tthe localedef utility\n\n"
2472 "\t-w\tTurn off all warning messages\n\n"
2473 "\t-w###\tTurn off a specific warning message\n\n"
2474 "\t-?\tWrite this message\n\n"
2475 "\t--help\tWrite this message\n\n"
2476 "\t--charmap\tWrite the character map.\n\n"
2478 "\tThe following operand is supported:\n\n"
2479 "\tname\tThe name of a locale category, the name of a keyword\n"
2480 "\t\tin a locale category, or the reserved name charmap.\n"
2481 "\t\tWhen charmap is specified, the utility writes the name\n"
2482 "\t\tof the character set description file or files used\n"
2483 "\t\tto create the current locale environment.\n\n";
2491print_ellipsis (
const char *mbchar,
2492 unsigned last_byte [2],
2493 unsigned last_ucs4 [2],
2494 unsigned last_wchar [2])
2497 const int open_width = last_ucs4 [0] < 0x10000 ? 4 : 8;
2498 const int close_width = last_ucs4 [1] < 0x10000 ? 4 : 8;
2502 int pad = 28 - open_width;
2504 const unsigned nchars = last_byte [1] - last_byte [0] + 1;
2508 pad -= close_width + 8;
2512 std::printf (
"<U%0*X>..<U%0*X>%*s%s\\x%02x "
2513 "# L'\\x%02x' (%u characters)\n",
2514 open_width, last_ucs4 [0],
2515 close_width, last_ucs4 [1], pad,
" ",
2516 mbchar, last_byte [0], last_wchar [0],
2522 std::printf (
"<U%0*X>%*s%s\\x%02x "
2524 open_width, last_ucs4 [0], pad,
" ",
2525 mbchar, last_byte [0], last_wchar [0]);
2528 last_byte [0] = last_byte [1] =
UINT_MAX;
2529 last_ucs4 [0] = last_ucs4 [1] = 0;
2530 last_wchar [0] = last_wchar [1] = 0;
2537print_charmap (
const __rw::__rw_codecvt_t *
cvt,
2539 const unsigned *tab,
2544 const unsigned*
const table =
cvt->n_to_w_tab ();
2551 const std::size_t mbchar_len = std::strlen (mbchar);
2555 const std::size_t count_inx = mbchar_len / 4 + 1;
2562 ++ntables [count_inx];
2565 unsigned last_byte [2] = {
UINT_MAX, 0 };
2566 unsigned last_ucs4 [2] = { 0, 0 };
2567 unsigned last_wchar [2] = { 0, 0 };
2572 if (tab [
i] & 0x80000000) {
2576 print_ellipsis (mbchar, last_byte, last_ucs4, last_wchar);
2584 const unsigned ucs4 =
cvt->get_ucs4_at_offset (tab [
i]);
2585 const unsigned wchar =
cvt->get_internal_at_offset (tab [
i]);
2589 last_ucs4 [0] = ucs4;
2590 last_wchar [0] = wchar;
2592 else if (1 < ucs4 - last_ucs4 [1] || 1 < wchar - last_wchar [1]) {
2594 print_ellipsis (mbchar, last_byte, last_ucs4, last_wchar);
2597 last_ucs4 [0] = ucs4;
2598 last_wchar [0] = wchar;
2602 last_ucs4 [1] = ucs4;
2603 last_wchar [1] = wchar;
2616 print_ellipsis (mbchar, last_byte, last_ucs4, last_wchar);
2627 ++nunused [count_inx];
2633 if (!(tab [
i] & 0x80000000)) {
2640 std::sprintf (mbchar + mbchar_len,
"\\x%02x",
i);
2642 print_charmap (
cvt, mbchar,
table + 256 * (tab [
i] & 0x7fffffff),
2643 ntables,
nchars, nunused);
2645 mbchar [mbchar_len] =
'\0';
2652print_charmap (
const __rw::__rw_codecvt_t *
cvt = 0)
2662 std::cout <<
"<escape_char> \\"
2663 <<
"\n<comment_char> #"
2664 <<
"\n<code_set_name> " <<
cvt->codeset_name ()
2665 <<
"\n<mb_cur_max> " << int (
cvt->mb_cur_max)
2669 std::cout <<
"# charmap data:"
2670 <<
"\n# charmap name: "
2671 <<
cvt->charmap_name ()
2672 <<
"\n# n_to_w_tab_off: "
2673 <<
cvt->n_to_w_tab_off
2674 <<
"\n# w_to_n_tab_off: "
2675 <<
cvt->w_to_n_tab_off
2676 <<
"\n# utf8_to_ext_tab_off: "
2677 <<
cvt->utf8_to_ext_tab_off
2678 <<
"\n# xliteration_off: "
2679 <<
cvt->xliteration_off
2680 <<
"\n# wchar_off: "
2682 <<
"\n# codeset_off: "
2684 <<
"\n# charmap_off: "
2686 <<
"\n# codecvt_ext_off: "
2687 <<
cvt->codecvt_ext_off
2697 unsigned ntables [64] = { 0 };
2702 unsigned nunused [64] = { 0 };
2707 unsigned nchars [64] = { 0 };
2711 std::cout <<
"END CHARMAP\n"
2712 <<
"\n# charmap stats:";
2715 if (0 !=
nchars [
i] || 0 != ntables [
i]) {
2717 const double waste =
2718 (100.0 * nunused [
i]) / (ntables [
i] *
UCHAR_MAX);
2720 std::cout <<
"\n# ";
2721 std::cout <<
i <<
" byte characters: " <<
nchars [
i]
2722 <<
" (" << ntables [
i] <<
" tables, "
2723 << unsigned (waste) <<
"% waste)";
2727 const double waste = (100.0 * nunused [0]) / (ntables [0] *
UCHAR_MAX);
2729 std::cout <<
"\n# total characters: " <<
nchars [0]
2730 <<
" (" << ntables [0] <<
" tables, "
2731 << unsigned (waste) <<
"% waste)\n";
2739print_lc_var (
const char* cat_name,
const char*
val,
2740 const char *lc_all,
const char *lang)
2742 std::cout << cat_name <<
'=';
2747 const char*
const strval =
2748 (lc_all ? lc_all :
val ?
val : lang ? lang :
"");
2752 for (
const char*
s = strval; *
s; ++
s) {
2756 std::cout <<
'\\' << *
s;
break;
2758 case '|':
case '&':
case '\\':
case '<':
case '>':
2761 if (
val) std::cout <<
'\\' << *
s;
2782 const char*
const lang = std::getenv (
"LANG");
2783 const char*
const lc_all = std::getenv (sect_lc_all);
2784 const char*
const lc_collate = std::getenv (sect_lc_collate);
2785 const char*
const lc_ctype = std::getenv (sect_lc_ctype);
2786 const char*
const lc_messages = std::getenv (sect_lc_messages);
2787 const char*
const lc_monetary = std::getenv (sect_lc_monetary);
2788 const char*
const lc_numeric = std::getenv (sect_lc_numeric);
2789 const char*
const lc_time = std::getenv (sect_lc_time);
2791 print_lc_var (
"LANG", lang ? lang :
"", 0, 0);
2792 print_lc_var (sect_lc_ctype, lc_ctype, lc_all, lang);
2793 print_lc_var (sect_lc_collate, lc_collate, lc_all, lang);
2794 print_lc_var (sect_lc_time, lc_time, lc_all, lang);
2795 print_lc_var (sect_lc_monetary, lc_monetary, lc_all, lang);
2796 print_lc_var (sect_lc_numeric, lc_numeric, lc_all, lang);
2797 print_lc_var (sect_lc_messages, lc_messages, lc_all, lang);
2798 print_lc_var (sect_lc_all, lc_all ? lc_all :
"", 0, 0);
2803static const struct {
2809 { sect_lc_time, print_lc_time, 0 },
2810 { sect_lc_monetary, print_lc_monetary, 0 },
2811 { sect_lc_numeric, print_lc_numeric, 0 },
2812 { sect_lc_ctype, print_lc_ctype, 0 },
2813 { sect_lc_collate, print_lc_collate, 0 },
2814 { sect_lc_messages, print_lc_messages, 0 },
2815 { sect_lc_all, print_lc_all, 0 },
2817 {
"abday", print_abday, -1 },
2818 {
"day", print_day, -1 },
2819 {
"abmon", print_abmon, -1 },
2820 {
"mon", print_mon, -1 },
2821 {
"am_pm", print_am_pm, -1 },
2822 {
"d_t_fmt", print_d_t_fmt, -1 },
2823 {
"t_fmt", print_t_fmt, -1 },
2824 {
"d_fmt", print_d_fmt, -1 },
2825 {
"t_fmt_ampm", print_t_fmt_ampm, -1 },
2826 {
"era_d_t_fmt", print_era_d_t_fmt, -1 },
2827 {
"era_t_fmt", print_era_t_fmt, -1 },
2828 {
"era_d_fmt", print_era_d_fmt, -1 },
2829 {
"era", print_era, -1 },
2830 {
"alt_digits", print_alt_digits, -1 },
2831 {
"yesexpr", print_yesexpr, -1 },
2832 {
"noexpr", print_noexpr, -1 },
2833 {
"int_curr_symbol", print_int_curr_symbol, -1 },
2834 {
"currency_symbol", print_currency_symbol, -1 },
2835 {
"mon_decimal_point", print_mon_decimal_point, -1 },
2836 {
"mon_thousands_sep", print_mon_thousands_sep, -1 },
2837 {
"mon_grouping", print_mon_grouping, -1 },
2838 {
"positive_sign", print_positive_sign, -1 },
2839 {
"negative_sign", print_negative_sign, -1 },
2840 {
"int_frac_digits", print_int_frac_digits, -1 },
2841 {
"frac_digits", print_frac_digits, -1 },
2842 {
"p_cs_precedes", print_p_cs_precedes, -1 },
2843 {
"p_sep_by_space", print_p_sep_by_space, -1 },
2844 {
"n_cs_precedes", print_n_cs_precedes, -1 },
2845 {
"n_sep_by_space", print_n_sep_by_space, -1 },
2846 {
"p_sign_posn", print_p_sign_posn, -1 },
2847 {
"n_sign_posn", print_n_sign_posn, -1 },
2848 {
"int_p_cs_precedes", print_int_p_cs_precedes, -1 },
2849 {
"int_p_sep_by_space", print_int_p_sep_by_space, -1 },
2850 {
"int_n_cs_precedes", print_int_n_cs_precedes, -1 },
2851 {
"int_n_sep_by_space", print_int_n_sep_by_space, -1 },
2852 {
"int_p_sign_posn", print_int_p_sign_posn, -1 },
2853 {
"int_n_sign_posn", print_int_n_sign_posn, -1 },
2854 {
"decimal_point", print_decimal_point, -1 },
2855 {
"thousands_sep", print_thousands_sep, -1 },
2856 {
"grouping", print_grouping, -1 },
2857 {
"upper", print_mask, std::ctype_base::upper },
2858 {
"lower", print_mask, std::ctype_base::lower },
2859 {
"space", print_mask, std::ctype_base::space },
2860 {
"print", print_mask, std::ctype_base::print },
2861 {
"cntrl", print_mask, std::ctype_base::cntrl },
2862 {
"alpha", print_mask, std::ctype_base::alpha },
2863 {
"digit", print_mask, std::ctype_base::digit },
2864 {
"punct", print_mask, std::ctype_base::punct },
2865 {
"graph", print_mask, std::ctype_base::graph },
2866 {
"xdigit", print_mask, std::ctype_base::xdigit },
2867 {
"tolower", print_tolower, -1 },
2868 {
"toupper", print_toupper, -1 },
2869 {
"charmap", print_charmap_name, 0 },
2878 const char*
const program_name = argv [0];
2889 while (0 != *++argv && 0 < argc-- &&
'-' == **argv) {
2895 print_locale_names ();
2901 print_keywords =
true;
2906 print_sect_names =
true;
2907 if (*(*argv + 1) ==
'k')
2908 print_keywords =
true;
2912 print_charmap_names ();
2924 posix_output =
false;
2931 posix_output =
false;
2935 if (std::strlen (*argv) == 1)
2946 if (0 == std::strcmp (*argv,
"-help")) {
2951 if (0 == std::strcmp (*argv,
"-charmap")) {
2959 issue_diag (504,
true, 0,
"%s: invalid option "
2960 "-%s\n", program_name, *argv);
2965 issue_diag (505,
true, 0,
"%s: missing argument\n Try '"
2966 "%s --help'\n", program_name, program_name);
2969 for (; 0 != *argv; ++argv) {
2971 for (std::size_t
i = 0; handlers [
i].name; ++
i) {
2972 if (0 == std::strcmp (*argv, handlers [
i].
name)) {
2975 -1 == handlers [
i].arg ? print_sect_names
2978 handlers [
i].print (handlers [
i].
name,
arg);
void count(T, T, const U &,...)
#define _RWSTD_STATIC_CAST(T, x)
char * get_installed_locales(int loc_cat)
void get_cname_aliases(const std::string &name, StringVector &aliases)
std::string get_C_encoding_locale(const std::string &codeset)
const std::map< unsigned char, std::string > & get_rn_cmap() const
static const char *const portable_charset[]
const std::map< wchar_t, std::string > & get_rw_cmap() const
const std::map< std::string, wchar_t > & get_mb_cmap() const
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
size_t strchk(const char *str)
size_t memchk(const void *addr, size_t nbytes)
const FacetData * init_section(const std::string &loc_path_root, const char *cat_name, const char *codeset_name, FacetData *)
int locale_main(int argc, char *argv[])
const void * init_struct(const std::string &loc_path_root, const char *cat_name, const char *codeset_name)
int validate(const void *addr, std::size_t nbytes)