FST  openfst-1.7.1
OpenFst Library
fstclosure-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 // Creates the Kleene closure of an FST.
5 
6 #include <cstring>
7 
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/script/closure.h>
13 #include <fst/script/getters.h>
14 
15 DECLARE_bool(closure_plus);
16 
17 int fstclosure_main(int argc, char **argv) {
18  namespace s = fst::script;
20 
21  string usage = "Creates the Kleene closure of an FST.\n\n Usage: ";
22  usage += argv[0];
23  usage += " [in.fst [out.fst]]\n";
24 
25  std::set_new_handler(FailedNewHandler);
26  SET_FLAGS(usage.c_str(), &argc, &argv, true);
27  if (argc > 3) {
28  ShowUsage();
29  return 1;
30  }
31 
32  const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
33  const string out_name = argc > 2 ? argv[2] : "";
34 
35  std::unique_ptr<MutableFstClass> fst(MutableFstClass::Read(in_name, true));
36  if (!fst) return 1;
37 
38  s::Closure(fst.get(), s::GetClosureType(FLAGS_closure_plus));
39 
40  return !fst->Write(out_name);
41 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void Closure(MutableFst< Arc > *fst, ClosureType closure_type)
Definition: closure.h:32
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
ClosureType GetClosureType(bool closure_plus)
Definition: getters.h:31
DECLARE_bool(closure_plus)
int fstclosure_main(int argc, char **argv)