| 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 26 matching lines...) Expand all Loading... |
| 37 return false; | 37 return false; |
| 38 } | 38 } |
| 39 hunspell::WordIterator iter = reader.GetAllWordIterator(); | 39 hunspell::WordIterator iter = reader.GetAllWordIterator(); |
| 40 | 40 |
| 41 int affix_ids[hunspell::BDict::MAX_AFFIXES_PER_WORD]; | 41 int affix_ids[hunspell::BDict::MAX_AFFIXES_PER_WORD]; |
| 42 | 42 |
| 43 static const int buf_size = 128; | 43 static const int buf_size = 128; |
| 44 char buf[buf_size]; | 44 char buf[buf_size]; |
| 45 for (size_t i = 0; i < org_words.size(); i++) { | 45 for (size_t i = 0; i < org_words.size(); i++) { |
| 46 int affix_matches = iter.Advance(buf, buf_size, affix_ids); | 46 int affix_matches = iter.Advance(buf, buf_size, affix_ids); |
| 47 if (affix_matches == 0) | 47 if (affix_matches == 0) { |
| 48 return false; // Found the end before we expectd. | 48 printf("Found the end before we expected\n"); |
| 49 if (org_words[i].first != buf) | 49 return false; |
| 50 return false; // Word doesn't match. | 50 } |
| 51 | 51 |
| 52 if (affix_matches != static_cast<int>(org_words[i].second.size())) | 52 if (org_words[i].first != buf) { |
| 53 return false; // Different number of affix indices. | 53 printf("Word doesn't match, word #%s\n", buf); |
| 54 return false; |
| 55 } |
| 56 |
| 57 if (affix_matches != static_cast<int>(org_words[i].second.size())) { |
| 58 printf("Different number of affix indices, word #%s\n", buf); |
| 59 return false; |
| 60 } |
| 54 | 61 |
| 55 // Check the individual affix indices. | 62 // Check the individual affix indices. |
| 56 for (size_t affix_index = 0; affix_index < org_words[i].second.size(); | 63 for (size_t affix_index = 0; affix_index < org_words[i].second.size(); |
| 57 affix_index++) { | 64 affix_index++) { |
| 58 if (affix_ids[affix_index] != org_words[i].second[affix_index]) | 65 if (affix_ids[affix_index] != org_words[i].second[affix_index]) { |
| 59 return false; // Index doesn't match. | 66 printf("Index doesn't match, word #%s\n", buf); |
| 67 return false; |
| 68 } |
| 60 } | 69 } |
| 61 } | 70 } |
| 62 | 71 |
| 63 return true; | 72 return true; |
| 64 } | 73 } |
| 65 | 74 |
| 66 int PrintHelp() { | 75 int PrintHelp() { |
| 67 printf("Usage: convert_dict <dicfile base name>\n\n"); | 76 printf("Usage: convert_dict <dicfile base name>\n\n"); |
| 68 printf("Example:\n"); | 77 printf("Example:\n"); |
| 69 printf(" convert_dict en-US\nwill read en-US.dic / en-US.aff and\n"); | 78 printf(" convert_dict en-US\nwill read en-US.dic / en-US.aff and\n"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 if (!out_file) { | 131 if (!out_file) { |
| 123 printf("ERROR writing file\n"); | 132 printf("ERROR writing file\n"); |
| 124 return 1; | 133 return 1; |
| 125 } | 134 } |
| 126 size_t written = fwrite(&serialized[0], 1, serialized.size(), out_file); | 135 size_t written = fwrite(&serialized[0], 1, serialized.size(), out_file); |
| 127 CHECK(written == serialized.size()); | 136 CHECK(written == serialized.size()); |
| 128 file_util::CloseFile(out_file); | 137 file_util::CloseFile(out_file); |
| 129 | 138 |
| 130 return 0; | 139 return 0; |
| 131 } | 140 } |
| OLD | NEW |