41static const char lc_name[] =
"LC_MONETARY";
44void Def::process_monetary ()
49 int nesting_level = 0;
51 mon_def_found_ =
true;
60 typedef unsigned char UChar;
69 if (nesting_level == 0)
77 "wrong section name in END directive\n");
85 "expected string following \"copy\" directive\n");
112 mon_st_.int_curr_symbol = convert_string (next.
name);
113 mon_st_.wint_curr_symbol = convert_wstring (next);
118 mon_st_.currency_symbol = convert_string (next.
name);
119 mon_st_.wcurrency_symbol = convert_wstring (next);
124 mon_st_.mon_decimal_point = convert_string (next.
name);
125 mon_st_.wmon_decimal_point = convert_wstring (next);
130 mon_st_.mon_thousands_sep = convert_string (next.
name);
131 mon_st_.wmon_thousands_sep = convert_wstring (next);
135 mon_st_.mon_grouping.clear();
137 mon_st_.mon_grouping += std::strtol (next.
name.c_str (), 0, 10);
142 mon_st_.positive_sign = convert_string (next.
name);
143 mon_st_.wpositive_sign = convert_wstring (next);
148 mon_st_.negative_sign = convert_string (next.
name);
149 mon_st_.wnegative_sign = convert_wstring (next);
153 pcharint = &mon_out_.frac_digits [0];
157 pcharint = &mon_out_.frac_digits [1 ];
162 pcharint = &mon_out_.p_cs_precedes [0];
167 pcharint = &mon_out_.p_sep_by_space [0];
172 pcharint = &mon_out_.n_cs_precedes [0];
177 pcharint = &mon_out_.n_sep_by_space [0];
182 pcharint = &mon_out_.p_sign_posn [0];
187 pcharint = &mon_out_.n_sign_posn [0];
192 pcharint = &mon_out_.p_cs_precedes [1 ];
197 pcharint = &mon_out_.p_sep_by_space [1 ];
202 pcharint = &mon_out_.n_cs_precedes [1 ];
207 pcharint = &mon_out_.n_sep_by_space [1 ];
212 pcharint = &mon_out_.p_sign_posn [1 ];
217 pcharint = &mon_out_.n_sign_posn [1 ];
229 const long val = std::strtol (next.
name.c_str (), &end, 10);
231 if (next.
name.empty () || *end ||
val < -1 || maxval <
val) {
235 "expected integer in [0, %li], got: %s\n",
236 maxval, next.
name.c_str ());
245void Def::create_format (
char format [4],
264 if (!mon_st_.positive_sign.empty())
267 "invalid combination of positive_sign "
268 "and p_sign_posn. Ignoring positive_sign")
270 mon_st_.positive_sign =
"()";
273 if (!mon_st_.negative_sign.empty())
276 "invalid combination of negative_sign "
277 "and n_sign_posn. Ignoring negative_sign")
279 mon_st_.negative_sign =
"()";
283 format[0] = std::money_base::sign;
284 if (cs_precedes == 0) {
285 format[1] = std::money_base::value;
286 format[2] = std::money_base::symbol;
289 format[1] = std::money_base::symbol;
290 format[2] = std::money_base::value;
295 format[0] = std::money_base::sign;
296 if (cs_precedes == 0) {
297 format[1] = std::money_base::value;
298 format[2] = std::money_base::symbol;
301 format[1] = std::money_base::symbol;
302 format[2] = std::money_base::value;
306 if (cs_precedes == 0) {
307 format[0] = std::money_base::value;
308 format[1] = std::money_base::symbol;
311 format[0] = std::money_base::symbol;
312 format[1] = std::money_base::value;
314 format[2] = std::money_base::sign;
317 if (cs_precedes == 0) {
318 format[0] = std::money_base::value;
319 format[1] = std::money_base::sign;
320 format[2] = std::money_base::symbol;
323 format[0] = std::money_base::sign;
324 format[1] = std::money_base::symbol;
325 format[2] = std::money_base::value;
329 if (cs_precedes == 0) {
330 format[0] = std::money_base::value;
331 format[1] = std::money_base::symbol;
332 format[2] = std::money_base::sign;
335 format[0] = std::money_base::symbol;
336 format[1] = std::money_base::sign;
337 format[2] = std::money_base::value;
345 if (sep_by_space == 0)
346 format[3] = std::money_base::none;
347 else if (sep_by_space == 1) {
348 if (format[0] == std::money_base::value) {
349 format[3] = format[2];
350 format[2] = format[1];
351 format[1] = std::money_base::space;
353 else if (format[2] == std::money_base::value) {
354 format[3] = format[2];
355 format[2] = std::money_base::space;
357 else if (format[0] == std::money_base::symbol) {
358 format[3] = format[2];
359 format[2] = format[1];
360 format[1] = std::money_base::space;
363 format[3] = format[2];
364 format[2] = std::money_base::space;
368 if (format[0] == std::money_base::value) {
369 format[3] = format[2];
370 format[2] = std::money_base::space;
372 else if (format[2] == std::money_base::value) {
373 format[3] = format[2];
374 format[2] = format[1];
375 format[1] = std::money_base::space;
377 else if (format[0] == std::money_base::symbol) {
378 format[3] = format[2];
379 format[2] = std::money_base::space;
382 format[3] = format[2];
383 format[2] = format[1];
384 format[1] = std::money_base::space;
392 assert (!dir_name.empty());
397 if (!mon_def_found_) {
399 "%s section not found, skipping\n", lc_name);
408 std::ofstream
out (dir_name.c_str(), std::ios::binary);
409 out.exceptions (std::ios::failbit | std::ios::badbit);
411 _RW::__rw_punct_t
punct;
414 punct.decimal_point_off [1] = 0;
416 punct.thousands_sep_off [1] =
417 unsigned (
punct.decimal_point_off [1]
418 + (mon_st_.wmon_decimal_point.size () + 1) * sizeof (
wchar_t));
420 punct.decimal_point_off [0] =
421 unsigned (
punct.thousands_sep_off [1]
422 + (mon_st_.wmon_thousands_sep.size () + 1) * sizeof (
wchar_t));
424 punct.thousands_sep_off [0] =
425 unsigned (
punct.decimal_point_off [0]
426 + mon_st_.mon_decimal_point.size () + 1);
429 unsigned (
punct.thousands_sep_off [0]
430 + mon_st_.mon_thousands_sep.size () + 1);
432 punct.punct_ext_off =
433 unsigned (
punct.grouping_off
434 + mon_st_.mon_grouping.size () + 1);
437 const std::size_t align =
sizeof punct.punct_ext_off;
440 const std::size_t misalign =
punct.punct_ext_off % align;
443 const std::size_t pad = misalign ? align - misalign : 0;
445 punct.punct_ext_off += unsigned (pad);
447 mon_out_.curr_symbol_off [1][1] = 0;
449 mon_out_.curr_symbol_off [0][1] =
450 unsigned (mon_out_.curr_symbol_off [1][1]
451 + (mon_st_.wint_curr_symbol.size () + 1) * sizeof (
wchar_t));
453 mon_out_.positive_sign_off [1] =
454 unsigned (mon_out_.curr_symbol_off [0][1]
455 + (mon_st_.wcurrency_symbol.size () + 1) * sizeof (
wchar_t));
457 mon_out_.negative_sign_off [1] =
458 unsigned (mon_out_.positive_sign_off [1]
459 + (mon_st_.wpositive_sign.size () + 1) * sizeof (
wchar_t));
463 mon_out_.curr_symbol_off [1][0] =
464 unsigned (mon_out_.negative_sign_off [1]
465 + (mon_st_.wnegative_sign.size () + 1) * sizeof (
wchar_t));
467 mon_out_.curr_symbol_off [0][0] =
468 unsigned (mon_out_.curr_symbol_off [1][0]
469 + mon_st_.int_curr_symbol.size () + 1);
471 mon_out_.positive_sign_off [0] =
472 unsigned (mon_out_.curr_symbol_off [0][0]
473 + mon_st_.currency_symbol.size() + 1);
475 mon_out_.negative_sign_off [0] =
476 unsigned (mon_out_.positive_sign_off [0]
477 + mon_st_.positive_sign.size () + 1);
479 mon_out_.codeset_off = unsigned (mon_out_.negative_sign_off [0]
480 + mon_st_.negative_sign.size () + 1);
482 mon_out_.charmap_off = unsigned (mon_out_.codeset_off
488 " decimal_point_off[] = { %u, %u }\n"
489 " thousand_sep_off[] = { %u, %u }\n"
490 " grouping_off = %u\n"
492 "}\n__rw_moneypunct_t {\n"
493 " curr_symbol_off[][] = { { %u, %u }, { %u, %u } }\n"
494 " positive_sign_off[] = { %u, %u }\n"
495 " negative_sign_off[] = { %u, %u }\n"
496 " codeset_off = %u\n"
497 " charmap_off = %u\n"
500 punct.decimal_point_off [0],
501 punct.decimal_point_off [1],
502 punct.thousands_sep_off [0],
503 punct.thousands_sep_off [1],
506 mon_out_.curr_symbol_off [0][0],
507 mon_out_.curr_symbol_off [0][1],
508 mon_out_.curr_symbol_off [1][0],
509 mon_out_.curr_symbol_off [1][1],
510 mon_out_.positive_sign_off [0],
511 mon_out_.negative_sign_off [1],
512 mon_out_.codeset_off,
513 mon_out_.charmap_off);
516 create_format (mon_out_.pos_format[0], mon_out_.p_sign_posn[0],
517 mon_out_.p_cs_precedes[0], mon_out_.p_sep_by_space[0],
520 create_format (mon_out_.neg_format[0], mon_out_.n_sign_posn[0],
521 mon_out_.n_cs_precedes[0], mon_out_.n_sep_by_space[0],
524 create_format (mon_out_.pos_format[1], mon_out_.p_sign_posn[1],
525 mon_out_.p_cs_precedes[1], mon_out_.p_sep_by_space[1],
528 create_format (mon_out_.neg_format[1], mon_out_.n_sign_posn[1],
529 mon_out_.n_cs_precedes[1], mon_out_.n_sep_by_space[1],
536 out.write ((
const char*)mon_st_.wmon_decimal_point.c_str(),
537 (mon_st_.wmon_decimal_point.size() + 1) *
sizeof(
wchar_t));
538 out.write ((
const char*)mon_st_.wmon_thousands_sep.c_str(),
539 (mon_st_.wmon_thousands_sep.size() + 1) *
sizeof(
wchar_t));
541 out << mon_st_.mon_decimal_point << std::ends
542 << mon_st_.mon_thousands_sep << std::ends
543 << mon_st_.mon_grouping << std::ends;
546 out.write (
"\0\0\0\0\0\0\0\0", pad);
549 out.write ((
char*)&mon_out_,
sizeof (mon_out_));
552 out.write ((
const char*)mon_st_.wint_curr_symbol.c_str(),
553 (mon_st_.wint_curr_symbol.size() + 1) *
sizeof(
wchar_t));
554 out.write ((
const char*)mon_st_.wcurrency_symbol.c_str(),
555 (mon_st_.wcurrency_symbol.size() + 1) *
sizeof(
wchar_t));
556 out.write ((
const char*)mon_st_.wpositive_sign.c_str(),
557 (mon_st_.wpositive_sign.size() + 1) *
sizeof(
wchar_t));
558 out.write ((
const char*)mon_st_.wnegative_sign.c_str(),
559 (mon_st_.wnegative_sign.size() + 1) *
sizeof(
wchar_t));
562 out << mon_st_.int_curr_symbol << std::ends
563 << mon_st_.currency_symbol << std::ends
564 << mon_st_.positive_sign << std::ends
565 << mon_st_.negative_sign << std::ends
const std::string & get_code_set_name() const
std::string get_charmap_name() const
void write_monetary(std::string dir_name)
void open(std::string, char='#', char='\\')
std::string strip_quotes(const std::string &str)
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
std::string get_pathname(const std::string &fname, const std::string &other)