From 896e80d9a7bef29b8d7379ff5b956b6ed9e595db Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 15 Jul 2016 23:00:00 +0200 Subject: [PATCH] win32: Show TIFF warnings on console Showing them in a window (default) is not acceptable for a console application like Tesseract which must be able to work in batch mode. Signed-off-by: Stefan Weil --- api/tesseractmain.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index 169bb424f..848a7a7fd 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -33,6 +33,23 @@ #include "openclwrapper.h" #include "osdetect.h" +#if defined(_WIN32) + +#include +#include + +static void Win32WarningHandler(const char* module, const char* fmt, + va_list ap) { + if (module != NULL) { + fprintf(stderr, "%s: ", module); + } + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} + +#endif /* _WIN32 */ + void PrintVersionInfo() { char *versionStrP; @@ -352,6 +369,11 @@ int main(int argc, char **argv) { int arg_i = 1; tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO; +#if defined(_WIN32) + /* Show libtiff warnings on console (not in GUI). */ + TIFFSetWarningHandler(Win32WarningHandler); +#endif /* _WIN32 */ + ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &list_langs, &print_parameters,