tesseract  4.0.0-1-g2a2b
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

◆ tprintf()

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

Definition at line 37 of file tprintf.cpp.

38 {
40  va_list args; // variable args
41  static FILE *debugfp = nullptr; // debug file
42  // debug window
43  int32_t offset = 0; // into message
44  static 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 (strcmp(debug_file.string(), "/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 && strlen(debug_file.string()) > 0) {
58  debugfp = fopen(debug_file.string(), "wb");
59  } else if (debugfp != nullptr && strlen(debug_file.string()) == 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:32
CCUtilMutex tprintfMutex
Definition: ccutil.cpp:59