Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
def.h
Go to the documentation of this file.
1
29#ifndef RWSTD_UTIL_DEF_H_INCLUDED
30#define RWSTD_UTIL_DEF_H_INCLUDED
31
32#include <list>
33#include <locale> // for ctype_base
34#include <map>
35#include <string>
36#include <vector>
37
38#include <cassert> // for assert()
39#include <climits> // for UCHAR_MAX
40#include <cstddef> // for size_t
41
42#include <loc/_localedef.h>
43
44#include "scanner.h"
45#include "charmap.h"
46
47
48class Def
49{
50public:
51
52 // the constructor takes in a pointer to the character map, the name
53 // of the file that hold the locale definiton, the name of the locale
54 // being created, and the value of mb_cur_max specified in the
55 // charmap file
56 Def(const char* filename,
57 const char* out_name,
58 Charmap& charmap, bool no_position);
59
60 // free up all the dynamically allocated memory
61 ~Def ();
62
63 // start point for processing the input files
64 void process_input ();
65
66 // write the LC_CTYPE file to the specified directory
67 void write_ctype(std::string dir_name);
68
69 void write_codecvt(std::string dir_name);
70
71 // write the LC_NUMERIC file to the specified directory
72 void write_numeric(std::string dir_name);
73
74 // write the LC_MONETARY file to the specified directory
75 void write_monetary(std::string dir_name);
76
77 // write the LC_TIME file to the specified directory
78 void write_time(std::string dir_name);
79
80 // write the LC_MESSAGES file to the specified directory
81 void write_messages(std::string dir_name);
82
83 // write the LC_COLLATE file to the specified directory
84 void write_collate(std::string dir_name);
85
86 // dump the collate information
87 void dump_collate ();
88
89 // have warnings occurred
91
92 // was the content of the locale definition file scanned ahead
94
96 typedef std::pair<token_t,token_t> token_pair_t;
97 typedef std::list<token_t> token_list_t;
98 typedef std::pair<token_t,token_list_t> collate_entry_t;
99 typedef std::pair<token_t,token_list_t> collate_elem_t;
100 typedef std::list<collate_entry_t> collate_entry_list_t;
101 struct collate_section_t;
102
104 std::string name;
107 };
108
109private:
110 struct ce_info_t;
111 struct collate_info_t;
112 friend struct ce_info_t;
113 friend struct collate_info_t;
114
115 // a struct used to represent the weights for each collating element
116 struct Weights_t {
117 unsigned char size;
118 unsigned int weight[256];
119 };
120
122 // collate preprocessing information
123
124 token_list_t script_list_;
125 token_list_t cs_list_;
126 token_list_t sym_list_;
127 std::list<collate_elem_t> ce_list_;
128 std::list<collate_section_t> section_list_;
129
130 // preprocessing for collate section
131 void preprocess_collate ();
132 void preprocess_order ();
133 void preprocess_reorder ();
134 void preprocess_reorder_section ();
135 void preprocess_collation_definitions();
136
137 void process_collation_definition ( bool, collate_entry_t&,
138 unsigned int, unsigned int);
139 unsigned int process_order_stmt (collate_section_t&);
140
141 bool insert_entries (token_t&, collate_entry_list_t&);
142 void remove_entry (collate_entry_t&);
143 void list_collate ();
144
145 // automatically fill any ctype categories that depend upon characters
146 // being defined in other categories
147 void auto_fill ();
148
149 // copy a category from one locale into the current locale
150 void copy_category(int cat, std::string name);
151
152 // copy a file
153 void copy_file(const std::string &name, const std::string &outname);
154
155 // process absolute ellipsis
156 std::size_t process_abs_ellipsis (const Scanner::token_t&,
157 std::ctype_base::mask);
158
159 // process hexadecimal symbolic ellipsis, decimal symbolic ellipsis,
160 // and double increment hexadecimal symbolic ellipsis
161 std::size_t process_sym_ellipsis (const std::string&,
162 const std::string&,
164 std::ctype_base::mask);
165
166 // parse the era string
167 void parse_era (const token_t&);
168
169 // process the ctype category specified by m with the exception of
170 // (e.g. std::ctype_base::upper)
171 void process_mask (std::ctype_base::mask, const char*);
172
173 // process the ctype toupper and tolower definitions
174 void process_upper_lower(Scanner::token_id tok);
175
176 // process the ctype section of the locale definition file
177 void process_ctype();
178
179 // process transliteration information
180 void process_xlit ();
181
182 void process_xlit_statement (std::size_t&);
183
184 // process the collate section of the locale definition file
185 void process_collate ();
186
187 // processing of collating definition statements
188 void process_collate_definition (bool, collate_entry_t&,
189 unsigned int&, unsigned int);
190
191 // helper function for process_collate() that processes the collition
192 // order of the collating elements
193 void process_order (collate_section_t&, unsigned int&);
194
195 // helper function for process_order() that processes the sequence
196 // of weights for each collating element
197 void process_weights(collate_entry_t&);
198
199 // get the next weight
200 bool get_weight (token_t&, Weights_t*, int);
201
202 // add a symbolic name to the collition array
203 void add_to_coll (const wchar_t val,
204 const Weights_t* weight_template,
205 const unsigned int coll_value,
206 const std::vector<bool>& ordinal_weights,
207 bool undefined_value);
208
209 // add missing values when the UNDEFINED keyword is found or at the
210 // end of the collition array if UNDEFINED is not found
211 void add_missing_values (const std::vector<bool> &ordinal_weights,
212 const Weights_t* weights_template,
213 unsigned int &coll_value, bool give_warning);
214
215 // process the monetary section of the locale definition file
216 void process_monetary();
217
218 // create the monetary formats
219 void create_format (char [4], char, char, char, bool);
220
221 // process the numeric section of the locale definition file
222 void process_numeric();
223
224 // extracts and converts an array of strings such as those
225 // representing the names of weekdays in the LC_TIME section
227 extract_string_array (std::string*, std::wstring*, std::size_t);
228
229
230 // process the time section of the locale definition file
231 void process_time();
232
233 // process the messages section of the locale definition file
234 void process_messages();
235
236 std::string convert_string (const std::string&);
237 std::wstring convert_wstring (const token_t&);
238 std::wstring convert_wstring (const std::vector<std::string>&);
239
240 void strip_pair(const std::string&, std::string&, std::string&);
241
242 // encode a wchar_t into utf8 encoding
243 std::string utf8_encode (wchar_t ch);
244
245 // convert a utf8 encoded string to the encoding for this locale
246 std::string convert_to_ext (wchar_t val);
247
248 bool get_n_val (const Scanner::token_t&, unsigned char &val);
249 bool get_w_val (const Scanner::token_t&, wchar_t &val);
250
251 // initialize the coll_map with all the characters in the codeset
252 void init_coll_map();
253
254 void gen_n_to_w_coll_tables (const std::string &charp,
255 unsigned int tab_num);
256
257 void gen_w_to_n_coll_tables (const std::string &charp,
258 unsigned int tab_num);
259
260 // the next useable offset for collating elements greater then UCHAR_MAX
261 unsigned int next_offset_;
262
263 Scanner::token_t next;
264
265 // the name of the locale we are creating
266 std::string output_name_;
267
268 // the charmap used to process the character map definition file
269 Charmap& charmap_;
270
271 // the scanner used to process the locale definition file
272 Scanner scanner_;
273
274 bool ctype_symlink_;
275 std::string ctype_filename_;
276
277
278 // maps characters to a mask value
279 std::map<wchar_t, unsigned int> mask_;
280
281 // maps characters to their lower case representation
282 std::map<wchar_t, wchar_t> lower_;
283
284 // maps characters to their upper case representation
285 std::map<wchar_t, wchar_t> upper_;
286
287 typedef std::map<std::string, unsigned int>::iterator mb_char_off_map_iter;
288
289 struct codecvt_offset_tab_t {
290 unsigned int off [UCHAR_MAX + 1];
291 };
292
293 void create_wchar_utf8_table ();
294 std::map<std::string, std::string> wchar_utf8_to_ext_;
295 typedef std::map<std::string, std::string>::iterator wchar_utf8_iter;
296
297 void gen_valid_coll_wchar_set ();
298
299 std::set<std::string> valid_coll_wchar_set_;
300 typedef std::set<std::string>::iterator valid_coll_wchar_set_iter;
301 std::set<std::string> valid_codecvt_wchar_set_;
302 typedef std::set<std::string>::iterator valid_codecvt_wchar_set_iter;
303
304 typedef std::map<unsigned, const codecvt_offset_tab_t*>
305 codecvt_offsets_map_t;
306
307 // generates conversion tables of all valid multibyte characters
308 // from a multibyte character map populated from the character
309 // set description file
310 std::size_t
311 gen_mbchar_tables (codecvt_offsets_map_t&,
312 std::map<std::string, unsigned>&,
313 const std::string& = "",
314 unsigned = 0);
315
316 std::size_t
317 gen_wchar_tables (codecvt_offsets_map_t&,
318 const std::string& = "",
319 unsigned = 0);
320
321 std::size_t
322 gen_utf8_tables (codecvt_offsets_map_t&,
323 std::map<std::string, unsigned>&,
324 const std::string& = "",
325 unsigned = 0);
326
327 std::set<std::string> valid_coll_mb_set_;
328
329 void gen_valid_coll_mb_set();
330
331 // generation of transliteration tables
332 void gen_xlit_data ();
333
334 // specifies if the locale file has already been written such as when
335 // the "copy" directive is used in a locale definition file
336 bool ctype_written_, codecvt_written_, collate_written_, time_written_,
337 num_written_, mon_written_, messages_written_;
338 bool ctype_def_found_, collate_def_found_,
339 time_def_found_, num_def_found_, mon_def_found_, messages_def_found_;
340
341 // specifies if the keyword UNDEFINED is used in the LC_COLLATE definition
342 bool undefined_keyword_found_;
343
344 // no_position_ is set by the "--no_position" command line option
345 // when true forward,postion orders will be treated like forward orders
346 bool no_position_;
347
348 // collate maps
349
350 struct offset_tab_t {
351 int first_offset;
352 unsigned int off[UCHAR_MAX + 1];
353 };
354
355 std::map<unsigned int, offset_tab_t> char_offs_;
356 typedef std::map<unsigned int, offset_tab_t>::iterator char_offs_iter;
357
358 std::map<unsigned int, offset_tab_t> w_to_n_coll_;
359 typedef std::map<unsigned int, offset_tab_t>::iterator w_to_n_coll_iter;
360
361 unsigned int next_tab_num_;
362 unsigned int next_wchar_coll_tab_num_;
363
364
365 struct ce_offset_tab_t {
366 int first_offset;
367 int last_offset;
368 unsigned int off[UCHAR_MAX + 1];
369 };
370 std::map<unsigned int, ce_offset_tab_t> n_ce_offs_;
371 typedef std::map<unsigned int, ce_offset_tab_t>::iterator n_ce_offs_iter;
372
373 std::map<unsigned int, ce_offset_tab_t> w_ce_offs_;
374 typedef std::map<unsigned int, ce_offset_tab_t>::iterator w_ce_offs_iter;
375
376 std::set<std::string> valid_n_ce_set;
377 typedef std::set<std::string>::iterator valid_n_ce_set_iter;
378
379 void gen_n_ce_tables (const std::set<std::string>,
380 unsigned int, unsigned int);
381 unsigned int next_n_ce_tab_num_;
382 void gen_w_ce_tables (const std::set<std::string>,
383 unsigned int, unsigned int);
384 unsigned int next_w_ce_tab_num_;
385
386 std::map<std::string, std::string>ce_sym_map_;
387 std::map<std::string, std::string>ce_wsym_map_;
388 typedef std::map<std::string, std::string>::iterator ce_sym_map_iter;
389 // off_mapr maps an offset value to the symbol name or collating element
390 std::map<unsigned int, std::string> off_mapr_;
391
392 // cs_map_ maps a collating symbol name to a collation value
393 std::map<std::string, unsigned int> cs_map_;
394 typedef std::map<std::string, unsigned int>::iterator cs_map_iter;
395
396 // transliteration information
397 struct xlit_offset_table {
398 unsigned int offset_table [UCHAR_MAX + 1];
399 };
400 typedef struct xlit_offset_table xlit_offset_table_t;
401 typedef std::map<wchar_t,std::list<std::string> > xlit_map_t;
402 typedef std::map<wchar_t, unsigned int> xlit_data_offset_map_t;
403 typedef std::map<unsigned int,xlit_offset_table_t> xlit_table_map_t;
404 xlit_map_t xlit_map_;
405 xlit_data_offset_map_t xlit_data_offset_map_;
406 xlit_table_map_t xlit_table_map_;
407
408 // the collate_info_t struct contains information concerning the collation
409 // of each character
410 struct collate_info_t{
411 unsigned int offset;
412 unsigned int coll_val;
413 unsigned int order;
414 Weights_t *weights;
415 };
416
417 // we need one collate_info_t to hold information about the undefined
418 // characters. All the other characters have collate_info_ts that are
419 // located in the coll_map.
420 collate_info_t undef_char_info_;
421
422 // the ce_info_t strurct contains information concerning the collation
423 // of a collating element.
424
425 struct ce_info_t {
426 unsigned int offset;
427 unsigned int coll_val;
428 unsigned int order;
429 Weights_t *weights;
430 std::wstring ce_wstr;
431 };
432
433 // The coll_map_ contains a mapping from the wide char value to the
434 // collition information about that value.
435 std::map<wchar_t, collate_info_t> coll_map_;
436 typedef std::map<wchar_t, collate_info_t>::iterator coll_map_iter;
437
438 // the ce_map_ contains a mapping from the symbolic collating element
439 // name to the collition information about that element
440 std::map <std::string, ce_info_t> ce_map_;
441 typedef std::map <std::string, ce_info_t>::iterator ce_map_iter;
442
443 // iterator type definitions for the maps
444 typedef std::map<wchar_t, unsigned int>::iterator mask_iter;
445 typedef std::map<wchar_t, wchar_t>::iterator upper_iter;
446 typedef std::map<wchar_t, wchar_t>::iterator lower_iter;
447 typedef std::map< std::string, unsigned char >::const_iterator n_cmap_iter;
448 typedef std::map<std::string, wchar_t>::const_iterator mb_cmap_iter;
449 typedef std::map<wchar_t, std::string>::const_iterator rmb_cmap_iter;
450 typedef std::map<std::string, wchar_t >::const_iterator w_cmap_iter;
451 typedef std::map<wchar_t, std::string >::const_iterator rw_cmap_iter;
452 typedef std::map<unsigned int, std::string>::iterator off_mapr_iter;
453 typedef std::map<std::string, wchar_t>::const_iterator ucs4_cmap_iter;
454
455 typedef std::list<std::string>::const_iterator symnames_list_iter;
456
457 // the structures used to hold the offsets for each locale category
458 // and any non-pointer locale information
459 _RW::__rw_punct_t num_punct_out_;
460 _RW::__rw_ctype_t ctype_out_;
461 _RW::__rw_time_t time_out_;
462 _RW::__rw_collate_t collate_out_;
463 _RW::__rw_mon_t mon_out_;
464 _RW::__rw_num_t num_out_;
465 _RW::__rw_messages_t messages_out_;
466
467 // structures used for internally holding locale information
468 // LC_CTYPE structures
469
470
471 struct ctype_t {
472 struct mask_elm {
473 wchar_t ch; // the wide character value
474 unsigned int mask; // the mask for that character
475 };
476 struct upper_elm {
477 wchar_t lower; // the lower case wide character
478 wchar_t upper; // the upper case wide character
479 };
480 struct lower_elm {
481 wchar_t upper; // the upper case wide character
482 wchar_t lower; // the lower case wide character
483 };
484
485 char max_mb_s; // the max number of bytes in a char
486 upper_elm* wtoupper_tab; // the wide char to_upper table
487 lower_elm* wtolower_tab; // the wide char to_lower table
488 mask_elm* wmask_tab; // the wide char mask_table
489
490 };
491
492
493 struct era_st {
494 std::string name;
495 std::string fmt;
496 std::wstring wname;
497 std::wstring wfmt;
498 _RW::__rw_time_t::era_t era_out;
499 };
500
501 std::list<era_st> era_list_;
502 typedef std::list<era_st>::iterator era_list_iter;
503
504 // LC_COLLATE structure
505 struct collate_t {
506 } ;
507
508
509
510 // LC_MONETARY structure
511 struct mon_t {
512 std::string int_curr_symbol; // narrow char* int_curr_symbol
513 std::string currency_symbol; // narrow char* currency_symbol
514 std::string mon_decimal_point; // narrow char* mon_decimal_point
515 std::string mon_thousands_sep; // narrow char* mon_thoucands_sep
516 std::string mon_grouping; // narrow char* mon_grouping
517 std::string positive_sign; // narrow char* positive_sign
518 std::string negative_sign; // narrow char* negative_sign
519 std::wstring wint_curr_symbol; // wide wchar_t* int_curr_symbol
520 std::wstring wcurrency_symbol; // wide wchar_t* currency_symbol
521 std::wstring wmon_decimal_point; // wide wchar_t* mon_decimal_point
522 std::wstring wmon_thousands_sep; // wide wchar_t* mon_thousands_sep
523 std::wstring wpositive_sign; // wide wchar_t* positive_sign
524 std::wstring wnegative_sign; // wide wchar_t* negative_sign
525 };
526
527
528
529 // LC_NUMERIC structure
530 struct num_t {
531 std::string decimal_point; // narrow char* decimal_point
532 std::string thousands_sep; // narrow char* thousands_sep
533 std::string grouping; // narrow char* grouping
534 std::string truename; // narrow char* truename
535 std::string falsename; // narrow char* falsename
536
537 std::wstring wdecimal_point; // wide wchar_t* decimal_point
538 std::wstring wthousands_sep; // wide wchar_t* thousands_sep
539 std::wstring wtruename; // wide wchar_t* truename
540 std::wstring wfalsename; // wide wchar_t* falsename
541 };
542
543 // list to hold the alternate digits
544 struct alt_digit_t {
545 std::string n_alt_digit;
546 std::wstring w_alt_digit;
547 unsigned int n_offset;
548 unsigned int w_offset;
549 };
550 std::list<alt_digit_t> alt_digits_;
551 typedef std::list<alt_digit_t>::iterator alt_digits_iter;
552
553 // LC_TIME structure
554 struct time_t {
555 std::string abday[7]; // narrow array of abbreviated days
556 std::string day[7]; // narrow array of days
557 std::string abmon[12]; // narrow array of abbreviated months
558 std::string mon[12]; // narrow array of months
559 std::string am_pm[2]; // narrow array of am/pm specifiers
560 std::string d_t_fmt; // narrow date and time format string
561 std::string d_fmt; // narrow date format string
562 std::string t_fmt; // narrow time format string
563 std::string t_fmt_ampm; // narrow time format string with am/pm
564 std::string era_d_t_fmt; // narrow era date and time format string
565 std::string era_d_fmt; // narrow era date format string
566 std::string era_t_fmt; // narrow era time format string
567
568
569
570 std::wstring wabday[7]; // wide array of abbreviated days
571 std::wstring wday[7]; // wide array of days
572 std::wstring wabmon[12]; // wide array of abbreviated months
573 std::wstring wmon[12]; // wide array of months
574 std::wstring wam_pm[2]; // wide array of am/pm specifiers
575 std::wstring wd_t_fmt; // wide date and time format string
576 std::wstring wd_fmt; // wide date format string
577 std::wstring wt_fmt; // wide time format string
578 std::wstring wt_fmt_ampm; // wide time format string with am/pm
579 std::wstring wera_d_t_fmt; // wide era date and time format string
580 std::wstring wera_d_fmt; // wide era date format string
581 std::wstring wera_t_fmt; // wide era time format string
582 } ;
583
584 // LC_MESSAGES structure
585 struct messages_t {
586 std::string yesexpr;
587 std::string noexpr;
588
589 std::wstring wyesexpr;
590 std::wstring wnoexpr;
591 };
592
593 messages_t messages_st_;
594 time_t time_st_;
595 ctype_t ctype_st_;
596 mon_t mon_st_;
597 num_t num_st_;
598 collate_t collate_st_;
599
600
601};
602
603
604inline std::string strip_quotes (const std::string& str)
605{
606 assert (0 != str.size ());
607 assert (str [0] == '\"');
608
609 // return a string from str[1] to the position of the end-quote
610 return std::string (str, 1, str.rfind ('\"') - 1);
611
612}
613
614
615#endif // RWSTD_UTIL_DEF_H_INCLUDED
#define off
Definition 17.names.cpp:507
#define offset
Definition 17.names.cpp:508
#define val
Definition 17.names.cpp:570
#define assert(expr)
Definition _cassert.h:40
Definition def.h:49
~Def()
Definition def.cpp:600
void write_time(std::string dir_name)
Definition time.cpp:351
void dump_collate()
Definition collate.cpp:1062
std::pair< token_t, token_t > token_pair_t
Definition def.h:96
std::pair< token_t, token_list_t > collate_entry_t
Definition def.h:98
void write_collate(std::string dir_name)
Definition collate.cpp:1156
std::list< collate_entry_t > collate_entry_list_t
Definition def.h:100
friend struct ce_info_t
Definition def.h:112
Scanner::token_t token_t
Definition def.h:95
void write_monetary(std::string dir_name)
Definition monetary.cpp:390
void write_messages(std::string dir_name)
Definition messages.cpp:121
std::pair< token_t, token_list_t > collate_elem_t
Definition def.h:99
void write_codecvt(std::string dir_name)
Definition codecvt.cpp:420
friend struct collate_info_t
Definition def.h:113
void write_numeric(std::string dir_name)
Definition numeric.cpp:140
void process_input()
Definition def.cpp:484
std::list< token_t > token_list_t
Definition def.h:97
bool warnings_occurred_
Definition def.h:90
bool scan_ahead_
Definition def.h:93
void write_ctype(std::string dir_name)
Definition ctype.cpp:826
const char * name
Definition codecvt1.cpp:72
std::string strip_quotes(const std::string &str)
Definition def.h:604
const char * str
Definition exec.cpp:170
#define UCHAR_MAX
Definition limits.h:60
std::string name
Definition def.h:104
token_list_t order
Definition def.h:105
collate_entry_list_t entries
Definition def.h:106
unsigned int mask
Definition def.h:474