Leptonica  1.83.1
Image processing and image analysis suite
environ.h
1 /*====================================================================*
2  - Copyright (C) 2001 Leptonica. All rights reserved.
3  -
4  - Redistribution and use in source and binary forms, with or without
5  - modification, are permitted provided that the following conditions
6  - are met:
7  - 1. Redistributions of source code must retain the above copyright
8  - notice, this list of conditions and the following disclaimer.
9  - 2. Redistributions in binary form must reproduce the above
10  - copyright notice, this list of conditions and the following
11  - disclaimer in the documentation and/or other materials
12  - provided with the distribution.
13  -
14  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18  - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
27 #ifndef LEPTONICA_ENVIRON_H
28 #define LEPTONICA_ENVIRON_H
29 
30 /*------------------------------------------------------------------------*
31  * Defines and includes differ for Unix and Windows. Also for Windows, *
32  * differentiate between conditionals based on platform and compiler. *
33  * For platforms: *
34  * _WIN32 => Windows, 32- or 64-bit *
35  * _WIN64 => Windows, 64-bit only *
36  * __CYGWIN__ => Cygwin *
37  * For compilers: *
38  * __GNUC__ => gcc *
39  * _MSC_VER => msvc *
40  *------------------------------------------------------------------------*/
41 
42 /* MS VC++ does not provide stdint.h, so define the missing types here */
43 
44 
45 #ifndef _MSC_VER
46 #include <stdint.h>
47 
48 #else
49 /* Note that _WIN32 is defined for both 32 and 64 bit applications,
50  whereas _WIN64 is defined only for the latter */
51 
52 #ifdef _WIN64
53 typedef __int64 intptr_t;
54 typedef unsigned __int64 uintptr_t;
55 #else
56 typedef int intptr_t;
57 typedef unsigned int uintptr_t;
58 #endif
59 
60 /* VC++6 doesn't seem to have powf, expf. */
61 #if (_MSC_VER < 1400)
62 #define powf(x, y) (float)pow((double)(x), (double)(y))
63 #define expf(x) (float)exp((double)(x))
64 #endif
65 
66 #endif /* _MSC_VER */
67 
68 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
69 #include <stdatomic.h>
70 typedef atomic_int l_atomic;
71 #else
72 typedef int l_atomic;
73 #endif
74 
75 #ifndef LEPT_DLL
76  /* Windows specifics */
77  #ifdef _WIN32
78  /* DLL EXPORTS and IMPORTS */
79  #if defined(LIBLEPT_EXPORTS)
80  #define LEPT_DLL __declspec(dllexport)
81  #elif defined(LIBLEPT_IMPORTS)
82  #define LEPT_DLL __declspec(dllimport)
83  #else
84  #define LEPT_DLL
85  #endif
86  #else /* non-Windows specifics */
87  #define LEPT_DLL
88  #endif /* _WIN32 */
89 #endif /* LEPT_DLL */
90 
91 #ifndef _WIN32 /* non-Windows specifics */
92  #include <stdint.h>
93 #endif /* _WIN32 */
94 
95 #ifdef __APPLE__
96  #include <Availability.h>
97 #endif /* __APPLE__ */
98 
99 typedef intptr_t l_intptr_t;
100 typedef uintptr_t l_uintptr_t;
101 
102 
103 /*--------------------------------------------------------------------*
104  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
105  * USER CONFIGURABLE *
106  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
107  * Environment variables with I/O libraries *
108  * Manual Configuration Only: NOT AUTO_CONF *
109  *--------------------------------------------------------------------*/
110 /*
111  * Leptonica provides interfaces to link to several external image
112  * I/O libraries, plus zlib. Setting any of these to 0 here causes
113  * non-functioning stubs to be linked.
114  */
115 #if !defined(HAVE_CONFIG_H) && !defined(ANDROID_BUILD) && !defined(OS_IOS)
116 
117  #if !defined(HAVE_LIBJPEG)
118  #define HAVE_LIBJPEG 1
119  #endif
120  #if !defined(HAVE_LIBTIFF)
121  #define HAVE_LIBTIFF 1
122  #endif
123  #if !defined(HAVE_LIBPNG)
124  #define HAVE_LIBPNG 1
125  #endif
126  #if !defined(HAVE_LIBZ)
127  #define HAVE_LIBZ 1
128  #endif
129  #if !defined(HAVE_LIBGIF)
130  #define HAVE_LIBGIF 0
131  #endif
132  #if !defined(HAVE_LIBUNGIF)
133  #define HAVE_LIBUNGIF 0
134  #endif
135  #if !defined(HAVE_LIBWEBP)
136  #define HAVE_LIBWEBP 0
137  #endif
138  #if !defined(HAVE_LIBWEBP_ANIM)
139  #define HAVE_LIBWEBP_ANIM 0
140  #endif
141  #if !defined(HAVE_LIBJP2K)
142  #define HAVE_LIBJP2K 0
143  #endif
144 
145 
146  /*-----------------------------------------------------------------------*
147  * Leptonica supports OpenJPEG 2.0+. If you have a version of openjpeg *
148  * (HAVE_LIBJP2K == 1) that is >= 2.0, set the path to the openjpeg.h *
149  * header in angle brackets here. *
150  *-----------------------------------------------------------------------*/
151  #define LIBJP2K_HEADER <openjpeg-2.3/openjpeg.h>
152 
153 #endif /* ! HAVE_CONFIG_H etc. */
154 
155 /*--------------------------------------------------------------------*
156  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
157  * USER CONFIGURABLE *
158  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
159  * Environ variables for image I/O without external libraries *
160  *--------------------------------------------------------------------*/
161 /*
162  * Leptonica supplies I/O support without using external libraries for:
163  * * image read/write for bmp, pnm
164  * * header read for jp2k
165  * * image wrapping write for pdf and ps.
166  * Setting any of these to 0 causes non-functioning stubs to be linked.
167  */
168 #define USE_BMPIO 1
169 #define USE_PNMIO 1
170 #define USE_JP2KHEADER 1
171 #define USE_PDFIO 1
172 #define USE_PSIO 1
173 
174 
175 /*-------------------------------------------------------------------------*
176  * On linux, BSD, macOS (> 10.12), android (sdk >= 23) and iOS(>= 11.0),
177  * you can redirect writing data from a filestream to memory using
178  * open_memstream() and redirect reading data from a filestream to
179  * reading from memory using fmemopen().
180  * Specifically, you can compress (write compressed data to memory
181  * from raster data in a Pix) and uncompress (read from compressed data
182  * in memory to raster data in a Pix).
183  * For png, tiff and webp, data is compressed and uncompressed directly
184  * to memory without the use of the POSIX.1 (2008) functions fmemopen()
185  * and open_memstream().
186  * For jpeg, jp2k, gif, pnm and bmp, these functions are used on systems
187  * that support them, and for those we define HAVE_FMEMOPEN to 1.
188  *-------------------------------------------------------------------------*/
189 #if !defined(HAVE_CONFIG_H) && \
190  (!defined(ANDROID_BUILD) || __ANDROID_API__ >= 23) && \
191  (!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
192  __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) && \
193  (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || \
194  __MAC_OS_X_VERSION_MIN_REQUIRED > 101200) && \
195  !defined(_WIN32)
196 #define HAVE_FMEMOPEN 1
197 #endif /* ! HAVE_CONFIG_H etc. */
198 
199 /*-------------------------------------------------------------------------*
200  * fstatat() is defined by POSIX, but some systems do not support it. *
201  * One example is older macOS systems (pre-10.10). *
202  * Also, dirfd() is required by fstatat(). *
203  * Play it safe and set the default values to 0. *
204  *-------------------------------------------------------------------------*/
205 #if !defined(HAVE_CONFIG_H)
206 #define HAVE_FSTATAT 0
207 #define HAVE_DIRFD 0
208 #endif /* ! HAVE_CONFIG_H */
209 
210 /*--------------------------------------------------------------------*
211  * It is desirable on Windows to have all temp files written to the same
212  * subdirectory of the Windows <Temp> directory, because files under <Temp>
213  * persist after reboot, and the regression tests write a lot of files.
214  * We write all test files to /tmp/lept or subdirectories of /tmp/lept.
215  * Windows temp files are specified as in unix, but have the translation
216  * /tmp/lept/xxx --> <Temp>/lept/xxx
217  *--------------------------------------------------------------------*/
218 
219 
220 /*--------------------------------------------------------------------*
221  * Built-in types *
222  *--------------------------------------------------------------------*/
223 typedef int l_ok;
224 typedef signed char l_int8;
225 typedef unsigned char l_uint8;
226 typedef short l_int16;
227 typedef unsigned short l_uint16;
228 typedef int l_int32;
229 typedef unsigned int l_uint32;
230 typedef float l_float32;
231 typedef double l_float64;
232 #ifdef COMPILER_MSVC
233 typedef __int64 l_int64;
234 typedef unsigned __int64 l_uint64;
235 #else
236 typedef long long l_int64;
237 typedef unsigned long long l_uint64;
238 #endif /* COMPILER_MSVC */
239 
240 
241 /*-------------------------------------------------------------------------*
242  * For security, the library is distributed in a configuration that does *
243  * not permit (1) forking with 'system', which is used for displaying *
244  * images and generating gnuplots, and (2) writing files with specified *
245  * compiled-in file names. All such writes are with functions such as *
246  * pixWriteDebug() where the "Debug" is appended to the usual name. *
247  * Whether the "Debug" version defaults to the standard version or is a *
248  * no-op depends on the value of this global variable. The default value *
249  * of LeptDebugOK is 0, and it is set in writefile.c. This value can be *
250  * over-ridden, for development and debugging, by setLeptDebugOK(). *
251  *-------------------------------------------------------------------------*/
252 LEPT_DLL extern l_int32 LeptDebugOK; /* default is 0 */
253 
254 
255 /*------------------------------------------------------------------------*
256  * Standard macros *
257  *------------------------------------------------------------------------*/
258 #ifndef L_MIN
260 #define L_MIN(x, y) (((x) < (y)) ? (x) : (y))
261 #endif
262 
263 #ifndef L_MAX
265 #define L_MAX(x, y) (((x) > (y)) ? (x) : (y))
266 #endif
267 
268 #ifndef L_ABS
270 #define L_ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
271 #endif
272 
273 #ifndef L_SIGN
275 #define L_SIGN(x) (((x) < 0) ? -1 : 1)
276 #endif
277 
278 #ifndef UNDEF
280 #define UNDEF -1
281 #endif
282 
283 #ifndef NULL
285 #define NULL 0
286 #endif
287 
288 #ifndef TRUE
290 #define TRUE 1
291 #endif
292 
293 #ifndef FALSE
295 #define FALSE 0
296 #endif
297 
298 
299 /*--------------------------------------------------------------------*
300  * Environment variables for endian dependence *
301  *--------------------------------------------------------------------*/
302 /*
303  * To control conditional compilation, one of two variables
304  *
305  * L_LITTLE_ENDIAN (e.g., for Intel X86)
306  * L_BIG_ENDIAN (e.g., for Sun SPARC, Mac Power PC)
307  *
308  * is defined when the GCC compiler is invoked.
309  * All code should compile properly for both hardware architectures.
310  */
311 
312 
313 /*------------------------------------------------------------------------*
314  * Simple search state variables *
315  *------------------------------------------------------------------------*/
317 enum {
318  L_NOT_FOUND = 0,
319  L_FOUND = 1
320 };
321 
322 
323 /*------------------------------------------------------------------------*
324  * Path separator conversion *
325  *------------------------------------------------------------------------*/
327 enum {
328  UNIX_PATH_SEPCHAR = 0,
329  WIN_PATH_SEPCHAR = 1
330 };
331 
332 
333 /*------------------------------------------------------------------------*
334  * Timing structs *
335  *------------------------------------------------------------------------*/
336 typedef void *L_TIMER;
337 
339 struct L_WallTimer {
340  l_int32 start_sec;
341  l_int32 start_usec;
342  l_int32 stop_sec;
343  l_int32 stop_usec;
344 };
345 typedef struct L_WallTimer L_WALLTIMER;
346 
347 
348 /*------------------------------------------------------------------------*
349  * Standard memory allocation *
350  * *
351  * All default heap allocation is through the system malloc and free. *
352  * *
353  * Leptonica also provides non-default allocation in two situations: *
354  * *
355  * (1) A special allocator/deallocator pair can be provided for the *
356  * pix image data array. This might be useful to prevent memory *
357  * fragmentation when large images are repeatedly allocated and *
358  * freed. See the PixMemoryManager in pix1.c for details, *
359  * where the default is defined. *
360  * *
361  * (2) Special allocator/deallocators can be provided for ALL heap *
362  * allocation if required, for example, for embedded systems. *
363  * For such builds, define LEPTONICA_INTERCEPT_ALLOC, and provide *
364  * custom leptonica_{malloc, calloc, realloc, free} functions. *
365  *------------------------------------------------------------------------*/
366 #ifdef LEPTONICA_INTERCEPT_ALLOC
367  #define LEPT_MALLOC(blocksize) leptonica_malloc(blocksize)
368  #define LEPT_CALLOC(numelem, elemsize) leptonica_calloc(numelem, elemsize)
369  #define LEPT_REALLOC(ptr, blocksize) leptonica_realloc(ptr, blocksize)
370  #define LEPT_FREE(ptr) leptonica_free(ptr)
371  void *leptonica_malloc(size_t blocksize);
372  void *leptonica_calloc(size_t numelem, size_t elemsize);
373  void *leptonica_realloc(void *ptr, size_t blocksize);
374  void leptonica_free(void *ptr);
375 #else
376  #define LEPT_MALLOC(blocksize) malloc(blocksize)
377  #define LEPT_CALLOC(numelem, elemsize) calloc(numelem, elemsize)
378  #define LEPT_REALLOC(ptr, blocksize) realloc(ptr, blocksize)
379  #define LEPT_FREE(ptr) free(ptr)
380 #endif /* LEPTONICA_INTERCEPT_ALLOC */
381 
382 /*------------------------------------------------------------------------*
383  * Control printing of error, warning, and info messages *
384  * *
385  * Leptonica never sends output to stdout. By default, all messages *
386  * go to stderr. However, we provide a mechanism for runtime *
387  * redirection of output, using a custom stderr handler defined *
388  * by the user. See utils1.c for details and examples. *
389  * *
390  * To omit all messages to stderr, simply define NO_CONSOLE_IO on the *
391  * command line. For finer grained control, we have a mechanism *
392  * based on the message severity level. The following assumes that *
393  * NO_CONSOLE_IO is not defined. *
394  * *
395  * Messages are printed if the message severity is greater than or equal *
396  * to the current severity threshold. The current severity threshold *
397  * is the greater of the compile-time severity, which is the minimum *
398  * severity that can be reported, and the run-time severity, which is *
399  * the severity threshold at the moment. *
400  * *
401  * The compile-time threshold determines which messages are compiled *
402  * into the library for potential printing. Messages below the *
403  * compile-time threshold are omitted and can never be printed. The *
404  * default compile-time threshold is L_SEVERITY_INFO, but this may be *
405  * overridden by defining MINIMUM_SEVERITY to the desired enumeration *
406  * identifier on the compiler command line. Defining NO_CONSOLE_IO on *
407  * the command line is the same as setting MINIMUM_SEVERITY to *
408  * L_SEVERITY_NONE. *
409  * *
410  * The run-time threshold determines which messages are printed during *
411  * library execution. It defaults to the compile-time threshold but *
412  * may be changed either statically by defining DEFAULT_SEVERITY to *
413  * the desired enumeration identifier on the compiler command line, or *
414  * dynamically by calling setMsgSeverity() to specify a new threshold. *
415  * The run-time threshold may also be set from the value of the *
416  * environment variable LEPT_MSG_SEVERITY by calling setMsgSeverity() *
417  * and specifying L_SEVERITY_EXTERNAL. *
418  * *
419  * In effect, the compile-time threshold setting says, "Generate code *
420  * to permit messages of equal or greater severity than this to be *
421  * printed, if desired," whereas the run-time threshold setting says, *
422  * "Print messages that have an equal or greater severity than this." *
423  *------------------------------------------------------------------------*/
424 
427 enum {
428  L_SEVERITY_EXTERNAL = 0, /* Get the severity from the environment */
429  L_SEVERITY_ALL = 1, /* Lowest severity: print all messages */
430  L_SEVERITY_DEBUG = 2, /* Print debugging and higher messages */
431  L_SEVERITY_INFO = 3, /* Print informational and higher messages */
432  L_SEVERITY_WARNING = 4, /* Print warning and higher messages */
433  L_SEVERITY_ERROR = 5, /* Print error and higher messages */
434  L_SEVERITY_NONE = 6 /* Highest severity: print no messages */
435 };
436 
437 /* No message less than the compile-time threshold will ever be
438  * reported, regardless of the current run-time threshold. This allows
439  * selection of the set of messages to include in the library. For
440  * example, setting the threshold to L_SEVERITY_WARNING eliminates all
441  * informational messages from the library. With that setting, both
442  * warning and error messages would be printed unless setMsgSeverity()
443  * was called, or DEFAULT_SEVERITY was redefined, to set the run-time
444  * severity to L_SEVERITY_ERROR. In that case, only error messages
445  * would be printed.
446  *
447  * This mechanism makes the library smaller and faster, by eliminating
448  * undesired message reporting and the associated run-time overhead for
449  * message threshold checking, because code for messages whose severity
450  * is lower than MINIMUM_SEVERITY won't be generated.
451  *
452  * A production library might typically permit ERROR messages to be
453  * generated, and a development library might permit DEBUG and higher.
454  * The actual messages printed (as opposed to generated) would depend
455  * on the current run-time severity threshold.
456  *
457  * This is a complex mechanism and a few examples may help.
458  * (1) No output permitted under any circumstances.
459  * Use: -DNO_CONSOLE_IO or -DMINIMUM_SEVERITY=6
460  * (2) Suppose you want to only allow error messages, and you don't
461  * want to permit info or warning messages at runtime.
462  * Use: -DMINIMUM_SEVERITY=5
463  * (3) Suppose you want to only allow error messages by default,
464  * but you will permit this to be over-ridden at runtime.
465  * Use: -DDEFAULT_SEVERITY=5
466  * and to allow info and warning override:
467  * setMsgSeverity(L_SEVERITY_INFO);
468  */
469 
470 #ifdef NO_CONSOLE_IO
471  #undef MINIMUM_SEVERITY
472  #undef DEFAULT_SEVERITY
473 
474  #define MINIMUM_SEVERITY L_SEVERITY_NONE
475  #define DEFAULT_SEVERITY L_SEVERITY_NONE
477 #else
478  #ifndef MINIMUM_SEVERITY
479  #define MINIMUM_SEVERITY L_SEVERITY_INFO
480  #endif
481 
482  #ifndef DEFAULT_SEVERITY
483  #define DEFAULT_SEVERITY MINIMUM_SEVERITY
484  #endif
485 #endif
486 
487 
489 LEPT_DLL extern l_int32 LeptMsgSeverity;
490 
491 /*
492  * <pre>
493  * Usage
494  * =====
495  * Messages are of two types.
496  *
497  * (1) The messages
498  * ERROR_INT(a,b,c) : returns l_int32
499  * ERROR_FLOAT(a,b,c) : returns l_float32
500  * ERROR_PTR(a,b,c) : returns void*
501  * are used to return from functions and take a fixed set of parameters:
502  * a : <message string>
503  * b : procName
504  * c : <return value from function>
505  * where procName is the name of the local variable naming the function.
506  *
507  * (2) The purely informational L_* messages
508  * L_ERROR(a,...)
509  * L_WARNING(a,...)
510  * L_INFO(a,...)
511  * do not take a return value, but they take at least two parameters:
512  * a : <message string> with optional format conversions
513  * v1 : procName (this must be included as the first vararg)
514  * v2, ... : optional varargs to match format converters in the message
515  *
516  * To return an error from a function that returns void, use:
517  * L_ERROR(<message string>, procName, [...])
518  * return;
519  *
520  * Implementation details
521  * ======================
522  * Messages are defined with the IF_SEV macro. The first parameter is
523  * the message severity, the second is the function to call if the
524  * message is to be printed, and the third is the return value if the
525  * message is to be suppressed. For example, we might have an
526  * informational message defined as:
527  *
528  * IF_SEV(L_SEVERITY_INFO, fprintf(.......), 0)
529  *
530  * The macro expands into a conditional. Because the first comparison
531  * is between two constants, an optimizing compiler will remove either
532  * the comparison (if it's true) or the entire macro expansion (if it
533  * is false). This means that there is no run-time overhead for
534  * messages whose severity falls below the minimum specified at compile
535  * time, and for others the overhead is one (not two) comparisons.
536  *
537  * The L_nnn() macros below do not return a value, but because the
538  * conditional operator requires one for the false condition, we
539  * specify a void expression.
540  * </pre>
541  */
542 
543 #ifdef NO_CONSOLE_IO
544 
545  #define PROCNAME(name)
546  #define ERROR_INT(a, b, c) ((l_int32)(c))
547  #define ERROR_FLOAT(a, b, c) ((l_float32)(c))
548  #define ERROR_PTR(a, b, c) ((void *)(c))
549  #define L_ERROR(a, ...)
550  #define L_WARNING(a, ...)
551  #define L_INFO(a, ...)
552 
553 #else
554 
555  #define PROCNAME(name) static const char procName[] = name
556  #define IF_SEV(l, t, f) \
557  ((l) >= MINIMUM_SEVERITY && (l) >= LeptMsgSeverity ? (t) : (f))
558 
559  #define ERROR_INT(a, b, c) \
560  IF_SEV(L_SEVERITY_ERROR, returnErrorInt((a), (b), (c)), (l_int32)(c))
561  #define ERROR_FLOAT(a, b, c) \
562  IF_SEV(L_SEVERITY_ERROR, returnErrorFloat((a), (b), (c)), (l_float32)(c))
563  #define ERROR_PTR(a, b, c) \
564  IF_SEV(L_SEVERITY_ERROR, returnErrorPtr((a), (b), (c)), (void *)(c))
565 
566  #define L_ERROR(a, ...) \
567  IF_SEV(L_SEVERITY_ERROR, \
568  (void)lept_stderr("Error in %s: " a, __VA_ARGS__), \
569  (void)0)
570  #define L_WARNING(a, ...) \
571  IF_SEV(L_SEVERITY_WARNING, \
572  (void)lept_stderr("Warning in %s: " a, __VA_ARGS__), \
573  (void)0)
574  #define L_INFO(a, ...) \
575  IF_SEV(L_SEVERITY_INFO, \
576  (void)lept_stderr("Info in %s: " a, __VA_ARGS__), \
577  (void)0)
578 
579 #if 0 /* Alternative method for controlling L_* message output */
580  #define L_ERROR(a, ...) \
581  { if (L_SEVERITY_ERROR >= MINIMUM_SEVERITY && \
582  L_SEVERITY_ERROR >= LeptMsgSeverity) \
583  lept_stderr("Error in %s: " a, __VA_ARGS__) \
584  }
585  #define L_WARNING(a, ...) \
586  { if (L_SEVERITY_WARNING >= MINIMUM_SEVERITY && \
587  L_SEVERITY_WARNING >= LeptMsgSeverity) \
588  lept_stderr("Warning in %s: " a, __VA_ARGS__) \
589  }
590  #define L_INFO(a, ...) \
591  { if (L_SEVERITY_INFO >= MINIMUM_SEVERITY && \
592  L_SEVERITY_INFO >= LeptMsgSeverity) \
593  lept_stderr("Info in %s: " a, __VA_ARGS__) \
594  }
595 #endif
596 
597 #endif /* NO_CONSOLE_IO */
598 
599 
600 /*------------------------------------------------------------------------*
601  * snprintf() renamed in MSVC (pre-VS2015) *
602  *------------------------------------------------------------------------*/
603 #if defined _MSC_VER && _MSC_VER < 1900
604 #define snprintf(buf, size, ...) _snprintf_s(buf, size, _TRUNCATE, __VA_ARGS__)
605 #endif
606 
607 
608 #endif /* LEPTONICA_ENVIRON_H */
LEPT_DLL l_int32 LeptMsgSeverity
Definition: utils1.c:119