55 std::string usage =
"Prints out binary FSTs in dot text format.\n\n Usage: ";
57 usage +=
" [binary.fst [text.dot]]\n";
59 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
65 const std::string in_name =
66 argc > 1 && strcmp(argv[1],
"-") != 0 ? argv[1] :
"";
68 std::unique_ptr<FstClass>
fst(FstClass::Read(in_name));
71 const std::string out_name =
72 argc > 2 && strcmp(argv[2],
"-") != 0 ? argv[2] :
"";
74 if (!out_name.empty()) {
77 LOG(ERROR) << argv[0] <<
": Open failed, file = " << out_name;
81 std::ostream &ostrm = fstrm.is_open() ? fstrm : std::cout;
83 std::unique_ptr<const SymbolTable> isyms;
84 if (!FST_FLAGS_isymbols.empty() && !FST_FLAGS_numeric) {
86 SymbolTable::ReadText(FST_FLAGS_isymbols,
87 FST_FLAGS_fst_field_separator));
91 std::unique_ptr<const SymbolTable> osyms;
92 if (!FST_FLAGS_osymbols.empty() && !FST_FLAGS_numeric) {
94 SymbolTable::ReadText(FST_FLAGS_osymbols,
95 FST_FLAGS_fst_field_separator));
99 std::unique_ptr<const SymbolTable> ssyms;
100 if (!FST_FLAGS_ssymbols.empty() && !FST_FLAGS_numeric) {
102 SymbolTable::ReadText(FST_FLAGS_osymbols,
103 FST_FLAGS_fst_field_separator));
104 if (!ssyms)
return 1;
107 if (!isyms && !FST_FLAGS_numeric && fst->InputSymbols()) {
108 isyms.reset(fst->InputSymbols()->Copy());
111 if (!osyms && !FST_FLAGS_numeric && fst->OutputSymbols()) {
112 osyms.reset(fst->OutputSymbols()->Copy());
116 const std::string dest = out_name.empty() ?
"stdout" : out_name;
117 s::Draw(*fst, isyms.get(), osyms.get(), ssyms.get(),
118 FST_FLAGS_acceptor, FST_FLAGS_title,
119 FST_FLAGS_width, FST_FLAGS_height,
120 FST_FLAGS_portrait, FST_FLAGS_vertical,
121 FST_FLAGS_ranksep, FST_FLAGS_nodesep,
122 FST_FLAGS_fontsize, FST_FLAGS_precision,
123 FST_FLAGS_float_format,
124 FST_FLAGS_show_weight_one, ostrm, dest);
void ShowUsage(bool long_usage=true)
int fstdraw_main(int argc, char **argv)
#define SET_FLAGS(usage, argc, argv, rmflags)
void Draw(FstDrawArgs *args)