4
/* config.h -- read config file and manage config properties
6
(c) 1998-2005 (W3C) MIT, ERCIM, Keio University
7
See tidy.h for the copyright notice.
12
$Date: 2005/03/31 13:10:34 $
15
config files associate a property name with a value.
17
// comments can start at the beginning of a line
18
# comments can start at the beginning of a line
19
name: short values fit onto one line
20
name: a really long value that
21
continues on the next line
23
property names are case insensitive and should be less than
24
60 characters in length and must start at the begining of
25
the line, as whitespace at the start of a line signifies a
35
typedef struct _tidy_option TidyOptionImpl;
37
typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt );
42
TidyConfigCategory category; /* put 'em in groups */
43
ctmbstr name; /* property name */
44
TidyOptionType type; /* string, int or bool */
45
ulong dflt; /* factory default */
46
ParseProperty* parser; /* parsing method, read-only if NULL */
47
const ctmbstr* pickList; /* pick list */
51
typedef struct _tidy_config
53
ulong value[ N_TIDY_OPTIONS + 1 ]; /* current config values */
54
ulong snapshot[ N_TIDY_OPTIONS + 1 ]; /* Snapshot of values to be restored later */
56
/* track what tags user has defined to eliminate unnecessary searches */
59
uint c; /* current char in input stream */
60
StreamIn* cfgIn; /* current input source */
66
TidyOptionId opt; /**< Identifier. */
67
ctmbstr doc; /**< HTML text */
68
TidyOptionId const *links; /**< Cross references.
69
Last element must be 'TidyUnknownOption'. */
73
const TidyOptionImpl* lookupOption( ctmbstr optnam );
74
const TidyOptionImpl* getOption( TidyOptionId optId );
76
TidyIterator getOptionList( TidyDocImpl* doc );
77
const TidyOptionImpl* getNextOption( TidyDocImpl* doc, TidyIterator* iter );
79
TidyIterator getOptionPickList( const TidyOptionImpl* option );
80
ctmbstr getNextOptionPick( const TidyOptionImpl* option, TidyIterator* iter );
82
const TidyOptionDoc* tidyOptGetDocDesc( TidyOptionId optId );
84
void InitConfig( TidyDocImpl* doc );
85
void FreeConfig( TidyDocImpl* doc );
87
Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val );
88
Bool SetOptionInt( TidyDocImpl* doc, TidyOptionId optId, ulong val );
89
Bool SetOptionBool( TidyDocImpl* doc, TidyOptionId optId, Bool val );
91
Bool ResetOptionToDefault( TidyDocImpl* doc, TidyOptionId optId );
92
void ResetConfigToDefault( TidyDocImpl* doc );
93
void TakeConfigSnapshot( TidyDocImpl* doc );
94
void ResetConfigToSnapshot( TidyDocImpl* doc );
96
void CopyConfig( TidyDocImpl* docTo, TidyDocImpl* docFrom );
99
Todd Lewis contributed this code for expanding
100
~/foo or ~your/foo according to $HOME and your
101
user name. This will only work on Unix systems.
103
ctmbstr ExpandTilde(ctmbstr filename);
105
int ParseConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
106
int ParseConfigFileEnc( TidyDocImpl* doc,
107
ctmbstr cfgfil, ctmbstr charenc );
109
int SaveConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
110
int SaveConfigSink( TidyDocImpl* doc, TidyOutputSink* sink );
112
/* returns false if unknown option, missing parameter, or
113
option doesn't use parameter
115
Bool ParseConfigOption( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
116
Bool ParseConfigValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
118
/* ensure that char encodings are self consistent */
119
Bool AdjustCharEncoding( TidyDocImpl* doc, int encoding );
121
/* ensure that config is self consistent */
122
void AdjustConfig( TidyDocImpl* doc );
124
Bool ConfigDiffThanDefault( TidyDocImpl* doc );
125
Bool ConfigDiffThanSnapshot( TidyDocImpl* doc );
127
int CharEncodingId( ctmbstr charenc );
128
ctmbstr CharEncodingName( int encoding );
129
ctmbstr CharEncodingOptName( int encoding );
131
void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename );
136
/* Debug lookup functions will be type-safe and assert option type match */
137
ulong _cfgGet( TidyDocImpl* doc, TidyOptionId optId );
138
Bool _cfgGetBool( TidyDocImpl* doc, TidyOptionId optId );
139
TidyTriState _cfgGetAutoBool( TidyDocImpl* doc, TidyOptionId optId );
140
ctmbstr _cfgGetString( TidyDocImpl* doc, TidyOptionId optId );
142
#define cfg(doc, id) _cfgGet( (doc), (id) )
143
#define cfgBool(doc, id) _cfgGetBool( (doc), (id) )
144
#define cfgAutoBool(doc, id) _cfgGetAutoBool( (doc), (id) )
145
#define cfgStr(doc, id) _cfgGetString( (doc), (id) )
149
/* Release build macros for speed */
150
#define cfg(doc, id) ((doc)->config.value[ (id) ])
151
#define cfgBool(doc, id) ((Bool) cfg(doc, id))
152
#define cfgAutoBool(doc, id) ((TidyTriState) cfg(doc, id))
153
#define cfgStr(doc, id) ((ctmbstr) cfg(doc, id))
159
/* parser for integer values */
160
ParseProperty ParseInt;
162
/* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no' or '1'/'0' */
163
ParseProperty ParseBool;
165
/* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no', '1'/'0'
167
ParseProperty ParseAutoBool;
169
/* a string excluding whitespace */
170
ParseProperty ParseName;
172
/* a CSS1 selector - CSS class naming for -clean option */
173
ParseProperty ParseCSS1Selector;
175
/* a string including whitespace */
176
ParseProperty ParseString;
178
/* a space or comma separated list of tag names */
179
ParseProperty ParseTagNames;
181
/* RAW, ASCII, LATIN0, LATIN1, UTF8, ISO2022, MACROMAN,
182
WIN1252, IBM858, UTF16LE, UTF16BE, UTF16, BIG5, SHIFTJIS
184
ParseProperty ParseCharEnc;
185
ParseProperty ParseNewline;
187
/* omit | auto | strict | loose | <fpi> */
188
ParseProperty ParseDocType;
190
/* keep-first or keep-last? */
191
ParseProperty ParseRepeatAttr;
193
#endif /* __CONFIG_H__ */