comparison mupdf-source/thirdparty/leptonica/src/environ.h @ 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 - 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.1+. If you have a version of openjpeg *
148 * (HAVE_LIBJP2K == 1) that is >= 2.1, set the path to the openjpeg.h *
149 * header in angle brackets here. *
150 *-----------------------------------------------------------------------*/
151 #define LIBJP2K_HEADER <openjpeg-2.5/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; /*!< return 0 if OK, 1 on error */
224 typedef signed char l_int8; /*!< signed 8-bit value */
225 typedef unsigned char l_uint8; /*!< unsigned 8-bit value */
226 typedef short l_int16; /*!< signed 16-bit value */
227 typedef unsigned short l_uint16; /*!< unsigned 16-bit value */
228 typedef int l_int32; /*!< signed 32-bit value */
229 typedef unsigned int l_uint32; /*!< unsigned 32-bit value */
230 typedef float l_float32; /*!< 32-bit floating point value */
231 typedef double l_float64; /*!< 64-bit floating point value */
232 #ifdef COMPILER_MSVC
233 typedef __int64 l_int64; /*!< signed 64-bit value */
234 typedef unsigned __int64 l_uint64; /*!< unsigned 64-bit value */
235 #else
236 typedef long long l_int64; /*!< signed 64-bit value */
237 typedef unsigned long long l_uint64; /*!< unsigned 64-bit value */
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
259 /*! Minimum of %x and %y */
260 #define L_MIN(x, y) (((x) < (y)) ? (x) : (y))
261 #endif
262
263 #ifndef L_MAX
264 /*! Maximum of %x and %y */
265 #define L_MAX(x, y) (((x) > (y)) ? (x) : (y))
266 #endif
267
268 #ifndef L_ABS
269 /*! Absolute value of %x */
270 #define L_ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
271 #endif
272
273 #ifndef L_SIGN
274 /*! Sign of %x */
275 #define L_SIGN(x) (((x) < 0) ? -1 : 1)
276 #endif
277
278 #ifndef UNDEF
279 /*! Undefined value */
280 #define UNDEF -1
281 #endif
282
283 #ifndef NULL
284 /*! NULL value */
285 #define NULL 0
286 #endif
287
288 #ifndef TRUE
289 /*! True value */
290 #define TRUE 1
291 #endif
292
293 #ifndef FALSE
294 /*! False value */
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 *------------------------------------------------------------------------*/
316 /*! Search State */
317 enum {
318 L_NOT_FOUND = 0,
319 L_FOUND = 1
320 };
321
322
323 /*------------------------------------------------------------------------*
324 * Path separator conversion *
325 *------------------------------------------------------------------------*/
326 /*! Path Separators */
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
338 /*! Timing struct */
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
425 /*! Control printing of error, warning and info messages */
426 /*! Message Control */
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 /*!< Compile-time default */
475 #define DEFAULT_SEVERITY L_SEVERITY_NONE /*!< Run-time default */
476
477 #else
478 #ifndef MINIMUM_SEVERITY
479 #define MINIMUM_SEVERITY L_SEVERITY_INFO /*!< Compile-time default */
480 #endif
481
482 #ifndef DEFAULT_SEVERITY
483 #define DEFAULT_SEVERITY MINIMUM_SEVERITY /*!< Run-time default */
484 #endif
485 #endif
486
487
488 /*! The run-time message severity threshold is defined in utils1.c. */
489 LEPT_DLL extern l_int32 LeptMsgSeverity;
490
491 /*
492 * <pre>
493 * Usage
494 * =====
495 * Messages are of three 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 three parameters:
502 * a : <message string>
503 * b : __func__ (the procedure name)
504 * c : <return value from function>
505 * A newline is added by the function after the message.
506 *
507 * (2) The messages
508 * ERROR_INT_1(a,f,b,c) : returns l_int32
509 * ERROR_FLOAT_1(a,f,b,c) : returns l_float32
510 * ERROR_PTR_1(a,f,b,c) : returns void*
511 * are used to return from functions and take four parameters:
512 * a : <message string>
513 * f : <second message string> (typically, a filename for an fopen()))
514 * b : __func__ (the procedure name)
515 * c : <return value from function>
516 * A newline is added by the function after the message.
517 *
518 * (3) The purely informational L_* messages
519 * L_ERROR(a,...)
520 * L_WARNING(a,...)
521 * L_INFO(a,...)
522 * do not take a return value, but they take at least two parameters:
523 * a : <message string> with optional format conversions
524 * v1 : procName (this must be included as the first vararg)
525 * v2, ... : optional varargs to match format converters in the message
526 * Unlike the messages that return a value in (2) and (3) above,
527 * here a newline needs to be included at the end of the message string.
528 *
529 * To return an error from a function that returns void, use:
530 * L_ERROR(<message string>, procName, [...])
531 * return;
532 *
533 * Implementation details
534 * ======================
535 * Messages are defined with the IF_SEV macro. The first parameter is
536 * the message severity, the second is the function to call if the
537 * message is to be printed, and the third is the return value if the
538 * message is to be suppressed. For example, we might have an
539 * informational message defined as:
540 *
541 * IF_SEV(L_SEVERITY_INFO, fprintf(.......), 0)
542 *
543 * The macro expands into a conditional. Because the first comparison
544 * is between two constants, an optimizing compiler will remove either
545 * the comparison (if it's true) or the entire macro expansion (if it
546 * is false). This means that there is no run-time overhead for
547 * messages whose severity falls below the minimum specified at compile
548 * time, and for others the overhead is one (not two) comparisons.
549 *
550 * The L_nnn() macros below do not return a value, but because the
551 * conditional operator requires one for the false condition, we
552 * specify a void expression.
553 * </pre>
554 */
555
556 #ifdef NO_CONSOLE_IO
557
558 #define PROCNAME(name)
559 #define ERROR_INT(a, b, c) ((l_int32)(c))
560 #define ERROR_FLOAT(a, b, c) ((l_float32)(c))
561 #define ERROR_PTR(a, b, c) ((void *)(c))
562 #define ERROR_INT_1(a, f, b, c) ((l_int32)(c))
563 #define ERROR_FLOAT_1(a, f, b, c) ((l_float32)(c))
564 #define ERROR_PTR_1(a, f, b, c) ((void *)(c))
565 #define L_ERROR(a, ...)
566 #define L_WARNING(a, ...)
567 #define L_INFO(a, ...)
568
569 #else
570
571 #define PROCNAME(name) static const char procName[] = name
572 #define IF_SEV(l, t, f) \
573 ((l) >= MINIMUM_SEVERITY && (l) >= LeptMsgSeverity ? (t) : (f))
574
575 #define ERROR_INT(a, b, c) \
576 IF_SEV(L_SEVERITY_ERROR, returnErrorInt((a), (b), (c)), (l_int32)(c))
577 #define ERROR_FLOAT(a, b, c) \
578 IF_SEV(L_SEVERITY_ERROR, returnErrorFloat((a), (b), (c)), (l_float32)(c))
579 #define ERROR_PTR(a, b, c) \
580 IF_SEV(L_SEVERITY_ERROR, returnErrorPtr((a), (b), (c)), (void *)(c))
581
582 #define ERROR_INT_1(a, f, b, c) \
583 IF_SEV(L_SEVERITY_ERROR, returnErrorInt1((a), (f), (b), (c)), \
584 (l_int32)(c))
585 #define ERROR_FLOAT_1(a, f, b, c) \
586 IF_SEV(L_SEVERITY_ERROR, returnErrorFloat1((a), (f), (b), (c)), \
587 (l_float32)(c))
588 #define ERROR_PTR_1(a, f, b, c) \
589 IF_SEV(L_SEVERITY_ERROR, returnErrorPtr1((a), (f), (b), (c)), \
590 (void *)(c))
591
592 #define L_ERROR(a, ...) \
593 IF_SEV(L_SEVERITY_ERROR, \
594 (void)lept_stderr("Error in %s: " a, __VA_ARGS__), \
595 (void)0)
596 #define L_WARNING(a, ...) \
597 IF_SEV(L_SEVERITY_WARNING, \
598 (void)lept_stderr("Warning in %s: " a, __VA_ARGS__), \
599 (void)0)
600 #define L_INFO(a, ...) \
601 IF_SEV(L_SEVERITY_INFO, \
602 (void)lept_stderr("Info in %s: " a, __VA_ARGS__), \
603 (void)0)
604
605 #if 0 /* Alternative method for controlling L_* message output */
606 #define L_ERROR(a, ...) \
607 { if (L_SEVERITY_ERROR >= MINIMUM_SEVERITY && \
608 L_SEVERITY_ERROR >= LeptMsgSeverity) \
609 lept_stderr("Error in %s: " a, __VA_ARGS__) \
610 }
611 #define L_WARNING(a, ...) \
612 { if (L_SEVERITY_WARNING >= MINIMUM_SEVERITY && \
613 L_SEVERITY_WARNING >= LeptMsgSeverity) \
614 lept_stderr("Warning in %s: " a, __VA_ARGS__) \
615 }
616 #define L_INFO(a, ...) \
617 { if (L_SEVERITY_INFO >= MINIMUM_SEVERITY && \
618 L_SEVERITY_INFO >= LeptMsgSeverity) \
619 lept_stderr("Info in %s: " a, __VA_ARGS__) \
620 }
621 #endif
622
623 #endif /* NO_CONSOLE_IO */
624
625
626 /*------------------------------------------------------------------------*
627 * snprintf() renamed in MSVC (pre-VS2015) *
628 *------------------------------------------------------------------------*/
629 #if defined _MSC_VER && _MSC_VER < 1900
630 #define snprintf(buf, size, ...) _snprintf_s(buf, size, _TRUNCATE, __VA_ARGS__)
631 #endif
632
633
634 #endif /* LEPTONICA_ENVIRON_H */