FST  openfst-1.7.2
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 
9 #include <memory>
10 #include <string>
11 
12 #include <fst/flags.h>
13 #include <fst/script/connect.h>
14 
15 int fstconnect_main(int argc, char **argv) {
16  namespace s = fst::script;
19 
20  string usage = "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 string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
32  const string out_name = argc > 2 ? argv[2] : "";
33 
34  std::unique_ptr<MutableFstClass> fst(MutableFstClass::Read(in_name, true));
35  if (!fst) return 1;
36 
37  s::Connect(fst.get());
38 
39  return !fst->Write(out_name);
40 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void Connect(MutableFst< Arc > *fst)
Definition: connect.h:268
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
int fstconnect_main(int argc, char **argv)