1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// farprintstrings.cc
2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Licensed under the Apache License, Version 2.0 (the "License");
4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// you may not use this file except in compliance with the License.
5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// You may obtain a copy of the License at
6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//     http://www.apache.org/licenses/LICENSE-2.0
8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Unless required by applicable law or agreed to in writing, software
10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// distributed under the License is distributed on an "AS IS" BASIS,
11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// See the License for the specific language governing permissions and
13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// limitations under the License.
14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Copyright 2005-2010 Google, Inc.
16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Author: allauzen@google.com (Cyril Allauzen)
17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// \file
19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Output as strings the string FSTs in a finite-state archive.
20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/extensions/far/farscript.h>
23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(filename_prefix, "", "Prefix to append to filenames");
25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(filename_suffix, "", "Suffix to append to filenames");
26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_int32(generate_filenames, 0,
27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson             "Generate N digit numeric filenames (def: use keys)");
28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(begin_key, "",
29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              "First key to extract (def: first key in archive)");
30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(end_key, "",
31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              "Last key to extract (def: last key in archive)");
32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// PrintStringsMain specific flag definitions.
33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_bool(print_key, false, "Prefix each string by its key");
34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(entry_type, "line", "Entry type: one of : "
35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              "\"file\" (one FST per file), \"line\" (one FST per line)");
36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(token_type, "symbol", "Token type: one of : "
37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson              "\"symbol\", \"byte\", \"utf8\"");
38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonDEFINE_string(symbols, "", "Label symbol table");
39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
41f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonint  main(int argc, char **argv) {
42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  namespace s = fst::script;
43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
44f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  string usage = "Print as string the string FSTs in an archive.\n\n Usage:";
45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  usage += argv[0];
46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  usage += " in1.far [in2.far ...]\n";
47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
48f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  std::set_new_handler(FailedNewHandler);
49f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  SetFlags(usage.c_str(), &argc, &argv, true);
50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  if (argc < 2) {
52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    ShowUsage();
53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return 1;
54f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
55f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  vector<string> ifilenames;
57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  for (int i = 1; i < argc; ++i)
58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    ifilenames.push_back(argv[i]);
59f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
60f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  string arc_type = fst::LoadArcTypeFromFar(ifilenames[0]);
61f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
62f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  s::FarPrintStrings(ifilenames, arc_type,
63f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                     fst::StringToFarEntryType(FLAGS_entry_type),
64f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                     fst::StringToFarTokenType(FLAGS_token_type),
65f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                     FLAGS_begin_key, FLAGS_end_key, FLAGS_print_key,
66f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                     FLAGS_symbols, FLAGS_generate_filenames,
67f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                     FLAGS_filename_prefix, FLAGS_filename_suffix);
68f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
69f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  return 0;
70f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}
71