FST  openfst-1.7.3
OpenFst Library
fstinfo-main.cc
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Prints out various information about an FST such as number of states
5 // and arcs and property values (see properties.h).
6 
7 #include <cstring>
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/script/info.h>
13 
14 DECLARE_string(arc_filter);
15 DECLARE_string(info_type);
16 DECLARE_bool(pipe);
17 DECLARE_bool(test_properties);
18 DECLARE_bool(fst_verify);
19 
20 int fstinfo_main(int argc, char **argv) {
21  namespace s = fst::script;
23 
24  std::string usage = "Prints out information about an FST.\n\n Usage: ";
25  usage += argv[0];
26  usage += " [in.fst]\n";
27 
28  std::set_new_handler(FailedNewHandler);
29  SET_FLAGS(usage.c_str(), &argc, &argv, true);
30  if (argc > 2) {
31  ShowUsage();
32  return 1;
33  }
34 
35  const std::string in_name =
36  (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : "";
37 
38  std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
39  if (!ifst) return 1;
40 
41  s::PrintFstInfo(*ifst, FLAGS_test_properties, FLAGS_arc_filter,
42  FLAGS_info_type, FLAGS_fst_verify, FLAGS_pipe);
43 
44  return 0;
45 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:121
int fstinfo_main(int argc, char **argv)
Definition: fstinfo-main.cc:20
DECLARE_bool(pipe)
void FailedNewHandler()
Definition: compat.cc:20
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:209
void PrintFstInfo(InfoArgs *args)
Definition: info.h:21
DECLARE_string(arc_filter)