Skip to content

Commit 8cb0418

Browse files
committed
Convert tprintf() to C++ style without va args and attributes.
1 parent 3299901 commit 8cb0418

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/ccutil/tprintf.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ FILE *get_debugfp() {
7070
return debugfp;
7171
}
7272

73-
// Trace printf.
74-
void tprintf(const char *format, ...) {
75-
FILE *f = get_debugfp();
76-
va_list args; // variable args
77-
va_start(args, format); // variable list
78-
vfprintf(f, format, args);
79-
va_end(args);
80-
}
81-
8273
TessErrStream tesserr;
8374

8475
} // namespace tesseract

src/ccutil/tprintf.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,22 @@
2121

2222
#include "params.h" // for INT_VAR_H
2323
#include <tesseract/export.h> // for TESS_API
24+
#include <utility> // for std::forward
2425

2526
namespace tesseract {
2627

27-
#if !defined(__GNUC__) && !defined(__attribute__)
28-
# define __attribute__(attr) // compiler without support for __attribute__
29-
#endif
30-
3128
// Disable some log messages by setting log_level > 0.
3229
extern TESS_API INT_VAR_H(log_level);
3330

34-
// Main logging function.
35-
extern TESS_API void tprintf( // Trace printf
36-
const char *format, ...) // Message
37-
__attribute__((format(printf, 1, 2)));
38-
3931
// Get file for debug output.
40-
FILE *get_debugfp();
32+
TESS_API FILE *get_debugfp();
4133

42-
} // namespace tesseract
34+
// Main logging function. Trace printf.
35+
template <typename ... Types>
36+
auto tprintf(Types && ... args) {
37+
return fprintf(get_debugfp(), std::forward<Types>(args)...);
38+
}
4339

44-
#undef __attribute__
40+
} // namespace tesseract
4541

4642
#endif // define TESSERACT_CCUTIL_TPRINTF_H

0 commit comments

Comments
 (0)