44static const char lc_name[] =
"LC_CTYPE";
50 if (
t.name.size() < 4 ||
t.name [0] !=
'<' ||
t.name [1] !=
'U') {
52 "Symbol could not be converted to UCS-4 value"
53 "(literal form should have been <Uxxxxxxxx>)");
56 long w = std::strtol (
t.name.substr (2,
t.name.size ()).c_str (),
58 if (
w > _RWSTD_WCHAR_MAX) {
61 throw loc_exception (
"symbol could not be converted to UCS-4 "
62 "value (value outside wchar_t range)");
73 n_cmap_iter n_cmap_pos;
79 if (charmap_.
get_n_cmap ().end () != n_cmap_pos)
80 val = n_cmap_pos->second;
104 w_cmap_iter w_cmap_pos;
110 if (charmap_.
get_w_cmap ().end () != w_cmap_pos)
111 val = w_cmap_pos->second;
130 std::ctype_base::mask
m)
134 typedef unsigned char UChar;
143 if (get_n_val (next, first) && get_n_val (nextnext,
last)) {
149 "illegal range [%u, %u] in LC_CTYPE definition\n",
153 ctype_out_.mask_tab [
val] |=
m;
161 if (get_w_val (next, wfirst) && get_w_val (nextnext, wlast)) {
163 for (
wchar_t val = wfirst;
val != wlast; ) {
165 const mask_iter mask_pos = mask_.find (
val);
167 if (mask_pos == mask_.end ())
168 mask_.insert (std::make_pair (
val,
m));
170 mask_pos->second |=
m;
178 mask_iter mask_pos = mask_.find (wlast);
179 if(mask_pos == mask_.end ())
180 mask_.insert (std::make_pair (wlast,
m));
182 mask_pos->second |=
m;
188 &next,
"beginning or endpoint of range "
189 "was not found in the character map; "
202process_sym_ellipsis (
const std::string& start_sym,
203 const std::string& end_sym,
205 std::ctype_base::mask
m)
220 while (idx < start_sym.size () && !std::isxdigit (start_sym [idx]))
221 begin += start_sym [idx++];
225 while (idx < start_sym.size () && !std::isdigit (start_sym [idx]))
226 begin += start_sym [idx++];
233 while (idx < start_sym.size () && start_sym [idx] !=
'>')
234 num_str += start_sym [idx++];
236 std::size_t num_len = num_str.size();
240 unsigned long num = std::strtoul (num_str.c_str(), (
char**)0,
base);
244 std::string sym_name;
249 len = std::sprintf (next_num,
"%lX",
num++);
255 len = std::sprintf (next_num,
"%lu",
num++);
260 sym_name.append (num_len -
len,
'0');
262 sym_name += next_num;
265 next.
name = sym_name;
269 if (get_n_val (next, n_val)) {
270 ctype_out_.mask_tab [n_val] |=
m;
274 if (get_w_val (next, w_val)) {
276 mask_iter mask_pos = mask_.find (w_val);
277 if (mask_pos != mask_.end())
278 mask_pos->second |=
m;
280 mask_.insert (std::make_pair (w_val,
m));
299 }
while (sym_name != end_sym);
315process_mask (std::ctype_base::mask
m,
const char *
name)
325 typedef unsigned char UChar;
329 switch (nextnext.
token) {
338 nchars += process_abs_ellipsis (nextnext,
m);
360 if (get_n_val (next, n_val)) {
361 ctype_out_.mask_tab [n_val] |=
m;
366 if (get_w_val (next, w_val)) {
368 const mask_iter mask_pos = mask_.find (w_val);
369 if (mask_pos == mask_.end ())
370 mask_.insert (std::make_pair (w_val,
m));
372 mask_pos->second |=
m;
400 "non-symbolic character %s found in ctype "
401 "definition.\n", next.
name.c_str())
403 if (next.
name.size () != 1)
406 "non-symbolic character %s in ctype "
407 "definition is longer than one char in "
408 "length. Ignoring character\n",
411 ctype_out_.mask_tab [
UChar (next.
name [0])] |=
m;
413 mask_iter mask_pos = mask_.find (mb_val);
414 if (mask_pos != mask_.end())
415 mask_pos->second |=
m;
417 mask_.insert (std::make_pair (mb_val,
m));
431 "done processing %s class (%lu characters)\n",
443 const char*
const name =
455 std::string sym, sym2;
459 strip_pair(next.
name, sym, sym2);
462 const n_cmap_iter sym1_pos = charmap_.
get_n_cmap().find (sym);
463 const n_cmap_iter sym2_pos = charmap_.
get_n_cmap().find (sym2);
467 ctype_out_.toupper_tab [sym1_pos->second] = sym2_pos->second;
469 ctype_out_.tolower_tab [sym1_pos->second] = sym2_pos->second;
475 const w_cmap_iter wsym1_pos = charmap_.
get_w_cmap().find (sym);
476 const w_cmap_iter wsym2_pos = charmap_.
get_w_cmap().find (sym2);
477 if (wsym1_pos == charmap_.
get_w_cmap().end ())
480 "unknown symbol name %s found in "
481 "%s definition\n", sym.c_str (), lc_name)
483 else if (wsym2_pos == charmap_.
get_w_cmap().end())
486 "unknown symbol name %s found in "
488 sym2.c_str (), lc_name)
492 upper_.insert (std::make_pair (wsym1_pos->second,
495 lower_.insert (std::make_pair (wsym1_pos->second,
504 "done processing to%s map (%lu characters)\n",
name,
nchars);
509process_xlit_statement (std::size_t &
nchars)
512 std::string sym_s (next.
name);
515 sym_w = convert_literal_to_ucs4 (next);
526 std::pair<xlit_map_t::iterator, bool>
res =
527 xlit_map_.insert (std::make_pair(sym_w, std::list<std::string>()));
528 if (
res.second ==
false) {
533 xlit_map_t::iterator& it =
res.first;
537 switch (next.
token) {
542 it->second.push_back(convert_to_ext(w_pos->second));
549 if (next.
name.size () <= 2)
555 std::string enc = convert_string (next.
name);
558 it->second.push_back (enc);
565 "ignoring unexpected token in "
566 "transliteration statement\n");
575 if (it->second.empty ())
576 xlit_map_.erase (it);
588 int nesting_level = 0;
589 std::list<std::string> file_list;
594 switch (next.
token) {
598 std::list<std::string> tmp_list;
602 next.
name.size () > 2)
603 tmp_list.push_back (next.
name);
607 file_list.insert (file_list.begin (),
608 tmp_list.begin (), tmp_list.end ());
611 std::string fname (file_list.front ());
612 file_list.pop_front ();
628 process_xlit_statement (
nchars);
632 if (nesting_level == 0)
640 if (file_list.empty ())
644 std::string fname (file_list.front ());
645 file_list.pop_front ();
665 "(%lu tokens, %lu characters)");
674 ctype_def_found_ =
true;
677 int nesting_level = 0;
692 "expected string following \"copy\" directive\n");
693#if !defined (_WIN32) && !defined (__CYGWIN__)
695 ctype_symlink_ =
true;
699 ctype_filename_ = output_name_;
701 ctype_filename_ = ctype_filename_.substr
702 (0, ctype_filename_.rfind
705 ctype_filename_ +=
".ctype.";
707 std::ifstream
f (ctype_filename_.c_str(), std::ios::binary);
710 ctype_written_ =
true;
744 process_mask (std::ctype_base::upper,
"upper");
748 process_mask (std::ctype_base::lower,
"lower");
752 process_mask (std::ctype_base::alpha,
"alpha");
756 process_mask (std::ctype_base::digit,
"digit");
760 process_mask (std::ctype_base::space,
"space");
764 process_mask (std::ctype_base::cntrl,
"cntrl");
768 process_mask (std::ctype_base::punct,
"punct");
772 process_mask (std::ctype_base::graph,
"graph");
776 process_mask (std::ctype_base::print,
"print");
780 process_mask (std::ctype_base::xdigit,
"xdigit");
803 if (nesting_level == 0)
810 "wrong section name in END directive\n");
829 assert (!dir_name.empty());
831 if (ctype_filename_.empty ()) {
833 ctype_symlink_ =
false;
838 if (ctype_def_found_ && !ctype_written_) {
841 "writing %s\n", ctype_filename_.c_str ());
843 std::ofstream
out (ctype_filename_.c_str(), std::ios::binary);
844 out.exceptions (std::ios::failbit | std::ios::badbit);
847 ctype_out_.wtoupper_off = 0;
848 ctype_out_.wtolower_off = unsigned (ctype_out_.wtoupper_off
849 + upper_.size() * sizeof (_RW::__rw_upper_elm));
850 ctype_out_.wmask_off = unsigned (ctype_out_.wtolower_off
851 + lower_.size() * sizeof (_RW::__rw_lower_elm));
852 ctype_out_.wmask_s = unsigned (mask_.size());
856 ctype_out_.codeset_off = unsigned (ctype_out_.wmask_off
857 + mask_.size() * sizeof (_RW::__rw_mask_elm));
858 ctype_out_.charmap_off = unsigned (ctype_out_.codeset_off
865 if(0 == ctype_out_.toupper_tab[
i])
866 ctype_out_.toupper_tab[
i] = (char)
i;
867 if(0 == ctype_out_.tolower_tab[
i])
868 ctype_out_.tolower_tab[
i] = (char)
i;
872 out.write ((
char*)&ctype_out_,
sizeof(ctype_out_));
875 for(upper_iter u_pos = upper_.begin(); u_pos != upper_.end(); u_pos++){
876 _RW::__rw_upper_elm elm = {u_pos->first, u_pos->second};
877 out.write((
char*)&elm,
sizeof(elm));
879 for(lower_iter l_pos = lower_.begin(); l_pos != lower_.end(); l_pos++){
880 _RW::__rw_lower_elm elm = {l_pos->first, l_pos->second};
881 out.write((
char*)&elm,
sizeof(elm));
883 for(mask_iter m_pos = mask_.begin(); m_pos != mask_.end(); m_pos++){
884 _RW::__rw_mask_elm elm = {m_pos->first, m_pos->second};
885 out.write((
char*)&elm,
sizeof(elm));
894#if !defined (_WIN32) && !defined (__CYGWIN__)
896 if (ctype_symlink_) {
898 std::string xname (ctype_filename_);
900 xname = std::string (
"..");
902 xname += ctype_filename_.substr (
904 ctype_filename_.size ());
907 std::string sname (lc_name);
bool convert_to_wc(const std::string &, const std::string &, wchar_t &)
int get_mb_cur_max() const
const std::string & get_code_set_name() const
const std::map< std::string, unsigned char > & get_n_cmap() const
std::string get_charmap_name() const
const std::map< std::string, wchar_t > & get_w_cmap() const
std::size_t mbcharlen(const std::string &) const
wchar_t increment_wchar(wchar_t) const
void write_ctype(std::string dir_name)
void open(std::string, char='#', char='\\')
unsigned long convert_escape(const char *, const char **=0, bool=false) const
std::string strip_quotes(const std::string &str)
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
void create_symlink(const std::string &dir, const std::string &xname, const std::string &sname)
std::string get_pathname(const std::string &fname, const std::string &other)