~ubuntu-branches/ubuntu/vivid/tidy/vivid

« back to all changes in this revision

Viewing changes to src/config.h

  • Committer: Bazaar Package Importer
  • Author(s): Jason Thomas
  • Date: 2008-01-20 21:46:03 UTC
  • mfrom: (0.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080120214603-oqicq5jwr1exrm55
Tags: 20080116cvs-2
* debian/control: build depends on xsltproc
  (closes: #461608)
* debian/tidy.preinst,postinst: add code to move old config file
  (closes: #461623)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
/* config.h -- read config file and manage config properties
5
5
  
6
 
  (c) 1998-2005 (W3C) MIT, ERCIM, Keio University
 
6
  (c) 1998-2006 (W3C) MIT, ERCIM, Keio University
7
7
  See tidy.h for the copyright notice.
8
8
 
9
9
  CVS Info :
10
10
 
11
11
    $Author: arnaud02 $ 
12
 
    $Date: 2005/03/31 13:10:34 $ 
13
 
    $Revision: 1.10 $ 
 
12
    $Date: 2006/12/29 16:31:08 $ 
 
13
    $Revision: 1.14 $ 
14
14
 
15
15
  config files associate a property name with a value.
16
16
 
42
42
    TidyConfigCategory  category;   /* put 'em in groups */
43
43
    ctmbstr             name;       /* property name */
44
44
    TidyOptionType      type;       /* string, int or bool */
45
 
    ulong               dflt;       /* factory default */
 
45
    ulong               dflt;       /* default for TidyInteger and TidyBoolean */
46
46
    ParseProperty*      parser;     /* parsing method, read-only if NULL */
47
47
    const ctmbstr*      pickList;   /* pick list */
 
48
    ctmbstr             pdflt;      /* default for TidyString */
48
49
};
49
50
 
 
51
typedef union
 
52
{
 
53
  ulong v;  /* Value for TidyInteger and TidyBoolean */
 
54
  char *p;  /* Value for TidyString */
 
55
} TidyOptionValue;
50
56
 
51
57
typedef struct _tidy_config
52
58
{
53
 
    ulong value[ N_TIDY_OPTIONS + 1 ];     /* current config values */
54
 
    ulong snapshot[ N_TIDY_OPTIONS + 1 ];  /* Snapshot of values to be restored later */
 
59
    TidyOptionValue value[ N_TIDY_OPTIONS + 1 ];     /* current config values */
 
60
    TidyOptionValue snapshot[ N_TIDY_OPTIONS + 1 ];  /* Snapshot of values to be restored later */
55
61
 
56
62
    /* track what tags user has defined to eliminate unnecessary searches */
57
63
    uint  defined_tags;
70
76
} TidyOptionDoc;
71
77
 
72
78
 
73
 
const TidyOptionImpl* lookupOption( ctmbstr optnam );
74
 
const TidyOptionImpl* getOption( TidyOptionId optId );
75
 
 
76
 
TidyIterator getOptionList( TidyDocImpl* doc );
77
 
const TidyOptionImpl*  getNextOption( TidyDocImpl* doc, TidyIterator* iter );
78
 
 
79
 
TidyIterator getOptionPickList( const TidyOptionImpl* option );
80
 
ctmbstr getNextOptionPick( const TidyOptionImpl* option, TidyIterator* iter );
81
 
 
82
 
const TidyOptionDoc* tidyOptGetDocDesc( TidyOptionId optId );
83
 
 
84
 
void InitConfig( TidyDocImpl* doc );
85
 
void FreeConfig( TidyDocImpl* doc );
86
 
 
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 );
90
 
 
91
 
Bool ResetOptionToDefault( TidyDocImpl* doc, TidyOptionId optId );
92
 
void ResetConfigToDefault( TidyDocImpl* doc );
93
 
void TakeConfigSnapshot( TidyDocImpl* doc );
94
 
void ResetConfigToSnapshot( TidyDocImpl* doc );
95
 
 
96
 
void CopyConfig( TidyDocImpl* docTo, TidyDocImpl* docFrom );
97
 
 
98
 
/*
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.
102
 
*/
103
 
ctmbstr ExpandTilde(ctmbstr filename);
104
 
 
105
 
int  ParseConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
106
 
int  ParseConfigFileEnc( TidyDocImpl* doc,
107
 
                         ctmbstr cfgfil, ctmbstr charenc );
108
 
 
109
 
int  SaveConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
110
 
int  SaveConfigSink( TidyDocImpl* doc, TidyOutputSink* sink );
 
79
const TidyOptionImpl* TY_(lookupOption)( ctmbstr optnam );
 
80
const TidyOptionImpl* TY_(getOption)( TidyOptionId optId );
 
81
 
 
82
TidyIterator TY_(getOptionList)( TidyDocImpl* doc );
 
83
const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* doc, TidyIterator* iter );
 
84
 
 
85
TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option );
 
86
ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option, TidyIterator* iter );
 
87
 
 
88
const TidyOptionDoc* TY_(OptGetDocDesc)( TidyOptionId optId );
 
89
 
 
90
void TY_(InitConfig)( TidyDocImpl* doc );
 
91
void TY_(FreeConfig)( TidyDocImpl* doc );
 
92
 
 
93
/* Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ); */
 
94
Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val );
 
95
Bool TY_(SetOptionBool)( TidyDocImpl* doc, TidyOptionId optId, Bool val );
 
96
 
 
97
Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId );
 
98
void TY_(ResetConfigToDefault)( TidyDocImpl* doc );
 
99
void TY_(TakeConfigSnapshot)( TidyDocImpl* doc );
 
100
void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc );
 
101
 
 
102
void TY_(CopyConfig)( TidyDocImpl* docTo, TidyDocImpl* docFrom );
 
103
 
 
104
int  TY_(ParseConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
 
105
int  TY_(ParseConfigFileEnc)( TidyDocImpl* doc,
 
106
                              ctmbstr cfgfil, ctmbstr charenc );
 
107
 
 
108
int  TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
 
109
int  TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink );
111
110
 
112
111
/* returns false if unknown option, missing parameter, or
113
112
   option doesn't use parameter
114
113
*/
115
 
Bool  ParseConfigOption( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
116
 
Bool  ParseConfigValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
 
114
Bool  TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
 
115
Bool  TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
117
116
 
118
117
/* ensure that char encodings are self consistent */
119
 
Bool  AdjustCharEncoding( TidyDocImpl* doc, int encoding );
120
 
 
121
 
/* ensure that config is self consistent */
122
 
void AdjustConfig( TidyDocImpl* doc );
123
 
 
124
 
Bool  ConfigDiffThanDefault( TidyDocImpl* doc );
125
 
Bool  ConfigDiffThanSnapshot( TidyDocImpl* doc );
126
 
 
127
 
int CharEncodingId( ctmbstr charenc );
128
 
ctmbstr CharEncodingName( int encoding );
129
 
ctmbstr CharEncodingOptName( int encoding );
130
 
 
131
 
void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename );
 
118
Bool  TY_(AdjustCharEncoding)( TidyDocImpl* doc, int encoding );
 
119
 
 
120
Bool  TY_(ConfigDiffThanDefault)( TidyDocImpl* doc );
 
121
Bool  TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc );
 
122
 
 
123
int TY_(CharEncodingId)( TidyDocImpl* doc, ctmbstr charenc );
 
124
ctmbstr TY_(CharEncodingName)( int encoding );
 
125
ctmbstr TY_(CharEncodingOptName)( int encoding );
 
126
 
 
127
/* void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename ); */
132
128
 
133
129
 
134
130
#ifdef _DEBUG
135
131
 
136
132
/* 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 );
 
133
ulong   TY_(_cfgGet)( TidyDocImpl* doc, TidyOptionId optId );
 
134
Bool    TY_(_cfgGetBool)( TidyDocImpl* doc, TidyOptionId optId );
 
135
TidyTriState TY_(_cfgGetAutoBool)( TidyDocImpl* doc, TidyOptionId optId );
 
136
ctmbstr TY_(_cfgGetString)( TidyDocImpl* doc, TidyOptionId optId );
141
137
 
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) )
 
138
#define cfg(doc, id)            TY_(_cfgGet)( (doc), (id) )
 
139
#define cfgBool(doc, id)        TY_(_cfgGetBool)( (doc), (id) )
 
140
#define cfgAutoBool(doc, id)    TY_(_cfgGetAutoBool)( (doc), (id) )
 
141
#define cfgStr(doc, id)         TY_(_cfgGetString)( (doc), (id) )
146
142
 
147
143
#else
148
144
 
149
145
/* Release build macros for speed */
150
 
#define cfg(doc, id)            ((doc)->config.value[ (id) ])
 
146
#define cfg(doc, id)            ((doc)->config.value[ (id) ].v)
151
147
#define cfgBool(doc, id)        ((Bool) cfg(doc, id))
152
148
#define cfgAutoBool(doc, id)    ((TidyTriState) cfg(doc, id))
153
 
#define cfgStr(doc, id)         ((ctmbstr) cfg(doc, id))
 
149
#define cfgStr(doc, id)         ((ctmbstr) (doc)->config.value[ (id) ].p)
154
150
 
155
151
#endif /* _DEBUG */
156
152
 
157
 
 
158
 
 
159
 
/* parser for integer values */
160
 
ParseProperty ParseInt;
161
 
 
162
 
/* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no' or '1'/'0' */
163
 
ParseProperty ParseBool;
164
 
 
165
 
/* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no', '1'/'0'
166
 
   or 'auto' */
167
 
ParseProperty ParseAutoBool;
168
 
 
169
 
/* a string excluding whitespace */
170
 
ParseProperty ParseName;
171
 
 
172
 
/* a CSS1 selector - CSS class naming for -clean option */
173
 
ParseProperty ParseCSS1Selector;
174
 
 
175
 
/* a string including whitespace */
176
 
ParseProperty ParseString;
177
 
 
178
 
/* a space or comma separated list of tag names */
179
 
ParseProperty ParseTagNames;
180
 
 
181
 
/* RAW, ASCII, LATIN0, LATIN1, UTF8, ISO2022, MACROMAN, 
182
 
   WIN1252, IBM858, UTF16LE, UTF16BE, UTF16, BIG5, SHIFTJIS
183
 
*/
184
 
ParseProperty ParseCharEnc;
185
 
ParseProperty ParseNewline;
186
 
 
187
 
/* omit | auto | strict | loose | <fpi> */
188
 
ParseProperty ParseDocType;
189
 
 
190
 
/* keep-first or keep-last? */
191
 
ParseProperty ParseRepeatAttr;
192
 
 
193
153
#endif /* __CONFIG_H__ */