tesseract  4.1.0
tprintf.h File Reference
#include "platform.h"

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 36 of file tprintf.cpp.

37 {
39  va_list args; // variable args
40  const char* debug_file_name = debug_file.string();
41  static FILE *debugfp = nullptr; // debug file
42  // debug window
43  int32_t offset = 0; // into message
44  char msg[MAX_MSG_LEN + 1];
45 
46  va_start(args, format); // variable list
47  // Format into msg
48  #ifdef _WIN32
49  offset += _vsnprintf(msg + offset, MAX_MSG_LEN - offset, format, args);
50  if (debug_file_name && strcmp(debug_file_name, "/dev/null") == 0)
51  debug_file.set_value("nul");
52  #else
53  offset += vsnprintf(msg + offset, MAX_MSG_LEN - offset, format, args);
54  #endif
55  va_end(args);
56 
57  if (debugfp == nullptr && debug_file_name && strlen(debug_file_name) > 0) {
58  debugfp = fopen(debug_file.string(), "wb");
59  } else if (debugfp != nullptr && debug_file_name && strlen(debug_file_name) == 0) {
60  fclose(debugfp);
61  debugfp = nullptr;
62  }
63  if (debugfp != nullptr)
64  fprintf(debugfp, "%s", msg);
65  else
66  fprintf(stderr, "%s", msg);
68 }
#define MAX_MSG_LEN
Definition: tprintf.cpp:31
CCUtilMutex tprintfMutex
Definition: ccutil.cpp:55