Modify the build system to assume config files by default. Modify tidyplatform
to accomodate these changes. Reformat tidyplatform for friendliness to new
developers.
This commit is contained in:
Jim Derry 2017-09-30 17:06:19 -04:00
parent 3658275f60
commit a4e0409323
6 changed files with 464 additions and 398 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

@ -862,7 +862,7 @@ static void help(TidyDoc tdoc, /**< The tidy document for which help is showing.
ctmbstr prog /**< The path of the current executable. */
)
{
tmbstr title_line = NULL;
tmbstr temp_string = NULL;
uint width = 78;
printf("\n");
@ -870,19 +870,26 @@ static void help(TidyDoc tdoc, /**< The tidy document for which help is showing.
printf("\n");
#ifdef PLATFORM_NAME
title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2A), PLATFORM_NAME);
temp_string = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2A), PLATFORM_NAME);
#else
title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2B) );
#endif
width = width < strlen(title_line) ? width : strlen(title_line);
printf( "%s\n", title_line );
width = width < strlen(temp_string) ? width : strlen(temp_string);
printf( "%s\n", temp_string );
printf( "%*.*s\n\n", width, width, ul);
free( title_line );
free( temp_string );
print_help_options( tdoc );
printf("\n");
printf( "%s", tidyLocalizedString(TC_TXT_HELP_3) );
#if defined(TIDY_CONFIG_FILE) && defined(TIDY_USER_CONFIG_FILE)
temp_string = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_3A), TIDY_CONFIG_FILE, TIDY_USER_CONFIG_FILE );
printf( tidyLocalizedString(TC_TXT_HELP_3), temp_string );
free( temp_string );
#else
printf( tidyLocalizedString(TC_TXT_HELP_3), "\n" );
#endif
printf("\n");
}

View File

@ -486,6 +486,7 @@ extern "C" {
FN(TC_TXT_HELP_2A) \
FN(TC_TXT_HELP_2B) \
FN(TC_TXT_HELP_3) \
FN(TC_TXT_HELP_3A) \
FN(TC_TXT_HELP_CONFIG) \
FN(TC_TXT_HELP_CONFIG_NAME) \
FN(TC_TXT_HELP_CONFIG_TYPE) \

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

View File

@ -722,7 +722,7 @@ static ctmbstr ExpandTilde( TidyDocImpl* doc, ctmbstr filename )
while ( *s && *s != '/' )
s++;
if ( t = TidyDocAlloc(doc, s - filename) )
if ( (t = TidyDocAlloc(doc, s - filename)) )
{
memcpy(t, filename+1, s-filename-1);
t[s-filename-1] = 0;

View File

@ -2222,7 +2222,8 @@ static languageDefinition language_en = { whichPluralForm_en, {
"Command Line Arguments for HTML Tidy:"
},
{/* This console output should be limited to 78 characters per line.
- The strings "Tidy" and "HTML Tidy" are the program name and must not be translated. */
- The strings "Tidy" and "HTML Tidy" are the program name and must not be translated.
- %s represents either a blank line, or TC_TXT_HELP_3A explaining environment options. */
TC_TXT_HELP_3, 0,
"\n"
"Tidy Configuration Options\n"
@ -2230,14 +2231,20 @@ static languageDefinition language_en = { whichPluralForm_en, {
" Use Tidy's configuration options as command line arguments in the form\n"
" of \"--some-option <value>\", for example, \"--indent-with-tabs yes\".\n"
"\n"
" You can also specify a file containing configuration options with the \n"
" -options <file> directive, or in one or more files specific to your \n"
" environment (see next section). \n"
"\n"
" For a list of all configuration options, use \"-help-config\" or refer\n"
" to the man page (if your OS has one).\n"
"\n"
"If your environment has an $HTML_TIDY variable set point to a Tidy \n"
"configuration file then Tidy will attempt to use it.\n"
"\n"
"On some platforms Tidy will also attempt to use a configuration specified \n"
"in /etc/tidy.conf or ~/.tidy.conf.\n"
"Configuration Files\n"
"===================\n"
" If your environment has an $HTML_TIDY variable set to point to a Tidy \n"
" configuration file, then Tidy will attempt to use it. \n"
"%s"
" Use \"-help-env\" for more information about how you can use the environment. \n"
" to specify Tidy options. \n"
"\n"
"Other\n"
"=====\n"
@ -2266,6 +2273,18 @@ static languageDefinition language_en = { whichPluralForm_en, {
" http://validator.w3.org/nu/\n"
"\n"
},
{/* This console output should be limited to 78 characters per line.
- The strings "Tidy" and "HTML Tidy" are the program name and must not be translated.
- Both parameters %s reflect file paths and names. */
TC_TXT_HELP_3A, 0,
"\n"
" Additionally, Tidy will automatically attempt to use configuration specified \n"
" in these files, if present: \n"
"\n"
" %s \n"
" %s \n"
"\n"
},
{/* This console output should be limited to 78 characters per line.
- The strings "Tidy" and "HTML Tidy" are the program name and must not be translated. */
TC_TXT_HELP_CONFIG, 0,