40static const char lc_name[] =
"LC_TIME";
44parse_era (
const token_t& tok)
49 std::string era = convert_string (tok.name);
56 const std::wstring wera = convert_wstring (tok);
60 const wchar_t*
const werap = wera.c_str ();
63 char* tokp = std::strtok (erap,
":");
64 const char direction = tokp ? *tokp :
'\0';
66 era_st tmp_era = era_st ();
69 tokp = std::strtok (0,
":");
72 "expected ':' in era definition\n");
76 std::sscanf (tokp,
"%d", &tmp_era.era_out.offset);
78 tmp_era.era_out.offset *= -1;
81 tokp = std::strtok (0,
":");
84 "expected ':' in era definition\n");
88 unsigned int tmp_mon, tmp_day;
89 std::sscanf (tokp,
"%d/%u/%u", &tmp_era.era_out.year[0],
92 tmp_era.era_out.month[0] = char(tmp_mon - 1);
93 tmp_era.era_out.day[0] = char(tmp_day);
97 tokp = std::strtok (0,
":");
100 "expected ':' in era definition\n");
104 if (std::strcmp (tokp,
"-*") == 0) {
105 tmp_era.era_out.year[1] = _RWSTD_INT_MIN;
106 tmp_era.era_out.month[1] = _RWSTD_CHAR_MIN;
107 tmp_era.era_out.day[1] = _RWSTD_CHAR_MIN;
109 else if (std::strcmp (tokp,
"+*") == 0) {
110 tmp_era.era_out.year[1] = _RWSTD_INT_MAX;
111 tmp_era.era_out.month[1] = _RWSTD_CHAR_MAX;
112 tmp_era.era_out.day[1] = _RWSTD_CHAR_MAX;
115 std::sscanf (tokp,
"%d/%u/%u", &tmp_era.era_out.year[1],
118 tmp_era.era_out.month[1] = char(tmp_mon - 1);
119 tmp_era.era_out.day[1] = char(tmp_day);
123 tokp = std::strtok (0,
":");
127 tokp = std::strtok (0,
":");
133 const wchar_t *wtokp = werap;
134 for (
int i = 0;
i < 4 && *wtokp;
i++)
135 while (*wtokp && *(wtokp++) !=
L':');
138 while (*wtokp !=
L':')
139 tmp_era.wname += *wtokp++;
146 tmp_era.wfmt = wtokp;
148 era_list_.push_back (tmp_era);
149 time_out_.num_eras++;
154extract_string_array (std::string *
str,
163 for (std::size_t
i = 0;
i != nelems; ++
i) {
172 str [
i] = convert_string (tok.
name);
173 wstr [
i] = convert_wstring (tok);
180void Def::process_time ()
185 int nesting_level = 0;
187 time_def_found_ =
true;
191 switch (next.
token) {
197 if (nesting_level == 0)
205 "wrong section name in END directive\n");
212 "expected string following \"copy\" directive\n");
236 const std::size_t nelems =
237 sizeof time_st_.abday /
sizeof *time_st_.abday;
239 next = extract_string_array (time_st_.abday,
247 const std::size_t nelems =
248 sizeof time_st_.day /
sizeof *time_st_.day;
250 next = extract_string_array (time_st_.day,
258 const std::size_t nelems =
259 sizeof time_st_.abmon /
sizeof *time_st_.abmon;
261 next = extract_string_array (time_st_.abmon,
269 const std::size_t nelems =
270 sizeof time_st_.mon /
sizeof *time_st_.mon;
272 next = extract_string_array (time_st_.mon,
280 time_st_.d_t_fmt = convert_string (next.
name);
281 time_st_.wd_t_fmt = convert_wstring (next);
286 time_st_.d_fmt = convert_string (next.
name);
287 time_st_.wd_fmt = convert_wstring (next);
291 time_st_.t_fmt = convert_string (next.
name);
292 time_st_.wt_fmt = convert_wstring (next);
296 const std::size_t nelems =
297 sizeof time_st_.am_pm /
sizeof *time_st_.am_pm;
299 next = extract_string_array (time_st_.am_pm,
307 time_st_.t_fmt_ampm = convert_string (next.
name);
308 time_st_.wt_fmt_ampm = convert_wstring (next);
319 time_st_.era_d_fmt = convert_string (next.
name);
320 time_st_.wera_d_fmt = convert_wstring (next);
324 time_st_.era_t_fmt = convert_string (next.
name);
325 time_st_.wera_t_fmt = convert_wstring (next);
329 time_st_.era_d_t_fmt = convert_string (next.
name);
330 time_st_.wera_d_t_fmt = convert_wstring (next);
336 digit.n_alt_digit = convert_string (next.
name);
337 digit.w_alt_digit = convert_wstring (next);
340 alt_digits_.push_back (digit);
353 assert (!dir_name.empty());
358 if (!time_def_found_) {
360 "%s section not found, skipping\n", lc_name);
370 std::ofstream
out (dir_name.c_str(), std::ios::binary);
371 out.exceptions (std::ios::failbit | std::ios::badbit);
375#define UINT(x) _RWSTD_STATIC_CAST(unsigned, x)
377 time_out_.num_alt_digits =
UINT (alt_digits_.size());
378 time_out_.era_off = 0;
380 time_out_.alt_digits_off =
UINT (time_out_.era_off +
381 sizeof (_RW::__rw_time_t::era_t) * era_list_.size());
384 time_out_.abday_off[1][0] =
UINT (time_out_.alt_digits_off +
385 2 * sizeof (
unsigned int) * time_out_.num_alt_digits);
387 for (
i = 1;
i < 7;
i++) {
388 time_out_.abday_off[1][
i] =
UINT (time_out_.abday_off[1][
i-1]
389 + (time_st_.wabday[
i-1].size() * sizeof (
wchar_t))
393 time_out_.day_off[1][0] =
UINT (time_out_.abday_off[1][6]
394 + time_st_.wabday[6].size() * sizeof (
wchar_t)
396 for (
i = 1;
i < 7;
i++) {
397 time_out_.day_off[1][
i] =
UINT (time_out_.day_off[1][
i-1]
398 + time_st_.wday[
i-1].size() * sizeof (
wchar_t)
402 time_out_.abmon_off[1][0] =
UINT (time_out_.day_off[1][6]
403 + time_st_.wday[6].size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
404 for (
i = 1;
i < 12;
i++) {
405 time_out_.abmon_off[1][
i] =
UINT (time_out_.abmon_off[1][
i-1]
406 + time_st_.wabmon[
i-1].size() * sizeof (
wchar_t)
410 time_out_.mon_off[1][0] =
UINT (time_out_.abmon_off[1][11]
411 + time_st_.wabmon[11].size() * sizeof (
wchar_t)
413 for (
i = 1;
i < 12;
i++) {
414 time_out_.mon_off[1][
i] =
UINT (time_out_.mon_off[1][
i-1]
415 + time_st_.wmon[
i-1].size() * sizeof (
wchar_t)
419 time_out_.am_pm_off[1][0] =
UINT (time_out_.mon_off[1][11]
420 + time_st_.wmon[11].size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
421 time_out_.am_pm_off[1][1] =
UINT (time_out_.am_pm_off[1][0]
422 + time_st_.wam_pm[0].size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
424 time_out_.d_t_fmt_off[1] =
UINT (time_out_.am_pm_off[1][1]
425 + time_st_.wam_pm[1].size() * sizeof (
wchar_t)
427 time_out_.d_fmt_off[1] =
UINT (time_out_.d_t_fmt_off[1]
428 + time_st_.wd_t_fmt.size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
429 time_out_.t_fmt_off[1] =
UINT (time_out_.d_fmt_off[1]
430 + time_st_.wd_fmt.size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
431 time_out_.t_fmt_ampm_off[1] =
UINT (time_out_.t_fmt_off[1]
432 + time_st_.wt_fmt.size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
434 time_out_.era_d_t_fmt_off[1] =
UINT (time_out_.t_fmt_ampm_off[1]
435 + time_st_.wt_fmt_ampm.size() * sizeof (
wchar_t)
437 time_out_.era_d_fmt_off[1] =
UINT (time_out_.era_d_t_fmt_off[1]
438 + time_st_.wera_d_t_fmt.size() * sizeof (
wchar_t)
440 time_out_.era_t_fmt_off[1] =
UINT (time_out_.era_d_fmt_off[1]
441 + time_st_.wera_d_fmt.size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
443 unsigned int next_off =
UINT (time_out_.era_t_fmt_off[1]
444 + time_st_.wera_t_fmt.size() * sizeof (
wchar_t) +
sizeof (
wchar_t));
445 era_list_iter era_list_it;
446 for (era_list_it = era_list_.begin(); era_list_it != era_list_.end();
448 era_list_it->era_out.name_off[1] = next_off;
449 next_off +=
UINT (era_list_it->wname.size()
450 * sizeof (
wchar_t) +
sizeof (
wchar_t));
451 era_list_it->era_out.fmt_off[1] = next_off;
452 next_off +=
UINT (era_list_it->wfmt.size()
453 * sizeof (
wchar_t) +
sizeof (
wchar_t));
456 alt_digits_iter alt_digits_it;
457 for (alt_digits_it = alt_digits_.begin();
458 alt_digits_it != alt_digits_.end(); alt_digits_it ++ ){
459 alt_digits_it->w_offset = next_off;
460 next_off +=
UINT ((alt_digits_it->w_alt_digit.size() + 1)
464 time_out_.abday_off[0][0] = next_off;
466 for (
i = 1;
i < 7;
i++) {
468 time_out_.abday_off[0][
i] =
UINT (time_out_.abday_off[0][
i-1]
469 + time_st_.abday[
i - 1].size() + 1);
472 time_out_.day_off[0][0] =
UINT (time_out_.abday_off[0][6]
473 + time_st_.abday[6].size() + 1);
474 for (
i = 1;
i < 7;
i++) {
476 time_out_.day_off[0][
i] =
UINT (time_out_.day_off[0][
i-1]
477 + time_st_.day[
i-1].size() + 1);
480 time_out_.abmon_off[0][0] =
UINT (time_out_.day_off[0][6]
481 + time_st_.day[6].size() + 1);
482 for (
i = 1;
i < 12;
i++) {
484 time_out_.abmon_off[0][
i] =
UINT (time_out_.abmon_off[0][
i-1]
485 + time_st_.abmon[
i-1].size() + 1);
488 time_out_.mon_off[0][0] =
UINT (time_out_.abmon_off[0][11]
489 + time_st_.abmon[11].size() + 1);
490 for (
i = 1;
i < 12;
i++) {
492 time_out_.mon_off[0][
i] =
UINT (time_out_.mon_off[0][
i-1]
493 + time_st_.mon[
i-1].size() + 1);
497 time_out_.am_pm_off[0][0] =
UINT (time_out_.mon_off[0][11]
498 + time_st_.mon[11].size() + 1);
499 time_out_.am_pm_off[0][1] =
UINT (time_out_.am_pm_off[0][0]
500 + time_st_.am_pm[0].size() + 1);
502 time_out_.d_t_fmt_off[0] =
UINT (time_out_.am_pm_off[0][1]
503 + time_st_.am_pm[1].size() + 1);
504 time_out_.d_fmt_off[0] =
UINT (time_out_.d_t_fmt_off[0]
505 + time_st_.d_t_fmt.size() + 1);
506 time_out_.t_fmt_off[0] =
UINT (time_out_.d_fmt_off[0]
507 + time_st_.d_fmt.size() + 1);
508 time_out_.t_fmt_ampm_off[0] =
UINT (time_out_.t_fmt_off[0]
509 + time_st_.t_fmt.size() + 1);
511 time_out_.era_d_t_fmt_off[0] =
UINT (time_out_.t_fmt_ampm_off[0]
512 + time_st_.t_fmt_ampm.size() + 1);
513 time_out_.era_d_fmt_off[0] =
UINT (time_out_.era_d_t_fmt_off[0]
514 + time_st_.era_d_t_fmt.size() + 1);
515 time_out_.era_t_fmt_off[0] =
UINT (time_out_.era_d_fmt_off[0]
516 + time_st_.era_d_fmt.size() + 1);
520 next_off =
UINT (time_out_.era_t_fmt_off[0]
521 + time_st_.era_t_fmt.size() + 1);
523 for (era_list_it = era_list_.begin(); era_list_it != era_list_.end();
525 era_list_it->era_out.name_off[0] = next_off;
526 next_off +=
UINT (era_list_it->name.size() + 1);
527 era_list_it->era_out.fmt_off[0] = next_off;
528 next_off +=
UINT (era_list_it->fmt.size() + 1);
531 for (alt_digits_it = alt_digits_.begin();
532 alt_digits_it != alt_digits_.end(); alt_digits_it ++ ){
533 alt_digits_it->n_offset = next_off;
534 next_off +=
UINT (alt_digits_it->n_alt_digit.size() + 1);
538 time_out_.codeset_off = next_off;
540 time_out_.charmap_off =
UINT (time_out_.codeset_off
544 out.write ((
char*)&time_out_,
sizeof(time_out_));
547 for (era_list_it = era_list_.begin(); era_list_it != era_list_.end();
549 out.write ((
const char*) &era_list_it->era_out,
550 sizeof (era_list_it->era_out));
554 for (alt_digits_it = alt_digits_.begin();
555 alt_digits_it != alt_digits_.end(); alt_digits_it ++ ){
556 out.write ((
const char*) &alt_digits_it->n_offset,
557 sizeof (alt_digits_it->n_offset));
558 out.write ((
const char*) &alt_digits_it->w_offset,
559 sizeof (alt_digits_it->w_offset));
563 for (
i = 0;
i < 7;
i++){
564 out.write ((
const char*)time_st_.wabday[
i].c_str(),
565 (time_st_.wabday[
i].size() + 1) *
sizeof (
wchar_t));
567 for (
i = 0;
i < 7;
i++)
568 out.write ((
const char*)time_st_.wday[
i].c_str(),
569 (time_st_.wday[
i].size() + 1) *
sizeof (
wchar_t));
570 for (
i = 0;
i < 12;
i++)
571 out.write ((
const char*)time_st_.wabmon[
i].c_str(),
572 (time_st_.wabmon[
i].size() + 1) *
sizeof (
wchar_t));
573 for (
i = 0;
i < 12;
i++)
574 out.write ((
const char*)time_st_.wmon[
i].c_str(),
575 (time_st_.wmon[
i].size() + 1) *
sizeof (
wchar_t));
576 for (
i = 0;
i < 2;
i++)
577 out.write ((
const char*)time_st_.wam_pm[
i].c_str(),
578 (time_st_.wam_pm[
i].size() + 1) *
sizeof (
wchar_t));
579 out.write ((
const char*)time_st_.wd_t_fmt.c_str(),
580 (time_st_.wd_t_fmt.size() + 1) *
sizeof (
wchar_t));
581 out.write ((
const char*)time_st_.wd_fmt.c_str(),
582 (time_st_.wd_fmt.size() + 1) *
sizeof (
wchar_t));
583 out.write ((
const char*)time_st_.wt_fmt.c_str(),
584 (time_st_.wt_fmt.size() + 1) *
sizeof (
wchar_t));
585 out.write ((
const char*)time_st_.wt_fmt_ampm.c_str(),
586 (time_st_.wt_fmt_ampm.size() + 1) *
sizeof (
wchar_t));
587 out.write ((
const char*)time_st_.wera_d_t_fmt.c_str(),
588 (time_st_.wera_d_t_fmt.size() + 1) *
sizeof (
wchar_t));
589 out.write ((
const char*)time_st_.wera_d_fmt.c_str(),
590 (time_st_.wera_d_fmt.size() + 1) *
sizeof (
wchar_t));
591 out.write ((
const char*)time_st_.wera_t_fmt.c_str(),
592 (time_st_.wera_t_fmt.size() + 1) *
sizeof (
wchar_t));
593 for (era_list_it = era_list_.begin(); era_list_it != era_list_.end();
595 out.write ((
const char*) era_list_it->wname.c_str(),
596 (era_list_it->wname.size() + 1) *
sizeof (
wchar_t));
597 out.write ((
const char*) era_list_it->wfmt.c_str(),
598 (era_list_it->wfmt.size() + 1) *
sizeof (
wchar_t));
600 for (alt_digits_it = alt_digits_.begin();
601 alt_digits_it != alt_digits_.end(); alt_digits_it ++ ){
602 out.write ((
const char*) alt_digits_it->w_alt_digit.c_str(),
603 (alt_digits_it->w_alt_digit.size() + 1)
608 for (
i = 0;
i < 7;
i++)
609 out << time_st_.abday[
i] << std::ends;
610 for (
i = 0;
i < 7;
i++)
611 out << time_st_.day[
i] << std::ends;
612 for (
i = 0;
i < 12;
i++)
613 out << time_st_.abmon[
i] << std::ends;
614 for (
i = 0;
i < 12;
i++)
615 out << time_st_.mon[
i] << std::ends;
616 for (
i = 0;
i < 2;
i++)
617 out << time_st_.am_pm[
i] << std::ends;
618 out << time_st_.d_t_fmt << std::ends;
619 out << time_st_.d_fmt << std::ends;
620 out << time_st_.t_fmt << std::ends;
621 out << time_st_.t_fmt_ampm << std::ends;
622 out << time_st_.era_d_t_fmt << std::ends;
623 out << time_st_.era_d_fmt << std::ends;
624 out << time_st_.era_t_fmt << std::ends;
625 for (era_list_it = era_list_.begin(); era_list_it != era_list_.end();
627 out << era_list_it->name << std::ends;
628 out << era_list_it->fmt << std::ends;
630 for (alt_digits_it = alt_digits_.begin();
631 alt_digits_it != alt_digits_.end(); alt_digits_it ++ ){
632 out << alt_digits_it->n_alt_digit << std::ends;
#define _RWSTD_CONST_CAST(T, x)
const std::string & get_code_set_name() const
std::string get_charmap_name() const
void write_time(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)