tesseract  5.0.0-alpha-619-ge9db
tprintf.cpp File Reference
#include <cstdio>
#include <cstdarg>
#include "params.h"
#include <tesseract/strngs.h>
#include "tprintf.h"

Go to the source code of this file.

Macros

#define MAX_MSG_LEN   2048
 

Functions

DLLSYM void tprintf (const char *format,...)
 

Macro Definition Documentation

◆ MAX_MSG_LEN

#define MAX_MSG_LEN   2048

Definition at line 29 of file tprintf.cpp.

Function Documentation

◆ tprintf()

DLLSYM void tprintf ( const char *  format,
  ... 
)

Definition at line 34 of file tprintf.cpp.

36 {
37  const char* debug_file_name = debug_file.c_str();
38  static FILE *debugfp = nullptr; // debug file
39 
40  if (debug_file_name == nullptr) {
41  // This should not happen.
42  return;
43  }
44 
45 #ifdef _WIN32
46  // Replace /dev/null by nul for Windows.
47  if (strcmp(debug_file_name, "/dev/null") == 0) {
48  debug_file_name = "nul";
49  debug_file.set_value(debug_file_name);
50  }
51 #endif
52 
53  if (debugfp == nullptr && debug_file_name[0] != '\0') {
54  debugfp = fopen(debug_file_name, "wb");
55  } else if (debugfp != nullptr && debug_file_name[0] == '\0') {
56  fclose(debugfp);
57  debugfp = nullptr;
58  }
59 
60  va_list args; // variable args
61  va_start(args, format); // variable list
62  if (debugfp != nullptr) {
63  vfprintf(debugfp, format, args);
64  } else {
65  vfprintf(stderr, format, args);
66  }
67  va_end(args);