www.pudn.com > TidyWin32-src.zip > TidyProxy.h


#ifndef TIDY_PROXY_H 
#define TIDY_PROXY_H 
 
#include "../TidyItf.h" 
 
// The CTidyProxy class manages interaction between the C++ world of 
// TidyGUI and the C world of tidy. 
// There must be only one instance of this class. 
 
//------------------------------------------------------------------- 
class CTidyProxy { 
public: 
	// Construction 
	CTidyProxy(bool bEnableAllOptions = false); 
 
	// Control methods 
	void Reset(); 
	void DoTidy(const char* sourceFileName, const char* destFileName = NULL); 
	void AdjustConfig(); 
	void LoadConfig(const char*); 
	void SaveConfig(ostream& os); 
	void CopyConfig(); 
	void ResetConfig(); 
 
	// General access methods 
	unsigned int GetTotalErrors() const; 
	unsigned int GetTotalWarnings() const; 
	unsigned int GetOptionErrors() const; 
 
	const list& GetTidyMsgs() const { return m_tidy_out_msgs; } 
	const string& GetTidyOutput() const { return m_outc_string; } 
 
	// Used by SetNewTags() 
	enum NewTagsTag { 
		NewEmptyTags, NewInlineTags, NewBlockTags, NewPreTags 
	}; 
 
	// Character encodings 
	enum CharEncoding { 
		Enc_Raw, Enc_ASCII, Enc_Latin1, Enc_UTF8, Enc_ISO2022, Enc_MacRoman 
	}; 
 
	// Used by Set/Getindent() 
	enum Logical3 { 
		Log3_False, Log3_True, Log3_Maybe 
	}; 
 
	// Configuration methods 
	// Generic 
	void SetBoolValue(bool val, tidy::Bool& dest) 
		{ dest = (val ? tidy::yes : tidy::no); } 
	bool GetBoolValue(const tidy::Bool& src) const 
		{ return (src == tidy::yes) ? true : false; } 
	// Markup 
	string GetDocType() const; 
	void SetDocType(const char*); 
	void SetTidyMark(bool b)	{ SetBoolValue(b, tidy::TidyMark); } 
	bool GetTidyMark() const	{ return GetBoolValue(tidy::TidyMark); } 
	void SetHideEndTags(bool b)	{ SetBoolValue(b, tidy::HideEndTags); } 
	bool GetHideEndTags() const	{ return GetBoolValue(tidy::HideEndTags); } 
	void SetEncloseBodyText(bool b)	{ SetBoolValue(b, tidy::EncloseBodyText); } 
	bool GetEncloseBodyText() const	{ return GetBoolValue(tidy::EncloseBodyText); } 
	void SetEncloseBlockText(bool b)	{ SetBoolValue(b, tidy::EncloseBlockText); } 
	bool GetEncloseBlockText() const	{ return GetBoolValue(tidy::EncloseBlockText); } 
	void SetNewTags(NewTagsTag, const char*); 
	const string& GetNewTags(NewTagsTag); 
	// Cleanup 
	void SetMakeClean(bool b)		{ SetBoolValue(b, tidy::MakeClean); } 
	bool GetMakeClean() const		{ return GetBoolValue(tidy::MakeClean); } 
	void SetDropFontTags(bool b)	{ SetBoolValue(b, tidy::DropFontTags); } 
	bool GetDropFontTags() const	{ return GetBoolValue(tidy::DropFontTags); } 
	void SetLogicalEmphasis(bool b)	{ SetBoolValue(b, tidy::LogicalEmphasis); } 
	bool GetLogicalEmphasis() const	{ return GetBoolValue(tidy::LogicalEmphasis); } 
	void SetDropEmptyParas(bool b)	{ SetBoolValue(b, tidy::DropEmptyParas); } 
	bool GetDropEmptyParas() const	{ return GetBoolValue(tidy::DropEmptyParas); } 
	void SetWord2000(bool b)		{ SetBoolValue(b, tidy::Word2000); } 
	bool GetWord2000() const		{ return GetBoolValue(tidy::Word2000); } 
	void SetFixComments(bool b)		{ SetBoolValue(b, tidy::FixComments); } 
	bool GetFixComments() const		{ return GetBoolValue(tidy::FixComments); } 
	void SetFixBackslash(bool b)	{ SetBoolValue(b, tidy::FixBackslash); } 
	bool GetFixBackslash() const	{ return GetBoolValue(tidy::FixBackslash); } 
	string GetAltText() const; 
	void SetAltText(const char*); 
	// XML 
	void SetXmlTags(bool b)	{ SetBoolValue(b, tidy::XmlTags); } 
	bool GetXmlTags() const	{ return GetBoolValue(tidy::XmlTags); } 
	void SetXmlOut(bool b)	{ SetBoolValue(b, tidy::XmlOut); } 
	bool GetXmlOut() const	{ return GetBoolValue(tidy::XmlOut); } 
	void SetxHTML(bool b)	{ SetBoolValue(b, tidy::xHTML); } 
	bool GetxHTML() const	{ return GetBoolValue(tidy::xHTML); } 
	void SetXmlPi(bool b)	{ SetBoolValue(b, tidy::XmlPi); } 
	bool GetXmlPi() const	{ return GetBoolValue(tidy::XmlPi); } 
	void SetXmlPIs(bool b)	{ SetBoolValue(b, tidy::XmlPIs); } 
	bool GetXmlPIs() const	{ return GetBoolValue(tidy::XmlPIs); } 
	void SetXmlSpace(bool b)	{ SetBoolValue(b, tidy::XmlSpace); } 
	bool GetXmlSpace() const	{ return GetBoolValue(tidy::XmlSpace); } 
	// Encoding 
	void SetCharEncoding(CharEncoding); 
	CharEncoding GetCharEncoding() const; 
	void SetNumEntities(bool b)		{ SetBoolValue(b, tidy::NumEntities); } 
	bool GetNumEntities() const		{ return GetBoolValue(tidy::NumEntities); } 
	void SetQuoteMarks(bool b)		{ SetBoolValue(b, tidy::QuoteMarks); } 
	bool GetQuoteMarks() const		{ return GetBoolValue(tidy::QuoteMarks); } 
	void SetQuoteNbsp(bool b)		{ SetBoolValue(b, tidy::QuoteNbsp); } 
	bool GetQuoteNbsp() const		{ return GetBoolValue(tidy::QuoteNbsp); } 
	void SetQuoteAmpersand(bool b)	{ SetBoolValue(b, tidy::QuoteAmpersand); } 
	bool GetQuoteAmpersand() const	{ return GetBoolValue(tidy::QuoteAmpersand); } 
	// Layout 
	void SetIndent(Logical3); 
	Logical3 GetIndent() const; 
	void SetIndentSpaces(unsigned int n)	{ tidy::spaces = n; } 
	unsigned int GetIndentSpaces() const	{ return tidy::spaces; } 
	void SetWrapMargin(unsigned int n)		{ tidy::wraplen = n; } 
	unsigned int GetWrapMargin() const		{ return tidy::wraplen; } 
	void SetTabSize(unsigned int n)			{ tidy::tabsize = n; } 
	unsigned int GetTabSize() const			{ return tidy::tabsize; } 
	void SetIndentAttributes(bool b)	{ SetBoolValue(b, tidy::IndentAttributes); } 
	bool GetIndentAttributes() const	{ return GetBoolValue(tidy::IndentAttributes); } 
	void SetWrapAttVals(bool b)			{ SetBoolValue(b, tidy::WrapAttVals); } 
	bool GetWrapAttVals() const			{ return GetBoolValue(tidy::WrapAttVals); } 
	void SetWrapScriptlets(bool b)		{ SetBoolValue(b, tidy::WrapScriptlets); } 
	bool GetWrapScriptlets() const		{ return GetBoolValue(tidy::WrapScriptlets); } 
	void SetWrapAsp(bool b)				{ SetBoolValue(b, tidy::WrapAsp); } 
	bool GetWrapAsp() const				{ return GetBoolValue(tidy::WrapAsp); } 
	void SetWrapJste(bool b)			{ SetBoolValue(b, tidy::WrapJste); } 
	bool GetWrapJste() const			{ return GetBoolValue(tidy::WrapJste); } 
	void SetWrapPhp(bool b)				{ SetBoolValue(b, tidy::WrapPhp); } 
	bool GetWrapPhp() const				{ return GetBoolValue(tidy::WrapPhp); } 
	void SetBreakBeforeBR(bool b)		{ SetBoolValue(b, tidy::BreakBeforeBR); } 
	bool GetBreakBeforeBR() const		{ return GetBoolValue(tidy::BreakBeforeBR); } 
	void SetUpperCaseTags(bool b)		{ SetBoolValue(b, tidy::UpperCaseTags); } 
	bool GetUpperCaseTags() const		{ return GetBoolValue(tidy::UpperCaseTags); } 
	void SetUpperCaseAttrs(bool b)		{ SetBoolValue(b, tidy::UpperCaseAttrs); } 
	bool GetUpperCaseAttrs() const		{ return GetBoolValue(tidy::UpperCaseAttrs); } 
	void SetLiteralAttribs(bool b)		{ SetBoolValue(b, tidy::LiteralAttribs); } 
	bool GetLiteralAttribs() const		{ return GetBoolValue(tidy::LiteralAttribs); } 
	// Operation 
	void SetOnlyErrors(bool b)		{ SetBoolValue(b, tidy::OnlyErrors); } 
	bool GetOnlyErrors() const		{ return GetBoolValue(tidy::OnlyErrors); } 
	void SetQuiet(bool b)			{ SetBoolValue(b, tidy::Quiet); } 
	bool GetQuiet() const			{ return GetBoolValue(tidy::Quiet); } 
	void SetShowWarnings(bool b)	{ SetBoolValue(b, tidy::ShowWarnings); } 
	bool GetShowWarnings() const	{ return GetBoolValue(tidy::ShowWarnings); } 
	void SetBurstSlides(bool b)		{ SetBoolValue(b, tidy::BurstSlides); } 
	bool GetBurstSlides() const		{ return GetBoolValue(tidy::BurstSlides); } 
	void Setwriteback(bool b)		{ SetBoolValue(b, CTidyProxy::writeback); } 
	bool Getwriteback() const		{ return GetBoolValue(CTidyProxy::writeback); } 
	void SetKeepFileTimes(bool b)	{ SetBoolValue(b, CTidyProxy::KeepFileTimes); } 
	bool GetKeepFileTimes() const	{ return GetBoolValue(CTidyProxy::KeepFileTimes); } 
	const string& GetErrorFile() const { return CTidyProxy::errfile; } 
	void SetErrorFile(const char* str) { CTidyProxy::errfile = str; } 
	void SetEmacs(bool b)	{ SetBoolValue(b, CTidyProxy::Emacs); } 
	bool GetEmacs() const	{ return GetBoolValue(CTidyProxy::Emacs); } 
 
private:	// methods 
	list ParseTags(const string&); 
	void DefineNewTags(NewTagsTag, const string&); 
 
	const char* BoolToStr(const tidy::Bool b); 
 
	typedef string SettingName, SettingVal; 
	typedef pair SettingPair; 
	typedef list ConfigListT; 
	ConfigListT BuildConfigList(); 
 
private:	// variables 
	bool m_bEnableAllOptions;	// if false KeepFileTimes, errfile and Emacs will have no effect 
	static FILE* m_fpErrFile; 
 
	// New tags are cached, because tidy::FreeConfig wipes them out 
	string m_NewEmptyTags, m_NewInlineTags, m_NewBlockTags, m_NewPreTags; 
 
	// writeback, KeepFileTimes, errfile and Emacs are not actually used by TidyGUI 
	tidy::Bool writeback; 
	tidy::Bool KeepFileTimes; 
	string errfile; 
	tidy::Bool Emacs; 
 
	static const char* TIDY_YES; 
	static const char* TIDY_NO; 
 
private:	// interface with tidy 
	static void tidy_out_Callback(FILE *fp, const char* msg); 
	static void outc_Callback(unsigned int c, FILE *fp); 
	static void defNewTag_Callback(newTagT tagType, const char* newTag); 
 
	static list m_tidy_out_msgs; 
	static string m_tidy_out_msg_line; 
	static string m_outc_string; 
	static string m_TidyDefinedEmptyTags, m_TidyDefinedInlineTags, 
		m_TidyDefinedBlockTags, m_TidyDefinedPreTags; 
}; 
 
//------------------------------------------------------------------- 
inline ostream& operator<<(ostream& ostr, const tidy::Bool b) 
{ 
	if (b == tidy::yes) 
		ostr << "yes"; 
	else ostr << "no"; 
	return ostr; 
} 
 
//------------------------------------------------------------------- 
#endif	// TIDY_PROXY_H