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: iccir $ 12 $Date: 2007/01/30 23:46:51 $ 13 $Revision: 1.3 $ 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 34struct _tidy_option; 35typedef struct _tidy_option TidyOptionImpl; 36 37typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt ); 38 39struct _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 51typedef union 52{ 53 ulong v; /* Value for TidyInteger and TidyBoolean */ 54 char *p; /* Value for TidyString */ 55} TidyOptionValue; 56 57typedef 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 71typedef 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 79const TidyOptionImpl* TY_(lookupOption)( ctmbstr optnam ); 80const TidyOptionImpl* TY_(getOption)( TidyOptionId optId ); 81 82TidyIterator TY_(getOptionList)( TidyDocImpl* doc ); 83const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* doc, TidyIterator* iter ); 84 85TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option ); 86ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option, TidyIterator* iter ); 87 88const TidyOptionDoc* TY_(OptGetDocDesc)( TidyOptionId optId ); 89 90void TY_(InitConfig)( TidyDocImpl* doc ); 91void TY_(FreeConfig)( TidyDocImpl* doc ); 92 93/* Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ); */ 94Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val ); 95Bool TY_(SetOptionBool)( TidyDocImpl* doc, TidyOptionId optId, Bool val ); 96 97Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId ); 98void TY_(ResetConfigToDefault)( TidyDocImpl* doc ); 99void TY_(TakeConfigSnapshot)( TidyDocImpl* doc ); 100void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc ); 101 102void TY_(CopyConfig)( TidyDocImpl* docTo, TidyDocImpl* docFrom ); 103 104int TY_(ParseConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil ); 105int TY_(ParseConfigFileEnc)( TidyDocImpl* doc, 106 ctmbstr cfgfil, ctmbstr charenc ); 107 108int TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil ); 109int TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink ); 110 111/* returns false if unknown option, missing parameter, or 112 option doesn't use parameter 113*/ 114Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal ); 115Bool TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal ); 116 117/* ensure that char encodings are self consistent */ 118Bool TY_(AdjustCharEncoding)( TidyDocImpl* doc, int encoding ); 119 120Bool TY_(ConfigDiffThanDefault)( TidyDocImpl* doc ); 121Bool TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc ); 122 123int TY_(CharEncodingId)( ctmbstr charenc ); 124ctmbstr TY_(CharEncodingName)( int encoding ); 125ctmbstr 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 */ 133ulong TY_(_cfgGet)( TidyDocImpl* doc, TidyOptionId optId ); 134Bool TY_(_cfgGetBool)( TidyDocImpl* doc, TidyOptionId optId ); 135TidyTriState TY_(_cfgGetAutoBool)( TidyDocImpl* doc, TidyOptionId optId ); 136ctmbstr 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