DCL 3.7.4
Loading...
Searching...
No Matches
HtmlGenerator Class Reference

#include <HtmlGenerator.h>

Inheritance diagram for HtmlGenerator:
Object

Public Member Functions

 HtmlGenerator (const wchar_t *pszIDocIniFileName)
virtual ~HtmlGenerator ()
void generateHeader (Writer &out, const wchar_t *pszHtmlTitle=NULL)
void generateFooter (Writer &out)
bool generate (Writer &out, const wchar_t *pszFileName, const wchar_t *pszLangSyntax=NULL)
bool generate (Writer &out, const wchar_t *pData, size_t nDataSize, const wchar_t *pszLangSyntax)
void setOption (int nTabWidth, bool bShowLineNumber)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Member Functions

void writeLineNumber (Writer &out)
void writeData (Writer &out, const wchar_t *pData, size_t nDataSize)
void writeBegin (Writer &out, BlockType type)
void writeEnd (Writer &out, BlockType type)
void generateHelper (Writer &out, const wchar_t *pData, size_t nDataSize, const wchar_t *pszLanguageTitle)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Protected Attributes

PointerArray __vSyntaxes
int __nTabWidth
bool __bShowLineNumber
int __nLineNumber
BlockType __currentType

Detailed Description

Definition at line 24 of file HtmlGenerator.h.

Constructor & Destructor Documentation

◆ HtmlGenerator()

__DCL_BEGIN_NAMESPACE HtmlGenerator::HtmlGenerator ( const wchar_t * pszIDocIniFileName)

Definition at line 21 of file HtmlGenerator.cpp.

22{
23 __DCL_ASSERT(pszIDocIniFileName && Files::exists(pszIDocIniFileName));
24// __strIniFileName = pszIDocIniFileName;
25 IniFile ini(pszIDocIniFileName);
26 String strTemp = ini.getString(L"MAIN", L"SYNTAXES");
27 __DCL_ASSERT(!strTemp.isEmpty());
28 StringArray list;
29 strTemp.split(L' ', list);
30
31 String strPath = Files::dirname(pszIDocIniFileName);
32 String strTitle;
33 String strExt;
34 String strSyntaxFile;
35 for(StringArray::Iterator it = list.begin(); it != list.end(); it++) {
36 strTitle = *it;
37 strExt = ini.getString(strTitle, L"FILE_EXTENSION");
38 strSyntaxFile = strPath + ini.getString(strTitle, L"SYNTAX_FILE");
39
40 __DCL_TRACE3(L"Syntax title[%ls] ext[%ls] filename[%ls]",
41 strTitle.data(), strExt.data(), strSyntaxFile.data());
42
43 DocSyntax* p = new DocSyntax(strTitle, strExt);
44 p->load(strSyntaxFile);
45 __vSyntaxes.add(p);
46 }
47
48 __nTabWidth = 4;
49 __bShowLineNumber = true;
50 __nLineNumber = 1;
51}
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
Definition Object.h:401
#define __DCL_ASSERT(expr)
Definition Object.h:394
bool load(const wchar_t *pszFileName)
Definition DocSyntax.cpp:36
static String dirname(const String &_path)
Definition Files.cpp:268
static bool exists(const String &_path)
Definition Files.cpp:109
PointerArray __vSyntaxes

◆ ~HtmlGenerator()

HtmlGenerator::~HtmlGenerator ( )
virtual

Definition at line 53 of file HtmlGenerator.cpp.

54{
55 if (!__vSyntaxes.isEmpty()) {
56 for(size_t i = 0; i < __vSyntaxes.size(); i++)
57 delete (DocSyntax*)__vSyntaxes[i];
58 }
59}

Member Function Documentation

◆ generate() [1/2]

bool HtmlGenerator::generate ( Writer & out,
const wchar_t * pData,
size_t nDataSize,
const wchar_t * pszLangSyntax )

Definition at line 266 of file HtmlGenerator.cpp.

272{
274 out,
275 pData,
276 nDataSize,
277 pszLangSyntax
278 );
279 return true;
280}
void generateHelper(Writer &out, const wchar_t *pData, size_t nDataSize, const wchar_t *pszLanguageTitle)

◆ generate() [2/2]

bool HtmlGenerator::generate ( Writer & out,
const wchar_t * pszFileName,
const wchar_t * pszLangSyntax = NULL )

Definition at line 219 of file HtmlGenerator.cpp.

224{
225 __DCL_ASSERT(pszFileName != NULL);
226
227 String strLangSyntax;
228 if (pszLangSyntax == NULL) {
229 const wchar_t* p = pszFileName + String::length(pszFileName);
230 while(--p > pszFileName) {
231 if (*p == '.') {
232 p++;
233 break;
234 }
235 }
236
237 if (p == pszFileName)
238 return false; // invalid file name;
239
240 DocSyntax* pSyntax = NULL;
241 for(size_t i = 0; i < __vSyntaxes.size(); i++) {
242 pSyntax = (DocSyntax*)(__vSyntaxes[i]);
243 if (pSyntax->isValidExtension(p)) {
244 strLangSyntax = pSyntax->languageTitle();
245 pszLangSyntax = strLangSyntax.data();
246 break;
247 }
248 }
249 }
250
251 __DCL_ASSERT(pszLangSyntax != NULL);
252 __DCL_ASSERT(Files::exists(pszFileName));
253
254 UTF8Decoder dec;
255 String text = Files::readText(pszFileName, dec);
256
258 out,
259 text,
260 text.length(),
261 pszLangSyntax
262 );
263 return true;
264}
#define NULL
Definition Config.h:312
const String & languageTitle() const
Definition DocSyntax.h:79
bool isValidExtension(const wchar_t *pszFileExt) const
Definition DocSyntax.cpp:67
static String readText(const String &_filename) __DCL_THROWS1(IOException *)
Definition Files.cpp:435

◆ generateFooter()

void HtmlGenerator::generateFooter ( Writer & out)

Definition at line 313 of file HtmlGenerator.cpp.

314{
315 String strFooter = L""
316 "\n</body>"
317 "\n</html>";
318
319 out << strFooter;
320}

◆ generateHeader()

void HtmlGenerator::generateHeader ( Writer & out,
const wchar_t * pszHtmlTitle = NULL )

Definition at line 288 of file HtmlGenerator.cpp.

292{
293 if (pszHtmlTitle == NULL)
294 pszHtmlTitle = L"Unknown File Name";
295
296 StringBuilder strHeader = L""
297 "<!DOCTYPE html>"
298 "\n<html lang=\"ko-KR\">"
299 "\n<head>"
300 "\n<meta charset=\"UTF-8\" >"
301 "\n<meta name=\"generator\" content=\"src2html 0.9\">"
302 "\n<meta name=\"author\" content=\"Daejung Kim &lt;daejung@sysdeveloper.net&gt; http://www.sysdeveloper.net/daejung\">"
303 "\n<title>";
304 strHeader += pszHtmlTitle;
305 strHeader += L"</title>";
306 strHeader += L""
307 "\n</head>"
308 "\n<body>";
309
310 out << strHeader;
311}

◆ generateHelper()

void HtmlGenerator::generateHelper ( Writer & out,
const wchar_t * pData,
size_t nDataSize,
const wchar_t * pszLanguageTitle )
protected

Definition at line 178 of file HtmlGenerator.cpp.

184{
186 DocSyntax* pSyntax = NULL;
187 for(size_t i = 0; i < __vSyntaxes.size(); i++) {
188 if (((DocSyntax*)__vSyntaxes[i])->isValidLanguage(pszLanguageTitle))
189 {
190 pSyntax = (DocSyntax*)__vSyntaxes[i];
191 break;
192 }
193 }
194 __DCL_ASSERT(pSyntax != NULL); // Not Found Syntax
195
196 if (__nTabWidth == 0)
197 __nTabWidth = pSyntax->tabWidth();
198
199 out << L"\n<pre style=\"background-color:white; color:black; font-style=normal; font-weight:normal\">";
200 __nLineNumber = 1;
202 writeLineNumber(out);
203
204 DocParser parser(pData, nDataSize, pSyntax);
205 DOC_BLOCK block;
206 while(parser.getNextBlock(block)) {
207 if (__currentType != block.type) {
209 writeBegin(out, block.type);
210 __currentType = block.type;
211 }
212
213 writeData(out, block.pData, block.nDataSize);
214 }
216 out << L"\n</pre>";
217}
@ normal
Definition DocParser.h:16
int tabWidth() const
Definition DocSyntax.h:89
void writeBegin(Writer &out, BlockType type)
void writeLineNumber(Writer &out)
void writeData(Writer &out, const wchar_t *pData, size_t nDataSize)
void writeEnd(Writer &out, BlockType type)
BlockType __currentType
BlockType type
Definition DocParser.h:26
const wchar_t * pData
Definition DocParser.h:24
size_t nDataSize
Definition DocParser.h:25

◆ setOption()

void HtmlGenerator::setOption ( int nTabWidth,
bool bShowLineNumber )

Definition at line 282 of file HtmlGenerator.cpp.

283{
284 __nTabWidth = nTabWidth;
285 __bShowLineNumber = bShowLineNumber;
286}

◆ writeBegin()

void HtmlGenerator::writeBegin ( Writer & out,
BlockType type )
protected

Definition at line 75 of file HtmlGenerator.cpp.

76{
77 switch(type) {
78 case normal :
79 break;
80 case comment :
81 out << L"<span style=\"color:green;\">";
82 break;
83 case quotation :
84 out << L"<span style=\"color:red;\">";
85 break;
86 case keyword :
87 out << L"<span style=\"color:blue;\">";
88 break;
89 default :
90 __DCL_ASSERT(false);
91 }
92}
@ quotation
Definition DocParser.h:18
@ comment
Definition DocParser.h:17
@ keyword
Definition DocParser.h:19

◆ writeData()

void HtmlGenerator::writeData ( Writer & out,
const wchar_t * pData,
size_t nDataSize )
protected

Definition at line 121 of file HtmlGenerator.cpp.

124{
125 const wchar_t* pStart = pData;
126 const wchar_t* pCurrent = pStart;
127
128 while(pCurrent < (pData + nDataSize)) {
129 switch(*pCurrent) {
130 case L'\t': {
131 if (__nTabWidth > 0) {
133 String str(L' ', __nTabWidth);
134 out.write(str.data(), str.length());
135 }
136 break;
137 }
138 case L'\r': {
139 if (__bShowLineNumber) {
141 }
142 break;
143 }
144 case L'\n': {
145 if (__bShowLineNumber) {
147 writeLineNumber(out);
148 }
149 else
150 out << L"\n";
151
152 break;
153 }
154 case '>': {
156 out << L"&gt;";
157 break;
158 }
159 case '<': {
161 out << L"&lt;";
162 break;
163 }
164 case '&': {
166 out << L"&amp;";
167 }
168 default: {
169 // out->write(pCurrent, 1);
170 ;
171 }
172 }
173 pCurrent++;
174 }
176}
#define FLUSH_PRIOR

◆ writeEnd()

void HtmlGenerator::writeEnd ( Writer & out,
BlockType type )
protected

Definition at line 94 of file HtmlGenerator.cpp.

95{
96 switch(type) {
97 case normal :
98 break;
99 case comment :
100 case quotation :
101 case keyword :
102 out << L"</span>";
103 break;
104 default :
105 __DCL_ASSERT(false);
106 }
107}

◆ writeLineNumber()

void HtmlGenerator::writeLineNumber ( Writer & out)
protected

Definition at line 65 of file HtmlGenerator.cpp.

66{
68
69 out << String::format(L"\n<span style=\"color:gray;\">%3d: ", __nLineNumber++);
70 out << L"</span>";
71
73}

Member Data Documentation

◆ __bShowLineNumber

bool HtmlGenerator::__bShowLineNumber
protected

Definition at line 67 of file HtmlGenerator.h.

◆ __currentType

BlockType HtmlGenerator::__currentType
protected

Definition at line 69 of file HtmlGenerator.h.

◆ __nLineNumber

int HtmlGenerator::__nLineNumber
protected

Definition at line 68 of file HtmlGenerator.h.

◆ __nTabWidth

int HtmlGenerator::__nTabWidth
protected

Definition at line 66 of file HtmlGenerator.h.

◆ __vSyntaxes

PointerArray HtmlGenerator::__vSyntaxes
protected

Definition at line 27 of file HtmlGenerator.h.


The documentation for this class was generated from the following files: