Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: source/tools/gennorm2/gennorm2.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/tools/dumpce/dumpce.dsw ('k') | source/tools/gennorm2/n2builder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ******************************************************************************* 2 *******************************************************************************
3 * 3 *
4 * Copyright (C) 2009-2012, International Business Machines 4 * Copyright (C) 2009-2014, International Business Machines
5 * Corporation and others. All Rights Reserved. 5 * Corporation and others. All Rights Reserved.
6 * 6 *
7 ******************************************************************************* 7 *******************************************************************************
8 * file name: gennorm2.cpp 8 * file name: gennorm2.cpp
9 * encoding: US-ASCII 9 * encoding: US-ASCII
10 * tab size: 8 (not used) 10 * tab size: 8 (not used)
11 * indentation:4 11 * indentation:4
12 * 12 *
13 * created on: 2009nov25 13 * created on: 2009nov25
14 * created by: Markus W. Scherer 14 * created by: Markus W. Scherer
(...skipping 16 matching lines...) Expand all
31 #include "charstr.h" 31 #include "charstr.h"
32 #include "normalizer2impl.h" 32 #include "normalizer2impl.h"
33 #include "toolutil.h" 33 #include "toolutil.h"
34 #include "uoptions.h" 34 #include "uoptions.h"
35 #include "uparse.h" 35 #include "uparse.h"
36 36
37 #if UCONFIG_NO_NORMALIZATION 37 #if UCONFIG_NO_NORMALIZATION
38 #include "unewdata.h" 38 #include "unewdata.h"
39 #endif 39 #endif
40 40
41 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
42
43 U_NAMESPACE_BEGIN 41 U_NAMESPACE_BEGIN
44 42
45 UBool beVerbose=FALSE, haveCopyright=TRUE; 43 UBool beVerbose=FALSE, haveCopyright=TRUE;
46 44
47 U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose); 45 U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose);
48 46
49 #if !UCONFIG_NO_NORMALIZATION 47 #if !UCONFIG_NO_NORMALIZATION
50 void parseFile(FILE *f, Normalizer2DataBuilder &builder); 48 void parseFile(FILE *f, Normalizer2DataBuilder &builder);
51 #endif 49 #endif
52 50
53 /* -------------------------------------------------------------------------- */ 51 /* -------------------------------------------------------------------------- */
54 52
55 enum { 53 enum {
56 HELP_H, 54 HELP_H,
57 HELP_QUESTION_MARK, 55 HELP_QUESTION_MARK,
58 VERBOSE, 56 VERBOSE,
59 COPYRIGHT, 57 COPYRIGHT,
60 SOURCEDIR, 58 SOURCEDIR,
61 OUTPUT_FILENAME, 59 OUTPUT_FILENAME,
62 UNICODE_VERSION, 60 UNICODE_VERSION,
61 WRITE_C_SOURCE,
63 OPT_FAST 62 OPT_FAST
64 }; 63 };
65 64
66 static UOption options[]={ 65 static UOption options[]={
67 UOPTION_HELP_H, 66 UOPTION_HELP_H,
68 UOPTION_HELP_QUESTION_MARK, 67 UOPTION_HELP_QUESTION_MARK,
69 UOPTION_VERBOSE, 68 UOPTION_VERBOSE,
70 UOPTION_COPYRIGHT, 69 UOPTION_COPYRIGHT,
71 UOPTION_SOURCEDIR, 70 UOPTION_SOURCEDIR,
72 UOPTION_DEF("output", 'o', UOPT_REQUIRES_ARG), 71 UOPTION_DEF("output", 'o', UOPT_REQUIRES_ARG),
73 UOPTION_DEF("unicode", 'u', UOPT_REQUIRES_ARG), 72 UOPTION_DEF("unicode", 'u', UOPT_REQUIRES_ARG),
73 UOPTION_DEF("csource", '\1', UOPT_NO_ARG),
74 UOPTION_DEF("fast", '\1', UOPT_NO_ARG) 74 UOPTION_DEF("fast", '\1', UOPT_NO_ARG)
75 }; 75 };
76 76
77 extern "C" int 77 extern "C" int
78 main(int argc, char* argv[]) { 78 main(int argc, char* argv[]) {
79 U_MAIN_INIT_ARGS(argc, argv); 79 U_MAIN_INIT_ARGS(argc, argv);
80 80
81 /* preset then read command line options */ 81 /* preset then read command line options */
82 options[SOURCEDIR].value=""; 82 options[SOURCEDIR].value="";
83 argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[HELP_H]), option s); 83 argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[HELP_H]), option s);
(...skipping 11 matching lines...) Expand all
95 options[HELP_H].doesOccur || options[HELP_QUESTION_MARK].doesOccur 95 options[HELP_H].doesOccur || options[HELP_QUESTION_MARK].doesOccur
96 ) { 96 ) {
97 /* 97 /*
98 * Broken into chunks because the C89 standard says the minimum 98 * Broken into chunks because the C89 standard says the minimum
99 * required supported string length is 509 bytes. 99 * required supported string length is 509 bytes.
100 */ 100 */
101 fprintf(stderr, 101 fprintf(stderr,
102 "Usage: %s [-options] infiles+ -o outputfilename\n" 102 "Usage: %s [-options] infiles+ -o outputfilename\n"
103 "\n" 103 "\n"
104 "Reads the infiles with normalization data and\n" 104 "Reads the infiles with normalization data and\n"
105 "creates a binary file (outputfilename) with the data.\n" 105 "creates a binary or C source file (outputfilename) with the data.\n "
106 "\n", 106 "\n",
107 argv[0]); 107 argv[0]);
108 fprintf(stderr, 108 fprintf(stderr,
109 "Options:\n" 109 "Options:\n"
110 "\t-h or -? or --help this usage text\n" 110 "\t-h or -? or --help this usage text\n"
111 "\t-v or --verbose verbose output\n" 111 "\t-v or --verbose verbose output\n"
112 "\t-c or --copyright include a copyright notice\n" 112 "\t-c or --copyright include a copyright notice\n"
113 "\t-u or --unicode Unicode version, followed by the version like 5.2.0\n"); 113 "\t-u or --unicode Unicode version, followed by the version like 5.2.0\n");
114 fprintf(stderr, 114 fprintf(stderr,
115 "\t-s or --sourcedir source directory, followed by the path\n" 115 "\t-s or --sourcedir source directory, followed by the path\n"
116 "\t-o or --output output filename\n"); 116 "\t-o or --output output filename\n"
117 "\t --csource writes a C source file with initializers\n");
117 fprintf(stderr, 118 fprintf(stderr,
118 "\t --fast optimize the .nrm file for fast normalization ,\n" 119 "\t --fast optimize the data for fast normalization,\n"
119 "\t which might increase its size (Writes fully decomposed\n" 120 "\t which might increase its size (Writes fully decomposed\n"
120 "\t regular mappings instead of delta mappings.\n " 121 "\t regular mappings instead of delta mappings.\n "
121 "\t You should measure the runtime speed to make sure that\n" 122 "\t You should measure the runtime speed to make sure that\n"
122 "\t this is a good trade-off.)\n"); 123 "\t this is a good trade-off.)\n");
123 return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; 124 return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
124 } 125 }
125 126
126 beVerbose=options[VERBOSE].doesOccur; 127 beVerbose=options[VERBOSE].doesOccur;
127 haveCopyright=options[COPYRIGHT].doesOccur; 128 haveCopyright=options[COPYRIGHT].doesOccur;
128 129
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 LocalStdioFilePointer f(fopen(filename.data(), "r")); 170 LocalStdioFilePointer f(fopen(filename.data(), "r"));
170 if(f==NULL) { 171 if(f==NULL) {
171 fprintf(stderr, "gennorm2 error: unable to open %s\n", filename.data ()); 172 fprintf(stderr, "gennorm2 error: unable to open %s\n", filename.data ());
172 exit(U_FILE_ACCESS_ERROR); 173 exit(U_FILE_ACCESS_ERROR);
173 } 174 }
174 builder->setOverrideHandling(Normalizer2DataBuilder::OVERRIDE_PREVIOUS); 175 builder->setOverrideHandling(Normalizer2DataBuilder::OVERRIDE_PREVIOUS);
175 parseFile(f.getAlias(), *builder); 176 parseFile(f.getAlias(), *builder);
176 filename.truncate(pathLength); 177 filename.truncate(pathLength);
177 } 178 }
178 179
179 builder->writeBinaryFile(options[OUTPUT_FILENAME].value); 180 if(options[WRITE_C_SOURCE].doesOccur) {
181 builder->writeCSourceFile(options[OUTPUT_FILENAME].value);
182 } else {
183 builder->writeBinaryFile(options[OUTPUT_FILENAME].value);
184 }
180 185
181 return errorCode.get(); 186 return errorCode.get();
182 187
183 #endif 188 #endif
184 } 189 }
185 190
186 #if !UCONFIG_NO_NORMALIZATION 191 #if !UCONFIG_NO_NORMALIZATION
187 192
188 void parseFile(FILE *f, Normalizer2DataBuilder &builder) { 193 void parseFile(FILE *f, Normalizer2DataBuilder &builder) {
189 IcuToolErrorCode errorCode("gennorm2/parseFile()"); 194 IcuToolErrorCode errorCode("gennorm2/parseFile()");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 fprintf(stderr, "gennorm2 error: parsing remove-mapping %s\n", l ine); 237 fprintf(stderr, "gennorm2 error: parsing remove-mapping %s\n", l ine);
233 exit(U_PARSE_ERROR); 238 exit(U_PARSE_ERROR);
234 } 239 }
235 for(UChar32 c=(UChar32)startCP; c<=(UChar32)endCP; ++c) { 240 for(UChar32 c=(UChar32)startCP; c<=(UChar32)endCP; ++c) {
236 builder.removeMapping(c); 241 builder.removeMapping(c);
237 } 242 }
238 continue; 243 continue;
239 } 244 }
240 if(*delimiter=='=' || *delimiter=='>') { 245 if(*delimiter=='=' || *delimiter=='>') {
241 UChar uchars[Normalizer2Impl::MAPPING_LENGTH_MASK]; 246 UChar uchars[Normalizer2Impl::MAPPING_LENGTH_MASK];
242 int32_t length=u_parseString(delimiter+1, uchars, LENGTHOF(uchars), NULL, errorCode); 247 int32_t length=u_parseString(delimiter+1, uchars, UPRV_LENGTHOF(ucha rs), NULL, errorCode);
243 if(errorCode.isFailure()) { 248 if(errorCode.isFailure()) {
244 fprintf(stderr, "gennorm2 error: parsing mapping string from %s\ n", line); 249 fprintf(stderr, "gennorm2 error: parsing mapping string from %s\ n", line);
245 exit(errorCode.reset()); 250 exit(errorCode.reset());
246 } 251 }
247 UnicodeString mapping(FALSE, uchars, length); 252 UnicodeString mapping(FALSE, uchars, length);
248 if(*delimiter=='=') { 253 if(*delimiter=='=') {
249 if(rangeLength!=1) { 254 if(rangeLength!=1) {
250 fprintf(stderr, 255 fprintf(stderr,
251 "gennorm2 error: round-trip mapping for more than 1 code point on %s\n", 256 "gennorm2 error: round-trip mapping for more than 1 code point on %s\n",
252 line); 257 line);
(...skipping 17 matching lines...) Expand all
270 U_NAMESPACE_END 275 U_NAMESPACE_END
271 276
272 /* 277 /*
273 * Hey, Emacs, please set the following: 278 * Hey, Emacs, please set the following:
274 * 279 *
275 * Local Variables: 280 * Local Variables:
276 * indent-tabs-mode: nil 281 * indent-tabs-mode: nil
277 * End: 282 * End:
278 * 283 *
279 */ 284 */
OLDNEW
« no previous file with comments | « source/tools/dumpce/dumpce.dsw ('k') | source/tools/gennorm2/n2builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698