This commit is contained in:
Jim Derry 2017-03-09 16:04:03 -05:00
parent b0bd27e9c1
commit ac242e9ea4
3 changed files with 32 additions and 23 deletions

View file

@ -693,6 +693,10 @@ 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 { typedef struct {
/* Some options aren't exposed in the API although they're available
in the enum. This struct is guaranteed to hold *all* Tidy options,
but be sure to use the public API iterators to access them!
*/
TidyOption topt[N_TIDY_OPTIONS]; TidyOption topt[N_TIDY_OPTIONS];
} AllOption_t; } AllOption_t;
@ -723,8 +727,7 @@ static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption )
tOption->topt[i] = NULL; /* sentinel */ tOption->topt[i] = NULL; /* sentinel */
qsort(tOption->topt, qsort(tOption->topt,
/* Do not sort the sentinel: hence `-1' */ i, /* there are i items, not including the sentinal */
sizeof(tOption->topt)/sizeof(tOption->topt[0])-1,
sizeof(tOption->topt[0]), sizeof(tOption->topt[0]),
cmpOpt); cmpOpt);
} }
@ -853,11 +856,11 @@ static void printXMLCrossRefEqConsole( TidyDoc tdoc, TidyOption topt )
{ {
localHit = *hit; localHit = *hit;
localize_option_names( &localHit ); localize_option_names( &localHit );
printf(" <eqconsole>%s</eqconsole>\n", localHit.name1); printf(" <eqconsole>%s</eqconsole>\n", get_escaped_name(localHit.name1));
if ( localHit.name2 ) if ( localHit.name2 )
printf(" <eqconsole>%s</eqconsole>\n", localHit.name2); printf(" <eqconsole>%s</eqconsole>\n", get_escaped_name(localHit.name2));
if ( localHit.name3 ) if ( localHit.name3 )
printf(" <eqconsole>%s</eqconsole>\n", localHit.name3); printf(" <eqconsole>%s</eqconsole>\n", get_escaped_name(localHit.name3));
} }
else else
@ -1318,13 +1321,16 @@ EXIT_CLEANLY:
static void optionDescribe( TidyDoc tdoc, char *tag ) static void optionDescribe( TidyDoc tdoc, char *tag )
{ {
tmbstr result = NULL; tmbstr result = NULL;
Bool allocated = no;
TidyOptionId topt; TidyOptionId topt;
topt = tidyOptGetIdForName( tag ); topt = tidyOptGetIdForName( tag );
if (topt < N_TIDY_OPTIONS) if (topt < N_TIDY_OPTIONS && ( tidyOptGetCategory( tidyGetOption(tdoc, topt)) != TidyInternalCategory ) )
{ {
result = cleanup_description( tidyOptGetDoc( tdoc, tidyGetOption( tdoc, topt ) ) ); result = cleanup_description( tidyOptGetDoc( tdoc, tidyGetOption( tdoc, topt ) ) );
allocated = yes;
} }
else else
{ {
@ -1335,7 +1341,7 @@ static void optionDescribe( TidyDoc tdoc, char *tag )
printf( "`--%s`\n\n", tag ); printf( "`--%s`\n\n", tag );
print1Column( "%-68.68s\n", 68, result ); print1Column( "%-68.68s\n", 68, result );
printf( "\n" ); printf( "\n" );
if ( (topt < N_TIDY_OPTIONS) && ( result ) ) if ( allocated )
free ( result ); free ( result );
} }

View file

@ -44,7 +44,8 @@ typedef enum
TidyDiagnostics, /**< Diagnostics */ TidyDiagnostics, /**< Diagnostics */
TidyPrettyPrint, /**< Output layout */ TidyPrettyPrint, /**< Output layout */
TidyEncoding, /**< Character encodings */ TidyEncoding, /**< Character encodings */
TidyMiscellaneous /**< File handling, message format, etc. */ TidyMiscellaneous, /**< File handling, message format, etc. */
TidyInternalCategory /**< Option is internal only. */
} TidyConfigCategory; } TidyConfigCategory;

View file

@ -148,6 +148,7 @@ static const ctmbstr sorterPicks[] =
#define PP TidyPrettyPrint #define PP TidyPrettyPrint
#define CE TidyEncoding #define CE TidyEncoding
#define MS TidyMiscellaneous #define MS TidyMiscellaneous
#define IR TidyInternalCategory
#define IN TidyInteger #define IN TidyInteger
#define BL TidyBoolean #define BL TidyBoolean
@ -216,8 +217,8 @@ static ParseProperty ParseTabs;
static const TidyOptionImpl option_defs[] = static const TidyOptionImpl option_defs[] =
{ {
{ TidyUnknownOption, MS, "unknown!", IN, 0, NULL, NULL }, { TidyUnknownOption, MS, "unknown!", IN, 0, NULL, NULL },
{ TidyDoctypeMode, MU, "doctype-mode", IN, TidyDoctypeAuto, NULL, doctypePicks }, { TidyDoctypeMode, IR, "doctype-mode", IN, TidyDoctypeAuto, NULL, doctypePicks },
{ TidyEmacsFile, MS, "gnu-emacs-file", ST, 0, ParseString, NULL }, { TidyEmacsFile, IR, "gnu-emacs-file", ST, 0, ParseString, NULL },
{ TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL }, { TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL },
{ TidyWrapLen, PP, "wrap", IN, 68, ParseInt, NULL }, { TidyWrapLen, PP, "wrap", IN, 68, ParseInt, NULL },
{ TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL }, { TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL },
@ -1595,20 +1596,21 @@ TidyIterator TY_(getOptionList)( TidyDocImpl* ARG_UNUSED(doc) )
const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* ARG_UNUSED(doc), const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* ARG_UNUSED(doc),
TidyIterator* iter ) TidyIterator* iter )
{ {
const TidyOptionImpl* option = NULL; const TidyOptionImpl* option = NULL;
size_t optId; size_t optId;
assert( iter != NULL ); assert( iter != NULL );
optId = (size_t) *iter; optId = (size_t) *iter;
if ( optId > TidyUnknownOption && optId < N_TIDY_OPTIONS ) if ( optId > TidyUnknownOption && optId < N_TIDY_OPTIONS )
{ {
option = &option_defs[ optId ]; /* Hide these internal options from the API entirely. */
optId++; while ( tidyOptGetCategory( tidyGetOption(NULL, optId) ) == TidyInternalCategory )
/* Hide these internal options from the API entirely. */ optId++;
if ( optId == TidyEmacsFile || optId == TidyDoctypeMode )
option = &option_defs[ optId ];
optId++; optId++;
} }
*iter = (TidyIterator) ( optId < N_TIDY_OPTIONS ? optId : (size_t)0 ); *iter = (TidyIterator) ( optId < N_TIDY_OPTIONS ? optId : (size_t)0 );
return option; return option;
} }
/* Use a 1-based array index as iterator: 0 == end-of-list /* Use a 1-based array index as iterator: 0 == end-of-list