55 std::string usage =
"Compiles a set of strings as FSTs and stores them in";
56 usage +=
" an FST archive.\n\n Usage: ";
58 usage +=
" [in1.txt [[in2.txt ...] out.far]]\n";
60 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
63 std::vector<std::string> sources;
64 if (FST_FLAGS_file_list_input) {
65 for (
int i = 1; i < argc - 1; ++i) {
66 std::ifstream istrm(argv[i]);
68 while (std::getline(istrm, str)) sources.push_back(str);
71 for (
int i = 1; i < argc - 1; ++i)
72 sources.push_back(strcmp(argv[i],
"-") != 0 ? argv[i] :
"");
73 if (sources.empty()) {
76 sources.push_back(argc == 2 && strcmp(argv[1],
"-") != 0 ? argv[1] :
"");
81 const std::string out_far =
82 argc > 2 && strcmp(argv[argc - 1],
"-") != 0 ? argv[argc - 1] :
"";
86 LOG(ERROR) <<
"Unknown or unsupported FAR entry type: " 87 << FST_FLAGS_entry_type;
93 LOG(ERROR) <<
"Unknown or unsupported FAR token type: " 94 << FST_FLAGS_token_type;
100 LOG(ERROR) <<
"Unknown or unsupported FAR type: " 101 << FST_FLAGS_far_type;
107 const std::string fst_type = FST_FLAGS_fst_type.empty()
109 : FST_FLAGS_fst_type;
111 const auto arc_type = FST_FLAGS_arc_type;
112 if (arc_type.empty())
return 1;
114 std::unique_ptr<FarWriterClass> writer(
116 if (!writer)
return 1;
119 sources, *writer, fst_type, FST_FLAGS_generate_keys,
120 entry_type, token_type, FST_FLAGS_symbols,
121 FST_FLAGS_unknown_symbol, FST_FLAGS_keep_symbols,
122 FST_FLAGS_initial_symbols,
123 FST_FLAGS_key_prefix, FST_FLAGS_key_suffix);
125 if (writer->Error()) {
126 FSTERROR() <<
"Error writing FAR: " << out_far;
bool GetTokenType(std::string_view str, TokenType *token_type)
int farcompilestrings_main(int argc, char **argv)
DECLARE_int32(generate_keys)
void ExpandArgs(int argc, char **argv, int *argcp, char ***argvp)
bool GetFarEntryType(std::string_view str, FarEntryType *entry_type)
#define SET_FLAGS(usage, argc, argv, rmflags)
bool GetFarType(std::string_view str, FarType *far_type)
DECLARE_bool(file_list_input)
void Create(const std::vector< std::string > &sources, FarWriterClass &writer, const int32_t generate_keys, const std::string &key_prefix, const std::string &key_suffix)
DECLARE_string(key_prefix)
void CompileStrings(const std::vector< std::string > &sources, FarWriterClass &writer, std::string_view fst_type, int32_t generate_keys, FarEntryType fet, TokenType tt, const std::string &symbols_source, const std::string &unknown_symbol, bool keep_symbols, bool initial_symbols, const std::string &key_prefix, const std::string &key_suffix)