1// farextract.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@google.com (Michael Riley)
17// Modified: jpr@google.com (Jake Ratkiewicz) to use new arc dispatch
18//
19// \file
20// Extracts component FSTs from an finite-state archive.
21//
22
23#include <fst/extensions/far/main.h>
24#include <fst/extensions/far/farscript.h>
25
26DEFINE_string(filename_prefix, "", "Prefix to append to filenames");
27DEFINE_string(filename_suffix, "", "Suffix to append to filenames");
28DEFINE_int32(generate_filenames, 0,
29             "Generate N digit numeric filenames (def: use keys)");
30DEFINE_string(begin_key, "",
31              "First key to extract (def: first key in archive)");
32DEFINE_string(end_key, "",
33              "Last key to extract (def: last key in archive)");
34
35
36int main(int argc, char **argv) {
37  namespace s = fst::script;
38
39  string usage = "Extracts FSTs from a finite-state archive.\n\n Usage:";
40  usage += argv[0];
41  usage += " in1.far [in2.far...]\n";
42
43  std::set_new_handler(FailedNewHandler);
44  SetFlags(usage.c_str(), &argc, &argv, true);
45
46  if (argc < 2) {
47    ShowUsage();
48    return 1;
49  }
50
51  vector<string> ifilenames;
52  for (int i = 1; i < argc; ++i)
53    ifilenames.push_back(argv[i]);
54
55  const string &arc_type = fst::LoadArcTypeFromFar(ifilenames[0]);
56
57  s::FarExtract(ifilenames, arc_type, FLAGS_generate_filenames,
58                FLAGS_begin_key, FLAGS_end_key, FLAGS_filename_prefix,
59                FLAGS_filename_suffix);
60
61  return 0;
62}
63