Added some internal structures and code to support the removal of config

options in the future, with full user notification. Right now this code is
dead, because no options have been removed. No version bump.
This commit is contained in:
Jim Derry 2017-10-07 16:11:51 -04:00
parent 217d05fe49
commit b31dd6fcc2
2 changed files with 281 additions and 99 deletions

View File

@ -29,24 +29,15 @@
#endif
void TY_(InitConfig)( TidyDocImpl* doc )
{
TidyClearMemory( &doc->config, sizeof(TidyConfigImpl) );
TY_(ResetConfigToDefault)( doc );
}
/*****************************************************************************
** Picklist Configuration
**
** Arrange so index can be cast to enum. Note that the value field in the
** following structures is not currently used in code; they're present for
** documentation purposes currently. The arrays must be populated in enum
** order.
******************************************************************************/
void TY_(FreeConfig)( TidyDocImpl* doc )
{
TY_(ResetConfigToDefault)( doc );
TY_(TakeConfigSnapshot)( doc );
}
/*
Arrange so index can be cast to enum. Note that the value field in the
following structures is not currently used in code; they're present for
documentation purposes currently. The arrays must be populated in enum order.
*/
static PickListItems boolPicks = {
{ "no", TidyNoState, { "0", "n", "f", "no", "false", NULL } },
{ "yes", TidyYesState, { "1", "y", "t", "yes", "true", NULL } },
@ -134,6 +125,10 @@ static PickListItems attributeCasePicks = {
};
/*****************************************************************************
** Option Configuration
******************************************************************************/
#define DG TidyDiagnostics
#define DD TidyDisplay
#define DT TidyDocumentIO
@ -156,43 +151,21 @@ static PickListItems attributeCasePicks = {
#define DLF DEFAULT_NL_CONFIG
static void AdjustConfig( TidyDocImpl* doc );
/* parser for integer values */
/* forward declarations */
static ParseProperty ParseInt;
/* a space or comma separated list */
static ParseProperty ParseList;
/* a string excluding whitespace */
static ParseProperty ParseName;
/* a CSS1 selector - CSS class naming for -clean option */
static ParseProperty ParseCSS1Selector;
/* a string including whitespace */
static ParseProperty ParseString;
/* a space or comma separated list of tag names */
static ParseProperty ParseTagNames;
/* RAW, ASCII, LATIN0, LATIN1, UTF8, ISO2022, MACROMAN,
WIN1252, IBM858, UTF16LE, UTF16BE, UTF16, BIG5, SHIFTJIS
*/
static ParseProperty ParseCharEnc;
/* html5 | omit | auto | strict | loose | <fpi> */
static ParseProperty ParseDocType;
/* 20150515 - support using tabs instead of spaces - Issue #108
*/
static ParseProperty ParseTabs;
/* General parser for options having picklists */
static ParseProperty ParsePickList;
/*****************************************************************/
/* Ensure struct order is same order as tidyenum.h:TidyOptionId! */
/*****************************************************************/
static const TidyOptionImpl option_defs[] =
{
{ TidyUnknownOption, IR, "unknown!", IN, 0, NULL, NULL },
@ -303,21 +276,49 @@ static const TidyOptionImpl option_defs[] =
};
/* Deleted options. This array keeps track of options that have been
** removed from Tidy, and suggests a replacement. When a deleted option is
** used, client programs will have the opportunity to consume the option
** first via the callback, and if not handled by the callback, will be
** handled by Tidy, generally by setting an alternate or new option.
*/
/*****************************************************************************
** Deleted Options Configuration
**
** Keep track of options that have been removed from Tidy, so that we can
** suggests a replacement. When a deleted option is used, client programs
** will have the opportunity to consume the option first via the callback,
** and if not handled by the callback, will be handled by Tidy, generally
** by setting an alternate or new option, in `subDeprecatedOption()`.
******************************************************************************/
static const struct {
ctmbstr name; /**< name of the deprecated option */
TidyOptionId replacementId; /**< Id of the replacement option, or 0 if none. */
} deprecatedOptions[] = {
// { "show-body-only", TidyBodyOnly }, /* WIP, for development purposes! */
// { "show-body-only", TidyBodyOnly },
{ NULL }
};
/*****************************************************************************
** Supporting Functions
******************************************************************************/
/* forward declarations */
static void AdjustConfig( TidyDocImpl* doc );
static Bool GetPickListValue();
void TY_(InitConfig)( TidyDocImpl* doc )
{
TidyClearMemory( &doc->config, sizeof(TidyConfigImpl) );
TY_(ResetConfigToDefault)( doc );
}
void TY_(FreeConfig)( TidyDocImpl* doc )
{
TY_(ResetConfigToDefault)( doc );
TY_(TakeConfigSnapshot)( doc );
}
/* Should only be called by options set by name
** thus, it is cheaper to do a few scans than set
** up every option in a hash table.
@ -381,6 +382,7 @@ static Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val )
return status;
}
Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val )
{
Bool status = ( optId < N_TIDY_OPTIONS );
@ -392,6 +394,7 @@ Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val )
return status;
}
Bool TY_(SetOptionBool)( TidyDocImpl* doc, TidyOptionId optId, Bool val )
{
Bool status = ( optId < N_TIDY_OPTIONS );
@ -420,6 +423,7 @@ static Bool OptionValueEqDefault( const TidyOptionImpl* option,
val->v == option->dflt;
}
Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId )
{
Bool status = ( optId > 0 && optId < N_TIDY_OPTIONS );
@ -435,6 +439,7 @@ Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId )
return status;
}
static void ReparseTagType( TidyDocImpl* doc, TidyOptionId optId )
{
ctmbstr tagdecl = cfgStr( doc, optId );
@ -443,6 +448,7 @@ static void ReparseTagType( TidyDocImpl* doc, TidyOptionId optId )
TidyDocFree( doc, dupdecl );
}
static Bool OptionValueIdentical( const TidyOptionImpl* option,
const TidyOptionValue* val1,
const TidyOptionValue* val2 )
@ -459,6 +465,7 @@ static Bool OptionValueIdentical( const TidyOptionImpl* option,
return val1->v == val2->v;
}
static Bool NeedReparseTagDecls( TidyDocImpl* doc,
const TidyOptionValue* current,
const TidyOptionValue* new,
@ -493,6 +500,7 @@ static Bool NeedReparseTagDecls( TidyDocImpl* doc,
return ret;
}
static void ReparseTagDecls( TidyDocImpl* doc, uint changedUserTags )
{
#define REPARSE_USERTAGS(USERTAGOPTION,USERTAGTYPE) \
@ -534,8 +542,6 @@ static Bool isOptionDeprecated( ctmbstr optName )
return getOptionReplacement( optName ) != N_TIDY_OPTIONS;
}
/* Forward declaration */
Bool GetPickListValue();
/* Aubstitute the new option for the deprecated one. */
static Bool subDeprecatedOption( TidyDocImpl* doc, ctmbstr oldName, ctmbstr oldValue)
@ -544,6 +550,8 @@ static Bool subDeprecatedOption( TidyDocImpl* doc, ctmbstr oldName, ctmbstr oldV
ctmbstr newName = TY_(getOption)( newOptId )->name;
TidyDoc tdoc = tidyImplToDoc( doc );
assert( isOptionDeprecated(oldName));
if ( newOptId == TidyUnknownOption )
{
TY_(Report)( doc, NULL, NULL, OPTION_REMOVED, oldName );
@ -557,29 +565,28 @@ static Bool subDeprecatedOption( TidyDocImpl* doc, ctmbstr oldName, ctmbstr oldV
{
uint value;
/* `show-body-only` used to use the boolPicks */
if ( GetPickListValue( oldValue, boolPicks, &value ) )
/* `show-body-only` used to use the autoBoolPicks */
if ( GetPickListValue( oldValue, autoBoolPicks, &value ) )
{
if ( value == TidyNoState )
{
TY_(SetOptionInt)( doc, newOptId, value );
TY_(Report)( doc, NULL, NULL, OPTION_REMOVED_UNAPPLIED, oldName, newName );
TY_(SetOptionBool)( doc, newOptId, value );
}
else
{
TY_(SetOptionBool)( doc, newOptId, value );
TY_(SetOptionInt)( doc, newOptId, value );
ctmbstr val = tidyOptGetCurrPick( tdoc, newOptId );
TY_(Report)( doc, NULL, NULL, OPTION_REMOVED_APPLIED, oldName, newName, val );
}
}
else
{
printf("-->Report bad argument %s\n", oldValue);
TY_(ReportBadArgument)(doc, oldName);
}
return yes;
}
return no;
}
@ -599,6 +606,7 @@ void TY_(ResetConfigToDefault)( TidyDocImpl* doc )
TY_(FreeDeclaredTags)( doc, tagtype_null );
}
void TY_(TakeConfigSnapshot)( TidyDocImpl* doc )
{
uint ixVal;
@ -614,6 +622,7 @@ void TY_(TakeConfigSnapshot)( TidyDocImpl* doc )
}
}
void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc )
{
uint ixVal;
@ -633,6 +642,7 @@ void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc )
ReparseTagDecls( doc, changedUserTags );
}
void TY_(CopyConfig)( TidyDocImpl* docTo, TidyDocImpl* docFrom )
{
if ( docTo != docFrom )
@ -703,12 +713,14 @@ static tchar GetC( TidyConfigImpl* config )
return EndOfStream;
}
static tchar FirstChar( TidyConfigImpl* config )
{
config->c = GetC( config );
return config->c;
}
static tchar AdvanceChar( TidyConfigImpl* config )
{
if ( config->c != EndOfStream )
@ -716,6 +728,7 @@ static tchar AdvanceChar( TidyConfigImpl* config )
return config->c;
}
static tchar SkipWhite( TidyConfigImpl* config )
{
while ( TY_(IsWhite)(config->c) && !TY_(IsNewline)(config->c) )
@ -723,23 +736,8 @@ static tchar SkipWhite( TidyConfigImpl* config )
return config->c;
}
/* skip until end of line
static tchar SkipToEndofLine( TidyConfigImpl* config )
{
while ( config->c != EndOfStream )
{
config->c = GetC( config );
if ( config->c == '\n' || config->c == '\r' )
break;
}
return config->c;
}
*/
/*
skip over line continuations
to start of next property
*/
/* skip over line continuations to start of next property */
static uint NextProperty( TidyConfigImpl* config )
{
do
@ -760,13 +758,12 @@ static uint NextProperty( TidyConfigImpl* config )
return config->c;
}
/*
Todd Lewis contributed this code for expanding
~/foo or ~your/foo according to $HOME and your
user name. This will work partially on any system
which defines $HOME. Support for ~user/foo will
work on systems that support getpwnam(userid),
namely Unix/Linux.
Todd Lewis contributed this code for expanding ~/foo or ~your/foo according
to $HOME and your user name. This will work partially on any system which
defines $HOME. Support for ~user/foo will work on systems that support
getpwnam(userid), namely Unix/Linux.
*/
static ctmbstr ExpandTilde( TidyDocImpl* doc, ctmbstr filename )
{
@ -823,6 +820,7 @@ static ctmbstr ExpandTilde( TidyDocImpl* doc, ctmbstr filename )
return (ctmbstr) filename;
}
Bool TIDY_CALL tidyFileExists( TidyDoc tdoc, ctmbstr filename )
{
TidyDocImpl* doc = tidyDocToImpl( tdoc );
@ -965,6 +963,7 @@ int TY_(ParseConfigFileEnc)( TidyDocImpl* doc, ctmbstr file, ctmbstr charenc )
return (doc->optionErrors > opterrs ? 1 : 0);
}
/* returns false if unknown option, missing parameter,
** or option doesn't use parameter
*/
@ -992,6 +991,7 @@ Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optval )
return status;
}
/* returns false if unknown option, missing parameter,
** or option doesn't use parameter
*/
@ -1095,6 +1095,7 @@ Bool TY_(AdjustCharEncoding)( TidyDocImpl* doc, int encoding )
return no;
}
/* ensure that config is self consistent */
void AdjustConfig( TidyDocImpl* doc )
{
@ -1187,6 +1188,7 @@ void TY_(DeclarePriorityAttrib)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr n
TidyDocFree( doc, catval );
}
/* a space or comma separated list of attribute names */
Bool ParseList( TidyDocImpl* doc, const TidyOptionImpl* option )
{
@ -1285,6 +1287,7 @@ Bool ParseInt( TidyDocImpl* doc, const TidyOptionImpl* entry )
return digits;
}
/* a string excluding whitespace */
Bool FUNC_UNUSED ParseName( TidyDocImpl* doc, const TidyOptionImpl* option )
{
@ -1306,6 +1309,7 @@ Bool FUNC_UNUSED ParseName( TidyDocImpl* doc, const TidyOptionImpl* option )
return ( i > 0 );
}
/* #508936 - CSS class naming for -clean option */
Bool ParseCSS1Selector( TidyDocImpl* doc, const TidyOptionImpl* option )
{
@ -1338,7 +1342,7 @@ Bool ParseCSS1Selector( TidyDocImpl* doc, const TidyOptionImpl* option )
/* Given a string, return the picklist value from an arbitrary picklist. */
Bool GetPickListValue( ctmbstr value, PickListItems* pickList, uint *result )
static Bool GetPickListValue( ctmbstr value, PickListItems* pickList, uint *result )
{
const PickListItem *item = NULL;
uint ix = 0;
@ -1367,7 +1371,7 @@ Bool GetPickListValue( ctmbstr value, PickListItems* pickList, uint *result )
determine the proper option value, and can be used by parsers in addition to
ParsePickList that require special handling.
*/
Bool GetParsePickListValue( TidyDocImpl* doc, const TidyOptionImpl* entry, uint *result )
static Bool GetParsePickListValue( TidyDocImpl* doc, const TidyOptionImpl* entry, uint *result )
{
TidyConfigImpl* cfg = &doc->config;
tchar c = SkipWhite( cfg );
@ -1455,6 +1459,7 @@ void TY_(DeclareUserTag)( TidyDocImpl* doc, TidyOptionId optId,
TidyDocFree( doc, catval );
}
/* a space or comma separated list of tag names */
Bool ParseTagNames( TidyDocImpl* doc, const TidyOptionImpl* option )
{
@ -1586,6 +1591,7 @@ Bool ParseString( TidyDocImpl* doc, const TidyOptionImpl* option )
return yes;
}
Bool ParseCharEnc( TidyDocImpl* doc, const TidyOptionImpl* option )
{
tmbchar buf[64] = {0};
@ -1623,6 +1629,7 @@ int TY_(CharEncodingId)( TidyDocImpl* ARG_UNUSED(doc), ctmbstr charenc )
return enc;
}
ctmbstr TY_(CharEncodingName)( int encoding )
{
ctmbstr encodingName = TY_(GetEncodingNameFromTidyId)(encoding);
@ -1633,6 +1640,7 @@ ctmbstr TY_(CharEncodingName)( int encoding )
return encodingName;
}
ctmbstr TY_(CharEncodingOptName)( int encoding )
{
ctmbstr encodingName = TY_(GetEncodingOptNameFromTidyId)(encoding);
@ -1643,6 +1651,7 @@ ctmbstr TY_(CharEncodingOptName)( int encoding )
return encodingName;
}
/*
doctype: html5 | omit | auto | strict | loose | <fpi>
@ -1681,6 +1690,7 @@ Bool ParseDocType( TidyDocImpl* doc, const TidyOptionImpl* option )
return status;
}
/* Use TidyOptionId as iterator.
** Send index of 1st option after TidyOptionUnknown as start of list.
*/
@ -1689,6 +1699,7 @@ TidyIterator TY_(getOptionList)( TidyDocImpl* ARG_UNUSED(doc) )
return (TidyIterator) (size_t)1;
}
/* Check if this item is last valid option.
** If so, zero out iterator.
*/
@ -1708,6 +1719,7 @@ const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* ARG_UNUSED(doc),
return option;
}
/* Use a 1-based array index as iterator: 0 == end-of-list
*/
TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option )
@ -1718,6 +1730,7 @@ TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option )
return (TidyIterator) ix;
}
ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option,
TidyIterator* iter )
{
@ -1742,6 +1755,7 @@ ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option,
return val;
}
static int WriteOptionString( const TidyOptionImpl* option,
ctmbstr sval, StreamOut* out )
{
@ -1757,6 +1771,7 @@ static int WriteOptionString( const TidyOptionImpl* option,
return 0;
}
static int WriteOptionInt( const TidyOptionImpl* option, uint ival, StreamOut* out )
{
tmbchar sval[ 32 ] = {0};
@ -1764,12 +1779,14 @@ static int WriteOptionInt( const TidyOptionImpl* option, uint ival, StreamOut*
return WriteOptionString( option, sval, out );
}
static int WriteOptionBool( const TidyOptionImpl* option, Bool bval, StreamOut* out )
{
ctmbstr sval = bval ? "yes" : "no";
return WriteOptionString( option, sval, out );
}
static int WriteOptionPick( const TidyOptionImpl* option, uint ival, StreamOut* out )
{
uint ix = 0;
@ -1788,6 +1805,7 @@ static int WriteOptionPick( const TidyOptionImpl* option, uint ival, StreamOut*
return -1;
}
Bool TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc )
{
int diff = memcmp( &doc->config.value, &doc->config.snapshot,
@ -1795,6 +1813,7 @@ Bool TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc )
return ( diff != 0 );
}
Bool TY_(ConfigDiffThanDefault)( TidyDocImpl* doc )
{
Bool diff = no;
@ -1865,6 +1884,7 @@ static int SaveConfigToStream( TidyDocImpl* doc, StreamOut* out )
return rc;
}
int TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil )
{
int status = -1;
@ -1882,6 +1902,7 @@ int TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil )
return status;
}
int TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink )
{
uint outenc = cfg( doc, TidyOutCharEncoding );
@ -1892,11 +1913,3 @@ int TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink )
return status;
}
/*
* local variables:
* mode: c
* indent-tabs-mode: nil
* c-basic-offset: 4
* eval: (c-set-offset 'substatement-open 0)
* end:
*/

View File

@ -57,6 +57,7 @@
*/
#define TIDY_PL_SIZE 16
/** Structs of this type contain information needed in order to present
** picklists, relate picklist entries to public enum values, and parse
** strings that are accepted in order to assign the value.
@ -67,6 +68,7 @@ typedef struct PickListItem {
ctmbstr inputs[10]; /**< String values that can select this value. */
} PickListItem;
/** An array of PickListItems, fixed in size for in-code declarations.
** Arrays must be populated in 0 to 10 order, as the option value is assigned
** based on this index and *not* on the structures' value field. It remains
@ -93,11 +95,11 @@ typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt );
*/
struct _tidy_option
{
TidyOptionId id;
TidyOptionId id; /**< The unique identifier for this option. */
TidyConfigCategory category; /**< The category of the option. */
ctmbstr name; /**< The name of the option. */
TidyOptionType type; /**< The date type for the option. */
ulong dflt; /**< Dfeault value for TidyInteger and TidyBoolean */
ulong dflt; /**< Default value for TidyInteger and TidyBoolean */
ParseProperty* parser; /**< Function to parse input; read-only if NULL. */
PickListItems* pickList; /**< The picklist of possible values for this option. */
ctmbstr pdflt; /**< Default value for TidyString. */
@ -108,10 +110,11 @@ struct _tidy_option
*/
typedef union
{
ulong v; /* Value for TidyInteger and TidyBoolean */
char *p; /* Value for TidyString */
ulong v; /**< Value for TidyInteger and TidyBoolean */
char *p; /**< Value for TidyString */
} TidyOptionValue;
/** This type is used to define a structure for keeping track of the values
** for each option.
*/
@ -134,77 +137,235 @@ typedef struct {
/** Given an option name, return an instance of an option.
** @param optnam The option name to retrieve.
** @returns The instance of the requested option.
*/
const TidyOptionImpl* TY_(lookupOption)( ctmbstr optnam );
/** Given an option ID, return an instance of an option.
** @param optId The option ID to retrieve.
** @returns The instance of the requested option.
*/
const TidyOptionImpl* TY_(getOption)( TidyOptionId optId );
/** Initiates an iterator to cycle through all of the available options.
** @param doc The Tidy document to get options.
** @returns An iterator token to be used with TY_(getNextOption)().
*/
TidyIterator TY_(getOptionList)( TidyDocImpl* doc );
/** Gets the next option provided by the iterator.
** @param doc The Tidy document to get options.
** @param iter The iterator token initialized by TY_(getOptionList)().
** @returns The instance of the next option.
*/
const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* doc, TidyIterator* iter );
/** Initiates an iterator to cycle through all of the available picklist
** possibilities.
** @param option An instance of an option for which to iterate a picklist.
** @returns An interator token to be used with TY_(getNextOptionPick)().
*/
TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option );
/** Gets the next picklist possibility provided by the iterator.
** @param option The instance of the option for which to iterate a picklist.
** @param iter The iterator token initialized by TY_(getOptionPickList)().
** @returns The next picklist entry.
*/
ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option, TidyIterator* iter );
#if SUPPORT_CONSOLE_APP
/** Returns the cross-reference information structure for optID, which is
** used for generating documentation.
** @param optId The option ID to get cross-reference information for.
** @returns Cross reference information.
*/
const TidyOptionDoc* TY_(OptGetDocDesc)( TidyOptionId optId );
#endif /* SUPPORT_CONSOLE_APP */
/** Initialize the configuration for the given Tidy document.
** @param doc The Tidy document.
*/
void TY_(InitConfig)( TidyDocImpl* doc );
/** Frees the configuration memory for the given Tidy document.
** @param doc The Tidy document.
*/
void TY_(FreeConfig)( TidyDocImpl* doc );
/* Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ); */
/** Sets the integer value for the given option Id.
** @param doc The Tidy document.
** @param optId The option ID to set.
** @param val The value to set.
** @returns Success or failure.
*/
Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val );
/** Sets the bool value for the given option Id.
** @param doc The Tidy document.
** @param optId The option ID to set.
** @param val The value to set.
** @returns Success or failure.
*/
Bool TY_(SetOptionBool)( TidyDocImpl* doc, TidyOptionId optId, Bool val );
/** Resets the given option to its default value.
** @param doc The Tidy document.
** @param optId The option ID to set.
** @returns Success or failure.
*/
Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId );
/** Resets all options in the document to their default values.
** @param doc The Tidy document.
*/
void TY_(ResetConfigToDefault)( TidyDocImpl* doc );
/** Stores a snapshot of all of the configuration values that can be
** restored later.
** @param doc The Tidy document.
*/
void TY_(TakeConfigSnapshot)( TidyDocImpl* doc );
/** Restores all of the configuration values to their snapshotted values.
** @param doc The Tidy document.
*/
void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc );
/** Copies the configuration from one document to another.
** @param docTo The destination Tidy document.
** @param docFrom The source Tidy document.
*/
void TY_(CopyConfig)( TidyDocImpl* docTo, TidyDocImpl* docFrom );
/** Attempts to parse the given config file into the document.
** @param doc The Tidy document.
** @param cfgfil The file to load.
** @returns a file system error code.
*/
int TY_(ParseConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
/** Attempts to parse the given config file into the document, using
** the provided encoding.
** @param doc The Tidy document.
** @param cfgfil The file to load.
** @param charenc The name of the encoding to use for reading the file.
** @returns a file system error code.
*/
int TY_(ParseConfigFileEnc)( TidyDocImpl* doc,
ctmbstr cfgfil, ctmbstr charenc );
/** Saves the current configuration for options not having default values
** into the specified file.
** @param doc The Tidy document.
** @param cfgfil The file to save.
** @returns a file system error code.
*/
int TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
/** Writes the current configuration for options not having default values
** into the specified sink.
** @param doc The Tidy document.
** @param sink The sink to save into.
** @returns a file system error code.
*/
int TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink );
/* returns false if unknown option, missing parameter, or
option doesn't use parameter
*/
/** Attempts to parse the provided value for the given option name. Returns
** false if unknown option, missing parameter, or the option doesn't
** use the parameter.
** @param doc The Tidy document.
** @param optnam The name of the option to be set.
** @param optVal The string value to attempt to parse.
** @returns Success or failure.
*/
Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
/** Attempts to parse the provided value for the given option id. Returns
** false if unknown option, missing parameter, or the option doesn't
** use the parameter.
** @param doc The Tidy document.
** @param optId The ID of the option to be set.
** @param optVal The string value to attempt to parse.
** @returns Success or failure.
*/
Bool TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
/* ensure that char encodings are self consistent */
/** Ensure that char encodings are self consistent.
** @param doc The Tidy document to adjust.
** @param encoding The encoding being applied.
** @returns A bool indicating success or failure.
*/
Bool TY_(AdjustCharEncoding)( TidyDocImpl* doc, int encoding );
/** Indicates whether or not the current configuration is completely default.
** @param doc The Tidy document.
** @returns The result.
*/
Bool TY_(ConfigDiffThanDefault)( TidyDocImpl* doc );
/** Indicates whether or not the current configuration is different from the
** stored snapshot.
** @param doc The Tidy document.
** @returns The result.
*/
Bool TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc );
/** Returns the character encoding ID for the given character encoding
** string.
** @param doc The Tidy document.
** @param charenc The name of the character encoding.
** @returns The Id of the character encoding.
*/
int TY_(CharEncodingId)( TidyDocImpl* doc, ctmbstr charenc );
/** Returns the full name of the encoding for the given ID.
** @param encoding The Id of the encoding.
** @returns The name of the character encoding.
*/
ctmbstr TY_(CharEncodingName)( int encoding );
/** Returns the Tidy command line option name of the encoding for the given ID.
** @param encoding The Id of the encoding.
** @returns The Tidy command line option representing the encoding.
*/
ctmbstr TY_(CharEncodingOptName)( int encoding );
/* Coordinates Config update and Tags data */
/** Coordinates Config update and Tags data.
** @param doc The Tidy document.
** @param optId The option ID the tag is intended for.
** @param tagType The type of tag (pre, inline, etc.).
** @param name The name of the new tag.
*/
void TY_(DeclareUserTag)( TidyDocImpl* doc, TidyOptionId optId,
uint tagType, ctmbstr name );
@ -225,9 +386,17 @@ ctmbstr TY_(_cfgGetString)( TidyDocImpl* doc, TidyOptionId optId );
#else
/* Release build macros for speed */
/** Access the raw, non-string uint value of the given option ID. */
#define cfg(doc, id) ((doc)->config.value[ (id) ].v)
/** Access the Bool value of the given option ID. */
#define cfgBool(doc, id) ((Bool) cfg(doc, id))
/** Access the TidyTriState value of the given option ID. */
#define cfgAutoBool(doc, id) ((TidyTriState) cfg(doc, id))
/** Access the string value of the given option ID. */
#define cfgStr(doc, id) ((ctmbstr) (doc)->config.value[ (id) ].p)
#endif /* _DEBUG */