HTML Tidy 5.8.0
The HTACG Tidy HTML Project
 
Loading...
Searching...
No Matches
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
32extern "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 Haiku platforms === */
319
320#if defined(__HAIKU__)
321# define HAIKU
322# ifndef PLATFORM_NAME
323# define PLATFORM_NAME "Haiku"
324# endif
325#endif
326
327/* === Convenience defines for Cygwin platforms === */
328
329#if defined(__CYGWIN__)
330# define CYGWIN_OS
331# ifndef PLATFORM_NAME
332# define PLATFORM_NAME "Cygwin"
333# endif
334# define FILENAMES_CASE_SENSITIVE 0
335#endif
336
337/* === Convenience defines for OpenVMS === */
338
339#if defined(__VMS)
340# define OPENVMS_OS
341# ifndef PLATFORM_NAME
342# define PLATFORM_NAME "OpenVMS"
343# endif
344# define FILENAMES_CASE_SENSITIVE 0
345#endif
346
347/* === Convenience defines for DEC Alpha OSF + gcc platforms === */
348
349#if defined(__osf__)
350# define OSF_OS
351# ifndef PLATFORM_NAME
352# define PLATFORM_NAME "DEC Alpha OSF"
353# endif
354#endif
355
356/* === Convenience defines for ARM platforms === */
357
358#if defined(__arm)
359# define ARM_OS
360# if defined(forARM) && defined(__NEWTON_H)
361 /* Using Newton C++ Tools ARMCpp compiler */
362# define NEWTON_OS
363# ifndef PLATFORM_NAME
364# define PLATFORM_NAME "Newton"
365# endif
366# else
367# ifndef PLATFORM_NAME
368# define PLATFORM_NAME "ARM"
369# endif
370# endif
371#endif
372
373
374/*=============================================================================
375 * Standard Library Includes
376 *===========================================================================*/
377
378#include <ctype.h>
379#include <stdio.h>
380#include <setjmp.h> /* for longjmp on error exit */
381#include <stdlib.h>
382#include <stdarg.h> /* may need <varargs.h> for Unix V */
383#include <string.h>
384#include <assert.h>
385
386#ifdef NEEDS_MALLOC_H
387# include <malloc.h>
388#endif
389
390#ifdef SUPPORT_GETPWNAM
391# include <pwd.h>
392#endif
393
394#ifdef NEEDS_UNISTD_H
395# include <unistd.h> /* needed for unlink on some Unix systems */
396#endif
397
398
399/*=============================================================================
400 * Case sensitive file systems
401 *===========================================================================*/
402
403/* By default, use case-sensitive filename comparison. */
404#ifndef FILENAMES_CASE_SENSITIVE
405# define FILENAMES_CASE_SENSITIVE 1
406#endif
407
408
409/*=============================================================================
410 * Last modified time preservation
411 * Tidy preserves the last modified time for the files it cleans up.
412 *
413 * If your platform doesn't support <utime.h> and the utime() function, or
414 * <sys/futime> and the futime() function then set PRESERVE_FILE_TIMES to 0.
415 *
416 * If your platform doesn't support <sys/utime.h> and the futime() function,
417 * then set HAS_FUTIME to 0.
418 *
419 * If your platform supports <utime.h> and the utime() function requires the
420 * file to be closed first, then set UTIME_NEEDS_CLOSED_FILE to 1.
421 *===========================================================================*/
422
423/* Keep old PRESERVEFILETIMES define for compatibility */
424#ifdef PRESERVEFILETIMES
425# undef PRESERVE_FILE_TIMES
426# define PRESERVE_FILE_TIMES PRESERVEFILETIMES
427#endif
428
429#ifndef PRESERVE_FILE_TIMES
430# if defined(RISC_OS) || defined(OPENVMS_OS) || defined(OSF_OS)
431# define PRESERVE_FILE_TIMES 0
432# else
433# define PRESERVE_FILE_TIMES 1
434# endif
435#endif
436
437#if PRESERVE_FILE_TIMES
438
439# ifndef HAS_FUTIME
440# 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__) || defined(__HAIKU__)
441# define HAS_FUTIME 0
442# else
443# define HAS_FUTIME 1
444# endif
445# endif
446
447# ifndef UTIME_NEEDS_CLOSED_FILE
448# if defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(MAC_OS) || defined(__MSL__) || defined(LINUX_OS)
449# define UTIME_NEEDS_CLOSED_FILE 1
450# else
451# define UTIME_NEEDS_CLOSED_FILE 0
452# endif
453# endif
454
455# if defined(MAC_OS_X) || (!defined(MAC_OS_CLASSIC) && !defined(__MSL__))
456# include <sys/types.h>
457# include <sys/stat.h>
458# else
459# include <stat.h>
460# endif
461
462# if HAS_FUTIME
463# include <sys/utime.h>
464# else
465# include <utime.h>
466# endif
467
468#if defined(__HAIKU__)
469#ifndef va_copy
470#define va_copy(dest, src) (dest = src)
471#endif
472#endif
473
474/* MS Windows needs _ prefix for Unix file functions.
475 Not required by Metrowerks Standard Library (MSL).
476
477 Tidy uses following for preserving the last modified time.
478
479 WINDOWS automatically set by Win16 compilers.
480 _WIN32 automatically set by Win32 compilers.
481*/
482# if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
483# define futime _futime
484# define fstat _fstat
485# define utimbuf _utimbuf /* Windows seems to want utimbuf */
486# define stat _stat
487# define utime _utime
488# define vsnprintf _vsnprintf
489# endif
490
491#endif
492
493
494/*=============================================================================
495 * Windows file functions
496 * Windows needs _ prefix for Unix file functions.
497 * Not required by Metrowerks Standard Library (MSL).
498 *
499 * WINDOWS automatically set by Win16 compilers.
500 * _WIN32 automatically set by Win32 compilers.
501 *===========================================================================*/
502
503#if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
504
505# if !(defined(__WATCOMC__) || defined(__MINGW32__))
506# define fileno _fileno
507# define setmode _setmode
508# endif
509
510# if defined(_MSC_VER)
511# define fileno _fileno
512#if !defined(NDEBUG) && !defined(ENABLE_DEBUG_LOG) && !defined(DISABLE_DEBUG_LOG)
513#define ENABLE_DEBUG_LOG
514#endif
515#endif
516
517# define access _access
518# define strcasecmp _stricmp
519
520# ifndef va_copy
521# define va_copy(dest, src) (dest = src)
522# endif
523
524# if _MSC_VER > 1000
525# pragma warning( disable : 4189 ) /* local variable is initialized but not referenced */
526# pragma warning( disable : 4100 ) /* unreferenced formal parameter */
527# pragma warning( disable : 4706 ) /* assignment within conditional expression */
528# endif
529
530# if _MSC_VER > 1300
531# pragma warning( disable : 4996 ) /* disable depreciation warning */
532# endif
533
534#endif /* _WIN32 */
535
536#if defined(_WIN32)
537
538# if (defined(_USRDLL) || defined(_WINDLL) || defined(BUILD_SHARED_LIB)) && !defined(TIDY_EXPORT) && !defined(TIDY_STATIC)
539# ifdef BUILDING_SHARED_LIB
540# define TIDY_EXPORT __declspec( dllexport )
541# else
542# define TIDY_EXPORT __declspec( dllimport )
543# endif
544# else
545# define TIDY_EXPORT extern
546# endif
547
548# ifndef TIDY_CALL
549# ifdef _WIN64
550# define TIDY_CALL __fastcall
551# else
552# define TIDY_CALL __stdcall
553# endif
554# endif
555
556#endif /* _WIN32 */
557
558
559/*=============================================================================
560 * Hack for gnu sys/types.h file which defines uint and ulong
561 *===========================================================================*/
562
563#if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS)
564# include <sys/types.h>
565#endif
566
567#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) && !defined(__HAIKU__)
568# undef uint
569 typedef unsigned int uint;
570#endif
571
572#if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32) || defined(__ANDROID__)
573# undef ulong
574 typedef unsigned long ulong;
575#endif
576
577
578/*=============================================================================
579 * Visibility support
580 * With GCC 4, __attribute__ ((visibility("default"))) can be used
581 * along compiling with tidylib with "-fvisibility=hidden". See
582 * http://gcc.gnu.org/wiki/Visibility and build/gmake/Makefile.
583 *===========================================================================*/
584/*
585#if defined(__GNUC__) && __GNUC__ >= 4
586# define TIDY_EXPORT __attribute__ ((visibility("default")))
587#endif
588*/
589
590
591/*=============================================================================
592 * Other definitions
593 *===========================================================================*/
594
595#ifndef TIDY_EXPORT /* Define it away for most builds */
596# define TIDY_EXPORT
597#endif
598
599#ifndef TIDY_STRUCT
600# define TIDY_STRUCT
601#endif
602
603typedef unsigned char byte;
604
605typedef uint tchar; /* single, full character */
606typedef char tmbchar; /* single, possibly partial character */
607#ifndef TMBSTR_DEFINED
608 typedef tmbchar* tmbstr; /* pointer to buffer of possibly partial chars */
609 typedef const tmbchar* ctmbstr; /* Ditto, but const */
610# define NULLSTR (tmbstr)""
611# define TMBSTR_DEFINED
612#endif
613
614#ifndef TIDY_CALL
615# define TIDY_CALL
616#endif
617
618#if defined(__GNUC__) || defined(__INTEL_COMPILER)
619# define ARG_UNUSED(x) x __attribute__((unused))
620# define FUNC_UNUSED __attribute__((unused))
621#else
622# define ARG_UNUSED(x) x
623# define FUNC_UNUSED
624#endif
625
626/* HAS_VSNPRINTF triggers the use of "vsnprintf", which is safe related to
627 buffer overflow. Therefore, we make it the default unless HAS_VSNPRINTF
628 has been defined. */
629#ifndef HAS_VSNPRINTF
630# define HAS_VSNPRINTF 1
631#endif
632
633#ifndef SUPPORT_POSIX_MAPPED_FILES
634# define SUPPORT_POSIX_MAPPED_FILES 1
635#endif
636
637/* `bool` is a reserved word in some but not all C++ compilers depending on age.
638 age. Work around is to avoid bool by introducing a new enum called `Bool`.
639*/
640
641/* We could use the C99 definition where supported
642typedef _Bool Bool;
643#define no (_Bool)0
644#define yes (_Bool)1
645*/
646typedef enum
647{
650} Bool;
651
652/* for NULL pointers
653#define null ((const void*)0)
654extern void* null;
655*/
656
657#if defined(DMALLOC)
658# include "dmalloc.h"
659#endif
660
661/* Opaque data structure.
662* Cast to implementation type struct within lib.
663* This will reduce inter-dependencies/conflicts w/ application code.
664*/
665#if 1
666#define opaque_type( typenam )\
667struct _##typenam { int _opaque; };\
668typedef struct _##typenam const * typenam
669#else
670#define opaque_type(typenam) typedef const void* typenam
671#endif
672
673/* Opaque data structure used to pass back
674** and forth to keep current position in a
675** list or other collection.
676*/
677opaque_type( TidyIterator );
678
679#ifdef __cplusplus
680} /* extern "C" */
681#endif
682
683#endif /* __TIDY_PLATFORM_H__ */
684
685/*
686 * local variables:
687 * mode: c
688 * indent-tabs-mode: nil
689 * c-basic-offset: 4
690 * eval: (c-set-offset 'substatement-open 0)
691 * end:
692 */
unsigned char byte
Definition tidyplatform.h:603
Bool
Definition tidyplatform.h:647
@ no
Definition tidyplatform.h:648
@ yes
Definition tidyplatform.h:649
uint tchar
Definition tidyplatform.h:605
#define opaque_type(typenam)
Definition tidyplatform.h:666
unsigned int uint
Definition tidyplatform.h:569
char tmbchar
Definition tidyplatform.h:606
const tmbchar * ctmbstr
Definition tidyplatform.h:609
tmbchar * tmbstr
Definition tidyplatform.h:608