1#ifndef __PLATFORM_H__ 2#define __PLATFORM_H__ 3 4/* platform.h -- Platform specifics 5 6 (c) 1998-2006 (W3C) MIT, ERCIM, Keio University 7 See tidy.h for the copyright notice. 8 9 CVS Info : 10 11 $Author: mrowe $ 12 $Date: 2010/12/17 11:35:37 $ 13 $Revision: 1.9 $ 14 15*/ 16 17#ifdef __cplusplus 18extern "C" { 19#endif 20 21/* 22 Uncomment and edit one of the following #defines if you 23 want to specify the config file at compile-time. 24*/ 25 26/* #define CONFIG_FILE "/etc/tidy_config.txt" */ /* original */ 27/* #define CONFIG_FILE "/etc/tidyrc" */ 28/* #define CONFIG_FILE "/etc/tidy.conf" */ 29 30/* 31 Uncomment the following #define if you are on a system 32 supporting the HOME environment variable. 33 It enables tidy to find config files named ~/.tidyrc if 34 the HTML_TIDY environment variable is not set. 35*/ 36/* #define USER_CONFIG_FILE "~/.tidyrc" */ 37 38/* 39 Uncomment the following #define if your 40 system supports the call getpwnam(). 41 E.g. Unix and Linux. 42 43 It enables tidy to find files named 44 ~your/foo for use in the HTML_TIDY environment 45 variable or CONFIG_FILE or USER_CONFIGFILE or 46 on the command line: -config ~joebob/tidy.cfg 47 48 Contributed by Todd Lewis. 49*/ 50 51/* #define SUPPORT_GETPWNAM */ 52 53 54/* Enable/disable support for Big5 and Shift_JIS character encodings */ 55#ifndef SUPPORT_ASIAN_ENCODINGS 56#define SUPPORT_ASIAN_ENCODINGS 1 57#endif 58 59/* Enable/disable support for UTF-16 character encodings */ 60#ifndef SUPPORT_UTF16_ENCODINGS 61#define SUPPORT_UTF16_ENCODINGS 1 62#endif 63 64/* Enable/disable support for additional accessibility checks */ 65#ifndef SUPPORT_ACCESSIBILITY_CHECKS 66#define SUPPORT_ACCESSIBILITY_CHECKS 1 67#endif 68 69/* Enable/disable changes by Apple Inc. */ 70#ifndef TIDY_APPLE_CHANGES 71#define TIDY_APPLE_CHANGES 1 72#endif 73 74 75/* Convenience defines for Mac platforms */ 76 77#if defined(macintosh) 78/* Mac OS 6.x/7.x/8.x/9.x, with or without CarbonLib - MPW or Metrowerks 68K/PPC compilers */ 79#define MAC_OS_CLASSIC 80#ifndef PLATFORM_NAME 81#define PLATFORM_NAME "Mac OS" 82#endif 83 84/* needed for access() */ 85#if !defined(_POSIX) && !defined(NO_ACCESS_SUPPORT) 86#define NO_ACCESS_SUPPORT 87#endif 88 89#ifdef SUPPORT_GETPWNAM 90#undef SUPPORT_GETPWNAM 91#endif 92 93#elif defined(__APPLE__) && defined(__MACH__) 94/* Mac OS X (client) 10.x (or server 1.x/10.x) - gcc or Metrowerks MachO compilers */ 95#define MAC_OS_X 96#ifndef PLATFORM_NAME 97#define PLATFORM_NAME "Mac OS X" 98#endif 99#endif 100 101/* Apple Inc. Changes: 102 2004-12-21 swilkin Added "#define HAS_VSNPRINTF 1" for Mac OS X 103 2004-10-05 swilkin Added "#define DFLT_REPL_CHARENC WIN1252" for Mac OS X 104*/ 105#if defined(TIDY_APPLE_CHANGES) 106#if defined(MAC_OS_X) 107#define HAS_VSNPRINTF 1 108#ifndef DFLT_REPL_CHARENC 109#define DFLT_REPL_CHARENC WIN1252 110#endif 111#endif 112#endif 113 114#if defined(MAC_OS_CLASSIC) || defined(MAC_OS_X) 115/* Any OS on Mac platform */ 116#define MAC_OS 117#define FILENAMES_CASE_SENSITIVE 0 118#define strcasecmp strcmp 119#ifndef DFLT_REPL_CHARENC 120#define DFLT_REPL_CHARENC MACROMAN 121#endif 122#endif 123 124/* Convenience defines for BSD like platforms */ 125 126#if defined(__FreeBSD__) 127#define BSD_BASED_OS 128#ifndef PLATFORM_NAME 129#define PLATFORM_NAME "FreeBSD" 130#endif 131 132#elif defined(__NetBSD__) 133#define BSD_BASED_OS 134#ifndef PLATFORM_NAME 135#define PLATFORM_NAME "NetBSD" 136#endif 137 138#elif defined(__OpenBSD__) 139#define BSD_BASED_OS 140#ifndef PLATFORM_NAME 141#define PLATFORM_NAME "OpenBSD" 142#endif 143 144#elif defined(__MINT__) 145#define BSD_BASED_OS 146#ifndef PLATFORM_NAME 147#define PLATFORM_NAME "FreeMiNT" 148#endif 149 150#elif defined(__bsdi__) 151#define BSD_BASED_OS 152#ifndef PLATFORM_NAME 153#define PLATFORM_NAME "BSD/OS" 154#endif 155 156#endif 157 158/* Convenience defines for Windows platforms */ 159 160#if defined(WINDOWS) || defined(_WIN32) 161 162#define WINDOWS_OS 163#ifndef PLATFORM_NAME 164#define PLATFORM_NAME "Windows" 165#endif 166 167#if defined(__MWERKS__) || defined(__MSL__) 168/* not available with Metrowerks Standard Library */ 169 170#ifdef SUPPORT_GETPWNAM 171#undef SUPPORT_GETPWNAM 172#endif 173 174/* needed for setmode() */ 175#if !defined(NO_SETMODE_SUPPORT) 176#define NO_SETMODE_SUPPORT 177#endif 178 179#define strcasecmp _stricmp 180 181#endif 182 183#if defined(__BORLANDC__) 184#define strcasecmp stricmp 185#endif 186 187#define FILENAMES_CASE_SENSITIVE 0 188 189#endif 190 191/* Convenience defines for Linux platforms */ 192 193#if defined(linux) && defined(__alpha__) 194/* Linux on Alpha - gcc compiler */ 195#define LINUX_OS 196#ifndef PLATFORM_NAME 197#define PLATFORM_NAME "Linux/Alpha" 198#endif 199 200#elif defined(linux) && defined(__sparc__) 201/* Linux on Sparc - gcc compiler */ 202#define LINUX_OS 203#ifndef PLATFORM_NAME 204#define PLATFORM_NAME "Linux/Sparc" 205#endif 206 207#elif defined(linux) && (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)) 208/* Linux on x86 - gcc compiler */ 209#define LINUX_OS 210#ifndef PLATFORM_NAME 211#define PLATFORM_NAME "Linux/x86" 212#endif 213 214#elif defined(linux) && defined(__powerpc__) 215/* Linux on PPC - gcc compiler */ 216#define LINUX_OS 217 218#if defined(__linux__) && defined(__powerpc__) 219 220/* #if #system(linux) */ 221/* MkLinux on PPC - gcc (egcs) compiler */ 222/* #define MAC_OS_MKLINUX */ 223#ifndef PLATFORM_NAME 224#define PLATFORM_NAME "MkLinux" 225#endif 226 227#else 228 229#ifndef PLATFORM_NAME 230#define PLATFORM_NAME "Linux/PPC" 231#endif 232 233#endif 234 235#elif defined(linux) || defined(__linux__) 236/* generic Linux */ 237#define LINUX_OS 238#ifndef PLATFORM_NAME 239#define PLATFORM_NAME "Linux" 240#endif 241 242#endif 243 244/* Convenience defines for Solaris platforms */ 245 246#if defined(sun) 247#define SOLARIS_OS 248#ifndef PLATFORM_NAME 249#define PLATFORM_NAME "Solaris" 250#endif 251#endif 252 253/* Convenience defines for HPUX + gcc platforms */ 254 255#if defined(__hpux) 256#define HPUX_OS 257#ifndef PLATFORM_NAME 258#define PLATFORM_NAME "HPUX" 259#endif 260#endif 261 262/* Convenience defines for RISCOS + gcc platforms */ 263 264#if defined(__riscos__) 265#define RISC_OS 266#ifndef PLATFORM_NAME 267#define PLATFORM_NAME "RISC OS" 268#endif 269#endif 270 271/* Convenience defines for OS/2 + icc/gcc platforms */ 272 273#if defined(__OS2__) || defined(__EMX__) 274#define OS2_OS 275#ifndef PLATFORM_NAME 276#define PLATFORM_NAME "OS/2" 277#endif 278#define FILENAMES_CASE_SENSITIVE 0 279#define strcasecmp stricmp 280#endif 281 282/* Convenience defines for IRIX */ 283 284#if defined(__sgi) 285#define IRIX_OS 286#ifndef PLATFORM_NAME 287#define PLATFORM_NAME "SGI IRIX" 288#endif 289#endif 290 291/* Convenience defines for AIX */ 292 293#if defined(_AIX) 294#define AIX_OS 295#ifndef PLATFORM_NAME 296#define PLATFORM_NAME "IBM AIX" 297#endif 298#endif 299 300 301/* Convenience defines for BeOS platforms */ 302 303#if defined(__BEOS__) 304#define BE_OS 305#ifndef PLATFORM_NAME 306#define PLATFORM_NAME "BeOS" 307#endif 308#endif 309 310/* Convenience defines for Cygwin platforms */ 311 312#if defined(__CYGWIN__) 313#define CYGWIN_OS 314#ifndef PLATFORM_NAME 315#define PLATFORM_NAME "Cygwin" 316#endif 317#define FILENAMES_CASE_SENSITIVE 0 318#endif 319 320/* Convenience defines for OpenVMS */ 321 322#if defined(__VMS) 323#define OPENVMS_OS 324#ifndef PLATFORM_NAME 325#define PLATFORM_NAME "OpenVMS" 326#endif 327#define FILENAMES_CASE_SENSITIVE 0 328#endif 329 330/* Convenience defines for DEC Alpha OSF + gcc platforms */ 331 332#if defined(__osf__) 333#define OSF_OS 334#ifndef PLATFORM_NAME 335#define PLATFORM_NAME "DEC Alpha OSF" 336#endif 337#endif 338 339/* Convenience defines for ARM platforms */ 340 341#if defined(__arm) 342#define ARM_OS 343 344#if defined(forARM) && defined(__NEWTON_H) 345 346/* Using Newton C++ Tools ARMCpp compiler */ 347#define NEWTON_OS 348#ifndef PLATFORM_NAME 349#define PLATFORM_NAME "Newton" 350#endif 351 352#else 353 354#ifndef PLATFORM_NAME 355#define PLATFORM_NAME "ARM" 356#endif 357 358#endif 359 360#endif 361 362#include <ctype.h> 363#include <stdio.h> 364#include <setjmp.h> /* for longjmp on error exit */ 365#include <stdlib.h> 366#include <stdarg.h> /* may need <varargs.h> for Unix V */ 367#include <string.h> 368#include <assert.h> 369 370#ifdef NEEDS_MALLOC_H 371#include <malloc.h> 372#endif 373 374#ifdef SUPPORT_GETPWNAM 375#include <pwd.h> 376#endif 377 378#ifdef NEEDS_UNISTD_H 379#include <unistd.h> /* needed for unlink on some Unix systems */ 380#endif 381 382/* This can be set at compile time. Usually Windows, 383** except for Macintosh builds. 384*/ 385#ifndef DFLT_REPL_CHARENC 386#define DFLT_REPL_CHARENC WIN1252 387#endif 388 389/* By default, use case-sensitive filename comparison. 390*/ 391#ifndef FILENAMES_CASE_SENSITIVE 392#define FILENAMES_CASE_SENSITIVE 1 393#endif 394 395 396/* 397 Tidy preserves the last modified time for the files it 398 cleans up. 399*/ 400 401/* 402 If your platform doesn't support <utime.h> and the 403 utime() function, or <sys/futime> and the futime() 404 function then set PRESERVE_FILE_TIMES to 0. 405 406 If your platform doesn't support <sys/utime.h> and the 407 futime() function, then set HAS_FUTIME to 0. 408 409 If your platform supports <utime.h> and the 410 utime() function requires the file to be 411 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__) 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 /* HASFUTIME */ 458 459/* 460 MS Windows needs _ prefix for Unix file functions. 461 Not required by Metrowerks Standard Library (MSL). 462 463 Tidy uses following for preserving the last modified time. 464 465 WINDOWS automatically set by Win16 compilers. 466 _WIN32 automatically set by Win32 compilers. 467*/ 468#if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__) 469 470#define futime _futime 471#define fstat _fstat 472#define utimbuf _utimbuf /* Windows seems to want utimbuf */ 473#define stat _stat 474#define utime _utime 475#define vsnprintf _vsnprintf 476#endif /* _WIN32 */ 477 478#endif /* PRESERVE_FILE_TIMES */ 479 480/* 481 MS 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#if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__) 488 489#ifndef __WATCOMC__ 490#define fileno _fileno 491#define setmode _setmode 492#endif 493 494#define access _access 495#define strcasecmp _stricmp 496 497#if _MSC_VER > 1000 498#pragma warning( disable : 4189 ) /* local variable is initialized but not referenced */ 499#pragma warning( disable : 4100 ) /* unreferenced formal parameter */ 500#pragma warning( disable : 4706 ) /* assignment within conditional expression */ 501#endif 502 503#endif /* _WIN32 */ 504 505#if defined(_WIN32) 506 507#if (defined(_USRDLL) || defined(_WINDLL)) && !defined(TIDY_EXPORT) 508#define TIDY_EXPORT __declspec( dllexport ) 509#endif 510 511#ifndef TIDY_CALL 512#ifdef _WIN64 513# define TIDY_CALL __fastcall 514#else 515# define TIDY_CALL __stdcall 516#endif 517#endif 518 519#endif /* _WIN32 */ 520 521/* hack for gnu sys/types.h file which defines uint and ulong */ 522 523#if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS) 524#include <sys/types.h> 525#endif 526#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) 527# undef uint 528typedef unsigned int uint; 529#endif 530#if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32) 531# undef ulong 532typedef unsigned long ulong; 533#endif 534 535/* 536With GCC 4, __attribute__ ((visibility("default"))) can be used along compiling with tidylib 537with "-fvisibility=hidden". See http://gcc.gnu.org/wiki/Visibility and build/gmake/Makefile. 538*/ 539/* 540#if defined(__GNUC__) && __GNUC__ >= 4 541#define TIDY_EXPORT __attribute__ ((visibility("default"))) 542#endif 543*/ 544 545#ifndef TIDY_EXPORT /* Define it away for most builds */ 546#define TIDY_EXPORT 547#endif 548 549#ifndef TIDY_STRUCT 550#define TIDY_STRUCT 551#endif 552 553typedef unsigned char byte; 554 555typedef uint tchar; /* single, full character */ 556typedef char tmbchar; /* single, possibly partial character */ 557#ifndef TMBSTR_DEFINED 558typedef tmbchar* tmbstr; /* pointer to buffer of possibly partial chars */ 559typedef const tmbchar* ctmbstr; /* Ditto, but const */ 560#define NULLSTR (tmbstr)"" 561#define TMBSTR_DEFINED 562#endif 563 564#ifndef TIDY_CALL 565#define TIDY_CALL 566#endif 567 568#if defined(__GNUC__) || defined(__INTEL_COMPILER) 569# define ARG_UNUSED(x) x __attribute__((unused)) 570#else 571# define ARG_UNUSED(x) x 572#endif 573 574/* HAS_VSNPRINTF triggers the use of "vsnprintf", which is safe related to 575 buffer overflow. Therefore, we make it the default unless HAS_VSNPRINTF 576 has been defined. */ 577#ifndef HAS_VSNPRINTF 578# define HAS_VSNPRINTF 1 579#endif 580 581/* 582 bool is a reserved word in some but 583 not all C++ compilers depending on age 584 work around is to avoid bool altogether 585 by introducing a new enum called Bool 586*/ 587/* We could use the C99 definition where supported 588typedef _Bool Bool; 589#define no (_Bool)0 590#define yes (_Bool)1 591*/ 592typedef enum 593{ 594 no, 595 yes 596} Bool; 597 598/* for NULL pointers 599#define null ((const void*)0) 600extern void* null; 601*/ 602 603#if defined(DMALLOC) 604#include "dmalloc.h" 605#endif 606 607void *MemAlloc(size_t size); 608void *MemRealloc(void *mem, size_t newsize); 609void MemFree(void *mem); 610void ClearMemory(void *, size_t size); 611void FatalError( ctmbstr msg ); 612 613/* Opaque data structure. 614* Cast to implementation type struct within lib. 615* This will reduce inter-dependencies/conflicts w/ application code. 616*/ 617#if 1 618#define opaque_type( typenam )\ 619struct _##typenam { int _opaque; };\ 620typedef struct _##typenam* typenam 621#else 622#define opaque_type(typenam) typedef void* typenam 623#endif 624 625/* Opaque data structure used to pass back 626** and forth to keep current position in a 627** list or other collection. 628*/ 629opaque_type( TidyIterator ); 630 631#ifdef __cplusplus 632} /* extern "C" */ 633#endif 634 635#endif /* __PLATFORM_H__ */ 636