Back

1     //------------------------------------------------------------------------------
2     // Module: Conv2HTML.h                                                        //
3     //                                                                            //
4     //    Converts source code into HTML using ...                                //
5     //       a) TItemStyle (a syntax highlighting style)                          //
6     //       b) TLanguage (a language definition)                                 //
7     //       c) TOptions (settings like tab stop positions)                       //
8     //                                                                            //
9     //    Copyright (c) 2000-2004 by Lars Haendel                                 //
10    //    Home: http://www.newty.de                                               //
11    //                                                                            //
12    //    This program is free software; you can redistribute it and/or modify    //
13    //    it under the terms of the GNU General Public License as published by    //
14    //    the Free Software Foundation as version 2 of the License.               //
15    //                                                                            //
16    //    This program is distributed in the hope that it will be useful,         //
17    //    but WITHOUT ANY WARRANTY; without even the implied warranty of          //
18    //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
19    //    GNU General Public License for more details.                            //
20    //                                                                            //
21    //    You should have received a copy of the GNU General Public License       //
22    //    along with this program; if not, write to the Free Software             //
23    //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               //
24    //                                                                            //
25    //------------------------------------------------------------------------------
26
27
28    #ifndef Conv2HTMLH
29    #define Conv2HTMLH
30
31    #include <iostream>                 // due to:  ifstream ...
32
33    #include "ItemStyle.h"              //          TItemStyle
34    #include "Options.h"                //          TOptions
35    #include "language.h"               //          TLanguage
36    #include "defines.h"                //          general defines
37
38    #define OK           0              // return codes
39    #define WRITE_FAILED 2
40    #define MAX_LEN_LINE 1024           // maximum length of a line
41
42    #define SZ_HTML_PRGNAME "Lore&#039;s Source to HTML Converter"
43    #define SZ_HTML_PRGLINK "www.newty.de/lsc/index.html"
44
45
46
47    //----------------------------------------------------------------------------------------------------------------------
48    // class TConv2HTML converts source code into HTML
49    class TConv2HTML
50    {
51    private:
52
53       //-------------------------------------------------------------------------------------------------------------------
54       //   parse functions and helpers
55       bool IsSymbol2(const char& c);                     // is character a "number-ending" symbol?
56
57       void ProcessComment(ofstream& file, const char*const& szLine, int& pos, const int& len, const int& h);
58       void ProcessPreproc(const char*const& szLine, int& pos, ofstream& des, const int& len, const int& h);
59       void ProcessString(ofstream& file, const char*const& szLine, int& pos, const int& len);
60       void ProcessNumber(ofstream& des, const char*const& szLine, int& pos, const int& len);
61       bool Check4Spaces (const char*const& szLine, int& pos);
62
63       //-------------------------------------------------------------------------------------------------------------------
64       //  functions which virtually(!) write HTML output
65       //  note: linefeeds/spaces are buffered and written in WriteItem() via a call of WriteWhiteSpaces()
66
67       void VirtuallyWriteLF(ofstream& file);              // write linefeed
68       inline void VirtuallyWriteTab();                    // write tab considering actual column
69       inline void VirtuallyWriteSpace();                  // write space
70
71
72       //-------------------------------------------------------------------------------------------------------------------
73       //  functions which really write HTML output
74       //  close all opened HTML tags
75       //  write a character replacing special characters like '&'
76       //  write tab
77       //  write all outstanding linefeeds and spaces
78       //  write identified code item
79       //  write header
80       //  write footer
81
82       void CloseHtmlTags(ofstream& file);
83       void WriteChar(ofstream& file, const char& c);
84       void WriteTab(ofstream& file);
85       void WriteWhiteSpaces(ofstream& file);
86       void WriteItem(ofstream& file, const TItemStyle::ItemType& itemType, const char*const& szCode, const int& nChar);
87
88       void WriteHeader(ofstream& file, const char*const& szSrcFileName, const char*const& szBackLink);
89       void WriteFooter(ofstream& file, const bool& f_Stop);
90
91
92       //-------------------------------------------------------------------------------------------------------------------
93       const TItemStyle* style;                           // syntax highlighting style
94       const TLanguage* lang;                             // language definition
95       const TOptions* options;                           // settings like tab stop positions
96
97       int  cMap[nItemType];                              // help-array which checks, if different items have the same color
98       int  col;                                          // column counter needed to evaluate tabs ('\t') in VirtuallyWriteTabs()
99       int  nItems;
100      int  nLines;                                       // number of outstanding linefeeds
101      int  nSpaces;                                      // number of outstanding spaces
102      int  line;
103      TItemStyle::ItemType IdType;                       // type identifier is mapped too
104
105      bool f_MultiLineComment;                           // flags indicating multiline comment, ...
106      bool f_MultiLinePreproc;                           // ... preprocessor directives or ...
107      bool f_MultiLineString;                            // strings
108
109      char cStringChar;                                  // character that started a multiline string
110      TItemStyle::ItemType lastType;                     // last item type for WriteItem(): needed to check color/style changes
111
112   public:
113
114      // constructor
115      TConv2HTML(const TItemStyle*const& _style, const TLanguage*const& _lang, const TOptions*const& _options);
116
117      // convert function which loads the file 'src' and writes the HTML code to 'des'
118      int Convert(ifstream& src, ofstream& des, const bool& f_Stop, int& progress, const char*const& szSrcFileName
119       , const char*const& szBackLink);
120   };
121   #endif

Top