Update CMakeLists and tidyplatform to include automatic support for using

runtime configuration files on Unix-like platforms. This addresses #584 in the
strictest sense, but some message work needs to happen as a result of this
change.

Additionally, the tidyplatform.h has been reformatted for legibility as part of
the continuing (slow) effort to improve our internal documentation.
This commit is contained in:
Jim Derry 2017-10-01 10:39:30 -04:00
parent 3658275f60
commit 298deb0a04
2 changed files with 408 additions and 369 deletions

View file

@ -157,16 +157,42 @@ if (TIDY_RC_NUMBER)
add_definitions ( -DRC_NUMBER="${TIDY_RC_NUMBER}" ) add_definitions ( -DRC_NUMBER="${TIDY_RC_NUMBER}" )
endif () endif ()
# Issue #188 - Support user items in platform.h
#=============================================================================
# Unix console application features
# By default on Unix-like systems when building for the console program,
# support runtime configuration files in /etc/ and in ~/. To prevent this,
# set ENABLE_CONFIG_FILES to NO. Specify -DTIDY_CONFIG_FILE and/or
# -DTIDY_USER_CONFIG_FILE to override the default paths in tidyplatform.h.
# @note: this section refactored to support #584.
#=============================================================================
if (UNIX AND SUPPORT_CONSOLE_APP)
option ( ENABLE_CONFIG_FILES "Set to OFF to disable Tidy runtime configuration file support" ON )
if ( ENABLE_CONFIG_FILES )
message(STATUS "*** Building support for runtime configuration files.")
add_definitions( -DTIDY_ENABLE_CONFIG_FILES )
# For example, /etc/tidy.conf
if (TIDY_CONFIG_FILE) if (TIDY_CONFIG_FILE)
add_definitions( -DTIDY_CONFIG_FILE="${TIDY_CONFIG_FILE}" ) add_definitions( -DTIDY_CONFIG_FILE="${TIDY_CONFIG_FILE}" )
endif () endif ()
# For example, ~/.tidy.rc
if (TIDY_USER_CONFIG_FILE) if (TIDY_USER_CONFIG_FILE)
add_definitions( -DTIDY_USER_CONFIG_FILE="${TIDY_USER_CONFIG_FILE}" ) add_definitions( -DTIDY_USER_CONFIG_FILE="${TIDY_USER_CONFIG_FILE}" )
endif () endif ()
if (SUPPORT_GETPWNAM)
# All Unixes support getpwnam(); undef'd in tidyplatform.h if necessary.
add_definitions( -DSUPPORT_GETPWNAM=1 ) add_definitions( -DSUPPORT_GETPWNAM=1 )
endif () endif ()
endif ()
if(BUILD_SHARED_LIB) if(BUILD_SHARED_LIB)
set(LIB_TYPE SHARED) set(LIB_TYPE SHARED)

View file

@ -32,39 +32,51 @@
extern "C" { extern "C" {
#endif #endif
/* /*=============================================================================
Uncomment and edit one of the following #defines if you * Unix console application features
want to specify the config file at compile-time. * By default on Unix-like systems when building for the console program,
*/ * support runtime configuration files in /etc/ and in ~/. To prevent this,
* set ENABLE_CONFIG_FILES to NO. Specify -DTIDY_CONFIG_FILE and/or
* -DTIDY_USER_CONFIG_FILE to override the default paths in tidyplatform.h.
* @note: this section refactored to support #584.
*===========================================================================*/
/* #define TIDY_CONFIG_FILE "/etc/tidy_config.txt" */ /* original */ /* #define ENABLE_CONFIG_FILES */
/* #define TIDY_CONFIG_FILE "/etc/tidyrc" */
/* #define TIDY_CONFIG_FILE "/etc/tidy.conf" */
/* #if defined(TIDY_ENABLE_CONFIG_FILES)
Uncomment the following #define if you are on a system # if !defined(TIDY_CONFIG_FILE)
supporting the HOME environment variable. # define TIDY_CONFIG_FILE "/etc/tidy.conf"
It enables tidy to find config files named ~/.tidyrc if # endif
the HTML_TIDY environment variable is not set. # if !defined(TIDY_USER_CONFIG_FILE)
*/ # define TIDY_USER_CONFIG_FILE "~/.tidyrc"
/* #define TIDY_USER_CONFIG_FILE "~/.tidyrc" */ # endif
#else
# if defined(TIDY_CONFIG_FILE)
# undef TIDY_CONFIG_FILE
# endif
# if defined(TIDY_USER_CONFIG_FILE)
# undef TIDY_USER_CONFIG_FILE
# endif
#endif
/*
Uncomment the following #define if your
system supports the call getpwnam().
E.g. Unix and Linux.
It enables tidy to find files named /*=============================================================================
~your/foo for use in the HTML_TIDY environment * Unix tilde expansion support
variable or CONFIG_FILE or USER_CONFIGFILE or * By default on Unix-like systems when building for the console program,
on the command line: -config ~joebob/tidy.cfg * this flag is set so that Tidy knows getpwname() is available. It allows
* tidy to find files named ~your/foo for use in the HTML_TIDY environment
Contributed by Todd Lewis. * variable or TIDY_CONFIG_FILE or TIDY_USER_CONFIG_FILE or on the command
*/ * command line: -config ~joebob/tidy.cfg
* Contributed by Todd Lewis.
*===========================================================================*/
/* #define SUPPORT_GETPWNAM */ /* #define SUPPORT_GETPWNAM */
/*=============================================================================
* Optional Tidy features support
*===========================================================================*/
/* Enable/disable support for Big5 and Shift_JIS character encodings */ /* Enable/disable support for Big5 and Shift_JIS character encodings */
#ifndef SUPPORT_ASIAN_ENCODINGS #ifndef SUPPORT_ASIAN_ENCODINGS
# define SUPPORT_ASIAN_ENCODINGS 1 # define SUPPORT_ASIAN_ENCODINGS 1
@ -91,7 +103,11 @@ extern "C" {
#endif #endif
/* Convenience defines for Mac platforms */ /*=============================================================================
* Platform specific convenience definitions
*===========================================================================*/
/* === Convenience defines for Mac platforms === */
#if defined(macintosh) #if defined(macintosh)
/* Mac OS 6.x/7.x/8.x/9.x, with or without CarbonLib - MPW or Metrowerks 68K/PPC compilers */ /* Mac OS 6.x/7.x/8.x/9.x, with or without CarbonLib - MPW or Metrowerks 68K/PPC compilers */
@ -124,7 +140,7 @@ extern "C" {
# define strcasecmp strcmp # define strcasecmp strcmp
#endif #endif
/* Convenience defines for BSD like platforms */ /* === Convenience defines for BSD-like platforms === */
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
# define BSD_BASED_OS # define BSD_BASED_OS
@ -161,10 +177,9 @@ extern "C" {
# ifndef PLATFORM_NAME # ifndef PLATFORM_NAME
# define PLATFORM_NAME "BSD/OS" # define PLATFORM_NAME "BSD/OS"
# endif # endif
#endif #endif
/* Convenience defines for Windows platforms */ /* === Convenience defines for Windows platforms === */
#if defined(WINDOWS) || defined(_WIN32) #if defined(WINDOWS) || defined(_WIN32)
@ -175,18 +190,14 @@ extern "C" {
# if defined(__MWERKS__) || defined(__MSL__) # if defined(__MWERKS__) || defined(__MSL__)
/* not available with Metrowerks Standard Library */ /* not available with Metrowerks Standard Library */
# ifdef SUPPORT_GETPWNAM # ifdef SUPPORT_GETPWNAM
# undef SUPPORT_GETPWNAM # undef SUPPORT_GETPWNAM
# endif # endif
/* needed for setmode() */ /* needed for setmode() */
# if !defined(NO_SETMODE_SUPPORT) # if !defined(NO_SETMODE_SUPPORT)
# define NO_SETMODE_SUPPORT # define NO_SETMODE_SUPPORT
# endif # endif
# define strcasecmp _stricmp # define strcasecmp _stricmp
# endif # endif
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
@ -196,9 +207,9 @@ extern "C" {
# define FILENAMES_CASE_SENSITIVE 0 # define FILENAMES_CASE_SENSITIVE 0
# define SUPPORT_POSIX_MAPPED_FILES 0 # define SUPPORT_POSIX_MAPPED_FILES 0
#endif #endif /* WINDOWS */
/* Convenience defines for Linux platforms */ /* === Convenience defines for Linux platforms === */
#if defined(linux) && defined(__alpha__) #if defined(linux) && defined(__alpha__)
/* Linux on Alpha - gcc compiler */ /* Linux on Alpha - gcc compiler */
@ -224,22 +235,15 @@ extern "C" {
#elif defined(linux) && defined(__powerpc__) #elif defined(linux) && defined(__powerpc__)
/* Linux on PPC - gcc compiler */ /* Linux on PPC - gcc compiler */
# define LINUX_OS # define LINUX_OS
# if defined(__linux__) && defined(__powerpc__) # if defined(__linux__) && defined(__powerpc__)
/* #if #system(linux) */
/* MkLinux on PPC - gcc (egcs) compiler */
/* #define MAC_OS_MKLINUX */
# ifndef PLATFORM_NAME # ifndef PLATFORM_NAME
/* MkLinux on PPC - gcc (egcs) compiler */
# define PLATFORM_NAME "MkLinux" # define PLATFORM_NAME "MkLinux"
# endif # endif
# else # else
# ifndef PLATFORM_NAME # ifndef PLATFORM_NAME
# define PLATFORM_NAME "Linux/PPC" # define PLATFORM_NAME "Linux/PPC"
# endif # endif
# endif # endif
#elif defined(linux) || defined(__linux__) #elif defined(linux) || defined(__linux__)
@ -248,10 +252,9 @@ extern "C" {
# ifndef PLATFORM_NAME # ifndef PLATFORM_NAME
# define PLATFORM_NAME "Linux" # define PLATFORM_NAME "Linux"
# endif # endif
#endif #endif
/* Convenience defines for Solaris platforms */ /* === Convenience defines for Solaris platforms === */
#if defined(sun) #if defined(sun)
# define SOLARIS_OS # define SOLARIS_OS
@ -260,7 +263,7 @@ extern "C" {
# endif # endif
#endif #endif
/* Convenience defines for HPUX + gcc platforms */ /* === Convenience defines for HPUX + gcc platforms === */
#if defined(__hpux) #if defined(__hpux)
# define HPUX_OS # define HPUX_OS
@ -269,7 +272,7 @@ extern "C" {
# endif # endif
#endif #endif
/* Convenience defines for RISCOS + gcc platforms */ /* === Convenience defines for RISCOS + gcc platforms === */
#if defined(__riscos__) #if defined(__riscos__)
# define RISC_OS # define RISC_OS
@ -278,7 +281,7 @@ extern "C" {
# endif # endif
#endif #endif
/* Convenience defines for OS/2 + icc/gcc platforms */ /* === Convenience defines for OS/2 + icc/gcc platforms === */
#if defined(__OS2__) || defined(__EMX__) #if defined(__OS2__) || defined(__EMX__)
# define OS2_OS # define OS2_OS
@ -289,7 +292,7 @@ extern "C" {
# define strcasecmp stricmp # define strcasecmp stricmp
#endif #endif
/* Convenience defines for IRIX */ /* === Convenience defines for IRIX === */
#if defined(__sgi) #if defined(__sgi)
# define IRIX_OS # define IRIX_OS
@ -298,7 +301,7 @@ extern "C" {
# endif # endif
#endif #endif
/* Convenience defines for AIX */ /* === Convenience defines for AIX === */
#if defined(_AIX) #if defined(_AIX)
# define AIX_OS # define AIX_OS
@ -307,8 +310,7 @@ extern "C" {
# endif # endif
#endif #endif
/* === Convenience defines for BeOS platforms === */
/* Convenience defines for BeOS platforms */
#if defined(__BEOS__) #if defined(__BEOS__)
# define BE_OS # define BE_OS
@ -317,7 +319,7 @@ extern "C" {
# endif # endif
#endif #endif
/* Convenience defines for Cygwin platforms */ /* === Convenience defines for Cygwin platforms === */
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
# define CYGWIN_OS # define CYGWIN_OS
@ -327,7 +329,7 @@ extern "C" {
# define FILENAMES_CASE_SENSITIVE 0 # define FILENAMES_CASE_SENSITIVE 0
#endif #endif
/* Convenience defines for OpenVMS */ /* === Convenience defines for OpenVMS === */
#if defined(__VMS) #if defined(__VMS)
# define OPENVMS_OS # define OPENVMS_OS
@ -337,7 +339,7 @@ extern "C" {
# define FILENAMES_CASE_SENSITIVE 0 # define FILENAMES_CASE_SENSITIVE 0
#endif #endif
/* Convenience defines for DEC Alpha OSF + gcc platforms */ /* === Convenience defines for DEC Alpha OSF + gcc platforms === */
#if defined(__osf__) #if defined(__osf__)
# define OSF_OS # define OSF_OS
@ -346,28 +348,27 @@ extern "C" {
# endif # endif
#endif #endif
/* Convenience defines for ARM platforms */ /* === Convenience defines for ARM platforms === */
#if defined(__arm) #if defined(__arm)
# define ARM_OS # define ARM_OS
# if defined(forARM) && defined(__NEWTON_H) # if defined(forARM) && defined(__NEWTON_H)
/* Using Newton C++ Tools ARMCpp compiler */ /* Using Newton C++ Tools ARMCpp compiler */
# define NEWTON_OS # define NEWTON_OS
# ifndef PLATFORM_NAME # ifndef PLATFORM_NAME
# define PLATFORM_NAME "Newton" # define PLATFORM_NAME "Newton"
# endif # endif
# else # else
# ifndef PLATFORM_NAME # ifndef PLATFORM_NAME
# define PLATFORM_NAME "ARM" # define PLATFORM_NAME "ARM"
# endif # endif
# endif
#endif #endif
#endif
/*=============================================================================
* Standard Library Includes
*===========================================================================*/
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
@ -389,30 +390,30 @@ extern "C" {
# include <unistd.h> /* needed for unlink on some Unix systems */ # include <unistd.h> /* needed for unlink on some Unix systems */
#endif #endif
/* By default, use case-sensitive filename comparison.
*/ /*=============================================================================
* Case sensitive file systems
*===========================================================================*/
/* By default, use case-sensitive filename comparison. */
#ifndef FILENAMES_CASE_SENSITIVE #ifndef FILENAMES_CASE_SENSITIVE
# define FILENAMES_CASE_SENSITIVE 1 # define FILENAMES_CASE_SENSITIVE 1
#endif #endif
/* /*=============================================================================
Tidy preserves the last modified time for the files it * Last modified time preservation
cleans up. * Tidy preserves the last modified time for the files it cleans up.
*/ *
* If your platform doesn't support <utime.h> and the utime() function, or
/* * <sys/futime> and the futime() function then set PRESERVE_FILE_TIMES to 0.
If your platform doesn't support <utime.h> and the *
utime() function, or <sys/futime> and the futime() * If your platform doesn't support <sys/utime.h> and the futime() function,
function then set PRESERVE_FILE_TIMES to 0. * then set HAS_FUTIME to 0.
*
If your platform doesn't support <sys/utime.h> and the * If your platform supports <utime.h> and the utime() function requires the
futime() function, then set HAS_FUTIME to 0. * file to be closed first, then set UTIME_NEEDS_CLOSED_FILE to 1.
*===========================================================================*/
If your platform supports <utime.h> and the
utime() function requires the file to be
closed first, then set UTIME_NEEDS_CLOSED_FILE to 1.
*/
/* Keep old PRESERVEFILETIMES define for compatibility */ /* Keep old PRESERVEFILETIMES define for compatibility */
#ifdef PRESERVEFILETIMES #ifdef PRESERVEFILETIMES
@ -457,10 +458,9 @@ extern "C" {
# include <sys/utime.h> # include <sys/utime.h>
# else # else
# include <utime.h> # include <utime.h>
#endif /* HASFUTIME */ # endif
/* /* MS Windows needs _ prefix for Unix file functions.
MS Windows needs _ prefix for Unix file functions.
Not required by Metrowerks Standard Library (MSL). Not required by Metrowerks Standard Library (MSL).
Tidy uses following for preserving the last modified time. Tidy uses following for preserving the last modified time.
@ -469,24 +469,26 @@ extern "C" {
_WIN32 automatically set by Win32 compilers. _WIN32 automatically set by Win32 compilers.
*/ */
# if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__) # if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
# define futime _futime # define futime _futime
# define fstat _fstat # define fstat _fstat
# define utimbuf _utimbuf /* Windows seems to want utimbuf */ # define utimbuf _utimbuf /* Windows seems to want utimbuf */
# define stat _stat # define stat _stat
# define utime _utime # define utime _utime
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
#endif /* _WIN32 */ # endif
#endif /* PRESERVE_FILE_TIMES */ #endif
/*
MS Windows needs _ prefix for Unix file functions.
Not required by Metrowerks Standard Library (MSL).
WINDOWS automatically set by Win16 compilers. /*=============================================================================
_WIN32 automatically set by Win32 compilers. * Windows file functions
*/ * Windows needs _ prefix for Unix file functions.
* Not required by Metrowerks Standard Library (MSL).
*
* WINDOWS automatically set by Win16 compilers.
* _WIN32 automatically set by Win32 compilers.
*===========================================================================*/
#if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__) #if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
# if !(defined(__WATCOMC__) || defined(__MINGW32__)) # if !(defined(__WATCOMC__) || defined(__MINGW32__))
@ -535,30 +537,43 @@ extern "C" {
#endif /* _WIN32 */ #endif /* _WIN32 */
/* hack for gnu sys/types.h file which defines uint and ulong */
/*=============================================================================
* Hack for gnu sys/types.h file which defines uint and ulong
*===========================================================================*/
#if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS) #if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS)
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#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) #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)
# undef uint # undef uint
typedef unsigned int uint; typedef unsigned int uint;
#endif #endif
#if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32) #if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32)
# undef ulong # undef ulong
typedef unsigned long ulong; typedef unsigned long ulong;
#endif #endif
/*
With GCC 4, __attribute__ ((visibility("default"))) can be used along compiling with tidylib /*=============================================================================
with "-fvisibility=hidden". See http://gcc.gnu.org/wiki/Visibility and build/gmake/Makefile. * Visibility support
*/ * With GCC 4, __attribute__ ((visibility("default"))) can be used
* along compiling with tidylib with "-fvisibility=hidden". See
* http://gcc.gnu.org/wiki/Visibility and build/gmake/Makefile.
*===========================================================================*/
/* /*
#if defined(__GNUC__) && __GNUC__ >= 4 #if defined(__GNUC__) && __GNUC__ >= 4
# define TIDY_EXPORT __attribute__ ((visibility("default"))) # define TIDY_EXPORT __attribute__ ((visibility("default")))
#endif #endif
*/ */
/*=============================================================================
* Other definitions
*===========================================================================*/
#ifndef TIDY_EXPORT /* Define it away for most builds */ #ifndef TIDY_EXPORT /* Define it away for most builds */
# define TIDY_EXPORT # define TIDY_EXPORT
#endif #endif
@ -601,12 +616,10 @@ typedef const tmbchar* ctmbstr; /* Ditto, but const */
# define SUPPORT_POSIX_MAPPED_FILES 1 # define SUPPORT_POSIX_MAPPED_FILES 1
#endif #endif
/* /* `bool` is a reserved word in some but not all C++ compilers depending on age.
bool is a reserved word in some but age. Work around is to avoid bool by introducing a new enum called `Bool`.
not all C++ compilers depending on age
work around is to avoid bool altogether
by introducing a new enum called Bool
*/ */
/* We could use the C99 definition where supported /* We could use the C99 definition where supported
typedef _Bool Bool; typedef _Bool Bool;
#define no (_Bool)0 #define no (_Bool)0