Debian Codegraph @

src/tools/DictConverter.cpp

raw symbols SCIP
1 /*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2026 Carbo Kuo and contributors
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include "src/DictConverter.hpp"
20 #include "src/CmdLineOutput.hpp"
21 #include "src/Exception.hpp"
22
23 using namespace opencc;
24
25 int main(int argc, const char* argv[]) {
26 try {
27 TCLAP::CmdLine cmd("Open Chinese Convert (OpenCC) Dictionary Tool", ' ',
28 OPENCC_VERSION);
29 CmdLineOutput cmdLineOutput;
30 cmd.setOutput(&cmdLineOutput);
31
32 std::vector<std::string> inputFormats{"text", "text_space", "ocd2", "ocd",
33 "cppjieba_utf8"};
34 TCLAP::ValuesConstraint<std::string> allowedInputVals(inputFormats);
35 std::vector<std::string> outputFormats{"text", "ocd2", "ocd"};
36 TCLAP::ValuesConstraint<std::string> allowedOutputVals(outputFormats);
37
38 TCLAP::ValueArg<std::string> toArg("t", "to", "Output format",
39 true /* required */, "" /* default */,
40 &allowedOutputVals /* type */, cmd);
41 TCLAP::ValueArg<std::string> fromArg("f", "from", "Input format",
42 true /* required */, "" /* default */,
43 &allowedInputVals /* type */, cmd);
44 TCLAP::ValueArg<std::string> outputArg(
45 "o", "output", "Path to output dictionary", true /* required */,
46 "" /* default */, "file" /* type */, cmd);
47 TCLAP::MultiArg<std::string> inputArg(
48 "i", "input", "Path to input dictionary", true /* required */,
49 "file" /* type */, cmd);
50 cmd.parse(argc, argv);
51 ConvertDictionary(inputArg.getValue(), outputArg.getValue(),
52 fromArg.getValue(), toArg.getValue());
53 } catch (TCLAP::ArgException& e) {
54 std::cerr << "error: " << e.error() << " for arg " << e.argId()
55 << std::endl;
56 return 1;
57 } catch (Exception& e) {
58 std::cerr << e.what() << std::endl;
59 return 1;
60 }
61 return 0;
62 }