1 // fstconcat.cc 2 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Copyright 2005-2010 Google, Inc. 16 // Author: riley (at) google.com (Michael Riley) 17 // Modified: jpr (at) google.com (Jake Ratkiewicz) to use FstClass 18 // 19 // \file 20 // Concatenates two FSTs. 21 // 22 23 #include <string> 24 25 #include <fst/script/concat.h> 26 27 int main(int argc, char **argv) { 28 namespace s = fst::script; 29 using fst::script::FstClass; 30 using fst::script::MutableFstClass; 31 32 string usage = "Concatenates two FSTs.\n\n Usage: "; 33 usage += argv[0]; 34 usage += " in1.fst in2.fst [out.fst]\n"; 35 36 std::set_new_handler(FailedNewHandler); 37 SET_FLAGS(usage.c_str(), &argc, &argv, true); 38 if (argc < 3 || argc > 4) { 39 ShowUsage(); 40 return 1; 41 } 42 43 string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1]; 44 string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2]; 45 string out_fname = argc > 3 ? argv[3] : ""; 46 47 if (in1_name.empty() && in2_name.empty()) { 48 LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input."; 49 return 1; 50 } 51 52 MutableFstClass *fst1 = MutableFstClass::Read(in1_name, true); 53 if (!fst1) return 1; 54 55 FstClass *fst2 = FstClass::Read(in2_name); 56 if (!fst2) return 1; 57 58 s::Concat(fst1, *fst2); 59 fst1->Write(out_fname); 60 61 return 0; 62 } 63