OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This tool converts Hunspell .aff/.dic pairs to a combined binary dictionary | 5 // This tool converts Hunspell .aff/.dic pairs to a combined binary dictionary |
6 // format (.bdic). This format is more compact, and can be more efficiently | 6 // format (.bdic). This format is more compact, and can be more efficiently |
7 // read by the client application. | 7 // read by the client application. |
8 // | 8 // |
9 // We do this conversion manually before publishing dictionary files. It is not | 9 // We do this conversion manually before publishing dictionary files. It is not |
10 // part of any build process. | 10 // part of any build process. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 int PrintHelp() { | 76 int PrintHelp() { |
77 printf("Usage: convert_dict <dicfile base name>\n\n"); | 77 printf("Usage: convert_dict <dicfile base name>\n\n"); |
78 printf("Example:\n"); | 78 printf("Example:\n"); |
79 printf(" convert_dict en-US\nwill read en-US.dic / en-US.aff and\n"); | 79 printf(" $ convert_dict en-US\nwill read en-US.dic, en-US.dic_delta, and " |
brettw
2011/01/20 23:49:58
The addition of $ is confusing here since I normal
| |
80 printf("generate en-US.bdic\n\n"); | 80 "en-US.aff and generate en-US.bdic\n\n"); |
81 return 1; | 81 return 1; |
82 } | 82 } |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
86 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
87 int wmain(int argc, wchar_t* argv[]) { | 87 int wmain(int argc, wchar_t* argv[]) { |
88 #else | 88 #else |
89 int main(int argc, char* argv[]) { | 89 int main(int argc, char* argv[]) { |
90 #endif | 90 #endif |
91 base::EnableTerminationOnHeapCorruption(); | 91 base::EnableTerminationOnHeapCorruption(); |
92 if (argc != 2) | 92 if (argc != 2) |
93 return PrintHelp(); | 93 return PrintHelp(); |
94 | 94 |
95 base::AtExitManager exit_manager; | 95 base::AtExitManager exit_manager; |
96 icu_util::Initialize(); | 96 icu_util::Initialize(); |
97 | 97 |
98 FilePath file_base = FilePath(argv[1]); | 98 FilePath file_base = FilePath(argv[1]); |
99 | 99 |
100 FilePath aff_path = file_base.ReplaceExtension(FILE_PATH_LITERAL(".aff")); | 100 FilePath aff_path = file_base.ReplaceExtension(FILE_PATH_LITERAL(".aff")); |
101 printf("Reading %" PRFilePath " ...\n", aff_path.value().c_str()); | 101 printf("Reading %" PRFilePath " ...\n", aff_path.value().c_str()); |
102 convert_dict::AffReader aff_reader(aff_path); | 102 convert_dict::AffReader aff_reader(aff_path); |
103 if (!aff_reader.Read()) { | 103 if (!aff_reader.Read()) { |
104 printf("Unable to read the aff file.\n"); | 104 printf("Unable to read the aff file.\n"); |
105 return 1; | 105 return 1; |
106 } | 106 } |
107 | 107 |
108 FilePath dic_path = file_base.ReplaceExtension(FILE_PATH_LITERAL(".dic")); | 108 FilePath dic_path = file_base.ReplaceExtension(FILE_PATH_LITERAL(".dic")); |
109 printf("Reading %" PRFilePath " ...\n", dic_path.value().c_str()); | 109 printf("Reading %" PRFilePath " ...\n", dic_path.value().c_str()); |
110 // DicReader will also read the .dic_delta file. | |
110 convert_dict::DicReader dic_reader(dic_path); | 111 convert_dict::DicReader dic_reader(dic_path); |
111 if (!dic_reader.Read(&aff_reader)) { | 112 if (!dic_reader.Read(&aff_reader)) { |
112 printf("Unable to read the dic file.\n"); | 113 printf("Unable to read the dic file.\n"); |
113 return 1; | 114 return 1; |
114 } | 115 } |
115 | 116 |
116 hunspell::BDictWriter writer; | 117 hunspell::BDictWriter writer; |
117 writer.SetComment(aff_reader.comments()); | 118 writer.SetComment(aff_reader.comments()); |
118 writer.SetAffixRules(aff_reader.affix_rules()); | 119 writer.SetAffixRules(aff_reader.affix_rules()); |
119 writer.SetAffixGroups(aff_reader.GetAffixGroups()); | 120 writer.SetAffixGroups(aff_reader.GetAffixGroups()); |
(...skipping 16 matching lines...) Expand all Loading... | |
136 if (!out_file) { | 137 if (!out_file) { |
137 printf("ERROR writing file\n"); | 138 printf("ERROR writing file\n"); |
138 return 1; | 139 return 1; |
139 } | 140 } |
140 size_t written = fwrite(&serialized[0], 1, serialized.size(), out_file); | 141 size_t written = fwrite(&serialized[0], 1, serialized.size(), out_file); |
141 CHECK(written == serialized.size()); | 142 CHECK(written == serialized.size()); |
142 file_util::CloseFile(out_file); | 143 file_util::CloseFile(out_file); |
143 | 144 |
144 return 0; | 145 return 0; |
145 } | 146 } |
OLD | NEW |