1 /********************************************************************** 2 * File: commandlineflags.h 3 * Description: Header file for commandline flag parsing. 4 * Author: Ranjith Unnikrishnan 5 * 6 * (C) Copyright 2013, Google Inc. 7 ** Licensed under the Apache License, Version 2.0 (the "License"); 8 ** you may not use this file except in compliance with the License. 9 ** You may obtain a copy of the License at 10 ** http://www.apache.org/licenses/LICENSE-2.0 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 * 17 **********************************************************************/ 18 #ifndef TESSERACT_TRAINING_COMMANDLINEFLAGS_H_ 19 #define TESSERACT_TRAINING_COMMANDLINEFLAGS_H_ 20 21 #include "export.h" 22 #include "params.h" 23 24 #include <cstdlib> 25 26 #define INT_PARAM_FLAG(name, val, comment) INT_VAR(FLAGS_##name, val, comment) 27 #define DECLARE_INT_PARAM_FLAG(name) extern INT_VAR_H(FLAGS_##name) 28 #define DOUBLE_PARAM_FLAG(name, val, comment) double_VAR(FLAGS_##name, val, comment) 29 #define DECLARE_DOUBLE_PARAM_FLAG(name) extern double_VAR_H(FLAGS_##name) 30 #define BOOL_PARAM_FLAG(name, val, comment) BOOL_VAR(FLAGS_##name, val, comment) 31 #define DECLARE_BOOL_PARAM_FLAG(name) extern BOOL_VAR_H(FLAGS_##name) 32 #define STRING_PARAM_FLAG(name, val, comment) STRING_VAR(FLAGS_##name, val, comment) 33 #define DECLARE_STRING_PARAM_FLAG(name) extern STRING_VAR_H(FLAGS_##name) 34 35 namespace tesseract { 36 37 // Flags from commontraining.cpp 38 // Command line arguments for font_properties, xheights and unicharset. 39 TESS_COMMON_TRAINING_API 40 DECLARE_INT_PARAM_FLAG(debug_level); 41 TESS_COMMON_TRAINING_API 42 DECLARE_STRING_PARAM_FLAG(D); 43 TESS_COMMON_TRAINING_API 44 DECLARE_STRING_PARAM_FLAG(F); 45 TESS_COMMON_TRAINING_API 46 DECLARE_STRING_PARAM_FLAG(O); 47 TESS_COMMON_TRAINING_API 48 DECLARE_STRING_PARAM_FLAG(U); 49 TESS_COMMON_TRAINING_API 50 DECLARE_STRING_PARAM_FLAG(X); 51 TESS_COMMON_TRAINING_API 52 DECLARE_STRING_PARAM_FLAG(fonts_dir); 53 TESS_COMMON_TRAINING_API 54 DECLARE_STRING_PARAM_FLAG(fontconfig_tmpdir); 55 TESS_COMMON_TRAINING_API 56 DECLARE_STRING_PARAM_FLAG(output_trainer); 57 TESS_COMMON_TRAINING_API 58 DECLARE_STRING_PARAM_FLAG(test_ch); 59 60 // Parse commandline flags and values. Prints the usage string and exits on 61 // input of --help or --version. 62 // 63 // If remove_flags is true, the argv pointer is advanced so that (*argv)[1] 64 // points to the first non-flag argument, (*argv)[0] points to the same string 65 // as before, and argc is decremented to reflect the new shorter length of argv. 66 // eg. If the input *argv is 67 // { "program", "--foo=4", "--bar=true", "file1", "file2" } with *argc = 5, the 68 // output *argv is { "program", "file1", "file2" } with *argc = 3 69 TESS_COMMON_TRAINING_API 70 void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, const bool remove_flags); 71 72 } // namespace tesseract 73 74 #endif // TESSERACT_TRAINING_COMMANDLINEFLAGS_H_ 75