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}" )
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)
add_definitions( -DTIDY_CONFIG_FILE="${TIDY_CONFIG_FILE}" )
endif ()
# For example, ~/.tidy.rc
if (TIDY_USER_CONFIG_FILE)
add_definitions( -DTIDY_USER_CONFIG_FILE="${TIDY_USER_CONFIG_FILE}" )
endif ()
if (SUPPORT_GETPWNAM)
# All Unixes support getpwnam(); undef'd in tidyplatform.h if necessary.
add_definitions( -DSUPPORT_GETPWNAM=1 )
endif ()
endif ()
if(BUILD_SHARED_LIB)
set(LIB_TYPE SHARED)

View file

@ -32,39 +32,51 @@
extern "C" {
#endif
/*
Uncomment and edit one of the following #defines if you
want to specify the config file at compile-time.
*/
/*=============================================================================
* 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.
*===========================================================================*/
/* #define TIDY_CONFIG_FILE "/etc/tidy_config.txt" */ /* original */
/* #define TIDY_CONFIG_FILE "/etc/tidyrc" */
/* #define TIDY_CONFIG_FILE "/etc/tidy.conf" */
/* #define ENABLE_CONFIG_FILES */
/*
Uncomment the following #define if you are on a system
supporting the HOME environment variable.
It enables tidy to find config files named ~/.tidyrc if
the HTML_TIDY environment variable is not set.
*/
/* #define TIDY_USER_CONFIG_FILE "~/.tidyrc" */
#if defined(TIDY_ENABLE_CONFIG_FILES)
# if !defined(TIDY_CONFIG_FILE)
# define TIDY_CONFIG_FILE "/etc/tidy.conf"
# endif
# if !defined(TIDY_USER_CONFIG_FILE)
# 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
variable or CONFIG_FILE or USER_CONFIGFILE or
on the command line: -config ~joebob/tidy.cfg
Contributed by Todd Lewis.
*/
/*=============================================================================
* Unix tilde expansion support
* By default on Unix-like systems when building for the console program,
* 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
* 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 */
/*=============================================================================
* Optional Tidy features support
*===========================================================================*/
/* Enable/disable support for Big5 and Shift_JIS character encodings */
#ifndef SUPPORT_ASIAN_ENCODINGS
# define SUPPORT_ASIAN_ENCODINGS 1
@ -91,7 +103,11 @@ extern "C" {
#endif
/* Convenience defines for Mac platforms */
/*=============================================================================
* Platform specific convenience definitions
*===========================================================================*/
/* === Convenience defines for Mac platforms === */
#if defined(macintosh)
/* 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
#endif
/* Convenience defines for BSD like platforms */
/* === Convenience defines for BSD-like platforms === */
#if defined(__FreeBSD__)
# define BSD_BASED_OS
@ -161,10 +177,9 @@ extern "C" {
# ifndef PLATFORM_NAME
# define PLATFORM_NAME "BSD/OS"
# endif
#endif
/* Convenience defines for Windows platforms */
/* === Convenience defines for Windows platforms === */
#if defined(WINDOWS) || defined(_WIN32)
@ -175,18 +190,14 @@ extern "C" {
# if defined(__MWERKS__) || defined(__MSL__)
/* not available with Metrowerks Standard Library */
# ifdef SUPPORT_GETPWNAM
# undef SUPPORT_GETPWNAM
# endif
/* needed for setmode() */
# if !defined(NO_SETMODE_SUPPORT)
# define NO_SETMODE_SUPPORT
# endif
# define strcasecmp _stricmp
# endif
# if defined(__BORLANDC__)
@ -196,9 +207,9 @@ extern "C" {
# define FILENAMES_CASE_SENSITIVE 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__)
/* Linux on Alpha - gcc compiler */
@ -224,22 +235,15 @@ extern "C" {
#elif defined(linux) && defined(__powerpc__)
/* Linux on PPC - gcc compiler */
# define LINUX_OS
# if defined(__linux__) && defined(__powerpc__)
/* #if #system(linux) */
/* MkLinux on PPC - gcc (egcs) compiler */
/* #define MAC_OS_MKLINUX */
# ifndef PLATFORM_NAME
/* MkLinux on PPC - gcc (egcs) compiler */
# define PLATFORM_NAME "MkLinux"
# endif
# else
# ifndef PLATFORM_NAME
# define PLATFORM_NAME "Linux/PPC"
# endif
# endif
#elif defined(linux) || defined(__linux__)
@ -248,10 +252,9 @@ extern "C" {
# ifndef PLATFORM_NAME
# define PLATFORM_NAME "Linux"
# endif
#endif
/* Convenience defines for Solaris platforms */
/* === Convenience defines for Solaris platforms === */
#if defined(sun)
# define SOLARIS_OS
@ -260,7 +263,7 @@ extern "C" {
# endif
#endif
/* Convenience defines for HPUX + gcc platforms */
/* === Convenience defines for HPUX + gcc platforms === */
#if defined(__hpux)
# define HPUX_OS
@ -269,7 +272,7 @@ extern "C" {
# endif
#endif
/* Convenience defines for RISCOS + gcc platforms */
/* === Convenience defines for RISCOS + gcc platforms === */
#if defined(__riscos__)
# define RISC_OS
@ -278,7 +281,7 @@ extern "C" {
# endif
#endif
/* Convenience defines for OS/2 + icc/gcc platforms */
/* === Convenience defines for OS/2 + icc/gcc platforms === */
#if defined(__OS2__) || defined(__EMX__)
# define OS2_OS
@ -289,7 +292,7 @@ extern "C" {
# define strcasecmp stricmp
#endif
/* Convenience defines for IRIX */
/* === Convenience defines for IRIX === */
#if defined(__sgi)
# define IRIX_OS
@ -298,7 +301,7 @@ extern "C" {
# endif
#endif
/* Convenience defines for AIX */
/* === Convenience defines for AIX === */
#if defined(_AIX)
# define AIX_OS
@ -307,8 +310,7 @@ extern "C" {
# endif
#endif
/* Convenience defines for BeOS platforms */
/* === Convenience defines for BeOS platforms === */
#if defined(__BEOS__)
# define BE_OS
@ -317,7 +319,7 @@ extern "C" {
# endif
#endif
/* Convenience defines for Cygwin platforms */
/* === Convenience defines for Cygwin platforms === */
#if defined(__CYGWIN__)
# define CYGWIN_OS
@ -327,7 +329,7 @@ extern "C" {
# define FILENAMES_CASE_SENSITIVE 0
#endif
/* Convenience defines for OpenVMS */
/* === Convenience defines for OpenVMS === */
#if defined(__VMS)
# define OPENVMS_OS
@ -337,7 +339,7 @@ extern "C" {
# define FILENAMES_CASE_SENSITIVE 0
#endif
/* Convenience defines for DEC Alpha OSF + gcc platforms */
/* === Convenience defines for DEC Alpha OSF + gcc platforms === */
#if defined(__osf__)
# define OSF_OS
@ -346,28 +348,27 @@ extern "C" {
# endif
#endif
/* Convenience defines for ARM platforms */
/* === Convenience defines for ARM platforms === */
#if defined(__arm)
# define ARM_OS
# if defined(forARM) && defined(__NEWTON_H)
/* Using Newton C++ Tools ARMCpp compiler */
# define NEWTON_OS
# ifndef PLATFORM_NAME
# define PLATFORM_NAME "Newton"
# endif
# else
# ifndef PLATFORM_NAME
# define PLATFORM_NAME "ARM"
# endif
# endif
#endif
#endif
/*=============================================================================
* Standard Library Includes
*===========================================================================*/
#include <ctype.h>
#include <stdio.h>
@ -389,30 +390,30 @@ extern "C" {
# include <unistd.h> /* needed for unlink on some Unix systems */
#endif
/* By default, use case-sensitive filename comparison.
*/
/*=============================================================================
* Case sensitive file systems
*===========================================================================*/
/* By default, use case-sensitive filename comparison. */
#ifndef FILENAMES_CASE_SENSITIVE
# define FILENAMES_CASE_SENSITIVE 1
#endif
/*
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 <sys/utime.h> and the
futime() function, then set HAS_FUTIME to 0.
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.
*/
/*=============================================================================
* Last modified time preservation
* 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 <sys/utime.h> and the futime() function,
* then set HAS_FUTIME to 0.
*
* 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 */
#ifdef PRESERVEFILETIMES
@ -457,10 +458,9 @@ extern "C" {
# include <sys/utime.h>
# else
# 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).
Tidy uses following for preserving the last modified time.
@ -469,24 +469,26 @@ extern "C" {
_WIN32 automatically set by Win32 compilers.
*/
# if defined(_WIN32) && !defined(__MSL__) && !defined(__BORLANDC__)
# define futime _futime
# define fstat _fstat
# define utimbuf _utimbuf /* Windows seems to want utimbuf */
# define stat _stat
# define utime _utime
# 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(__WATCOMC__) || defined(__MINGW32__))
@ -535,30 +537,43 @@ extern "C" {
#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)
# include <sys/types.h>
#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)
# undef uint
typedef unsigned int uint;
#endif
#if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32)
# undef ulong
typedef unsigned long ulong;
#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
# define TIDY_EXPORT __attribute__ ((visibility("default")))
#endif
*/
/*=============================================================================
* Other definitions
*===========================================================================*/
#ifndef TIDY_EXPORT /* Define it away for most builds */
# define TIDY_EXPORT
#endif
@ -601,12 +616,10 @@ typedef const tmbchar* ctmbstr; /* Ditto, but const */
# define SUPPORT_POSIX_MAPPED_FILES 1
#endif
/*
bool is a reserved word in some but
not all C++ compilers depending on age
work around is to avoid bool altogether
by introducing a new enum called Bool
/* `bool` is a reserved word in some but not all C++ compilers depending on age.
age. Work around is to avoid bool by introducing a new enum called `Bool`.
*/
/* We could use the C99 definition where supported
typedef _Bool Bool;
#define no (_Bool)0