HTML Tidy  5.6.0
The HTACG Tidy HTML Project
tidyplatform.h
Go to the documentation of this file.
1 #ifndef __TIDY_PLATFORM_H__
2 #define __TIDY_PLATFORM_H__
3 
4 /**************************************************************************//**
5  * @file
6  * Platform specific definitions, specifics, and headers. This file is
7  * included by `tidy.h` already, and need not be included separately. Among
8  * other things, the PLATFORM_NAME is defined and the most common systems
9  * headers are included.
10  *
11  * @note It should be largely unnecessary to modify this file unless adding
12  * support for a completely new architecture. Most options defined in this
13  * file specify defaults that can be overriden by the build system; for
14  * example, passing -D flags to CMake.
15  *
16  * @author Charles Reitzel [creitzel@rcn.com]
17  * @author HTACG, et al (consult git log)
18  *
19  * @copyright
20  * Copyright (c) 1998-2017 World Wide Web Consortium (Massachusetts
21  * Institute of Technology, European Research Consortium for Informatics
22  * and Mathematics, Keio University).
23  * @copyright
24  * See tidy.h for license.
25  *
26  * @date Created 2001-05-20 by Charles Reitzel
27  * @date Updated 2002-07-01 by Charles Reitzel
28  * @date Further modifications: consult git log.
29  ******************************************************************************/
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*=============================================================================
36  * Unix console application features
37  * By default on Unix-like systems when building for the console program,
38  * support runtime configuration files in /etc/ and in ~/. To prevent this,
39  * set ENABLE_CONFIG_FILES to NO. Specify -DTIDY_CONFIG_FILE and/or
40  * -DTIDY_USER_CONFIG_FILE to override the default paths in tidyplatform.h.
41  * @note: this section refactored to support #584.
42  *===========================================================================*/
43 
44 /* #define ENABLE_CONFIG_FILES */
45 
46 #if defined(TIDY_ENABLE_CONFIG_FILES)
47 # if !defined(TIDY_CONFIG_FILE)
48 # define TIDY_CONFIG_FILE "/etc/tidy.conf"
49 # endif
50 # if !defined(TIDY_USER_CONFIG_FILE)
51 # define TIDY_USER_CONFIG_FILE "~/.tidyrc"
52 # endif
53 #else
54 # if defined(TIDY_CONFIG_FILE)
55 # undef TIDY_CONFIG_FILE
56 # endif
57 # if defined(TIDY_USER_CONFIG_FILE)
58 # undef TIDY_USER_CONFIG_FILE
59 # endif
60 #endif
61 
62 
63 /*=============================================================================
64  * Unix tilde expansion support
65  * By default on Unix-like systems when building for the console program,
66  * this flag is set so that Tidy knows getpwname() is available. It allows
67  * tidy to find files named ~your/foo for use in the HTML_TIDY environment
68  * variable or TIDY_CONFIG_FILE or TIDY_USER_CONFIG_FILE or on the command
69  * command line: -config ~joebob/tidy.cfg
70  * Contributed by Todd Lewis.
71  *===========================================================================*/
72 
73 /* #define SUPPORT_GETPWNAM */
74 
75 
76 /*=============================================================================
77  * Optional Tidy features support
78  *===========================================================================*/
79 
80 /* Enable/disable support for additional languages */
81 #ifndef SUPPORT_LOCALIZATIONS
82 # define SUPPORT_LOCALIZATIONS 1
83 #endif
84 
85 /* Enable/disable support for console */
86 #ifndef SUPPORT_CONSOLE_APP
87 # define SUPPORT_CONSOLE_APP 1
88 #endif
89 
90 
91 /*=============================================================================
92  * Platform specific convenience definitions
93  *===========================================================================*/
94 
95 /* === Convenience defines for Mac platforms === */
96 
97 #if defined(macintosh)
98 /* Mac OS 6.x/7.x/8.x/9.x, with or without CarbonLib - MPW or Metrowerks 68K/PPC compilers */
99 # define MAC_OS_CLASSIC
100 # ifndef PLATFORM_NAME
101 # define PLATFORM_NAME "Mac OS"
102 # endif
103 
104 /* needed for access() */
105 # if !defined(_POSIX) && !defined(NO_ACCESS_SUPPORT)
106 # define NO_ACCESS_SUPPORT
107 # endif
108 
109 # ifdef SUPPORT_GETPWNAM
110 # undef SUPPORT_GETPWNAM
111 # endif
112 
113 #elif defined(__APPLE__) && defined(__MACH__)
114  /* Mac OS X (client) 10.x (or server 1.x/10.x) - gcc or Metrowerks MachO compilers */
115 # define MAC_OS_X
116 # ifndef PLATFORM_NAME
117 # include "TargetConditionals.h"
118 # if TARGET_OS_IOS
119 # define PLATFORM_NAME "Apple iOS"
120 # elif TARGET_OS_MAC
121 # define PLATFORM_NAME "Apple macOS"
122 # elif TARGET_OS_TV
123 # define PLATFORM_NAME "Apple tvOS"
124 # elif TARGET_OS_WATCH
125 # define PLATFORM_NAME "Apple watchOS"
126 # else
127 # define PLATFORM_NAME "Apple Unknown OS"
128 # endif
129 # endif
130 #endif
131 
132 #if defined(MAC_OS_CLASSIC) || defined(MAC_OS_X)
133 /* Any OS on Mac platform */
134 # define MAC_OS
135 # define FILENAMES_CASE_SENSITIVE 0
136 # define strcasecmp strcmp
137 #endif
138 
139 /* === Convenience defines for BSD-like platforms === */
140 
141 #if defined(__FreeBSD__)
142 # define BSD_BASED_OS
143 # ifndef PLATFORM_NAME
144 # define PLATFORM_NAME "FreeBSD"
145 # endif
146 
147 #elif defined(__NetBSD__)
148 # define BSD_BASED_OS
149 # ifndef PLATFORM_NAME
150 # define PLATFORM_NAME "NetBSD"
151 # endif
152 
153 #elif defined(__OpenBSD__)
154 # define BSD_BASED_OS
155 # ifndef PLATFORM_NAME
156 # define PLATFORM_NAME "OpenBSD"
157 # endif
158 
159 #elif defined(__DragonFly__)
160 # define BSD_BASED_OS
161 # ifndef PLATFORM_NAME
162 # define PLATFORM_NAME "DragonFly"
163 # endif
164 
165 #elif defined(__MINT__)
166 # define BSD_BASED_OS
167 # ifndef PLATFORM_NAME
168 # define PLATFORM_NAME "FreeMiNT"
169 # endif
170 
171 #elif defined(__bsdi__)
172 # define BSD_BASED_OS
173 # ifndef PLATFORM_NAME
174 # define PLATFORM_NAME "BSD/OS"
175 # endif
176 #endif
177 
178 /* === Convenience defines for Windows platforms === */
179 
180 #if defined(WINDOWS) || defined(_WIN32)
181 
182 # define WINDOWS_OS
183 # ifndef PLATFORM_NAME
184 # define PLATFORM_NAME "Windows"
185 # endif
186 
187 # if defined(__MWERKS__) || defined(__MSL__)
188  /* not available with Metrowerks Standard Library */
189 # ifdef SUPPORT_GETPWNAM
190 # undef SUPPORT_GETPWNAM
191 # endif
192  /* needed for setmode() */
193 # if !defined(NO_SETMODE_SUPPORT)
194 # define NO_SETMODE_SUPPORT
195 # endif
196 # define strcasecmp _stricmp
197 # endif
198 
199 # if defined(__BORLANDC__)
200 # define strcasecmp stricmp
201 # endif
202 
203 # define FILENAMES_CASE_SENSITIVE 0
204 # define SUPPORT_POSIX_MAPPED_FILES 0
205 
206 #endif /* WINDOWS */
207 
208 /* === Convenience defines for Linux platforms === */
209 
210 #if defined(linux) && defined(__alpha__)
211  /* Linux on Alpha - gcc compiler */
212 # define LINUX_OS
213 # ifndef PLATFORM_NAME
214 # define PLATFORM_NAME "Linux/Alpha"
215 # endif
216 
217 #elif defined(linux) && defined(__sparc__)
218  /* Linux on Sparc - gcc compiler */
219 # define LINUX_OS
220 # ifndef PLATFORM_NAME
221 # define PLATFORM_NAME "Linux/Sparc"
222 # endif
223 
224 #elif defined(linux) && (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__))
225  /* Linux on x86 - gcc compiler */
226 # define LINUX_OS
227 # ifndef PLATFORM_NAME
228 # define PLATFORM_NAME "Linux/x86"
229 # endif
230 
231 #elif defined(linux) && defined(__powerpc__)
232  /* Linux on PPC - gcc compiler */
233 # define LINUX_OS
234 # if defined(__linux__) && defined(__powerpc__)
235 # ifndef PLATFORM_NAME
236  /* MkLinux on PPC - gcc (egcs) compiler */
237 # define PLATFORM_NAME "MkLinux"
238 # endif
239 # else
240 # ifndef PLATFORM_NAME
241 # define PLATFORM_NAME "Linux/PPC"
242 # endif
243 # endif
244 
245 #elif defined(linux) || defined(__linux__)
246  /* generic Linux */
247 # define LINUX_OS
248 # ifndef PLATFORM_NAME
249 # define PLATFORM_NAME "Linux"
250 # endif
251 #endif
252 
253 /* === Convenience defines for Solaris platforms === */
254 
255 #if defined(sun)
256 # define SOLARIS_OS
257 # ifndef PLATFORM_NAME
258 # define PLATFORM_NAME "Solaris"
259 # endif
260 #endif
261 
262 /* === Convenience defines for HPUX + gcc platforms === */
263 
264 #if defined(__hpux)
265 # define HPUX_OS
266 # ifndef PLATFORM_NAME
267 # define PLATFORM_NAME "HPUX"
268 # endif
269 #endif
270 
271 /* === Convenience defines for RISCOS + gcc platforms === */
272 
273 #if defined(__riscos__)
274 # define RISC_OS
275 # ifndef PLATFORM_NAME
276 # define PLATFORM_NAME "RISC OS"
277 # endif
278 #endif
279 
280 /* === Convenience defines for OS/2 + icc/gcc platforms === */
281 
282 #if defined(__OS2__) || defined(__EMX__)
283 # define OS2_OS
284 # ifndef PLATFORM_NAME
285 # define PLATFORM_NAME "OS/2"
286 # endif
287 # define FILENAMES_CASE_SENSITIVE 0
288 # define strcasecmp stricmp
289 #endif
290 
291 /* === Convenience defines for IRIX === */
292 
293 #if defined(__sgi)
294 # define IRIX_OS
295 # ifndef PLATFORM_NAME
296 # define PLATFORM_NAME "SGI IRIX"
297 # endif
298 #endif
299 
300 /* === Convenience defines for AIX === */
301 
302 #if defined(_AIX)
303 # define AIX_OS
304 # ifndef PLATFORM_NAME
305 # define PLATFORM_NAME "IBM AIX"
306 # endif
307 #endif
308 
309 /* === Convenience defines for BeOS platforms === */
310 
311 #if defined(__BEOS__)
312 # define BE_OS
313 # ifndef PLATFORM_NAME
314 # define PLATFORM_NAME "BeOS"
315 # endif
316 #endif
317 
318 /* === Convenience defines for Cygwin platforms === */
319 
320 #if defined(__CYGWIN__)
321 # define CYGWIN_OS
322 # ifndef PLATFORM_NAME
323 # define PLATFORM_NAME "Cygwin"
324 # endif
325 # define FILENAMES_CASE_SENSITIVE 0
326 #endif
327 
328 /* === Convenience defines for OpenVMS === */
329 
330 #if defined(__VMS)
331 # define OPENVMS_OS
332 # ifndef PLATFORM_NAME
333 # define PLATFORM_NAME "OpenVMS"
334 # endif
335 # define FILENAMES_CASE_SENSITIVE 0
336 #endif
337 
338 /* === Convenience defines for DEC Alpha OSF + gcc platforms === */
339 
340 #if defined(__osf__)
341 # define OSF_OS
342 # ifndef PLATFORM_NAME
343 # define PLATFORM_NAME "DEC Alpha OSF"
344 # endif
345 #endif
346 
347 /* === Convenience defines for ARM platforms === */
348 
349 #if defined(__arm)
350 # define ARM_OS
351 # if defined(forARM) && defined(__NEWTON_H)
352  /* Using Newton C++ Tools ARMCpp compiler */
353 # define NEWTON_OS
354 # ifndef PLATFORM_NAME
355 # define PLATFORM_NAME "Newton"
356 # endif
357 # else
358 # ifndef PLATFORM_NAME
359 # define PLATFORM_NAME "ARM"
360 # endif
361 # endif
362 #endif
363 
364 
365 /*=============================================================================
366  * Standard Library Includes
367  *===========================================================================*/
368 
369 #include <ctype.h>
370 #include <stdio.h>
371 #include <setjmp.h> /* for longjmp on error exit */
372 #include <stdlib.h>
373 #include <stdarg.h> /* may need <varargs.h> for Unix V */
374 #include <string.h>
375 #include <assert.h>
376 
377 #ifdef NEEDS_MALLOC_H
378 # include <malloc.h>
379 #endif
380 
381 #ifdef SUPPORT_GETPWNAM
382 # include <pwd.h>
383 #endif
384 
385 #ifdef NEEDS_UNISTD_H
386 # include <unistd.h> /* needed for unlink on some Unix systems */
387 #endif
388 
389 
390 /*=============================================================================
391  * Case sensitive file systems
392  *===========================================================================*/
393 
394 /* By default, use case-sensitive filename comparison. */
395 #ifndef FILENAMES_CASE_SENSITIVE
396 # define FILENAMES_CASE_SENSITIVE 1
397 #endif
398 
399 
400 /*=============================================================================
401  * Last modified time preservation
402  * Tidy preserves the last modified time for the files it cleans up.
403  *
404  * If your platform doesn't support <utime.h> and the utime() function, or
405  * <sys/futime> and the futime() function then set PRESERVE_FILE_TIMES to 0.
406  *
407  * If your platform doesn't support <sys/utime.h> and the futime() function,
408  * then set HAS_FUTIME to 0.
409  *
410  * If your platform supports <utime.h> and the utime() function requires the
411  * file to be closed first, then set UTIME_NEEDS_CLOSED_FILE to 1.
412  *===========================================================================*/
413 
414 /* Keep old PRESERVEFILETIMES define for compatibility */
415 #ifdef PRESERVEFILETIMES
416 # undef PRESERVE_FILE_TIMES
417 # define PRESERVE_FILE_TIMES PRESERVEFILETIMES
418 #endif
419 
420 #ifndef PRESERVE_FILE_TIMES
421 # if defined(RISC_OS) || defined(OPENVMS_OS) || defined(OSF_OS)
422 # define PRESERVE_FILE_TIMES 0
423 # else
424 # define PRESERVE_FILE_TIMES 1
425 # endif
426 #endif
427 
428 #if PRESERVE_FILE_TIMES
429 
430 # ifndef HAS_FUTIME
431 # if defined(CYGWIN_OS) || defined(BE_OS) || defined(OS2_OS) || defined(HPUX_OS) || defined(SOLARIS_OS) || defined(LINUX_OS) || defined(BSD_BASED_OS) || defined(MAC_OS) || defined(__MSL__) || defined(IRIX_OS) || defined(AIX_OS) || defined(__BORLANDC__) || defined(__GLIBC__)
432 # define HAS_FUTIME 0
433 # else
434 # define HAS_FUTIME 1
435 # endif
436 # endif
437 
438 # ifndef UTIME_NEEDS_CLOSED_FILE
439 # if defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(MAC_OS) || defined(__MSL__) || defined(LINUX_OS)
440 # define UTIME_NEEDS_CLOSED_FILE 1
441 # else
442 # define UTIME_NEEDS_CLOSED_FILE 0
443 # endif
444 # endif
445 
446 # if defined(MAC_OS_X) || (!defined(MAC_OS_CLASSIC) && !defined(__MSL__))
447 # include <sys/types.h>
448 # include <sys/stat.h>
449 # else
450 # include <stat.h>
451 # endif
452 
453 # if HAS_FUTIME
454 # include <sys/utime.h>
455 # else
456 # include <utime.h>
457 # endif
458 
459 /* MS Windows needs _ prefix for Unix file functions.
460  Not required by Metrowerks Standard Library (MSL).
461 
462  Tidy uses following for preserving the last modified time.
463 
464  WINDOWS automatically set by Win16 compilers.
465  _WIN32 automatically set by Win32 compilers.
466 */
467 # if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
468 # define futime _futime
469 # define fstat _fstat
470 # define utimbuf _utimbuf /* Windows seems to want utimbuf */
471 # define stat _stat
472 # define utime _utime
473 # define vsnprintf _vsnprintf
474 # endif
475 
476 #endif
477 
478 
479 /*=============================================================================
480  * Windows file functions
481  * Windows needs _ prefix for Unix file functions.
482  * Not required by Metrowerks Standard Library (MSL).
483  *
484  * WINDOWS automatically set by Win16 compilers.
485  * _WIN32 automatically set by Win32 compilers.
486  *===========================================================================*/
487 
488 #if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
489 
490 # if !(defined(__WATCOMC__) || defined(__MINGW32__))
491 # define fileno _fileno
492 # define setmode _setmode
493 # endif
494 
495 # if defined(_MSC_VER)
496 # define fileno _fileno
497 #if !defined(NDEBUG) && !defined(ENABLE_DEBUG_LOG) && !defined(DISABLE_DEBUG_LOG)
498 #define ENABLE_DEBUG_LOG
499 #endif
500 #endif
501 
502 # define access _access
503 # define strcasecmp _stricmp
504 
505 # ifndef va_copy
506 # define va_copy(dest, src) (dest = src)
507 # endif
508 
509 # if _MSC_VER > 1000
510 # pragma warning( disable : 4189 ) /* local variable is initialized but not referenced */
511 # pragma warning( disable : 4100 ) /* unreferenced formal parameter */
512 # pragma warning( disable : 4706 ) /* assignment within conditional expression */
513 # endif
514 
515 # if _MSC_VER > 1300
516 # pragma warning( disable : 4996 ) /* disable depreciation warning */
517 # endif
518 
519 #endif /* _WIN32 */
520 
521 #if defined(_WIN32)
522 
523 # if (defined(_USRDLL) || defined(_WINDLL) || defined(BUILD_SHARED_LIB)) && !defined(TIDY_EXPORT) && !defined(TIDY_STATIC)
524 # ifdef BUILDING_SHARED_LIB
525 # define TIDY_EXPORT __declspec( dllexport )
526 # else
527 # define TIDY_EXPORT __declspec( dllimport )
528 # endif
529 # else
530 # define TIDY_EXPORT extern
531 # endif
532 
533 # ifndef TIDY_CALL
534 # ifdef _WIN64
535 # define TIDY_CALL __fastcall
536 # else
537 # define TIDY_CALL __stdcall
538 # endif
539 # endif
540 
541 #endif /* _WIN32 */
542 
543 
544 /*=============================================================================
545  * Hack for gnu sys/types.h file which defines uint and ulong
546  *===========================================================================*/
547 
548 #if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS)
549 # include <sys/types.h>
550 #endif
551 
552 #if !defined(HPUX_OS) && !defined(CYGWIN_OS) && !defined(MAC_OS_X) && !defined(BE_OS) && !defined(SOLARIS_OS) && !defined(BSD_BASED_OS) && !defined(OSF_OS) && !defined(IRIX_OS) && !defined(AIX_OS) && !defined(LINUX_OS)
553 # undef uint
554  typedef unsigned int uint;
555 #endif
556 
557 #if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32)
558 # undef ulong
559  typedef unsigned long ulong;
560 #endif
561 
562 
563 /*=============================================================================
564  * Visibility support
565  * With GCC 4, __attribute__ ((visibility("default"))) can be used
566  * along compiling with tidylib with "-fvisibility=hidden". See
567  * http://gcc.gnu.org/wiki/Visibility and build/gmake/Makefile.
568  *===========================================================================*/
569 /*
570 #if defined(__GNUC__) && __GNUC__ >= 4
571 # define TIDY_EXPORT __attribute__ ((visibility("default")))
572 #endif
573 */
574 
575 
576 /*=============================================================================
577  * Other definitions
578  *===========================================================================*/
579 
580 #ifndef TIDY_EXPORT /* Define it away for most builds */
581 # define TIDY_EXPORT
582 #endif
583 
584 #ifndef TIDY_STRUCT
585 # define TIDY_STRUCT
586 #endif
587 
588 typedef unsigned char byte;
589 
590 typedef uint tchar; /* single, full character */
591 typedef char tmbchar; /* single, possibly partial character */
592 #ifndef TMBSTR_DEFINED
593  typedef tmbchar* tmbstr; /* pointer to buffer of possibly partial chars */
594  typedef const tmbchar* ctmbstr; /* Ditto, but const */
595 # define NULLSTR (tmbstr)""
596 # define TMBSTR_DEFINED
597 #endif
598 
599 #ifndef TIDY_CALL
600 # define TIDY_CALL
601 #endif
602 
603 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
604 # define ARG_UNUSED(x) x __attribute__((unused))
605 # define FUNC_UNUSED __attribute__((unused))
606 #else
607 # define ARG_UNUSED(x) x
608 # define FUNC_UNUSED
609 #endif
610 
611 /* HAS_VSNPRINTF triggers the use of "vsnprintf", which is safe related to
612  buffer overflow. Therefore, we make it the default unless HAS_VSNPRINTF
613  has been defined. */
614 #ifndef HAS_VSNPRINTF
615 # define HAS_VSNPRINTF 1
616 #endif
617 
618 #ifndef SUPPORT_POSIX_MAPPED_FILES
619 # define SUPPORT_POSIX_MAPPED_FILES 1
620 #endif
621 
622 /* `bool` is a reserved word in some but not all C++ compilers depending on age.
623  age. Work around is to avoid bool by introducing a new enum called `Bool`.
624 */
625 
626 /* We could use the C99 definition where supported
627 typedef _Bool Bool;
628 #define no (_Bool)0
629 #define yes (_Bool)1
630 */
631 typedef enum
632 {
633  no,
635 } Bool;
636 
637 /* for NULL pointers
638 #define null ((const void*)0)
639 extern void* null;
640 */
641 
642 #if defined(DMALLOC)
643 # include "dmalloc.h"
644 #endif
645 
646 /* Opaque data structure.
647 * Cast to implementation type struct within lib.
648 * This will reduce inter-dependencies/conflicts w/ application code.
649 */
650 #if 1
651 #define opaque_type( typenam )\
652 struct _##typenam { int _opaque; };\
653 typedef struct _##typenam const * typenam
654 #else
655 #define opaque_type(typenam) typedef const void* typenam
656 #endif
657 
658 /* Opaque data structure used to pass back
659 ** and forth to keep current position in a
660 ** list or other collection.
661 */
662 opaque_type( TidyIterator );
663 
664 #ifdef __cplusplus
665 } /* extern "C" */
666 #endif
667 
668 #endif /* __TIDY_PLATFORM_H__ */
669 
670 /*
671  * local variables:
672  * mode: c
673  * indent-tabs-mode: nil
674  * c-basic-offset: 4
675  * eval: (c-set-offset 'substatement-open 0)
676  * end:
677  */
unsigned char byte
Definition: tidyplatform.h:588
const tmbchar * ctmbstr
Definition: tidyplatform.h:594
Definition: tidyplatform.h:633
Bool
Definition: tidyplatform.h:631
tmbchar * tmbstr
Definition: tidyplatform.h:593
unsigned int uint
Definition: tidyplatform.h:554
char tmbchar
Definition: tidyplatform.h:591
Definition: tidyplatform.h:634
#define opaque_type(typenam)
Definition: tidyplatform.h:651
uint tchar
Definition: tidyplatform.h:590