FST  openfst-1.7.1
OpenFst Library
fstconcat-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 // Concatenates two FSTs.
5 
6 #include <cstring>
7 
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/log.h>
13 #include <fst/script/concat.h>
14 
15 int fstconcat_main(int argc, char **argv) {
16  namespace s = fst::script;
19 
20  string usage = "Concatenates two FSTs.\n\n Usage: ";
21  usage += argv[0];
22  usage += " in1.fst in2.fst [out.fst]\n";
23 
24  std::set_new_handler(FailedNewHandler);
25  SET_FLAGS(usage.c_str(), &argc, &argv, true);
26  if (argc < 3 || argc > 4) {
27  ShowUsage();
28  return 1;
29  }
30 
31  const string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1];
32  const string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2];
33  const string out_name = argc > 3 ? argv[3] : "";
34 
35  if (in1_name.empty() && in2_name.empty()) {
36  LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input";
37  return 1;
38  }
39 
40  std::unique_ptr<MutableFstClass> fst1(MutableFstClass::Read(in1_name, true));
41  if (!fst1) return 1;
42 
43  std::unique_ptr<FstClass> fst2(FstClass::Read(in2_name));
44  if (!fst2) return 1;
45 
46  s::Concat(fst1.get(), *fst2);
47 
48  return !fst1->Write(out_name);
49 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
#define LOG(type)
Definition: log.h:48
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
int fstconcat_main(int argc, char **argv)
void Concat(MutableFst< Arc > *fst1, const Fst< Arc > &fst2)
Definition: concat.h:32