MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / main

Function main

plugins/jieba/tools/cppjieba_dict.cpp:242–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240} // namespace
241
242int main(int argc, char** argv) {
243 std::vector<std::string> input_paths;
244 std::string output_path;
245
246 for (int i = 1; i < argc; ++i) {
247 const std::string arg = argv[i];
248 if (arg == "-i") {
249 if (i + 1 >= argc) {
250 std::cerr << "cppjieba_dict: missing value after -i" << std::endl;
251 PrintUsage(std::cerr);
252 return 1;
253 }
254 input_paths.push_back(argv[++i]);
255 continue;
256 }
257 if (arg == "-o") {
258 if (i + 1 >= argc) {
259 std::cerr << "cppjieba_dict: missing value after -o" << std::endl;
260 PrintUsage(std::cerr);
261 return 1;
262 }
263 if (!output_path.empty()) {
264 std::cerr << "cppjieba_dict: exactly one -o is required" << std::endl;
265 PrintUsage(std::cerr);
266 return 1;
267 }
268 output_path = argv[++i];
269 continue;
270 }
271
272 std::cerr << "cppjieba_dict: unknown argument: " << arg << std::endl;
273 PrintUsage(std::cerr);
274 return 1;
275 }
276
277 if (input_paths.empty()) {
278 std::cerr << "cppjieba_dict: at least one -i is required" << std::endl;
279 PrintUsage(std::cerr);
280 return 1;
281 }
282 if (output_path.empty()) {
283 std::cerr << "cppjieba_dict: exactly one -o is required" << std::endl;
284 PrintUsage(std::cerr);
285 return 1;
286 }
287
288 try {
289 std::map<std::string, std::vector<std::string> > entries;
290 LoadBaseDict(input_paths.front(), entries);
291 for (size_t i = 1; i < input_paths.size(); ++i) {
292 LoadUserDict(input_paths[i], entries);
293 }
294 WriteOcd2(entries, output_path);
295 std::cout << "Wrote " << entries.size() << " entries to " << output_path
296 << std::endl;
297 } catch (const std::exception& e) {
298 std::cerr << "cppjieba_dict: " << e.what() << std::endl;
299 return 1;

Callers

nothing calls this directly

Calls 8

PrintUsageFunction · 0.85
LoadBaseDictFunction · 0.85
LoadUserDictFunction · 0.85
WriteOcd2Function · 0.85
push_backMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected