HTML Tidy  5.4.0
The HTACG Tidy HTML Project
config.h
Go to the documentation of this file.
1 #ifndef __CONFIG_H__
2 #define __CONFIG_H__
3 
4 /* config.h -- read config file and manage config properties
5 
6  (c) 1998-2006 (W3C) MIT, ERCIM, Keio University
7  See tidy.h for the copyright notice.
8 
9  config files associate a property name with a value.
10 
11  // comments can start at the beginning of a line
12  # comments can start at the beginning of a line
13  name: short values fit onto one line
14  name: a really long value that
15  continues on the next line
16 
17  property names are case insensitive and should be less than
18  60 characters in length and must start at the begining of
19  the line, as whitespace at the start of a line signifies a
20  line continuation.
21 
22 */
23 
24 #include "forward.h"
25 #include "tidy.h"
26 #include "streamio.h"
27 
28 struct _tidy_option;
29 typedef struct _tidy_option TidyOptionImpl;
30 
31 typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt );
32 
34 {
36  TidyConfigCategory category; /* put 'em in groups */
37  ctmbstr name; /* property name */
38  TidyOptionType type; /* string, int or bool */
39  ulong dflt; /* default for TidyInteger and TidyBoolean */
40  ParseProperty* parser; /* parsing method, read-only if NULL */
41  const ctmbstr* pickList; /* pick list */
42  ctmbstr pdflt; /* default for TidyString */
43 };
44 
45 typedef union
46 {
47  ulong v; /* Value for TidyInteger and TidyBoolean */
48  char *p; /* Value for TidyString */
50 
51 typedef struct _tidy_config
52 {
53  TidyOptionValue value[ N_TIDY_OPTIONS + 1 ]; /* current config values */
54  TidyOptionValue snapshot[ N_TIDY_OPTIONS + 1 ]; /* Snapshot of values to be restored later */
55 
56  /* track what tags user has defined to eliminate unnecessary searches */
58 
59  uint c; /* current char in input stream */
60  StreamIn* cfgIn; /* current input source */
61 
63 
64 
65 /* Used to build a table of documentation cross-references. */
66 typedef struct {
67  TidyOptionId opt; /**< Identifier. */
68  TidyOptionId const *links; /**< Cross references. Last element must be 'TidyUnknownOption'. */
70 
71 
72 const TidyOptionImpl* TY_(lookupOption)( ctmbstr optnam );
73 const TidyOptionImpl* TY_(getOption)( TidyOptionId optId );
74 
75 TidyIterator TY_(getOptionList)( TidyDocImpl* doc );
76 const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* doc, TidyIterator* iter );
77 
78 TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option );
79 ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option, TidyIterator* iter );
80 
81 const TidyOptionDoc* TY_(OptGetDocDesc)( TidyOptionId optId );
82 
83 void TY_(InitConfig)( TidyDocImpl* doc );
84 void TY_(FreeConfig)( TidyDocImpl* doc );
85 
86 /* Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ); */
87 Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val );
88 Bool TY_(SetOptionBool)( TidyDocImpl* doc, TidyOptionId optId, Bool val );
89 
90 Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId );
91 void TY_(ResetConfigToDefault)( TidyDocImpl* doc );
92 void TY_(TakeConfigSnapshot)( TidyDocImpl* doc );
93 void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc );
94 
95 void TY_(CopyConfig)( TidyDocImpl* docTo, TidyDocImpl* docFrom );
96 
97 int TY_(ParseConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
98 int TY_(ParseConfigFileEnc)( TidyDocImpl* doc,
99  ctmbstr cfgfil, ctmbstr charenc );
100 
101 int TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
102 int TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink );
103 
104 /* returns false if unknown option, missing parameter, or
105  option doesn't use parameter
106 */
107 Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
108 Bool TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
109 
110 /* ensure that char encodings are self consistent */
111 Bool TY_(AdjustCharEncoding)( TidyDocImpl* doc, int encoding );
112 
113 Bool TY_(ConfigDiffThanDefault)( TidyDocImpl* doc );
114 Bool TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc );
115 
116 int TY_(CharEncodingId)( TidyDocImpl* doc, ctmbstr charenc );
117 ctmbstr TY_(CharEncodingName)( int encoding );
118 ctmbstr TY_(CharEncodingOptName)( int encoding );
119 
120 /* void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename ); */
121 
122 
123 #ifdef _DEBUG
124 
125 /* Debug lookup functions will be type-safe and assert option type match */
126 ulong TY_(_cfgGet)( TidyDocImpl* doc, TidyOptionId optId );
127 Bool TY_(_cfgGetBool)( TidyDocImpl* doc, TidyOptionId optId );
128 TidyTriState TY_(_cfgGetAutoBool)( TidyDocImpl* doc, TidyOptionId optId );
129 ctmbstr TY_(_cfgGetString)( TidyDocImpl* doc, TidyOptionId optId );
130 
131 #define cfg(doc, id) TY_(_cfgGet)( (doc), (id) )
132 #define cfgBool(doc, id) TY_(_cfgGetBool)( (doc), (id) )
133 #define cfgAutoBool(doc, id) TY_(_cfgGetAutoBool)( (doc), (id) )
134 #define cfgStr(doc, id) TY_(_cfgGetString)( (doc), (id) )
135 
136 #else
137 
138 /* Release build macros for speed */
139 #define cfg(doc, id) ((doc)->config.value[ (id) ].v)
140 #define cfgBool(doc, id) ((Bool) cfg(doc, id))
141 #define cfgAutoBool(doc, id) ((TidyTriState) cfg(doc, id))
142 #define cfgStr(doc, id) ((ctmbstr) (doc)->config.value[ (id) ].p)
143 
144 #endif /* _DEBUG */
145 
146 #endif /* __CONFIG_H__ */
Definition: config.h:45
TidyOptionId opt
Identifier.
Definition: config.h:67
StreamIn * cfgIn
Definition: config.h:60
ctmbstr name
Definition: config.h:37
TidyOptionId id
Definition: config.h:35
const tmbchar * ctmbstr
Definition: tidyplatform.h:556
Definition: config.h:33
Definition: config.h:51
TidyOptionId
Option IDs Used to get/set option values.
Definition: tidyenum.h:44
Definition: config.h:66
Bool
Definition: tidyplatform.h:593
const ctmbstr * pickList
Definition: config.h:41
TidyTriState
AutoBool values used by ParseBool, ParseTriState, ParseIndent, ParseBOM.
Definition: tidyenum.h:191
Defines HTML Tidy API implemented by tidy library.
ulong v
Definition: config.h:47
uint c
Definition: config.h:59
ulong dflt
Definition: config.h:39
TidyConfigCategory
Categories of Tidy configuration options.
Definition: tidyenum.h:26
uint defined_tags
Definition: config.h:57
unsigned int uint
Definition: tidyplatform.h:525
TidyOutputSink - accepts raw bytes of output.
Definition: tidy.h:613
TidyOptionId const * links
Cross references.
Definition: config.h:68
char * p
Definition: config.h:48
Must be last.
Definition: tidyenum.h:175
Bool() ParseProperty(TidyDocImpl *doc, const TidyOptionImpl *opt)
Definition: config.h:31
#define TY_(str)
Definition: forward.h:23
ctmbstr pdflt
Definition: config.h:42
ParseProperty * parser
Definition: config.h:40
TidyConfigCategory category
Definition: config.h:36
TidyOptionType type
Definition: config.h:38
TidyOptionType
Option data types.
Definition: tidyenum.h:181