Click here to Skip to main content
15,882,017 members
Articles / Programming Languages / Visual Basic

EfTidy: The Tidy Library Wrapper

Rate me:
Please Sign up or sign in to vote.
4.91/5 (36 votes)
6 Sep 2013GPL310 min read 184.6K   5K   88  
A free component for HTML parsing and cleaning
#ifndef __CONFIG_H__
#define __CONFIG_H__

/* config.h -- read config file and manage config properties
  
  (c) 1998-2004 (W3C) MIT, ERCIM, Keio University
  See tidy.h for the copyright notice.

  CVS Info :

    $Author: arnaud02 $ 
    $Date: 2004/12/06 15:32:08 $ 
    $Revision: 1.7 $ 

  config files associate a property name with a value.

  // comments can start at the beginning of a line
  # comments can start at the beginning of a line
  name: short values fit onto one line
  name: a really long value that
   continues on the next line

  property names are case insensitive and should be less than
  60 characters in length and must start at the begining of
  the line, as whitespace at the start of a line signifies a
  line continuation.

*/

#include "forward.h"
#include "tidy.h"
#include "streamio.h"

struct _tidy_option;
typedef struct _tidy_option TidyOptionImpl;

typedef Bool (ParseProperty)( TidyDocImpl* doc, const TidyOptionImpl* opt );

struct _tidy_option
{
    TidyOptionId        id;
    TidyConfigCategory  category;   /* put 'em in groups */
    ctmbstr             name;       /* property name */
    TidyOptionType      type;       /* string, int or bool */
    ulong               dflt;       /* factory default */
    ParseProperty*      parser;     /* parsing method, read-only if NULL */
    const ctmbstr*      pickList;   /* pick list */
};


typedef struct _tidy_config
{
    ulong value[ N_TIDY_OPTIONS + 1 ];     /* current config values */
    ulong snapshot[ N_TIDY_OPTIONS + 1 ];  /* Snapshot of values to be restored later */

    /* track what tags user has defined to eliminate unnecessary searches */
    uint  defined_tags;

    uint c;           /* current char in input stream */
    StreamIn* cfgIn;  /* current input source */

} TidyConfigImpl;


const TidyOptionImpl* lookupOption( ctmbstr optnam );
const TidyOptionImpl* getOption( TidyOptionId optId );

TidyIterator getOptionList( TidyDocImpl* doc );
const TidyOptionImpl*  getNextOption( TidyDocImpl* doc, TidyIterator* iter );

TidyIterator getOptionPickList( const TidyOptionImpl* option );
ctmbstr getNextOptionPick( const TidyOptionImpl* option, TidyIterator* iter );

void InitConfig( TidyDocImpl* doc );
void FreeConfig( TidyDocImpl* doc );

Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val );
Bool SetOptionInt( TidyDocImpl* doc, TidyOptionId optId, ulong val );
Bool SetOptionBool( TidyDocImpl* doc, TidyOptionId optId, Bool val );

Bool ResetOptionToDefault( TidyDocImpl* doc, TidyOptionId optId );
void ResetConfigToDefault( TidyDocImpl* doc );
void TakeConfigSnapshot( TidyDocImpl* doc );
void ResetConfigToSnapshot( TidyDocImpl* doc );

void CopyConfig( TidyDocImpl* docTo, TidyDocImpl* docFrom );

/*
 Todd Lewis contributed this code for expanding
 ~/foo or ~your/foo according to $HOME and your
 user name. This will only work on Unix systems.
*/
ctmbstr ExpandTilde(ctmbstr filename);

int  ParseConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
int  ParseConfigFileEnc( TidyDocImpl* doc,
                         ctmbstr cfgfil, ctmbstr charenc );

int  SaveConfigFile( TidyDocImpl* doc, ctmbstr cfgfil );
int  SaveConfigSink( TidyDocImpl* doc, TidyOutputSink* sink );

/* returns false if unknown option, missing parameter, or
   option doesn't use parameter
*/
Bool  ParseConfigOption( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optVal );
Bool  ParseConfigValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optVal );

/* ensure that char encodings are self consistent */
Bool  AdjustCharEncoding( TidyDocImpl* doc, int encoding );

/* ensure that config is self consistent */
void AdjustConfig( TidyDocImpl* doc );

Bool  ConfigDiffThanDefault( TidyDocImpl* doc );
Bool  ConfigDiffThanSnapshot( TidyDocImpl* doc );

int CharEncodingId( ctmbstr charenc );
ctmbstr CharEncodingName( int encoding );

void SetEmacsFilename( TidyDocImpl* doc, ctmbstr filename );


#ifdef _DEBUG

/* Debug lookup functions will be type-safe and assert option type match */
ulong   _cfgGet( TidyDocImpl* doc, TidyOptionId optId );
Bool    _cfgGetBool( TidyDocImpl* doc, TidyOptionId optId );
ctmbstr _cfgGetString( TidyDocImpl* doc, TidyOptionId optId );

#define cfg(doc, id)            _cfgGet( (doc), (id) )
#define cfgBool(doc, id)        _cfgGetBool( (doc), (id) )
#define cfgStr(doc, id)         _cfgGetString( (doc), (id) )

#else

/* Release build macros for speed */
#define cfg(doc, id)            ((doc)->config.value[ (id) ])
#define cfgBool(doc, id)        ((Bool) cfg(doc, id))
#define cfgStr(doc, id)         ((ctmbstr) cfg(doc, id))

#endif /* _DEBUG */



/* parser for integer values */
ParseProperty ParseInt;

/* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no' or '1'/'0' */
ParseProperty ParseBool;

/* parser for 't'/'f', 'true'/'false', 'y'/'n', 'yes'/'no', '1'/'0'
   or 'auto' */
ParseProperty ParseAutoBool;

/* a string excluding whitespace */
ParseProperty ParseName;

/* a CSS1 selector - CSS class naming for -clean option */
ParseProperty ParseCSS1Selector;

/* a string including whitespace */
ParseProperty ParseString;

/* a space or comma separated list of tag names */
ParseProperty ParseTagNames;

/* RAW, ASCII, LATIN0, LATIN1, UTF8, ISO2022, MACROMAN, 
   WIN1252, IBM858, UTF16LE, UTF16BE, UTF16, BIG5, SHIFTJIS
*/
ParseProperty ParseCharEnc;
ParseProperty ParseNewline;

/* omit | auto | strict | loose | <fpi> */
ParseProperty ParseDocType;

/* keep-first or keep-last? */
ParseProperty ParseRepeatAttr;

#endif /* __CONFIG_H__ */

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
India India
He used to have biography here Smile | :) , but now he will hire someone (for free offcourse Big Grin | :-D ), Who writes his biography on his behalf Smile | :)

He is Great Fan of Mr. Johan Rosengren (his idol),Lim Bio Liong, Nishant S and DavidCrow and Believes that, he will EXCEL in his life by following there steps!!!

He started with Visual C++ then moved to C# then he become language agnostic, you give him task,tell him the language or platform, he we start immediately, if he knows the language otherwise he quickly learn it and start contributing productively

Last but not the least, For good 8 years he was Visual CPP MSMVP!

Comments and Discussions