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 CVS Info : 10 11 $Author: arnaud02 $ 12 $Date: 2006/12/29 16:31:08 $ 13 $Revision: 1.14 $ 14 15 config files associate a property name with a value. 16 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 22 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 26 line continuation. 27 28 */ 29 30 #include "forward.h" 31 #include "tidy.h" 32 #include "streamio.h" 33 34 struct _tidy_option; 35 typedef struct _tidy_option TidyOptionImpl; 36 37 typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt ); 38 39 struct _tidy_option 40 { 41 TidyOptionId id; 42 TidyConfigCategory category; /* put 'em in groups */ 43 ctmbstr name; /* property name */ 44 TidyOptionType type; /* string, int or bool */ 45 ulong dflt; /* default for TidyInteger and TidyBoolean */ 46 ParseProperty* parser; /* parsing method, read-only if NULL */ 47 const ctmbstr* pickList; /* pick list */ 48 ctmbstr pdflt; /* default for TidyString */ 49 }; 50 51 typedef union 52 { 53 ulong v; /* Value for TidyInteger and TidyBoolean */ 54 char *p; /* Value for TidyString */ 55 } TidyOptionValue; 56 57 typedef struct _tidy_config 58 { 59 TidyOptionValue value[ N_TIDY_OPTIONS + 1 ]; /* current config values */ 60 TidyOptionValue snapshot[ N_TIDY_OPTIONS + 1 ]; /* Snapshot of values to be restored later */ 61 62 /* track what tags user has defined to eliminate unnecessary searches */ 63 uint defined_tags; 64 65 uint c; /* current char in input stream */ 66 StreamIn* cfgIn; /* current input source */ 67 68 } TidyConfigImpl; 69 70 71 typedef struct { 72 TidyOptionId opt; /**< Identifier. */ 73 ctmbstr doc; /**< HTML text */ 74 TidyOptionId const *links; /**< Cross references. 75 Last element must be 'TidyUnknownOption'. */ 76 } TidyOptionDoc; 77 78 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 ); 110 111 /* returns false if unknown option, missing parameter, or 112 option doesn't use parameter 113 */ 114 Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal ); 115 Bool TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal ); 116 117 /* ensure that char encodings are self consistent */ 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 ); */ 128 129 130 #ifdef _DEBUG 131 132 /* Debug lookup functions will be type-safe and assert option type match */ 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 ); 137 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) ) 142 143 #else 144 145 /* Release build macros for speed */ 146 #define cfg(doc, id) ((doc)->config.value[ (id) ].v) 147 #define cfgBool(doc, id) ((Bool) cfg(doc, id)) 148 #define cfgAutoBool(doc, id) ((TidyTriState) cfg(doc, id)) 149 #define cfgStr(doc, id) ((ctmbstr) (doc)->config.value[ (id) ].p) 150 151 #endif /* _DEBUG */ 152 153 #endif /* __CONFIG_H__ */ 154