HTML Tidy  0.1
config.h
00001 #ifndef __CONFIG_H__
00002 #define __CONFIG_H__
00003 
00004 /* config.h -- read config file and manage config properties
00005   
00006   (c) 1998-2006 (W3C) MIT, ERCIM, Keio University
00007   See tidy.h for the copyright notice.
00008 
00009   CVS Info :
00010 
00011     $Author: arnaud02 $ 
00012     $Date: 2006/12/29 16:31:08 $ 
00013     $Revision: 1.14 $ 
00014 
00015   config files associate a property name with a value.
00016 
00017   // comments can start at the beginning of a line
00018   # comments can start at the beginning of a line
00019   name: short values fit onto one line
00020   name: a really long value that
00021    continues on the next line
00022 
00023   property names are case insensitive and should be less than
00024   60 characters in length and must start at the begining of
00025   the line, as whitespace at the start of a line signifies a
00026   line continuation.
00027 
00028 */
00029 
00030 #include "forward.h"
00031 #include "tidy.h"
00032 #include "streamio.h"
00033 
00034 struct _tidy_option;
00035 typedef struct _tidy_option TidyOptionImpl;
00036 
00037 typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt );
00038 
00039 struct _tidy_option
00040 {
00041     TidyOptionId        id;
00042     TidyConfigCategory  category;   /* put 'em in groups */
00043     ctmbstr             name;       /* property name */
00044     TidyOptionType      type;       /* string, int or bool */
00045     ulong               dflt;       /* default for TidyInteger and TidyBoolean */
00046     ParseProperty*      parser;     /* parsing method, read-only if NULL */
00047     const ctmbstr*      pickList;   /* pick list */
00048     ctmbstr             pdflt;      /* default for TidyString */
00049 };
00050 
00051 typedef union
00052 {
00053   ulong v;  /* Value for TidyInteger and TidyBoolean */
00054   char *p;  /* Value for TidyString */
00055 } TidyOptionValue;
00056 
00057 typedef struct _tidy_config
00058 {
00059     TidyOptionValue value[ N_TIDY_OPTIONS + 1 ];     /* current config values */
00060     TidyOptionValue snapshot[ N_TIDY_OPTIONS + 1 ];  /* Snapshot of values to be restored later */
00061 
00062     /* track what tags user has defined to eliminate unnecessary searches */
00063     uint  defined_tags;
00064 
00065     uint c;           /* current char in input stream */
00066     StreamIn* cfgIn;  /* current input source */
00067 
00068 } TidyConfigImpl;
00069 
00070 
00071 typedef struct {
00072   TidyOptionId opt;          /**< Identifier. */
00073   ctmbstr doc;               /**< HTML text */
00074   TidyOptionId const *links; /**< Cross references.
00075                              Last element must be 'TidyUnknownOption'. */
00076 } TidyOptionDoc;
00077 
00078 
00079 const TidyOptionImpl* TY_(lookupOption)( ctmbstr optnam );
00080 const TidyOptionImpl* TY_(getOption)( TidyOptionId optId );
00081 
00082 TidyIterator TY_(getOptionList)( TidyDocImpl* doc );
00083 const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* doc, TidyIterator* iter );
00084 
00085 TidyIterator TY_(getOptionPickList)( const TidyOptionImpl* option );
00086 ctmbstr TY_(getNextOptionPick)( const TidyOptionImpl* option, TidyIterator* iter );
00087 
00088 const TidyOptionDoc* TY_(OptGetDocDesc)( TidyOptionId optId );
00089 
00090 void TY_(InitConfig)( TidyDocImpl* doc );
00091 void TY_(FreeConfig)( TidyDocImpl* doc );
00092 
00093 /* Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ); */
00094 Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val );
00095 Bool TY_(SetOptionBool)( TidyDocImpl* doc, TidyOptionId optId, Bool val );
00096 
00097 Bool TY_(ResetOptionToDefault)( TidyDocImpl* doc, TidyOptionId optId );
00098 void TY_(ResetConfigToDefault)( TidyDocImpl* doc );
00099 void TY_(TakeConfigSnapshot)( TidyDocImpl* doc );
00100 void TY_(ResetConfigToSnapshot)( TidyDocImpl* doc );
00101 
00102 void TY_(CopyConfig)( TidyDocImpl* docTo, TidyDocImpl* docFrom );
00103 
00104 int  TY_(ParseConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
00105 int  TY_(ParseConfigFileEnc)( TidyDocImpl* doc,
00106                               ctmbstr cfgfil, ctmbstr charenc );
00107 
00108 int  TY_(SaveConfigFile)( TidyDocImpl* doc, ctmbstr cfgfil );
00109 int  TY_(SaveConfigSink)( TidyDocImpl* doc, TidyOutputSink* sink );
00110 
00111 /* returns false if unknown option, missing parameter, or
00112    option doesn't use parameter
00113 */
00114 Bool  TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
00115 Bool  TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );
00116 
00117 /* ensure that char encodings are self consistent */
00118 Bool  TY_(AdjustCharEncoding)( TidyDocImpl* doc, int encoding );
00119 
00120 Bool  TY_(ConfigDiffThanDefault)( TidyDocImpl* doc );
00121 Bool  TY_(ConfigDiffThanSnapshot)( TidyDocImpl* doc );
00122 
00123 int TY_(CharEncodingId)( TidyDocImpl* doc, ctmbstr charenc );
00124 ctmbstr TY_(CharEncodingName)( int encoding );
00125 ctmbstr TY_(CharEncodingOptName)( int encoding );
00126 
00127 /* void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename ); */
00128 
00129 
00130 #ifdef _DEBUG
00131 
00132 /* Debug lookup functions will be type-safe and assert option type match */
00133 ulong   TY_(_cfgGet)( TidyDocImpl* doc, TidyOptionId optId );
00134 Bool    TY_(_cfgGetBool)( TidyDocImpl* doc, TidyOptionId optId );
00135 TidyTriState TY_(_cfgGetAutoBool)( TidyDocImpl* doc, TidyOptionId optId );
00136 ctmbstr TY_(_cfgGetString)( TidyDocImpl* doc, TidyOptionId optId );
00137 
00138 #define cfg(doc, id)            TY_(_cfgGet)( (doc), (id) )
00139 #define cfgBool(doc, id)        TY_(_cfgGetBool)( (doc), (id) )
00140 #define cfgAutoBool(doc, id)    TY_(_cfgGetAutoBool)( (doc), (id) )
00141 #define cfgStr(doc, id)         TY_(_cfgGetString)( (doc), (id) )
00142 
00143 #else
00144 
00145 /* Release build macros for speed */
00146 #define cfg(doc, id)            ((doc)->config.value[ (id) ].v)
00147 #define cfgBool(doc, id)        ((Bool) cfg(doc, id))
00148 #define cfgAutoBool(doc, id)    ((TidyTriState) cfg(doc, id))
00149 #define cfgStr(doc, id)         ((ctmbstr) (doc)->config.value[ (id) ].p)
00150 
00151 #endif /* _DEBUG */
00152 
00153 #endif /* __CONFIG_H__ */