Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccutil/tprintf.cpp @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /********************************************************************** | |
| 2 * File: tprintf.cpp | |
| 3 * Description: Trace version of printf - portable between UX and NT | |
| 4 * Author: Phil Cheatle | |
| 5 * | |
| 6 * (C) Copyright 1995, Hewlett-Packard Ltd. | |
| 7 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 ** you may not use this file except in compliance with the License. | |
| 9 ** You may obtain a copy of the License at | |
| 10 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 ** Unless required by applicable law or agreed to in writing, software | |
| 12 ** distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 ** See the License for the specific language governing permissions and | |
| 15 ** limitations under the License. | |
| 16 * | |
| 17 **********************************************************************/ | |
| 18 | |
| 19 // Include automatically generated configuration file if running autoconf. | |
| 20 #ifdef HAVE_CONFIG_H | |
| 21 # include "config_auto.h" | |
| 22 #endif | |
| 23 | |
| 24 #include "tesserrstream.h" | |
| 25 #include "tprintf.h" | |
| 26 | |
| 27 #include "params.h" | |
| 28 | |
| 29 #include <climits> // for INT_MAX | |
| 30 #include <cstdarg> | |
| 31 #include <cstdio> | |
| 32 | |
| 33 namespace tesseract { | |
| 34 | |
| 35 INT_VAR(log_level, INT_MAX, "Logging level"); | |
| 36 | |
| 37 static STRING_VAR(debug_file, "", "File to send tprintf output to"); | |
| 38 | |
| 39 // File for debug output. | |
| 40 FILE *debugfp; | |
| 41 | |
| 42 // Set output for log messages. | |
| 43 // The output is written to stderr if debug_file is empty. | |
| 44 // Otherwise it is written to debug_file. | |
| 45 // It is possible to switch between stderr and debug_file output: | |
| 46 // tprintf("write to configured output\n"); | |
| 47 // debug_file = ""; | |
| 48 // tprintf("write to stderr\n"); | |
| 49 // debug_file = "/tmp/log"; | |
| 50 // tprintf("write to /tmp/log\n"); | |
| 51 // debug_file = ""; | |
| 52 // tprintf("write to stderr\n"); | |
| 53 FILE *get_debugfp() { | |
| 54 if (debug_file.empty()) { | |
| 55 // Write to stderr. | |
| 56 if (debugfp != stderr && debugfp != nullptr) { | |
| 57 fclose(debugfp); | |
| 58 } | |
| 59 debugfp = stderr; | |
| 60 } else if (debugfp == stderr || debugfp == nullptr) { | |
| 61 // Write to file. | |
| 62 #ifdef _WIN32 | |
| 63 if (debug_file == "/dev/null") { | |
| 64 // Replace /dev/null by nul for Windows. | |
| 65 debug_file = "nul"; | |
| 66 } | |
| 67 #endif | |
| 68 debugfp = fopen(debug_file.c_str(), "wb"); | |
| 69 } | |
| 70 return debugfp; | |
| 71 } | |
| 72 | |
| 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 | |
| 82 TessErrStream tesserr; | |
| 83 | |
| 84 } // namespace tesseract |
