From b57afc7c784c6b6aea55f3f25af0b491103992ef Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 2 Jul 2018 17:40:13 +0200 Subject: [PATCH] Replace Efopen by fopen and remove efio.cpp, efio.h Signed-off-by: Stefan Weil --- src/ccmain/tessedit.cpp | 1 - src/classify/blobclass.cpp | 14 +++++---- src/classify/cutoffs.cpp | 1 - src/classify/mastertrainer.cpp | 3 +- src/classify/normmatch.cpp | 1 - src/classify/outfeat.cpp | 1 - src/classify/picofeat.cpp | 1 - src/cutil/Makefile.am | 4 +-- src/cutil/efio.cpp | 55 --------------------------------- src/cutil/efio.h | 32 ------------------- src/dict/stopper.cpp | 1 - src/training/cntraining.cpp | 18 ++++++----- src/training/commontraining.cpp | 1 - src/training/mergenf.cpp | 1 - src/training/mftraining.cpp | 1 - 15 files changed, 21 insertions(+), 114 deletions(-) delete mode 100644 src/cutil/efio.cpp delete mode 100644 src/cutil/efio.h diff --git a/src/ccmain/tessedit.cpp b/src/ccmain/tessedit.cpp index c9c292b05c..cdbf58ce2e 100644 --- a/src/ccmain/tessedit.cpp +++ b/src/ccmain/tessedit.cpp @@ -36,7 +36,6 @@ #include "stopper.h" #include "intmatcher.h" #include "chop.h" -#include "efio.h" #include "danerror.h" #include "globals.h" #ifndef ANDROID_BUILD diff --git a/src/classify/blobclass.cpp b/src/classify/blobclass.cpp index ae6e590eb9..457ceb3431 100644 --- a/src/classify/blobclass.cpp +++ b/src/classify/blobclass.cpp @@ -24,7 +24,6 @@ #include #include "classify.h" -#include "efio.h" #include "featdefs.h" #include "mf.h" #include "normfeat.h" @@ -95,12 +94,15 @@ void Classify::LearnBlob(const STRING& fontname, TBLOB* blob, // Writes stored training data to a .tr file based on the given filename. // Returns false on error. bool Classify::WriteTRFile(const STRING& filename) { + bool result = false; STRING tr_filename = filename + ".tr"; - FILE* fp = Efopen(tr_filename.string(), "wb"); - const size_t len = tr_file_data_.length(); - const bool result = - fwrite(&tr_file_data_[0], sizeof(tr_file_data_[0]), len, fp) == len; - fclose(fp); + FILE* fp = fopen(tr_filename.string(), "wb"); + if (fp) { + const size_t len = tr_file_data_.length(); + result = + fwrite(&tr_file_data_[0], sizeof(tr_file_data_[0]), len, fp) == len; + fclose(fp); + } tr_file_data_.truncate_at(0); return result; } diff --git a/src/classify/cutoffs.cpp b/src/classify/cutoffs.cpp index b10c65f909..dce414ff97 100644 --- a/src/classify/cutoffs.cpp +++ b/src/classify/cutoffs.cpp @@ -23,7 +23,6 @@ #include #include "classify.h" -#include "efio.h" #include "globals.h" #include "helpers.h" #include "serialis.h" diff --git a/src/classify/mastertrainer.cpp b/src/classify/mastertrainer.cpp index 682d25bb65..90ecd12b97 100644 --- a/src/classify/mastertrainer.cpp +++ b/src/classify/mastertrainer.cpp @@ -30,7 +30,6 @@ #include "allheaders.h" #include "boxread.h" #include "classify.h" -#include "efio.h" #include "errorcounter.h" #include "featdefs.h" #include "sampleiterator.h" @@ -121,7 +120,7 @@ void MasterTrainer::ReadTrainingSamples(const char* page_name, const int cn_feature_type = ShortNameToFeatureType(feature_defs, kCNFeatureType); const int geo_feature_type = ShortNameToFeatureType(feature_defs, kGeoFeatureType); - FILE* fp = Efopen(page_name, "rb"); + FILE* fp = fopen(page_name, "rb"); if (fp == nullptr) { tprintf("Failed to open tr file: %s\n", page_name); return; diff --git a/src/classify/normmatch.cpp b/src/classify/normmatch.cpp index 44ef7fe268..0522e3d297 100644 --- a/src/classify/normmatch.cpp +++ b/src/classify/normmatch.cpp @@ -26,7 +26,6 @@ #include "classify.h" #include "clusttool.h" #include "const.h" -#include "efio.h" #include "emalloc.h" #include "globals.h" #include "helpers.h" diff --git a/src/classify/outfeat.cpp b/src/classify/outfeat.cpp index a05319ad3b..261b06fb00 100644 --- a/src/classify/outfeat.cpp +++ b/src/classify/outfeat.cpp @@ -21,7 +21,6 @@ #include "outfeat.h" #include "classify.h" -#include "efio.h" #include "featdefs.h" #include "mfoutline.h" #include "ocrfeatures.h" diff --git a/src/classify/picofeat.cpp b/src/classify/picofeat.cpp index a0657cb56b..5445fd6ffd 100644 --- a/src/classify/picofeat.cpp +++ b/src/classify/picofeat.cpp @@ -21,7 +21,6 @@ #include "picofeat.h" #include "classify.h" -#include "efio.h" #include "featdefs.h" #include "fpoint.h" #include "mfoutline.h" diff --git a/src/cutil/Makefile.am b/src/cutil/Makefile.am index 931437021b..596ed9cc70 100644 --- a/src/cutil/Makefile.am +++ b/src/cutil/Makefile.am @@ -8,13 +8,13 @@ AM_CPPFLAGS += -DTESS_EXPORTS \ endif noinst_HEADERS = \ - bitvec.h callcpp.h const.h cutil.h cutil_class.h danerror.h efio.h \ + bitvec.h callcpp.h const.h cutil.h cutil_class.h danerror.h \ emalloc.h globals.h \ oldlist.h structures.h noinst_LTLIBRARIES = libtesseract_cutil.la libtesseract_cutil_la_SOURCES = \ - bitvec.cpp callcpp.cpp cutil.cpp cutil_class.cpp danerror.cpp efio.cpp \ + bitvec.cpp callcpp.cpp cutil.cpp cutil_class.cpp danerror.cpp \ emalloc.cpp \ oldlist.cpp structures.cpp diff --git a/src/cutil/efio.cpp b/src/cutil/efio.cpp deleted file mode 100644 index 943efc9baf..0000000000 --- a/src/cutil/efio.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - ** Filename: efio.c - ** Purpose: Utility I/O routines - ** Author: Dan Johnson - ** History: 5/21/89, DSJ, Created. - ** - ** (c) Copyright Hewlett-Packard Company, 1988. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** 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 Files and Type Defines -----------------------------------------------------------------------------*/ -#include "efio.h" -#include "danerror.h" -#include -#include - -#define MAXERRORMESSAGE 256 - -/*---------------------------------------------------------------------------- - Public Code -----------------------------------------------------------------------------*/ -/** - * This routine attempts to open the specified file in the - * specified mode. If the file can be opened, a pointer to - * the open file is returned. If the file cannot be opened, - * an error is trapped. - * @param Name name of file to be opened - * @param Mode mode to be used to open file - * @return Pointer to open file. - * @note Globals: None - * @note Exceptions: #FOPENERROR unable to open specified file - * @note History: 5/21/89, DSJ, Created. - */ -FILE *Efopen(const char *Name, const char *Mode) { - FILE *File; - char ErrorMessage[MAXERRORMESSAGE]; - - File = fopen (Name, Mode); - if (File == nullptr) { - sprintf (ErrorMessage, "Unable to open %s", Name); - DoError(FOPENERROR, ErrorMessage); - return (nullptr); - } - else - return (File); -} /* Efopen */ diff --git a/src/cutil/efio.h b/src/cutil/efio.h deleted file mode 100644 index 593e6b66cb..0000000000 --- a/src/cutil/efio.h +++ /dev/null @@ -1,32 +0,0 @@ -/****************************************************************************** - ** Filename: efio.h - ** Purpose: Definition of file I/O routines - ** Author: Dan Johnson - ** History: 5/21/89, DSJ, Created. - ** - ** (c) Copyright Hewlett-Packard Company, 1988. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** 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. - ******************************************************************************/ -#ifndef EFIO_H -#define EFIO_H - -/**---------------------------------------------------------------------------- - Include Files and Type Defines -----------------------------------------------------------------------------**/ -#include - -#define FOPENERROR 3000 - -/**---------------------------------------------------------------------------- - Public Function Prototype -----------------------------------------------------------------------------**/ -FILE *Efopen(const char *Name, const char *Mode); -#endif diff --git a/src/dict/stopper.cpp b/src/dict/stopper.cpp index 47986aedc7..94e2706eba 100644 --- a/src/dict/stopper.cpp +++ b/src/dict/stopper.cpp @@ -27,7 +27,6 @@ #include "const.h" #include "danerror.h" #include "dict.h" -#include "efio.h" #include "helpers.h" #include "matchdefs.h" #include "pageres.h" diff --git a/src/training/cntraining.cpp b/src/training/cntraining.cpp index baf6cd5447..1945b5a17c 100644 --- a/src/training/cntraining.cpp +++ b/src/training/cntraining.cpp @@ -24,7 +24,6 @@ Include Files and Type Defines ----------------------------------------------------------------------------*/ #include "oldlist.h" -#include "efio.h" #include "emalloc.h" #include "featdefs.h" #include "tessopt.h" @@ -120,7 +119,6 @@ int main(int argc, char *argv[]) { Config = CNConfig; const char *PageName; - FILE *TrainingPage; LIST CharList = NIL_LIST; CLUSTERER *Clusterer = nullptr; LIST ProtoList = NIL_LIST; @@ -134,11 +132,14 @@ int main(int argc, char *argv[]) { int num_fonts = 0; while ((PageName = GetNextFilename(argc, argv)) != nullptr) { printf("Reading %s ...\n", PageName); - TrainingPage = Efopen(PageName, "rb"); - ReadTrainingSamples(FeatureDefs, PROGRAM_FEATURE_TYPE, 100, nullptr, - TrainingPage, &CharList); - fclose(TrainingPage); - ++num_fonts; + FILE *TrainingPage = fopen(PageName, "rb"); + ASSERT_HOST(TrainingPage); + if (TrainingPage) { + ReadTrainingSamples(FeatureDefs, PROGRAM_FEATURE_TYPE, 100, nullptr, + TrainingPage, &CharList); + fclose(TrainingPage); + ++num_fonts; + } } printf("Clustering ...\n"); // To allow an individual font to form a separate cluster, @@ -220,7 +221,8 @@ static void WriteNormProtos(const char *Directory, LIST LabeledProtoList, } Filename += "normproto"; printf ("\nWriting %s ...", Filename.string()); - File = Efopen (Filename.string(), "wb"); + File = fopen(Filename.string(), "wb"); + ASSERT_HOST(File); fprintf(File, "%0d\n", feature_desc->NumParams); WriteParamDesc(File, feature_desc->NumParams, feature_desc->ParamDesc); iterate(LabeledProtoList) diff --git a/src/training/commontraining.cpp b/src/training/commontraining.cpp index 4e099ca0c0..c244591c20 100644 --- a/src/training/commontraining.cpp +++ b/src/training/commontraining.cpp @@ -21,7 +21,6 @@ #include "classify.h" #include "cluster.h" #include "clusttool.h" -#include "efio.h" #include "emalloc.h" #include "featdefs.h" #include "fontinfo.h" diff --git a/src/training/mergenf.cpp b/src/training/mergenf.cpp index 94bdc215c9..30d9e641c8 100644 --- a/src/training/mergenf.cpp +++ b/src/training/mergenf.cpp @@ -17,7 +17,6 @@ ******************************************************************************/ #include "mergenf.h" #include "host.h" -#include "efio.h" #include "clusttool.h" #include "cluster.h" #include "oldlist.h" diff --git a/src/training/mftraining.cpp b/src/training/mftraining.cpp index 82863d0bed..98036c73ff 100644 --- a/src/training/mftraining.cpp +++ b/src/training/mftraining.cpp @@ -39,7 +39,6 @@ #include "clusttool.h" #include "commontraining.h" #include "danerror.h" -#include "efio.h" #include "emalloc.h" #include "featdefs.h" #include "fontinfo.h"