Skip to content

Commit

Permalink
Check library version for training executables
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Apr 15, 2018
1 parent a6fef12 commit 8c3045f
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 8 deletions.
2 changes: 2 additions & 0 deletions training/ambiguous_words.cpp
Expand Up @@ -24,12 +24,14 @@
#include <stdio.h>

#include "baseapi.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "helpers.h"
#include "strngs.h"
#include "dict.h"
#include "tesseractclass.h"

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();

// Parse input arguments.
if (argc != 4 && (argc != 6 || strcmp(argv[1], "-l") != 0)) {
Expand Down
1 change: 1 addition & 0 deletions training/classifier_tester.cpp
Expand Up @@ -111,6 +111,7 @@ static tesseract::ShapeClassifier* InitializeClassifier(
// full : Tesseract full classifier.
// with an input trainer.)
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
STRING file_prefix;
tesseract::MasterTrainer* trainer =
Expand Down
2 changes: 2 additions & 0 deletions training/cntraining.cpp
Expand Up @@ -124,6 +124,8 @@ CLUSTERCONFIG CNConfig =
* @note History: Fri Aug 18 08:56:17 1989, DSJ, Created.
*/
int main(int argc, char *argv[]) {
tesseract::CheckSharedLibraryVersion();

// Set the global Config parameters before parsing the command line.
Config = CNConfig;

Expand Down
3 changes: 3 additions & 0 deletions training/combine_lang_model.cpp
Expand Up @@ -15,7 +15,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "lang_model_helpers.h"
#include "tprintf.h"
#include "unicharset_training_utils.h"
Expand All @@ -38,6 +40,7 @@ BOOL_PARAM_FLAG(pass_through_recoder, false,
" unicharset. Otherwise, potentially a compression of it");

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);

// Check validity of input flags.
Expand Down
3 changes: 3 additions & 0 deletions training/combine_tessdata.cpp
Expand Up @@ -18,6 +18,7 @@
//
///////////////////////////////////////////////////////////////////////

#include "commontraining.h" // CheckSharedLibraryVersion
#include "lstmrecognizer.h"
#include "tessdatamanager.h"

Expand Down Expand Up @@ -65,6 +66,8 @@
// components from tessdata/eng.traineddata.
//
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();

int i;
tesseract::TessdataManager tm;
if (argc == 2) {
Expand Down
19 changes: 19 additions & 0 deletions training/commontraining.h
Expand Up @@ -14,6 +14,10 @@
#ifndef TESSERACT_TRAINING_COMMONTRAINING_H_
#define TESSERACT_TRAINING_COMMONTRAINING_H_

#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#include "baseapi.h"
#endif
#include "cluster.h"
#include "commandlineflags.h"
#include "featdefs.h"
Expand Down Expand Up @@ -63,6 +67,21 @@ void ParseArguments(int* argc, char*** argv);

namespace tesseract {

// Check whether the shared tesseract library is the right one.
// This function must be inline because otherwise it would be part of
// the shared library, so it could not compare the versions.
static inline void CheckSharedLibraryVersion()
{
#ifdef HAVE_CONFIG_H
if (!!strcmp(TESSERACT_VERSION_STR, TessBaseAPI::Version())) {
tprintf("ERROR: shared library version mismatch (was %s, expected %s\n"
"Did you use a wrong shared tesseract library?\n",
TessBaseAPI::Version(), TESSERACT_VERSION_STR);
exit(1);
}
#endif
}

// Helper loads shape table from the given file.
ShapeTable* LoadShapeTable(const STRING& file_prefix);
// Helper to write the shape_table.
Expand Down
3 changes: 3 additions & 0 deletions training/dawg2wordlist.cpp
Expand Up @@ -17,6 +17,7 @@
//
///////////////////////////////////////////////////////////////////////

#include "commontraining.h" // CheckSharedLibraryVersion
#include "dawg.h"
#include "host.h"
#include "serialis.h"
Expand Down Expand Up @@ -72,6 +73,8 @@ int WriteDawgAsWordlist(const UNICHARSET &unicharset,
}

int main(int argc, char *argv[]) {
tesseract::CheckSharedLibraryVersion();

if (argc != 4) {
tprintf("Print all the words in a given dawg.\n");
tprintf("Usage: %s <unicharset> <dawgfile> <wordlistfile>\n",
Expand Down
1 change: 1 addition & 0 deletions training/lstmeval.cpp
Expand Up @@ -36,6 +36,7 @@ INT_PARAM_FLAG(verbosity, 1,
"Amount of diagnosting information to output (0-2).");

int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
if (FLAGS_model.empty()) {
tprintf("Must provide a --model!\n");
Expand Down
1 change: 1 addition & 0 deletions training/lstmtraining.cpp
Expand Up @@ -71,6 +71,7 @@ const int kNumPagesPerBatch = 100;
// The program iterates over the inputs, feeding the data to the network,
// until the error rate reaches a specified target or max_iterations is reached.
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();
ParseArguments(&argc, &argv);
// Purify the model name in case it is based on the network string.
if (FLAGS_model_output.empty()) {
Expand Down
4 changes: 3 additions & 1 deletion training/merge_unicharsets.cpp
Expand Up @@ -17,10 +17,12 @@
//
///////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include "commontraining.h" // CheckSharedLibraryVersion
#include "unicharset.h"

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();

// Print usage
if (argc < 4) {
printf("Usage: %s unicharset-in-1 ... unicharset-in-n unicharset-out\n",
Expand Down
2 changes: 2 additions & 0 deletions training/mftraining.cpp
Expand Up @@ -228,6 +228,8 @@ static void SetupConfigMap(ShapeTable* shape_table, IndexMapBiDi* config_map) {
* @note History: Mon May 18 1998, Christy Russson, Revistion started.
*/
int main (int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();

ParseArguments(&argc, &argv);

ShapeTable* shape_table = nullptr;
Expand Down
6 changes: 2 additions & 4 deletions training/set_unicharset_properties.cpp
Expand Up @@ -12,11 +12,8 @@
// object, fills it with properties about the unichars it contains and writes
// the result back to a file.

#include <stdlib.h>
#include <string.h>
#include <string>

#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "tprintf.h"
#include "unicharset_training_utils.h"

Expand All @@ -30,6 +27,7 @@ DECLARE_STRING_PARAM_FLAG(O);
DECLARE_STRING_PARAM_FLAG(X);

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);

// Check validity of input flags.
Expand Down
2 changes: 2 additions & 0 deletions training/shapeclustering.cpp
Expand Up @@ -45,6 +45,8 @@ STRING_PARAM_FLAG(canonical_class2, "", "Class to show ambigs for");
// Otherwise, if FLAGS_canonical_class1 is set, prints a table of font-wise
// cluster distances between FLAGS_canonical_class1 and FLAGS_canonical_class2.
int main(int argc, char **argv) {
tesseract::CheckSharedLibraryVersion();

ParseArguments(&argc, &argv);

STRING file_prefix;
Expand Down
2 changes: 2 additions & 0 deletions training/text2image.cpp
Expand Up @@ -40,6 +40,7 @@
#include "allheaders.h" // from leptonica
#include "boxchar.h"
#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "degradeimage.h"
#include "errcode.h"
#include "fileio.h"
Expand Down Expand Up @@ -672,6 +673,7 @@ static int Main() {
}

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
return Main();
}
3 changes: 2 additions & 1 deletion training/unicharset_extractor.cpp
Expand Up @@ -24,11 +24,11 @@
#include <cstdlib>
#include "boxread.h"
#include "commandlineflags.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "genericvector.h"
#include "lang_model_helpers.h"
#include "normstrngs.h"
#include "strngs.h"
#include "tprintf.h"
#include "unicharset.h"
#include "unicharset_training_utils.h"

Expand Down Expand Up @@ -95,6 +95,7 @@ static int Main(int argc, char** argv) {
} // namespace tesseract

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();
if (argc > 1) {
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
}
Expand Down
5 changes: 3 additions & 2 deletions training/wordlist2dawg.cpp
Expand Up @@ -20,9 +20,8 @@
// Given a file that contains a list of words (one word per line) this program
// generates the corresponding squished DAWG file.

#include <stdio.h>

#include "classify.h"
#include "commontraining.h" // CheckSharedLibraryVersion
#include "dawg.h"
#include "dict.h"
#include "emalloc.h"
Expand All @@ -32,6 +31,8 @@
#include "unicharset.h"

int main(int argc, char** argv) {
tesseract::CheckSharedLibraryVersion();

if (!(argc == 4 || (argc == 5 && strcmp(argv[1], "-t") == 0) ||
(argc == 6 && strcmp(argv[1], "-r") == 0))) {
printf("Usage: %s [-t | -r [reverse policy] ] word_list_file"
Expand Down

0 comments on commit 8c3045f

Please sign in to comment.