FST  openfst-1.7.1
OpenFst Library
fstsynchronize-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 // Synchronizes an FST.
5 
6 #include <cstring>
7 
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/script/synchronize.h>
13 
14 int fstsynchronize_main(int argc, char **argv) {
15  namespace s = fst::script;
18 
19  string usage = "Synchronizes an FST.\n\n Usage: ";
20  usage += argv[0];
21  usage += " [in.fst [out.fst]]\n";
22 
23  std::set_new_handler(FailedNewHandler);
24  SET_FLAGS(usage.c_str(), &argc, &argv, true);
25  if (argc > 3) {
26  ShowUsage();
27  return 1;
28  }
29 
30  const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
31  const string out_name = argc > 2 ? argv[2] : "";
32 
33  std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
34  if (!ifst) return 1;
35 
36  VectorFstClass ofst(ifst->ArcType());
37 
38  s::Synchronize(*ifst, &ofst);
39 
40  return !ofst.Write(out_name);
41 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void Synchronize(SynchronizeArgs *args)
Definition: synchronize.h:18
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
int fstsynchronize_main(int argc, char **argv)