diff --git a/src/ccmain/recogtraining.cpp b/src/ccmain/recogtraining.cpp index d9c0af8a31..a9a7f267e7 100644 --- a/src/ccmain/recogtraining.cpp +++ b/src/ccmain/recogtraining.cpp @@ -21,7 +21,6 @@ #include "boxread.h" #include "control.h" -#include "cutil.h" #include "host.h" #include "ratngs.h" #include "reject.h" @@ -45,7 +44,11 @@ FILE *Tesseract::init_recog_training(const STRING &fname) { const char *lastdot = strrchr(output_fname.string(), '.'); if (lastdot != nullptr) output_fname[lastdot - output_fname.string()] = '\0'; output_fname += ".txt"; - FILE *output_file = open_file(output_fname.string(), "a+"); + FILE *output_file = fopen(output_fname.string(), "a+"); + if (output_file == nullptr) { + tprintf("Error: Could not open file %s\n", output_fname.string()); + ASSERT_HOST(output_file); + } return output_file; } @@ -85,7 +88,11 @@ void Tesseract::recog_training_segmented(const STRING &fname, if (lastdot != nullptr) box_fname[lastdot - box_fname.string()] = '\0'; box_fname += ".box"; // ReadNextBox() will close box_file - FILE *box_file = open_file(box_fname.string(), "r"); + FILE *box_file = fopen(box_fname.string(), "r"); + if (box_file == nullptr) { + tprintf("Error: Could not open file %s\n", box_fname.string()); + ASSERT_HOST(box_file); + } PAGE_RES_IT page_res_it; page_res_it.page_res = page_res; diff --git a/src/cutil/Makefile.am b/src/cutil/Makefile.am index 596ed9cc70..80705f3fec 100644 --- a/src/cutil/Makefile.am +++ b/src/cutil/Makefile.am @@ -15,6 +15,6 @@ noinst_HEADERS = \ noinst_LTLIBRARIES = libtesseract_cutil.la libtesseract_cutil_la_SOURCES = \ - bitvec.cpp callcpp.cpp cutil.cpp cutil_class.cpp danerror.cpp \ + bitvec.cpp callcpp.cpp cutil_class.cpp danerror.cpp \ emalloc.cpp \ oldlist.cpp structures.cpp diff --git a/src/cutil/cutil.cpp b/src/cutil/cutil.cpp deleted file mode 100644 index 1d1067974a..0000000000 --- a/src/cutil/cutil.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -*-C-*- - ****************************************************************************** - * - * File: cutil.cpp - * Description: General utility functions - * Author: Mark Seaman, SW Productivity - * Created: Fri Oct 16 14:37:00 1987 - * Modified: Wed Jun 6 16:29:17 1990 (Mark Seaman) marks@hpgrlt - * Language: C - * Package: N/A - * Status: Reusable Software Component - * - * (c) Copyright 1987, Hewlett-Packard Company. - ** 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 "cutil.h" -#include "tprintf.h" -#include "callcpp.h" - -#include - -#define RESET_COUNT 2000 - -/********************************************************************** - * open_file - * - * Open a file for reading or writing. If the file name parameter is - * nullptr use stdin (or stdout) for the file. If the file can not be - * opened then call the error routine. - **********************************************************************/ -FILE *open_file(const char *filename, const char *mode) { - FILE *thisfile = nullptr; - if ((thisfile = fopen (filename, mode)) == nullptr) { - tprintf ("Could not open file, %s\n", filename); - exit (1); - } - return (thisfile); -} - -/// Check whether the file exists -bool exists_file(const char *filename) { - bool exists = false; - FILE *f = nullptr; - if ((f = fopen(filename, "rb")) != nullptr) { - fclose(f); - exists = true; - } - return exists; -} diff --git a/src/cutil/cutil.h b/src/cutil/cutil.h index 7d07fe1cd3..acbd552cd8 100644 --- a/src/cutil/cutil.h +++ b/src/cutil/cutil.h @@ -85,13 +85,5 @@ typedef void (*void_dest) (void *); #define print_string(str) \ printf ("%s\n", str) -/*---------------------------------------------------------------------- - F u n c t i o n s -----------------------------------------------------------------------*/ - -FILE *open_file(const char *filename, const char *mode); - -bool exists_file(const char *filename); - #include "cutil_class.h" #endif diff --git a/src/dict/dawg.cpp b/src/dict/dawg.cpp index b557eceaee..07de6cca58 100644 --- a/src/dict/dawg.cpp +++ b/src/dict/dawg.cpp @@ -28,7 +28,6 @@ #include "dawg.h" -#include "cutil.h" #include "dict.h" #include "emalloc.h" #include "helpers.h" @@ -78,7 +77,11 @@ int Dawg::check_for_words(const char *filename, int misses = 0; UNICHAR_ID wildcard = unicharset.unichar_to_id(kWildcard); - word_file = open_file (filename, "r"); + word_file = fopen(filename, "r"); + if (word_file == nullptr) { + tprintf("Error: Could not open file %s\n", filename); + ASSERT_HOST(word_file); + } while (fgets (string, CHARS_PER_LINE, word_file) != nullptr) { chomp_string(string); // remove newline diff --git a/src/dict/dict.cpp b/src/dict/dict.cpp index 8a6b796e40..245e74d037 100644 --- a/src/dict/dict.cpp +++ b/src/dict/dict.cpp @@ -650,7 +650,11 @@ void Dict::add_document_word(const WERD_CHOICE &best_choice) { if (save_doc_words) { STRING filename(getCCUtil()->imagefile); filename += ".doc"; - FILE *doc_word_file = open_file (filename.string(), "a"); + FILE *doc_word_file = fopen(filename.string(), "a"); + if (doc_word_file == nullptr) { + tprintf("Error: Could not open file %s\n", filename.string()); + ASSERT_HOST(doc_word_file); + } fprintf(doc_word_file, "%s\n", best_choice.debug_string().string()); fclose(doc_word_file);