From ce1e638a0f5aa9c11ab2567df9ac03cbb0687204 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 4 Apr 2017 14:07:20 -0400 Subject: [PATCH 1/2] Added documentation to tidy.c for potential developers to look at and understand. - No version bump as no API was changed; just comments and reorganization. - Built and tested in macOS, Win10, and Ubuntu. --- console/tidy.c | 1311 +++++++++++++++++++++++++++++------------------- 1 file changed, 798 insertions(+), 513 deletions(-) diff --git a/console/tidy.c b/console/tidy.c index bf1b0f0..9ee258f 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -1,17 +1,29 @@ -/* - tidy.c - HTML TidyLib command line driver - - Copyright (c) 1998-2008 World Wide Web Consortium - (Massachusetts Institute of Technology, European Research - Consortium for Informatics and Mathematics, Keio University). - All Rights Reserved. - - */ +/***************************************************************************//** + * @file + * HTML TidyLib command line driver. + * + * This console application utilizing LibTidy in order to offer a complete + * console application offering all of the features of LibTidy. + * + * @author HTACG, et al (consult git log) + * + * @copyright + * Copyright (c) 1998-2017 World Wide Web Consortium (Massachusetts + * Institute of Technology, European Research Consortium for Informatics + * and Mathematics, Keio University) and HTACG. + * @par + * All Rights Reserved. + * @par + * See `tidy.h` for the complete license. + * + * @date Additional updates: consult git log + ******************************************************************************/ #include "tidy.h" -#include "locale.h" +#include "tidybuffio.h" +#include "locale.h" /* for determing and setting locale */ #if defined(_WIN32) -#include /* Force console to UTF8. */ +#include /* Force console to UTF8. */ #endif #if !defined(NDEBUG) && defined(_MSC_VER) #include "sprtf.h" @@ -21,17 +33,36 @@ #define SPRTF printf #endif -static FILE* errout = NULL; /* set to stderr */ -/* static FILE* txtout = NULL; */ /* set to stdout */ +/** Tidy will send errors to this file, which will be stderr later. */ +static FILE* errout = NULL; #if defined(_WIN32) +/** On Windows, we will store the original code page here. */ static uint win_cp; /* original Windows code page */ #endif -/** - ** Indicates whether or not two filenames are the same. + +/** @defgroup console_application Tidy Console Application + ** @copydoc tidy.c + ** @{ */ -static Bool samefile( ctmbstr filename1, ctmbstr filename2 ) + + +/* MARK: - Miscellaneous Utilities */ +/***************************************************************************//** + ** @defgroup utilities_misc Miscellaneous Utilities + ** This group contains general utilities used in the console application. + ******************************************************************************* + ** @{ + */ + + +/** Indicates whether or not two filenames are the same. + ** @result Returns a Bool indicating whether the filenames are the same. + */ +static Bool samefile(ctmbstr filename1, /**< First filename */ + ctmbstr filename2 /**< Second filename */ + ) { #if FILENAMES_CASE_SENSITIVE return ( strcmp( filename1, filename2 ) == 0 ); @@ -41,10 +72,9 @@ static Bool samefile( ctmbstr filename1, ctmbstr filename2 ) } -/** - ** Handles exit cleanup. +/** Handles exit cleanup. */ -static void tidy_cleanup() +static void tidy_cleanup( void ) { #if defined(_WIN32) /* Restore original Windows code page. */ @@ -52,8 +82,8 @@ static void tidy_cleanup() #endif } -/** - ** Exits with an error in the event of an out of memory condition. + +/** Exits with an error in the event of an out of memory condition. */ static void outOfMemory(void) { @@ -62,10 +92,50 @@ static void outOfMemory(void) } -/** - ** Used by `print2Columns` and `print3Columns` to manage whitespace. +/** Create a new, allocated string with a format and arguments. + ** @result Returns a new, allocated string that you must free. */ -static const char *cutToWhiteSpace(const char *s, uint offset, char *sbuf) +static tmbstr stringWithFormat(const ctmbstr fmt, /**< The format string. */ + ... /**< Variable arguments. */ + ) +{ + va_list argList; + tmbstr result = NULL; + int len = 0; + + va_start(argList, fmt); + len = vsnprintf( result, 0, fmt, argList ); + va_end(argList); + + if (!(result = malloc( len + 1) )) + outOfMemory(); + + va_start(argList, fmt); + vsnprintf( result, len + 1, fmt, argList); + va_end(argList); + + return result; +} + + +/** @} end utilities_misc group */ +/* MARK: - Output Helping Functions */ +/***************************************************************************//** + ** @defgroup utilities_output Output Helping Functions + ** This group functions that aid the formatting of output. + ******************************************************************************* + ** @{ + */ + + +/** Used by `print1Column`, `print2Columns` and `print3Columns` to manage + ** wrapping text within columns. + ** @result The pointer to the next part of the string to output. + */ +static const char *cutToWhiteSpace(const char *s, /**< starting point of desired string to output */ + uint offset, /**< column width desired */ + char *sbuf /**< the buffer to output */ + ) { if (!s) { @@ -109,10 +179,13 @@ static const char *cutToWhiteSpace(const char *s, uint offset, char *sbuf) } } -/** - ** Outputs one column of text. + +/** Outputs one column of text. */ -static void print1Column( const char* fmt, uint l1, const char *c1 ) +static void print1Column(const char* fmt, /**< The format string for formatting the output. */ + uint l1, /**< The width of the column. */ + const char *c1 /**< The content of the column. */ + ) { const char *pc1=c1; char *c1buf = (char *)malloc(l1+1); @@ -126,11 +199,15 @@ static void print1Column( const char* fmt, uint l1, const char *c1 ) free(c1buf); } -/** - ** Outputs two columns of text. + +/** Outputs two columns of text. */ -static void print2Columns( const char* fmt, uint l1, uint l2, - const char *c1, const char *c2 ) +static void print2Columns(const char* fmt, /**< The format string for formatting the output. */ + uint l1, /**< The width of column 1. */ + uint l2, /**< The width of column 2. */ + const char *c1, /**< The contents of column 1. */ + const char *c2 /**< The contents of column 2. */ +) { const char *pc1=c1, *pc2=c2; char *c1buf = (char *)malloc(l1+1); @@ -142,19 +219,24 @@ static void print2Columns( const char* fmt, uint l1, uint l2, { pc1 = cutToWhiteSpace(pc1, l1, c1buf); pc2 = cutToWhiteSpace(pc2, l2, c2buf); - printf(fmt, - c1buf[0]!='\0'?c1buf:"", - c2buf[0]!='\0'?c2buf:""); + printf(fmt, l1, l1, c1buf[0]!='\0'?c1buf:"", + l2, l2, c2buf[0]!='\0'?c2buf:""); } while (pc1 || pc2); free(c1buf); free(c2buf); } -/** - ** Outputs three columns of text. + +/** Outputs three columns of text. */ -static void print3Columns( const char* fmt, uint l1, uint l2, uint l3, - const char *c1, const char *c2, const char *c3 ) +static void print3Columns(const char* fmt, /**< The three column format string. */ + uint l1, /**< Width of column 1. */ + uint l2, /**< Width of column 2. */ + uint l3, /**< Width of column 3. */ + const char *c1, /**< Content of column 1. */ + const char *c2, /**< Content of column 2. */ + const char *c3 /**< Content of column 3. */ + ) { const char *pc1=c1, *pc2=c2, *pc3=c3; char *c1buf = (char *)malloc(l1+1); @@ -179,17 +261,41 @@ static void print3Columns( const char* fmt, uint l1, uint l2, uint l3, free(c3buf); } -/** - ** Format strings and decorations used in output. + +/** Provides the `unknown option` output to the current errout. */ -static const char helpfmt[] = " %-25.25s %-52.52s\n"; +static void unknownOption(TidyDoc tdoc, /**< The Tidy document. */ + uint c /**< The unknown option. */ + ) +{ + fprintf( errout, tidyLocalizedString( TC_STRING_UNKNOWN_OPTION ), (char)c ); + fprintf( errout, "\n"); +} + + +/** @} end utilities_output group */ +/* MARK: - CLI Options Utilities */ +/***************************************************************************//** + ** @defgroup options_cli CLI Options Utilities + ** These structures, arrays, declarations, and definitions are used throughout + ** this console application. + ******************************************************************************* + ** @{ + */ + + +/** @name Format strings and decorations used in output. + ** @{ + */ + +static const char helpfmt[] = " %-*.*s %-*.*s\n"; static const char helpul[] = "-----------------------------------------------------------------"; static const char fmt[] = "%-27.27s %-9.9s %-40.40s\n"; -static const char valfmt[] = "%-27.27s %-9.9s %-39.39s\n"; static const char ul[] = "================================================================="; -/** - ** This enum is used to categorize the options for help output. +/** @} */ + +/** This enum is used to categorize the options for help output. */ typedef enum { @@ -202,8 +308,7 @@ typedef enum CmdOptCatLAST } CmdOptCategory; -/** - ** This array contains headings that will be used in help ouput. +/** This array contains headings that will be used in help ouput. */ static const struct { ctmbstr mnemonic; /**< Used in XML as a class. */ @@ -216,9 +321,8 @@ static const struct { { "xml", TC_STRING_XML } }; -/** - ** The struct and subsequent array keep the help output structured - ** because we _also_ output all of this stuff as as XML. +/** The struct and subsequent array keep the help output structured + ** because we _also_ output all of this stuff as as XML. */ typedef struct { CmdOptCategory cat; /**< Category */ @@ -230,8 +334,9 @@ typedef struct { ctmbstr name3; /**< Name */ } CmdOptDesc; -/* All instances of %s will be substituted with localized string - specified by the subKey field. */ +/** All instances of %s will be substituted with localized string + ** specified by the subKey field. + */ static const CmdOptDesc cmdopt_defs[] = { { CmdOptFileManip, "-output <%s>", TC_OPT_OUTPUT, TC_LABEL_FILE, "output-file: <%s>", "-o <%s>" }, { CmdOptFileManip, "-config <%s>", TC_OPT_CONFIG, TC_LABEL_FILE, NULL }, @@ -287,33 +392,10 @@ static const CmdOptDesc cmdopt_defs[] = { { CmdOptMisc, NULL, 0, 0, NULL } }; -/** - ** Create a new string with a format and arguments. - */ -static tmbstr stringWithFormat( const ctmbstr fmt, ... ) -{ - va_list argList; - tmbstr result = NULL; - int len = 0; - va_start(argList, fmt); - len = vsnprintf( result, 0, fmt, argList ); - va_end(argList); - - if (!(result = malloc( len + 1) )) - outOfMemory(); - - va_start(argList, fmt); - vsnprintf( result, len + 1, fmt, argList); - va_end(argList); - - return result; -} - - -/** - ** Option names aren't localized, but the sample fields - ** are, for example should be in Spanish. +/** Option names aren't localized, but the sample fields should be localized. + ** For example, `` should be `` in Spanish. + ** @param pos A CmdOptDesc array with fields that must be localized. */ static void localize_option_names( CmdOptDesc *pos) { @@ -327,45 +409,11 @@ static void localize_option_names( CmdOptDesc *pos) pos->eqconfig = stringWithFormat(pos->eqconfig, fileString); } -/** - ** Retrieve the options' names from the structure as a single - ** string. - */ -static tmbstr get_option_names( const CmdOptDesc* pos ) -{ - tmbstr name; - uint len; - CmdOptDesc localPos = *pos; - localize_option_names( &localPos ); - - len = strlen(localPos.name1); - if (localPos.name2) - len += 2+strlen(localPos.name2); - if (localPos.name3) - len += 2+strlen(localPos.name3); - - name = (tmbstr)malloc(len+1); - if (!name) outOfMemory(); - strcpy(name, localPos.name1); - free((tmbstr)localPos.name1); - if (localPos.name2) - { - strcat(name, ", "); - strcat(name, localPos.name2); - free((tmbstr)localPos.name2); - } - if (localPos.name3) - { - strcat(name, ", "); - strcat(name, localPos.name3); - free((tmbstr)localPos.name3); - } - return name; -} - -/** - ** Escape a name for XML output. +/** Escape a name for XML output. For example, `-output ` becomes + ** `-output <file>` for use in XML. + ** @param name The option name to escape. + ** @result Returns an allocated string. */ static tmbstr get_escaped_name( ctmbstr name ) { @@ -414,124 +462,20 @@ static tmbstr get_escaped_name( ctmbstr name ) return escpName; } -/** - ** Outputs a complete help option (text) + +/** @} end CLI Options Definitions Utilities group */ +/* MARK: - Configuration Options Utilities */ +/***************************************************************************//** + ** @defgroup utilities_cli_options Configuration Options Utilities + ** Provide utilities to manipulate configuration options for output. + ******************************************************************************* + ** @{ */ -static void print_help_option( void ) -{ - CmdOptCategory cat = CmdOptCatFIRST; - const CmdOptDesc* pos = cmdopt_defs; - for( cat=CmdOptCatFIRST; cat!=CmdOptCatLAST; ++cat) - { - ctmbstr name = tidyLocalizedString(cmdopt_catname[cat].key); - size_t len = strlen(name); - printf("%s\n", name ); - printf("%*.*s\n", (int)len, (int)len, helpul ); - for( pos=cmdopt_defs; pos->name1; ++pos) - { - tmbstr name; - if (pos->cat != cat) - continue; - name = get_option_names( pos ); - print2Columns( helpfmt, 25, 52, name, tidyLocalizedString( pos->key ) ); - free(name); - } - printf("\n"); - } -} -/** - ** Outputs an XML element for an option. - */ -static void print_xml_help_option_element( ctmbstr element, ctmbstr name ) -{ - tmbstr escpName; - if (!name) - return; - - printf(" <%s>%s\n", element, escpName = get_escaped_name(name), element); - free(escpName); -} - -/** - ** Outputs a complete help option (XML) - */ -static void print_xml_help_option( void ) -{ - const CmdOptDesc* pos; - CmdOptDesc localPos; - - for( pos=cmdopt_defs; pos->name1; ++pos) - { - localPos = *pos; - localize_option_names(&localPos); - printf(" \n"); - } -} - -/** - ** Provides the -xml-help service. - */ -static void xml_help( void ) -{ - printf( "\n" - "\n", tidyLibraryVersion()); - print_xml_help_option(); - printf( "\n" ); -} - -/** - ** Returns the final name of the tidy executable. - */ -static ctmbstr get_final_name( ctmbstr prog ) -{ - ctmbstr name = prog; - int c; - size_t i, len = strlen(prog); - for (i = 0; i < len; i++) { - c = prog[i]; - if ((( c == '/' ) || ( c == '\\' )) && prog[i+1]) - name = &prog[i+1]; - } - return name; -} - -/** - ** Handles the -help service. - */ -static void help( ctmbstr prog ) -{ - tmbstr title_line = NULL; - - printf( tidyLocalizedString(TC_TXT_HELP_1), get_final_name(prog),tidyLibraryVersion() ); - -#ifdef PLATFORM_NAME - title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2A), PLATFORM_NAME); -#else - title_line = stringWithFormat( tidyLocalizedString(TC_TXT_HELP_2B) ); -#endif - printf( "%s\n", title_line ); - printf("%*.*s\n", (int)strlen(title_line), (int)strlen(title_line), ul); - free( title_line ); - printf( "\n"); - - print_help_option(); - - printf( "%s", tidyLocalizedString(TC_TXT_HELP_3) ); -} - -/** - ** Utility to determine if an option is an AutoBool. +/** Utility to determine if an option is an AutoBool. + ** @param topt The option to check. + ** @result Returns a Bool indicating whether the option is an Autobool or not. */ static Bool isAutoBool( TidyOption topt ) { @@ -551,10 +495,10 @@ static Bool isAutoBool( TidyOption topt ) return no; } -/** - ** Returns the configuration category name for the - ** specified configuration category id. This will be - ** used as an XML class attribute value. +/** Returns the configuration category name for the specified configuration + ** category id. This will be used as an XML class attribute value. + ** @param id The TidyConfigCategory for which to lookup the category name. + ** @result Returns the configuration category, such as "diagnostics". */ static ctmbstr ConfigCategoryName( TidyConfigCategory id ) { @@ -569,28 +513,34 @@ static ctmbstr ConfigCategoryName( TidyConfigCategory id ) return "never_here"; /* only for the compiler warning */ } -/** - ** Structure maintains a description of an option. +/** Structure maintains a description of a configuration ption. */ typedef struct { - ctmbstr name; /**< Name */ - ctmbstr cat; /**< Category */ - uint catid; /**< Category ID */ - ctmbstr type; /**< "String, ... */ - ctmbstr vals; /**< Potential values. If NULL, use an external function */ - ctmbstr def; /**< default */ + ctmbstr name; /**< Name */ + ctmbstr cat; /**< Category */ + uint catid; /**< Category ID */ + ctmbstr type; /**< "String, ... */ + ctmbstr vals; /**< Potential values. If NULL, use an external function */ + ctmbstr def; /**< default */ tmbchar tempdefs[80]; /**< storage for default such as integer */ - Bool haveVals; /**< if yes, vals is valid */ + Bool haveVals; /**< if yes, vals is valid */ } OptionDesc; +/** A type for a function pointer for a function used to print out options + ** descriptions. + ** @param TidyDoc The document. + ** @param TidyOption The Tidy option. + ** @param OptionDesc A pointer to the option description structure. + */ typedef void (*OptionFunc)( TidyDoc, TidyOption, OptionDesc * ); -/** - ** Create OptionDesc "d" related to "opt" +/** Create OptionDesc "d" related to "opt" */ -static -void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) +static void GetOption(TidyDoc tdoc, /**< The tidy document. */ + TidyOption topt, /**< The option to create a description for. */ + OptionDesc *d /**< [out] The new option description. */ + ) { TidyOptionId optId = tidyOptGetId( topt ); TidyOptionType optTyp = tidyOptGetType( topt ); @@ -602,8 +552,7 @@ void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) d->def = NULL; d->haveVals = yes; - /* Handle special cases first. - */ + /* Handle special cases first. */ switch ( optId ) { case TidyDuplicateAttrs: @@ -689,27 +638,29 @@ void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) } } -/** - ** Array holding all options. Contains a trailing sentinel. +/** Array holding all options. Contains a trailing sentinel. */ typedef struct { TidyOption topt[N_TIDY_OPTIONS]; } AllOption_t; -/** - ** A simple option comparator. - **/ -static int cmpOpt(const void* e1_, const void *e2_) +/** A simple option comparator, used for sorting the options. + ** @result Returns an integer indicating the result of the comparison. + */ +static int cmpOpt(const void* e1_, /**< Item A to compare. */ + const void *e2_ /**< Item B to compare. */ + ) { const TidyOption* e1 = (const TidyOption*)e1_; const TidyOption* e2 = (const TidyOption*)e2_; return strcmp(tidyOptGetName(*e1), tidyOptGetName(*e2)); } -/** - ** Returns options sorted. - **/ -static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption ) +/** Returns options sorted. + */ +static void getSortedOption(TidyDoc tdoc, /**< The Tidy document. */ + AllOption_t *tOption /**< [out] The list of options. */ + ) { TidyIterator pos = tidyGetOptionList( tdoc ); uint i = 0; @@ -728,10 +679,11 @@ static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption ) cmpOpt); } -/** - ** An iterator for the sorted options. - **/ -static void ForEachSortedOption( TidyDoc tdoc, OptionFunc OptionPrint ) +/** An iterator for the sorted options. + */ +static void ForEachSortedOption(TidyDoc tdoc, /**< The Tidy document. */ + OptionFunc OptionPrint /**< The printing function to be used. */ + ) { AllOption_t tOption; const TidyOption *topt; @@ -746,10 +698,11 @@ static void ForEachSortedOption( TidyDoc tdoc, OptionFunc OptionPrint ) } } -/** - ** An iterator for the unsorted options. - **/ -static void ForEachOption( TidyDoc tdoc, OptionFunc OptionPrint ) +/** An iterator for the unsorted options. + */ +static void ForEachOption(TidyDoc tdoc, /**< The Tidy document. */ + OptionFunc OptionPrint /**< The printing function to be used. */ +) { TidyIterator pos = tidyGetOptionList( tdoc ); @@ -763,9 +716,9 @@ static void ForEachOption( TidyDoc tdoc, OptionFunc OptionPrint ) } } -/** - ** Prints an option's allowed value as specified in its pick list. - **/ +/** Prints an option's allowed value as specified in its pick list. + ** @param topt The Tidy option. + */ static void PrintAllowedValuesFromPick( TidyOption topt ) { TidyIterator pos = tidyOptGetPickList( topt ); @@ -782,10 +735,11 @@ static void PrintAllowedValuesFromPick( TidyOption topt ) } } -/** - ** Prints an option's allowed values. - **/ -static void PrintAllowedValues( TidyOption topt, const OptionDesc *d ) +/** Prints an option's allowed values. + */ +static void PrintAllowedValues(TidyOption topt, /**< The Tidy option. */ + const OptionDesc *d /**< The OptionDesc for the option. */ + ) { if (d->vals) printf( "%s", d->vals ); @@ -793,164 +747,162 @@ static void PrintAllowedValues( TidyOption topt, const OptionDesc *d ) PrintAllowedValuesFromPick( topt ); } -/** - ** Prints for XML an option's . - **/ -static void printXMLDescription( TidyDoc tdoc, TidyOption topt ) + +/** @} end utilities_cli_options group */ +/* MARK: - Provide the -help Service */ +/***************************************************************************//** + ** @defgroup service_help Provide the -help Service + ******************************************************************************* + ** @{ + */ + + +/** Retrieve the option's name(s) from the structure as a single string, + ** localizing the field values if application. For example, this might + ** return `-output , -o `. + ** @param pos A CmdOptDesc array item for which to get the names. + ** @result Returns the name(s) for the option as a single string. + */ +static tmbstr get_option_names( const CmdOptDesc* pos ) { - ctmbstr doc = tidyOptGetDoc( tdoc, topt ); + tmbstr name; + uint len; + CmdOptDesc localPos = *pos; - if (doc) - printf(" %s\n", doc); - else + localize_option_names( &localPos ); + + len = strlen(localPos.name1); + if (localPos.name2) + len += 2+strlen(localPos.name2); + if (localPos.name3) + len += 2+strlen(localPos.name3); + + name = (tmbstr)malloc(len+1); + if (!name) outOfMemory(); + strcpy(name, localPos.name1); + free((tmbstr)localPos.name1); + if (localPos.name2) { - printf(" \n"); - fprintf(stderr, tidyLocalizedString(TC_STRING_OPT_NOT_DOCUMENTED), - tidyOptGetName( topt )); - fprintf(stderr, "\n"); - + strcat(name, ", "); + strcat(name, localPos.name2); + free((tmbstr)localPos.name2); } -} - -/** - ** Prints for XML an option's . - **/ -static void printXMLCrossRef( TidyDoc tdoc, TidyOption topt ) -{ - TidyOption optLinked; - TidyIterator pos = tidyOptGetDocLinksList(tdoc, topt); - while( pos ) + if (localPos.name3) { - optLinked = tidyOptGetNextDocLinks(tdoc, &pos ); - printf(" %s\n",tidyOptGetName(optLinked)); + strcat(name, ", "); + strcat(name, localPos.name3); + free((tmbstr)localPos.name3); } + return name; } -/** - ** Prints for XML an option's . - **/ -static void printXMLCrossRefEqConsole( TidyDoc tdoc, TidyOption topt ) +/** Returns the final name of the tidy executable by eliminating the path + ** name components from the executable name. + ** @param prog The path of the current executable. + */ +static ctmbstr get_final_name( ctmbstr prog ) { - const CmdOptDesc* pos = cmdopt_defs; - const CmdOptDesc* hit = NULL; - CmdOptDesc localHit; - enum { sizeBuffer = 50 }; /* largest config name is 27 chars so far... */ - char buffer[sizeBuffer]; + ctmbstr name = prog; + int c; + size_t i; + size_t len = strlen(prog); - for( pos=cmdopt_defs; pos->name1; ++pos) + for (i = 0; i < len; i++) { - snprintf(buffer, sizeBuffer, "%s:", tidyOptGetName( topt )); - if ( pos->eqconfig && (strncmp(buffer, pos->eqconfig, strlen(buffer)) == 0) ) + c = prog[i]; + if ((( c == '/' ) || ( c == '\\' )) && prog[i+1]) { - hit = pos; - break; + name = &prog[i+1]; } } - if ( hit ) - { - localHit = *hit; - localize_option_names( &localHit ); - printf(" %s\n", get_escaped_name(localHit.name1)); - if ( localHit.name2 ) - printf(" %s\n", get_escaped_name(localHit.name2)); - if ( localHit.name3 ) - printf(" %s\n", get_escaped_name(localHit.name3)); - - } - else - printf(" %s\n", " "); + return name; } - -/** - ** Prints for XML an option. - **/ -static void printXMLOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) -{ - if ( tidyOptGetCategory(topt) == TidyInternalCategory ) - return; - - printf( " \n" ); -} - - -/** - ** Handles the -xml-config service. - **/ -static void XMLoptionhelp( TidyDoc tdoc ) -{ - printf( "\n" - "\n", tidyLibraryVersion()); - ForEachOption( tdoc, printXMLOption ); - printf( "\n" ); -} - -/** - * Prints the Windows language names that Tidy recognizes, - * using the specified format string. +/** Outputs all of the complete help options (text). + ** @param tdoc The Tidydoc whose options are being printed. */ -void tidyPrintWindowsLanguageNames( ctmbstr format ) +static void print_help_options( TidyDoc tdoc ) { - const tidyLocaleMapItem *item; - TidyIterator i = getWindowsLanguageList(); - ctmbstr winName; - ctmbstr posixName; + CmdOptCategory cat = CmdOptCatFIRST; + const CmdOptDesc* pos = cmdopt_defs; + uint col1, col2; + uint width = 78; - while (i) { - item = getNextWindowsLanguage(&i); - winName = TidyLangWindowsName( item ); - posixName = TidyLangPosixName( item ); - if ( format ) - printf( format, winName, posixName ); - else - printf( "%-20s -> %s\n", winName, posixName ); + for( cat=CmdOptCatFIRST; cat!=CmdOptCatLAST; ++cat) + { + ctmbstr name = tidyLocalizedString(cmdopt_catname[cat].key); + size_t len = width < strlen(name) ? width : strlen(name); + printf( "%s\n", name ); + printf( "%*.*s\n", (int)len, (int)len, helpul ); + + /* Tidy's "standard" 78-column output was always 25:52 ratio, so let's + try to preserve this approximately 1:2 ratio regardless of whatever + silly thing the user might have set for a console width, with a + maximum of 50 characters for the first column. + */ + col1 = width / 3; /* one third of the available */ + col1 = col1 < 1 ? 1 : col1; /* at least 1 */ + col1 = col1 > 35 ? 35 : col1; /* no greater than 35 */ + col2 = width - col1 - 2; /* allow two spaces */ + col2 = col2 < 1 ? 1 : col2; /* at least 1 */ + + for( pos=cmdopt_defs; pos->name1; ++pos) + { + tmbstr name; + if (pos->cat != cat) + continue; + name = get_option_names( pos ); + print2Columns( helpfmt, col1, col2, name, tidyLocalizedString( pos->key ) ); + free(name); + } + printf("\n"); } } - -/** - * Prints the languages the are currently built into Tidy, - * using the specified format string. +/** Handles the -help service. */ -void tidyPrintTidyLanguageNames( ctmbstr format ) +static void help(TidyDoc tdoc, /**< The tidy document for which help is showing. */ + ctmbstr prog /**< The path of the current executable. */ + ) { - ctmbstr item; - TidyIterator i = getInstalledLanguageList(); + tmbstr title_line = NULL; + uint width = 78; - while (i) { - item = getNextInstalledLanguage(&i); - if ( format ) - printf( format, item ); - else - printf( "%s\n", item ); - } + printf("\n"); + printf( tidyLocalizedString(TC_TXT_HELP_1), get_final_name(prog), tidyLibraryVersion() ); + printf("\n"); + +#ifdef PLATFORM_NAME + title_line = 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 ); + printf( "%*.*s\n\n", width, width, ul); + free( title_line ); + + print_help_options( tdoc ); + + printf("\n"); + printf( "%s", tidyLocalizedString(TC_TXT_HELP_3) ); + printf("\n"); } +/** @} end service_help group */ +/* MARK: - Provide the -help-config Service */ +/***************************************************************************//** + ** @defgroup service_help_config Provide the -help-config Service + ******************************************************************************* + ** @{ + */ -/** - ** Retrieves allowed values from an option's pick list. + +/** Retrieves allowed values from an option's pick list. + ** @param topt A TidyOption for which to get the allowed values. + ** @result A string containing the allowed values. */ static tmbstr GetAllowedValuesFromPick( TidyOption topt ) { @@ -988,10 +940,12 @@ static tmbstr GetAllowedValuesFromPick( TidyOption topt ) return val; } -/** - ** Retrieves allowed values for an option. +/** Retrieves allowed values for an option. + ** @result A string containing the allowed values. */ -static tmbstr GetAllowedValues( TidyOption topt, const OptionDesc *d ) +static tmbstr GetAllowedValues(TidyOption topt, /**< A TidyOption for which to get the allowed values. */ + const OptionDesc *d /**< A pointer to the OptionDesc array. */ + ) { if (d->vals) { @@ -1004,11 +958,12 @@ static tmbstr GetAllowedValues( TidyOption topt, const OptionDesc *d ) return GetAllowedValuesFromPick( topt ); } -/** - ** Prints a single option. +/** Prints a single option. */ -static void printOption( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, - OptionDesc *d ) +static void printOption(TidyDoc ARG_UNUSED(tdoc), /**< The Tidy document. */ + TidyOption topt, /**< The option to print. */ + OptionDesc *d /**< A pointer to the OptionDesc array. */ + ) { if (tidyOptGetCategory( topt ) == TidyInternalCategory ) return; @@ -1032,11 +987,15 @@ static void printOption( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, } } -/** - ** Handles the -help-config service. +/** Handles the -help-config service. + ** @remark We will not support console word wrapping for the configuration + ** options table. If users really have a small console, then they + * should make it wider or output to a file. + ** @param tdoc The Tidy document. */ static void optionhelp( TidyDoc tdoc ) { + printf( "\n" ); printf( "%s", tidyLocalizedString( TC_TXT_HELP_CONFIG ) ); printf( fmt, @@ -1050,10 +1009,19 @@ static void optionhelp( TidyDoc tdoc ) } -/** - ** Cleans up the HTML-laden option descriptions for console - ** output. It's just a simple HTML filtering/replacement function. - ** Will return an allocated string. +/** @} end service_lang_help group */ +/* MARK: - Provide the -help-option Service */ +/***************************************************************************//** + ** @defgroup service_help_option Provide the -help-option Service + ******************************************************************************* + ** @{ + */ + + +/** Cleans up the HTML-laden option descriptions for console output. It's + ** just a simple HTML filtering/replacement function. + ** @param description The option description. + ** @result Returns an allocated string with some HTML stripped away. */ static tmbstr cleanup_description( ctmbstr description ) { @@ -1311,14 +1279,15 @@ EXIT_CLEANLY: } -/** - ** Handles the -help-option service. +/** Handles the -help-option service. */ -static void optionDescribe( TidyDoc tdoc, char *tag ) +static void optionDescribe(TidyDoc tdoc, /**< The Tidy Document */ + char *option /**< The name of the option. */ + ) { tmbstr result = NULL; Bool allocated = no; - TidyOptionId topt = tidyOptGetIdForName( tag ); + TidyOptionId topt = tidyOptGetIdForName( option ); uint tcat = tidyOptGetCategory( tidyGetOption(tdoc, topt)); if (topt < N_TIDY_OPTIONS && tcat != TidyInternalCategory ) @@ -1332,19 +1301,104 @@ static void optionDescribe( TidyDoc tdoc, char *tag ) } printf( "\n" ); - printf( "`--%s`\n\n", tag ); - print1Column( "%-68.68s\n", 68, result ); + printf( "`--%s`\n\n", option ); + print1Column( "%-78.78s\n", 78, result ); printf( "\n" ); if ( allocated ) free ( result ); } -/** - * Prints the option value for a given option. +/** @} end service_help_option group */ +/* MARK: - Provide the -lang help Service */ +/***************************************************************************//** + ** @defgroup service_lang_help Provide the -lang help Service + ******************************************************************************* + ** @{ */ -static void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, - OptionDesc *d ) + + +/** Prints the Windows language names that Tidy recognizes, using the specified + ** format string. + ** @param format A format string used to display the Windows language names, + ** or NULL to use the built-in default format. + */ +void tidyPrintWindowsLanguageNames( ctmbstr format ) +{ + const tidyLocaleMapItem *item; + TidyIterator i = getWindowsLanguageList(); + ctmbstr winName; + ctmbstr posixName; + + while (i) { + item = getNextWindowsLanguage(&i); + winName = TidyLangWindowsName( item ); + posixName = TidyLangPosixName( item ); + if ( format ) + printf( format, winName, posixName ); + else + printf( "%-20s -> %s\n", winName, posixName ); + } +} + + +/** Prints the languages the are currently built into Tidy, using the specified + ** format string. + ** @param format A format string used to display the Windows language names, + ** or NULL to use the built-in default format. + */ +void tidyPrintTidyLanguageNames( ctmbstr format ) +{ + ctmbstr item; + TidyIterator i = getInstalledLanguageList(); + + while (i) { + item = getNextInstalledLanguage(&i); + if ( format ) + printf( format, item ); + else + printf( "%s\n", item ); + } +} + + +/** Handles the -lang help service. + ** @remark We will not support console word wrapping for the tables. If users + ** really have a small console, then they should make it wider or + ** output to a file. + ** @param tdoc The Tidy document. + */ +static void lang_help( TidyDoc tdoc ) +{ + printf( "\n" ); + printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_1) ); + printf( "\n" ); + tidyPrintWindowsLanguageNames(" %-20s -> %s\n"); + printf( "\n" ); + printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_2) ); + printf( "\n" ); + tidyPrintTidyLanguageNames(" %s\n"); + printf( "\n" ); + printf( tidyLocalizedString(TC_TXT_HELP_LANG_3), tidyGetLanguage() ); + printf( "\n" ); +} + + +/** @} end service_lang_help group */ +/* MARK: - Provide the -show-config Service */ +/***************************************************************************//** + ** @defgroup service_show_config Provide the -show-config Service + ******************************************************************************* + ** @{ + */ + + +/** Prints the option value for a given option. + */ +static void printOptionValues(TidyDoc ARG_UNUSED(tdoc), /**< The Tidy document. */ + TidyOption topt, /**< The option for which to show values. */ + OptionDesc *d /**< The OptionDesc array. */ + ) { TidyOptionId optId = tidyOptGetId( topt ); @@ -1364,10 +1418,7 @@ static void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos); if ( pos ) { - if ( *d->name ) - printf( valfmt, d->name, d->type, d->def ); - else - printf( fmt, d->name, d->type, d->def ); + printf( fmt, d->name, d->type, d->def ); d->name = ""; d->type = ""; } @@ -1383,19 +1434,19 @@ static void printOptionValues( TidyDoc ARG_UNUSED(tdoc), TidyOption topt, { if ( ! d->def ) d->def = ""; - if ( *d->name ) - printf( valfmt, d->name, d->type, d->def ); - else - printf( fmt, d->name, d->type, d->def ); + printf( fmt, d->name, d->type, d->def ); } } -/** - ** Handles the -show-config service. +/** Handles the -show-config service. + ** @remark We will not support console word wrapping for the table. If users + ** really have a small console, then they should make it wider or + ** output to a file. + ** @param tdoc The Tidy Document. */ static void optionvalues( TidyDoc tdoc ) { - printf( "\n%s\n\n", tidyLocalizedString(TC_STRING_CONF_HEADER) ); + printf( "\n%s\n", tidyLocalizedString(TC_STRING_CONF_HEADER) ); printf( fmt, tidyLocalizedString(TC_STRING_CONF_NAME), tidyLocalizedString(TC_STRING_CONF_TYPE), tidyLocalizedString(TC_STRING_CONF_VALUE) ); @@ -1404,10 +1455,19 @@ static void optionvalues( TidyDoc tdoc ) ForEachSortedOption( tdoc, printOptionValues ); } -/** - ** Handles the -version service. + +/** @} end service_show_config group */ +/* MARK: - Provide the -version Service */ +/***************************************************************************//** + ** @defgroup service_version Provide the -version Service + ******************************************************************************* + ** @{ */ -static void version( void ) + + +/** Handles the -version service. + */ +static void version( TidyDoc tdoc ) { #ifdef PLATFORM_NAME printf( tidyLocalizedString( TC_STRING_VERS_A ), PLATFORM_NAME, tidyLibraryVersion() ); @@ -1418,42 +1478,161 @@ static void version( void ) } -/** - ** Handles the printing of option description for - ** -xml-options-strings service. - **/ -static void printXMLOptionString( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) +/** @} end service_version group */ +/* MARK: - Provide the -xml-config Service */ +/***************************************************************************//** + ** @defgroup service_xml_config Provide the -xml-config Service + ******************************************************************************* + ** @{ + */ + + +/** Prints for XML an option's . + */ +static void printXMLDescription(TidyDoc tdoc, /**< The Tidy document. */ + TidyOption topt /**< The option. */ + ) { - if ( tidyOptIsReadOnly(topt) ) + ctmbstr doc = tidyOptGetDoc( tdoc, topt ); + + if (doc) + printf(" %s\n", doc); + else + { + printf(" \n"); + fprintf(stderr, tidyLocalizedString(TC_STRING_OPT_NOT_DOCUMENTED), + tidyOptGetName( topt )); + fprintf(stderr, "\n"); + + } +} + +/** Prints for XML an option's ``. + */ +static void printXMLCrossRef(TidyDoc tdoc, /**< The Tidy document. */ + TidyOption topt /**< The option. */ + ) +{ + TidyOption optLinked; + TidyIterator pos = tidyOptGetDocLinksList(tdoc, topt); + while( pos ) + { + optLinked = tidyOptGetNextDocLinks(tdoc, &pos ); + printf(" %s\n",tidyOptGetName(optLinked)); + } +} + + +/** Prints for XML an option's ``. + */ +static void printXMLCrossRefEqConsole(TidyDoc tdoc, /**< The Tidy document. */ + TidyOption topt /**< The option. */ + ) +{ + const CmdOptDesc* pos = cmdopt_defs; + const CmdOptDesc* hit = NULL; + CmdOptDesc localHit; + enum { sizeBuffer = 50 }; /* largest config name is 27 chars so far... */ + char buffer[sizeBuffer]; + + for( pos=cmdopt_defs; pos->name1; ++pos) + { + snprintf(buffer, sizeBuffer, "%s:", tidyOptGetName( topt )); + if ( pos->eqconfig && (strncmp(buffer, pos->eqconfig, strlen(buffer)) == 0) ) + { + hit = pos; + break; + } + } + + if ( hit ) + { + localHit = *hit; + tmbstr localName; + localize_option_names( &localHit ); + printf(" %s\n", localName = get_escaped_name(localHit.name1)); + free((tmbstr)localHit.name1); + free(localName); + if ( localHit.name2 ) + { + printf(" %s\n", localName = get_escaped_name(localHit.name2)); + free((tmbstr)localHit.name2); + free(localName); + } + if ( localHit.name3 ) + { + printf(" %s\n", localName = get_escaped_name(localHit.name3)); + free((tmbstr)localHit.name3); + free(localName); + } + + } + else + printf(" %s\n", " "); +} + + +/** Prints for XML an option. + */ +static void printXMLOption(TidyDoc tdoc, /**< The Tidy document. */ + TidyOption topt, /**< The option. */ + OptionDesc *d /**< The OptionDesc for the option. */ + ) +{ + if ( tidyOptGetCategory(topt) == TidyInternalCategory ) return; - printf( " \n" ); } -/** - ** Handles the -xml-options-strings service. - ** This service is primarily helpful to developers and localizers to test - ** that option description strings as represented on screen output are - ** correct and do not break tidy. - **/ -static void xml_options_strings( TidyDoc tdoc ) + +/** Handles the -xml-config service. + ** @param tdoc The Tidy document. + */ +static void XMLoptionhelp( TidyDoc tdoc ) { printf( "\n" - "\n", tidyLibraryVersion()); - ForEachOption( tdoc, printXMLOptionString); - printf( "\n" ); + "\n", tidyLibraryVersion()); + ForEachOption( tdoc, printXMLOption ); + printf( "\n" ); } -/** - ** Handles the -xml-error-strings service. - ** This service is primarily helpful to developers who need to generate - ** an updated list of strings to expect when using `TidyReportFilter3`. - ** Included in the output is the current string associated with the error - ** symbol. +/** @} end service_xml_config group */ +/* MARK: - Provide the -xml-error-strings Service */ +/***************************************************************************//** + ** @defgroup service_xml_error_strings Provide the -xml-error-strings Service + ******************************************************************************* + ** @{ + */ + + +/** Handles the -xml-error-strings service. + ** This service is primarily helpful to developers who need to generate an + ** updated list of strings to expect when using one of the message callbacks. + ** Included in the output is the current string associated with the error + ** symbol. + ** @param tdoc The Tidy document. **/ static void xml_error_strings( TidyDoc tdoc ) { @@ -1481,18 +1660,122 @@ static void xml_error_strings( TidyDoc tdoc ) } +/** @} end service_xml_error_strings group */ +/* MARK: - Provide the -xml-help Service */ +/***************************************************************************//** + ** @defgroup service_xmlhelp Provide the -xml-help Service + ******************************************************************************* + ** @{ + */ + +/** Outputs an XML element for a CLI option, escaping special characters as + ** required. For example, it might print `-output <file>`. + */ +static void print_xml_help_option_element(ctmbstr element, /**< XML element name. */ + ctmbstr name /**< The contents of the element. */ + ) +{ + tmbstr escpName; + if (!name) + return; + + printf(" <%s>%s\n", element, escpName = get_escaped_name(name), element); + free(escpName); +} + +/** Provides the -xml-help service. + */ +static void xml_help( void ) +{ + const CmdOptDesc* pos; + CmdOptDesc localPos; + + printf( "\n" + "\n", tidyLibraryVersion()); + + for( pos=cmdopt_defs; pos->name1; ++pos) + { + localPos = *pos; + localize_option_names(&localPos); + printf(" \n"); + + if (localPos.name1) free((tmbstr)localPos.name1); + if (localPos.name2) free((tmbstr)localPos.name2); + if (localPos.name3) free((tmbstr)localPos.name3); + } + + printf( "\n" ); +} -/** - ** Handles the -xml-strings service. - ** This service was primarily helpful to developers and localizers to - ** compare localized strings to the built in `en` strings. It's probably - ** better to use our POT/PO workflow with your favorite tools, or simply - ** diff the language header files directly. - ** **Important:** The attribute `id` is not a specification, promise, or - ** part of an API. You must not depend on this value. For strings meant - ** for error output, the `label` attribute will contain the stringified - ** version of the internal key for the string. +/** @} end service_xmlhelp group */ +/* MARK: - Provide the -xml-options-strings Service */ +/***************************************************************************//** + ** @defgroup service_xml_opts_strings Provide the -xml-options-strings Service + ******************************************************************************* + ** @{ + */ + + +/** Handles printing of option description for -xml-options-strings service. + **/ +static void printXMLOptionString(TidyDoc tdoc, /**< The Tidy document. */ + TidyOption topt, /**< The option. */ + OptionDesc *d /**< The OptionDesc array. */ + ) +{ + if ( tidyOptGetCategory(topt) == TidyInternalCategory ) + return; + + printf( " \n" ); +} + + +/** Handles the -xml-options-strings service. + ** This service is primarily helpful to developers and localizers to test + ** that option description strings as represented on screen output are + ** correct and do not break tidy. + ** @param tdoc The Tidy document. + */ +static void xml_options_strings( TidyDoc tdoc ) +{ + printf( "\n" + "\n", tidyLibraryVersion()); + ForEachOption( tdoc, printXMLOptionString); + printf( "\n" ); +} + + +/** @} end service_xml_opts_strings group */ +/* MARK: - Provide the -xml-strings Service */ +/***************************************************************************//** + ** @defgroup service_xml_strings Provide the -xml-strings Service + ******************************************************************************* + ** @{ + */ + + +/** Handles the -xml-strings service. + ** This service was primarily helpful to developers and localizers to compare + ** localized strings to the built in `en` strings. It's probably better to use + ** our POT/PO workflow with your favorite tools, or simply diff the language + ** header files directly. + ** @note The attribute `id` is not a specification, promise, or part of an + ** API. You must not depend on this value. For strings meant for error + ** output, the `label` attribute will contain the stringified version of + ** the internal key for the string. */ static void xml_strings( void ) { @@ -1530,39 +1813,26 @@ static void xml_strings( void ) } -/** - ** Handles the -lang help service. +/** @} end service_xml_strings group */ +/* MARK: - Experimental Stuff */ +/***************************************************************************//** + ** @defgroup experimental_stuff Experimental Stuff + ** From time to time the developers might leave stuff here that you can use + ** to experiment on their own, or that they're using to experiment with. + ******************************************************************************* + ** @{ */ -static void lang_help( void ) -{ - printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_1) ); - tidyPrintWindowsLanguageNames(" %-20s -> %s\n"); - printf( "%s", tidyLocalizedString(TC_TXT_HELP_LANG_2) ); - tidyPrintTidyLanguageNames(" %s\n"); - printf( tidyLocalizedString(TC_TXT_HELP_LANG_3), tidyGetLanguage() ); -} -/** - ** Provides the `unknown option` output. - */ -static void unknownOption( uint c ) -{ - fprintf( errout, tidyLocalizedString( TC_STRING_UNKNOWN_OPTION ), (char)c ); - fprintf( errout, "\n"); -} - - -/** - ** This callback from LibTidy allows the console application to examine an - ** error message before allowing LibTidy to display it. Currently the body - ** of the function is not compiled into Tidy, but if you're interested in - ** how to use the new message API, then enable it. Possible applications in - ** future console Tidy might be to do things like: - ** - allow user-defined filtering - ** - sort the report output by line number - ** - other things that are user facing and best not put into LibTidy - ** proper. +/** This callback from LibTidy allows the console application to examine an + ** error message before allowing LibTidy to display it. Currently the body + ** of the function is not compiled into Tidy, but if you're interested in + ** how to use the new message API, then enable it. Possible applications in + ** future console Tidy might be to do things like: + ** - allow user-defined filtering + ** - sort the report output by line number + ** - other things that are user facing and best not put into LibTidy + ** proper. */ static Bool TIDY_CALL reportCallback(TidyMessage tmessage) { @@ -1613,10 +1883,16 @@ static Bool TIDY_CALL reportCallback(TidyMessage tmessage) } - -/** - ** MAIN -- let's do something here. +/** @} end experimental_stuff group */ +/* MARK: - main() */ +/***************************************************************************//** + ** @defgroup main Main + ** Let's do something here! + ******************************************************************************* + ** @{ */ + + int main( int argc, char** argv ) { ctmbstr prog = argv[0]; @@ -1624,7 +1900,7 @@ int main( int argc, char** argv ) TidyDoc tdoc = tidyCreate(); int status = 0; tmbstr locale = NULL; - tidySetMessageCallback( tdoc, reportCallback); + tidySetMessageCallback( tdoc, reportCallback); /* experimental group */ uint contentErrors = 0; uint contentWarnings = 0; @@ -1634,8 +1910,10 @@ int main( int argc, char** argv ) /* Set an atexit handler. */ atexit( tidy_cleanup ); - + + /*************************************/ /* Set the locale for tidy's output. */ + /*************************************/ locale = tidySystemLocale(locale); tidySetLanguage(locale); if ( locale ) @@ -1651,6 +1929,7 @@ int main( int argc, char** argv ) SetConsoleOutputCP(CP_UTF8); #endif + #if !defined(NDEBUG) && defined(_MSC_VER) set_log_file((char *)"temptidy.txt", 0); /* add_append_log(1); */ @@ -1784,7 +2063,7 @@ int main( int argc, char** argv ) { if ( strcasecmp(argv[2], "help") == 0 ) { - lang_help(); + lang_help( tdoc ); exit(0); } if ( !tidySetLanguage( argv[2] ) ) @@ -1805,7 +2084,7 @@ int main( int argc, char** argv ) strcasecmp(arg, "-help") == 0 || strcasecmp(arg, "h") == 0 || *arg == '?' ) { - help( prog ); + help( tdoc, prog ); tidyRelease( tdoc ); return 0; /* success */ } @@ -1928,7 +2207,7 @@ int main( int argc, char** argv ) strcasecmp(arg, "-version") == 0 || strcasecmp(arg, "v") == 0 ) { - version(); + version( tdoc ); tidyRelease( tdoc ); return 0; /* success */ @@ -2021,7 +2300,7 @@ int main( int argc, char** argv ) break; default: - unknownOption( c ); + unknownOption( tdoc, c ); break; } } @@ -2032,6 +2311,7 @@ int main( int argc, char** argv ) continue; } + if ( argc > 1 ) { htmlfil = argv[1]; @@ -2134,6 +2414,11 @@ int main( int argc, char** argv ) return 0; } + +/** @} end main group */ +/** @} end console_application group */ + + /* * local variables: * mode: c From 24afc6a6fad2cba04fab88448b2305a1584fdbb8 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Tue, 4 Apr 2017 14:32:29 -0400 Subject: [PATCH 2/2] Fixed some casting issues that Ubuntu object to. - Test on macOS, Win10, Ubuntu. - No version bump for this change. --- src/messageobj.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/messageobj.c b/src/messageobj.c index b9c8df7..3156356 100644 --- a/src/messageobj.c +++ b/src/messageobj.c @@ -384,7 +384,7 @@ TidyMessageArgument TY_(getNextMessageArgument)( TidyMessageImpl message, TidyIt TidyFormatParameterType TY_(getArgType)( TidyMessageImpl message, TidyMessageArgument* arg ) { - int argNum = (int)*arg; + int argNum = (int)(size_t)*arg; assert( argNum <= message.argcount ); return message.arguments[argNum].type; @@ -393,7 +393,7 @@ TidyFormatParameterType TY_(getArgType)( TidyMessageImpl message, TidyMessageArg ctmbstr TY_(getArgFormat)( TidyMessageImpl message, TidyMessageArgument* arg ) { - int argNum = (int)*arg; + int argNum = (int)(size_t)*arg; assert( argNum <= message.argcount ); return message.arguments[argNum].format; @@ -402,7 +402,7 @@ ctmbstr TY_(getArgFormat)( TidyMessageImpl message, TidyMessageArgument* arg ) ctmbstr TY_(getArgValueString)( TidyMessageImpl message, TidyMessageArgument* arg ) { - int argNum = (int)*arg; + int argNum = (int)(size_t)*arg; assert( argNum <= message.argcount ); assert( message.arguments[argNum].type == tidyFormatType_STRING); @@ -412,7 +412,7 @@ ctmbstr TY_(getArgValueString)( TidyMessageImpl message, TidyMessageArgument* ar uint TY_(getArgValueUInt)( TidyMessageImpl message, TidyMessageArgument* arg ) { - int argNum = (int)*arg; + int argNum = (int)(size_t)*arg; assert( argNum <= message.argcount ); assert( message.arguments[argNum].type == tidyFormatType_UINT); @@ -422,7 +422,7 @@ uint TY_(getArgValueUInt)( TidyMessageImpl message, TidyMessageArgument* arg ) int TY_(getArgValueInt)( TidyMessageImpl message, TidyMessageArgument* arg ) { - int argNum = (int)*arg; + int argNum = (int)(size_t)*arg; assert( argNum <= message.argcount ); assert( message.arguments[argNum].type == tidyFormatType_INT); @@ -432,7 +432,7 @@ int TY_(getArgValueInt)( TidyMessageImpl message, TidyMessageArgument* arg ) double TY_(getArgValueDouble)( TidyMessageImpl message, TidyMessageArgument* arg ) { - int argNum = (int)*arg; + int argNum = (int)(size_t)*arg; assert( argNum <= message.argcount ); assert( message.arguments[argNum].type == tidyFormatType_DOUBLE);