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.
*/
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];
} AllOption_t;
@ -723,8 +727,7 @@ static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption )
tOption->topt[i] = NULL; /* sentinel */
qsort(tOption->topt,
/* Do not sort the sentinel: hence `-1' */
sizeof(tOption->topt)/sizeof(tOption->topt[0])-1,
i, /* there are i items, not including the sentinal */
sizeof(tOption->topt[0]),
cmpOpt);
}
@ -853,11 +856,11 @@ static void printXMLCrossRefEqConsole( TidyDoc tdoc, TidyOption topt )
{
localHit = *hit;
localize_option_names( &localHit );
printf(" <eqconsole>%s</eqconsole>\n", localHit.name1);
printf(" <eqconsole>%s</eqconsole>\n", get_escaped_name(localHit.name1));
if ( localHit.name2 )
printf(" <eqconsole>%s</eqconsole>\n", localHit.name2);
printf(" <eqconsole>%s</eqconsole>\n", get_escaped_name(localHit.name2));
if ( localHit.name3 )
printf(" <eqconsole>%s</eqconsole>\n", localHit.name3);
printf(" <eqconsole>%s</eqconsole>\n", get_escaped_name(localHit.name3));
}
else
@ -1318,13 +1321,16 @@ EXIT_CLEANLY:
static void optionDescribe( TidyDoc tdoc, char *tag )
{
tmbstr result = NULL;
Bool allocated = no;
TidyOptionId topt;
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 ) ) );
allocated = yes;
}
else
{
@ -1335,7 +1341,7 @@ static void optionDescribe( TidyDoc tdoc, char *tag )
printf( "`--%s`\n\n", tag );
print1Column( "%-68.68s\n", 68, result );
printf( "\n" );
if ( (topt < N_TIDY_OPTIONS) && ( result ) )
if ( allocated )
free ( result );
}

View file

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

View file

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