FST  openfst-1.7.3
OpenFst Library
fstconnect-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 // Removes useless (inaccessible or non-coaccessible) states and arcs from an
5 // FST.
6 
7 #include <cstring>
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/script/connect.h>
13 
14 int fstconnect_main(int argc, char **argv) {
15  namespace s = fst::script;
18 
19  std::string usage =
20  "Removes useless states and arcs from an FST.\n\n Usage: ";
21  usage += argv[0];
22  usage += " [in.fst [out.fst]]\n";
23 
24  std::set_new_handler(FailedNewHandler);
25  SET_FLAGS(usage.c_str(), &argc, &argv, true);
26  if (argc > 3) {
27  ShowUsage();
28  return 1;
29  }
30 
31  const std::string in_name =
32  (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
33  const std::string out_name =
34  (argc > 2 && strcmp(argv[2], "-") != 0) ? argv[2] : "";
35 
36  std::unique_ptr<MutableFstClass> fst(MutableFstClass::Read(in_name, true));
37  if (!fst) return 1;
38 
39  s::Connect(fst.get());
40 
41  return !fst->Write(out_name);
42 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:121
void Connect(MutableFst< Arc > *fst)
Definition: connect.h:268
void FailedNewHandler()
Definition: compat.cc:20
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:209
int fstconnect_main(int argc, char **argv)