1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
Taken from
https://github.com/qvint/ungoogled-chromium-fedora/commit/a68fdd679566da5134d916776f14e00c8e6a8042
--- a/chrome/tools/convert_dict/BUILD.gn
+++ b/chrome/tools/convert_dict/BUILD.gn
@@ -32,6 +32,7 @@ executable("convert_dict") {
"//base",
"//base:i18n",
"//build/win:default_exe_manifest",
+ "//components/spellcheck/common",
"//third_party/hunspell",
]
}
--- a/chrome/tools/convert_dict/convert_dict.cc
+++ b/chrome/tools/convert_dict/convert_dict.cc
@@ -26,6 +26,7 @@
#include "build/build_config.h"
#include "chrome/tools/convert_dict/aff_reader.h"
#include "chrome/tools/convert_dict/dic_reader.h"
+#include "components/spellcheck/common/spellcheck_common.h"
#include "third_party/hunspell/google/bdict_reader.h"
#include "third_party/hunspell/google/bdict_writer.h"
@@ -78,13 +79,32 @@ bool VerifyWords(const convert_dict::Dic
}
int PrintHelp() {
- printf("Usage: convert_dict <dicfile base name>\n\n");
- printf("Example:\n");
- printf(" convert_dict en-US\nwill read en-US.dic, en-US.dic_delta, and "
- "en-US.aff from the current directory and generate en-US.bdic\n\n");
+ printf(
+ "Usage:\n"
+ " dict-utility list\n"
+ " dict-utility convert <aff_path> <dic_path> <out_path>\n");
return 1;
}
+int PrintList() {
+ base::FilePath root("/");
+ std::vector<std::string> languages = spellcheck::SpellCheckLanguages();
+
+ for (auto &language : languages) {
+ std::string language_region =
+ spellcheck::GetSpellCheckLanguageRegion(language);
+ base::FilePath language_bdic_path =
+ spellcheck::GetVersionedFileName(language, root).BaseName();
+
+ printf("%s\t%s\t%s\n",
+ language.c_str(),
+ language_region.c_str(),
+ language_bdic_path.value().c_str());
+ }
+
+ return 0;
+}
+
} // namespace
#if BUILDFLAG(IS_WIN)
@@ -93,16 +113,15 @@ int wmain(int argc, wchar_t* argv[]) {
int main(int argc, char* argv[]) {
#endif
base::EnableTerminationOnHeapCorruption();
- if (argc != 2)
+ if (argc == 2 && strcmp(argv[1], "list") == 0)
+ return PrintList();
+ if (argc != 5 || strcmp(argv[1], "convert") != 0)
return PrintHelp();
base::AtExitManager exit_manager;
base::i18n::InitializeICU();
- base::FilePath file_base = base::FilePath(UNSAFE_TODO(argv[1]));
-
- base::FilePath aff_path =
- file_base.ReplaceExtension(FILE_PATH_LITERAL(".aff"));
+ base::FilePath aff_path = base::FilePath(argv[2]);
printf("Reading %" PRFilePath " ...\n", aff_path.value().c_str());
convert_dict::AffReader aff_reader(aff_path);
if (!aff_reader.Read()) {
@@ -110,8 +129,7 @@ int main(int argc, char* argv[]) {
return 1;
}
- base::FilePath dic_path =
- file_base.ReplaceExtension(FILE_PATH_LITERAL(".dic"));
+ base::FilePath dic_path = base::FilePath(argv[3]);
printf("Reading %" PRFilePath " ...\n", dic_path.value().c_str());
// DicReader will also read the .dic_delta file.
convert_dict::DicReader dic_reader(dic_path);
@@ -137,8 +155,7 @@ int main(int argc, char* argv[]) {
return 1;
}
- base::FilePath out_path =
- file_base.ReplaceExtension(FILE_PATH_LITERAL(".bdic"));
+ base::FilePath out_path = base::FilePath(argv[4]);
printf("Writing %" PRFilePath " ...\n", out_path.value().c_str());
FILE* out_file = base::OpenFile(out_path, "wb");
if (!out_file) {
--- a/components/spellcheck/common/spellcheck_common.cc
+++ b/components/spellcheck/common/spellcheck_common.cc
@@ -18,8 +18,6 @@
namespace spellcheck {
-namespace {
-
struct LanguageRegion {
const char* language; // The language.
const char* language_region; // language & region, used by dictionaries.
@@ -105,8 +103,6 @@ std::string GetSpellCheckLanguageRegion(
return std::string(input_language);
}
-} // namespace
-
base::FilePath GetVersionedFileName(std::string_view input_language,
const base::FilePath& dict_dir) {
// The default dictionary version is 3-0. This version indicates that the bdic
--- a/components/spellcheck/common/spellcheck_common.h
+++ b/components/spellcheck/common/spellcheck_common.h
@@ -46,6 +46,7 @@ base::FilePath GetVersionedFileName(std:
// no single dictionary for English, so this function returns an empty string
// for "en".
std::string GetCorrespondingSpellCheckLanguage(std::string_view language);
+std::string GetSpellCheckLanguageRegion(std::string_view input_language);
// Get SpellChecker supported languages.
std::vector<std::string> SpellCheckLanguages();
|