45gen_mbchar_tables (codecvt_offsets_map_t &tab,
46 std::map<std::string, unsigned> &off_map,
47 const std::string &charp ,
53 static unsigned ntabs = 0;
54 static std::set<std::string>* pfx_set = 0;
59 pfx_set =
new std::set<std::string>;
72 off_map.insert (std::make_pair (it->first,
off));
76 for (std::string
prefix = it->first; 1 <
prefix.size (); ) {
89 codecvt_offset_tab_t*
const offsets =
new codecvt_offset_tab_t;
91 std::string mb_char (charp +
'\0');
95 unsigned char cur_char = (
unsigned char)
i;
97 mb_char [mb_char.size () - 1] = char (cur_char);
99 if (mb_map_end == charmap_.
get_mb_cmap ().find (mb_char)) {
103 if (pfx_set->find (mb_char) == pfx_set->end ()) {
112 offsets->off [cur_char] = ++ntabs | 0x80000000;
115 nchars += gen_mbchar_tables (tab, off_map, mb_char, ntabs);
121 offsets->off [cur_char] = off_map.find (mb_char)->second;
127 tab.insert (std::make_pair (tabno, offsets));
140gen_wchar_tables (codecvt_offsets_map_t &tab,
141 const std::string &charp ,
147 static unsigned ntabs = 0;
148 static std::set<std::string> *pfx_set = 0;
149 static std::map<std::string, unsigned> *off_map = 0;
150 static std::map<std::string, std::string> *utf_map = 0;
153 pfx_set =
new std::set<std::string>;
154 off_map =
new std::map<std::string, unsigned>;
155 utf_map =
new std::map<std::string, std::string>;
164 off_map->insert (std::make_pair (it->first,
off));
166 off += unsigned (it->first.size ()) + 1;
168 std::string utf = utf8_encode (it->second);
170 utf_map->insert (std::make_pair (utf, it->first));
172 while (1 < utf.size ()) {
173 utf = utf.substr (0, utf.size () - 1);
174 pfx_set->insert (utf);
179 codecvt_offset_tab_t*
const offsets =
new codecvt_offset_tab_t;
184 std::string mb_char (charp +
'\0');
188 unsigned char cur_char = (
unsigned char)
i;
190 mb_char [mb_char.size () - 1] = char (cur_char);
192 const wchar_utf8_iter it = utf_map->find (mb_char);
193 if (it == utf_map->end ()) {
194 if (pfx_set->find (mb_char) == pfx_set->end ()) {
198 offsets->off [cur_char] = ++ntabs | 0x80000000;
200 nchars += gen_wchar_tables (tab, mb_char, ntabs);
204 offsets->off [cur_char] = off_map->find (it->second)->second;
210 tab.insert (std::make_pair (tabno, offsets));
226gen_utf8_tables (codecvt_offsets_map_t &tab,
227 std::map<std::string, unsigned> &off_map,
228 const std::string &charp ,
231 static unsigned ntabs = 0;
232 static std::set<std::string> *pfx_set = 0;
233 static std::map<std::string, wchar_t> *utf_map = 0;
236 pfx_set =
new std::set<std::string>;
238 const ucs4_cmap_iter first = charmap_.
get_ucs4_cmap ().begin ();
241 for (ucs4_cmap_iter it = first; it !=
last; ++it) {
243 for (std::string
prefix = utf8_encode (it->second);
252 typedef std::map<std::string, wchar_t>::iterator utf8_map_iter;
255 utf_map =
new std::map<std::string, wchar_t>;
257 const ucs4_cmap_iter first = charmap_.
get_ucs4_cmap ().begin ();
260 for (ucs4_cmap_iter it = first; it !=
last; ++it) {
261 const std::string utf = utf8_encode (it->second);
262 utf_map->insert (std::make_pair (utf, it->second));
266 codecvt_offset_tab_t*
const offsets =
new codecvt_offset_tab_t;
271 std::string mb_char = charp +
'\0';
275 unsigned char cur_char = (
unsigned char)
i;
277 mb_char [mb_char.size () - 1] = char (cur_char);
279 const utf8_map_iter where = utf_map->find (mb_char);
281 if (where == utf_map->end ()) {
282 if (pfx_set->find (mb_char) == pfx_set->end ()) {
286 offsets->off [cur_char] = ++ntabs | 0x80000000;
287 nchars += gen_utf8_tables (tab, off_map, mb_char, ntabs);
296 const wchar_t int_enc = charmap_.
get_w_cmap().find (
str)->second;
302 offsets->off [cur_char] = off_map.find (
str)->second;
308 tab.insert (std::make_pair (tabno, offsets));
327 unsigned int data_offset = 0;
330 xlit_map_t::const_iterator it = xlit_map_.begin ();
331 for (; it != xlit_map_.end (); ++it) {
333 xlit_data_offset_map_.insert (
334 std::make_pair (it->first,data_offset));
337 std::list<std::string>::const_iterator sit =
339 for (; sit != it->second.end (); ++sit) {
340 data_offset += unsigned (sit->size ()) + 1;
347 xlit_offset_table_t table0;
353 xlit_table_map_.insert (std::make_pair(0, table0));
355 const xlit_map_t::const_iterator xlit_map_end = xlit_map_.end ();
358 for (it = xlit_map_.begin (); it != xlit_map_end; ++it) {
361 const std::string utf8_rep (utf8_encode (it->first));
362 data_offset = xlit_data_offset_map_.find (it->first)->second;
366 unsigned int table_idx = 0;
368 const std::string::const_iterator utf8_rep_end = utf8_rep.end ();
369 std::string::const_iterator string_it = utf8_rep.begin ();
371 for (; string_it != utf8_rep_end; ++string_it) {
374 const xlit_table_map_t::iterator
res =
375 xlit_table_map_.find (table_idx);
380 unsigned char off_idx = (
unsigned char)*string_it;
384 if (
res->second.offset_table [off_idx] ==
UINT_MAX) {
388 if ((string_it + 1) == utf8_rep.end ()) {
389 xlit_data_offset_map_t::const_iterator data_it =
390 xlit_data_offset_map_.find (it->first);
391 assert (data_it != xlit_data_offset_map_.end ());
394 res->second.offset_table [off_idx] = data_it->second;
399 xlit_offset_table_t
table;
404 unsigned int tmp = unsigned (xlit_table_map_.size ());
405 xlit_table_map_.insert (std::make_pair(
tmp,
table));
408 res->second.offset_table [off_idx] =
tmp | 0x80000000;
412 res->second.offset_table [off_idx] & 0x7FFFFFFF;
423 if (codecvt_written_)
432 if (std::ifstream (dir_name.c_str ())) {
434 "%s exists, skipping\n", dir_name.c_str ());
442 codecvt_offsets_map_t mbchar_offs;
443 std::map<std::string, unsigned> off_map;
444 const std::size_t n_mbchars = gen_mbchar_tables (mbchar_offs, off_map);
449 codecvt_offsets_map_t wchar_offs;
450 const std::size_t n_wchars = gen_wchar_tables (wchar_offs);
455 codecvt_offsets_map_t uchar_offs;
456 const std::size_t n_uchars = gen_utf8_tables (uchar_offs, off_map);
468 _RW::__rw_codecvt_t codecvt_out;
469 std::memset (&codecvt_out, 0,
sizeof codecvt_out);
471#define UINT(x) _RWSTD_STATIC_CAST(unsigned, x)
474 codecvt_out.n_to_w_tab_off = 0;
475 codecvt_out.w_to_n_tab_off =
UINT (codecvt_out.n_to_w_tab_off
476 + mbchar_offs.size () * (
UCHAR_MAX + 1) * sizeof (
unsigned));
478 codecvt_out.utf8_to_ext_tab_off =
UINT (codecvt_out.w_to_n_tab_off
479 + wchar_offs.size () * (
UCHAR_MAX + 1) * sizeof (
unsigned));
482 codecvt_out.xliteration_off =
UINT (codecvt_out.utf8_to_ext_tab_off
483 + uchar_offs.size () * (
UCHAR_MAX + 1) * sizeof (
unsigned));
485 codecvt_out.wchar_off =
UINT (codecvt_out.xliteration_off
486 + xlit_table_map_.size () * (
UCHAR_MAX + 1) * sizeof (
unsigned));
488 codecvt_out.codeset_off =
UINT (codecvt_out.wchar_off
489 + charmap_.
get_mb_cmap ().size () * 2 * sizeof (
wchar_t));
491 codecvt_out.charmap_off =
UINT (codecvt_out.codeset_off
494 const std::size_t mb_offset =
UINT (codecvt_out.charmap_off
499 std::size_t xlit_data_offset = mb_offset;
505 xlit_data_offset += iter->first.size() + 1;
510 const xlit_table_map_t::const_iterator xlit_table_map_end =
511 xlit_table_map_.end ();
513 xlit_table_map_t::iterator xit = xlit_table_map_.begin ();
514 for (; xit != xlit_table_map_end; ++xit) {
516 if (xit->second.offset_table [
i] & 0x80000000)
519 xit->second.offset_table [
i] +=
UINT (xlit_data_offset);
528 std::ofstream
out (dir_name.c_str(), std::ios::binary);
529 out.exceptions (std::ios::failbit | std::ios::badbit);
532 out.write ((
char*)&codecvt_out,
sizeof codecvt_out);
534 typedef codecvt_offsets_map_t::iterator off_iter_t;
539 "writing %lu multibyte tables (%lu characters)\n",
540 mbchar_offs.size (), n_mbchars);
542 for (off_iter_t it = mbchar_offs.begin (); it != mbchar_offs.end (); ++it) {
545 const unsigned off = it->second->off [
i];
547 out.write ((
const char*)&
off,
sizeof off);
554 mbchar_offs.clear ();
559 "writing %lu wchar_t tables (%lu characters)\n",
560 wchar_offs.size (), n_wchars);
562 for (off_iter_t it = wchar_offs.begin (); it != wchar_offs.end (); ++it) {
567 unsigned off = it->second->off [
i];
569 if (!(
off & 0x80000000))
572 out.write ((
const char*)&
off,
sizeof off);
584 "writing %lu UTF-8 tables (%lu characters)\n",
585 uchar_offs.size (), n_uchars);
587 for (off_iter_t it = uchar_offs.begin (); it != uchar_offs.end (); ++it) {
592 unsigned off = it->second->off [
i];
594 if (!(
off & 0x80000000))
597 out.write ((
const char*)&
off,
sizeof off);
609 "writing transliteration table (size %lu)\n",
610 xlit_table_map_.size ());
612 xit = xlit_table_map_.begin ();
613 for (; xit != xlit_table_map_end; ++xit) {
614 const unsigned int* ptable = &xit->second.offset_table [0];
615 for (
unsigned int i = 0;
i <
UCHAR_MAX + 1; ++
i, ++ptable)
616 out.write ((
const char*)ptable, sizeof (
unsigned int));
620 "writing the UCS table (%lu characters)\n",
623 const mb_cmap_iter n_cmap2_end = charmap_.
get_mb_cmap ().end ();
627 iter != n_cmap2_end; ++iter) {
628 out.write ((
const char*)&iter->second,
sizeof (iter->second));
631 (iter->second)->second))->second,
642 iter != n_cmap2_end; ++iter) {
643 out.write (iter->first.c_str(), iter->first.size() + 1);
647 "writing transliteration data (size %lu)\n",
651 xlit_map_t::const_iterator xlit_data_it = xlit_map_.begin ();
652 for (; xlit_data_it != xlit_map_.end (); ++xlit_data_it) {
653 std::list<std::string>::const_iterator sit =
654 xlit_data_it->second.begin ();
655 for (; sit != xlit_data_it->second.end (); ++sit) {
656 out.write (sit->c_str (), sit->size () + 1);
const std::map< wchar_t, std::string > & get_rmb_cmap() const
int get_mb_cur_max() const
const std::string & get_code_set_name() const
const std::map< wchar_t, std::string > & get_rucs4_cmap() const
std::string get_charmap_name() const
const std::map< wchar_t, std::string > & get_rw_cmap() const
const std::map< std::string, wchar_t > & get_w_cmap() const
const std::map< std::string, wchar_t > & get_ucs4_cmap() const
const std::map< std::string, wchar_t > & get_mb_cmap() const
void write_codecvt(std::string dir_name)
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
long prefix(const entry_type &entry)
std::map< std::string, wchar_t >::const_iterator n_cmap_citer2