FST  openfst-1.7.2
OpenFst Library
fstinvert-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 // Inverts a transduction.
5 
6 #include <cstring>
7 
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/script/invert.h>
13 
14 int fstinvert_main(int argc, char **argv) {
15  namespace s = fst::script;
17 
18  string usage = "Inverts a transduction.\n\n Usage: ";
19  usage += argv[0];
20  usage += " [in.fst [out.fst]]\n";
21 
22  std::set_new_handler(FailedNewHandler);
23  SET_FLAGS(usage.c_str(), &argc, &argv, true);
24  if (argc > 3) {
25  ShowUsage();
26  return 1;
27  }
28 
29  const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
30  const string out_name = argc > 2 ? argv[2] : "";
31 
32  std::unique_ptr<MutableFstClass> fst(MutableFstClass::Read(in_name, true));
33  if (!fst) return 1;
34 
35  s::Invert(fst.get());
36 
37  return !fst->Write(out_name);
38 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void Invert(const Fst< Arc > &ifst, MutableFst< Arc > *ofst)
Definition: invert.h:54
int fstinvert_main(int argc, char **argv)
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214