1// farprintstrings.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: allauzen@google.com (Cyril Allauzen) 17// 18// \file 19// Output as strings the string FSTs in a finite-state archive. 20// 21 22#include <fst/extensions/far/farscript.h> 23 24DEFINE_string(filename_prefix, "", "Prefix to append to filenames"); 25DEFINE_string(filename_suffix, "", "Suffix to append to filenames"); 26DEFINE_int32(generate_filenames, 0, 27 "Generate N digit numeric filenames (def: use keys)"); 28DEFINE_string(begin_key, "", 29 "First key to extract (def: first key in archive)"); 30DEFINE_string(end_key, "", 31 "Last key to extract (def: last key in archive)"); 32// PrintStringsMain specific flag definitions. 33DEFINE_bool(print_key, false, "Prefix each string by its key"); 34DEFINE_string(entry_type, "line", "Entry type: one of : " 35 "\"file\" (one FST per file), \"line\" (one FST per line)"); 36DEFINE_string(token_type, "symbol", "Token type: one of : " 37 "\"symbol\", \"byte\", \"utf8\""); 38DEFINE_string(symbols, "", "Label symbol table"); 39 40 41int main(int argc, char **argv) { 42 namespace s = fst::script; 43 44 string usage = "Print as string the string FSTs in an archive.\n\n Usage:"; 45 usage += argv[0]; 46 usage += " in1.far [in2.far ...]\n"; 47 48 std::set_new_handler(FailedNewHandler); 49 SetFlags(usage.c_str(), &argc, &argv, true); 50 51 if (argc < 2) { 52 ShowUsage(); 53 return 1; 54 } 55 56 vector<string> ifilenames; 57 for (int i = 1; i < argc; ++i) 58 ifilenames.push_back(argv[i]); 59 60 string arc_type = fst::LoadArcTypeFromFar(ifilenames[0]); 61 62 s::FarPrintStrings(ifilenames, arc_type, 63 fst::StringToFarEntryType(FLAGS_entry_type), 64 fst::StringToFarTokenType(FLAGS_token_type), 65 FLAGS_begin_key, FLAGS_end_key, FLAGS_print_key, 66 FLAGS_symbols, FLAGS_generate_filenames, 67 FLAGS_filename_prefix, FLAGS_filename_suffix); 68 69 return 0; 70} 71