tesseract  4.00.00dev
merge_unicharsets.cpp
Go to the documentation of this file.
1 // File: merge_unicharsets.cpp
3 // Description: Simple tool to merge two or more unicharsets.
4 // Author: Ray Smith
5 // Created: Wed Sep 30 16:09:01 PDT 2015
6 //
7 // (C) Copyright 2015, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 
20 #include <stdio.h>
21 #include "unicharset.h"
22 
23 int main(int argc, char** argv) {
24  // Print usage
25  if (argc < 4) {
26  printf("Usage: %s unicharset-in-1 ... unicharset-in-n unicharset-out\n",
27  argv[0]);
28  exit(1);
29  }
30 
31  UNICHARSET input_unicharset, result_unicharset;
32  for (int arg = 1; arg < argc - 1; ++arg) {
33  // Load the input unicharset
34  if (input_unicharset.load_from_file(argv[arg])) {
35  printf("Loaded unicharset of size %d from file %s\n",
36  input_unicharset.size(), argv[arg]);
37  result_unicharset.AppendOtherUnicharset(input_unicharset);
38  } else {
39  printf("Failed to load unicharset from file %s!!\n", argv[arg]);
40  exit(1);
41  }
42  }
43 
44  // Save the combined unicharset.
45  if (result_unicharset.save_to_file(argv[argc - 1])) {
46  printf("Wrote unicharset file %s.\n", argv[argc - 1]);
47  } else {
48  printf("Cannot save unicharset file %s.\n", argv[argc - 1]);
49  exit(1);
50  }
51  return 0;
52 }
void AppendOtherUnicharset(const UNICHARSET &src)
Definition: unicharset.cpp:439
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:348
bool save_to_file(const char *const filename) const
Definition: unicharset.h:308
int size() const
Definition: unicharset.h:299
int main(int argc, char **argv)