EnglishРусский  

   ..

   htmlfromcode.g

   main.g

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

source\example\converthtml\htmlfromcode.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2004-2006, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project.
  5 * http://www.gentee.com
  6 * 
  7 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  8 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  9 * ACCEPTANCE OF THE AGREEMENT.
 10 *
 11 * ID: htmlfromcode 31.10.06
 12 *
 13 * Author: Aleksandr Antypenko ( santy )
 14 *
 15 * Summary: Function converting from gentee code to the html 
 16 *
 17 ******************************************************************************/
 18 
 19 define
 20 {
 21    DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">"
 22    REST = "<body>\n<!-- Generated with ge2html by Alex Antypenko -->\n<code>\n<pre>\n"
 23    HEADER = "\$DOCTYPE$ <html>\n \$REST"
 24    CSS_FILE = ".comment  {color:#cc9999;}\n .keyword  {color:#000000;font-weight: bold;}\n .builtin  {color:#006600;font-weight: bold;}\n .string  {color:#00A033;}\n .syschar {color:#993333;}\n .operchar {color:#330033;}\n .bracket3 {color:#0000FF;}\n .numlines {color:#000000;}\n .number {color:#009999;}\n .type {color:#0000FF;}"
 25    HEADER_CSS = "\$DOCTYPE$\n<html>\n<head>\n<style>\n<!-- \n \$CSS_FILE$ \n-->\n</style>\n</head>\n\$REST$"
 26    HEADER_CSS_FILE = "\$DOCTYPE$\n<html>\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"genteecode.css\">\n</head>\n\$REST$"
 27    FOOTER = "\n</pre>\n</code>\n</body>\n</html>"
 28    END_TAGS = "</font>"
 29    END_TAGS_CSS = "</span>"
 30 
 31 } 
 32 
 33 include
 34 {
 35    $"..\..\lib\lex\lex.g"
 36    "lexfgentee.g"
 37 } 
 38 
 39 global
 40 {
 41    arr tags of str = %{
 42       "",      // normal
 43       "<font color=\"#cc9999\">",      // comment
 44       "<font color=\"#000000\">",      // keyword 
 45       "<font color=\"#006600\">",      // builtin #FF00FF - ping
 46       "<font color=\"#00A033\">",      // string
 47       "<font color=\"#993333\">",      // syschar
 48       "<font color=\"#330033\">",      // operchar
 49       "<font color=\"#0000FF\">",      // bracket #3
 50       "<font color=\"#000000\">",      // numLines
 51       "<font color=\"#009999\">",      // Number
 52       "<font color=\"#00ccff\">"       // type       
 53    } 
 54    arr tags_css of str = %{
 55       "",      // normal, nothing needed
 56       "<span class=comment>",      // comment
 57       "<span class=keyword>",      // keyword
 58       "<span class=builtin>",      // builtin
 59       "<span class=string>",       // string
 60       "<span class=syschar>",      // syschar
 61       "<span class=operchar>",     // bracket #2
 62       "<span class=bracket3>",     // bracket #3
 63       "<span class=numlines>",     // numLines
 64       "<span class=number>",       // number
 65       "<span class=type>"          // type      
 66    } 
 67 }
 68  
 69 /*-----------------------------------------------------------------------------
 70 *
 71 * ID: num2str 31.10.06 <version>
 72 * 
 73 * Summary: Convert number lines to the string type
 74 *
 75 * Parameters: 
 76 *           uint number   -  number of lines
 77 *				
 78 * Return :
 79 *        str - converted string
 80 *        
 81 -----------------------------------------------------------------------------*/
 82 func str num2str < result >( uint number )
 83 {
 84    str tmpStr ;
 85    int2str( tmpStr, "%d", number ) ;
 86    result = tmpStr.fillspacer( 5 ) ;
 87 } 
 88 /*-----------------------------------------------------------------------------
 89 *
 90 * ID: detag 31.10.06 <version>
 91 * 
 92 * Summary: Change "<" or ">" symbols on "<" ;">","
 93 *
 94 * Parameters: 
 95 *           str stringInfo    -  string for converting
 96 *				
 97 * Return :
 98 *        str - converted string
 99 *        
100 -----------------------------------------------------------------------------*/
101 func str detag < result >( str stringInfo )
102 {
103    str strResult
104    uint i
105    for i = 0, i <= *stringInfo-1, ++i
106    {
107       str strTmp
108       if( stringInfo [ i ] == 0x3C ) : strResult += "<"
109       elif( stringInfo [ i ] == 0x3E ) : strResult += ">"
110       elif (stringInfo [ i ] == 0x22)  : strResult += """
111       else 
112       {
113         strResult += char2str(strTmp,stringInfo [ i ])
114         strTmp.clear()
115       }
116    } 
117    result = strResult
118 } 
119 
120 /*------------------------------------------------------------------------------
121 * ID: htmlcodegentee 31.10.06 <version>
122 * 
123 * Summary: Convert gentee code to the html
124 
125 *   Function formatfile - 
126 *     
127 *   Parameters: 
128 *           str namefile    -  name of input file
129 *	    str OutToFile   -  buffer for converting html code
130 *				
131 *   Return :
132 *        1 - converting buffer
133 *
134 ------------------------------------------------------------------------------*/
135 func int htmlcodegentee( str namefile, str outToFile )
136 {
137    str inBuffer, strOutFile, strLine, stemp
138    arrout outArr
139    uint lex, off, i
140    uint igt   // The current gtitem   
141    uint startPos, sMainValue, countMult = 0
142    byte bNewLine = 1, inBlock = 0, bDot = 0, bDugky = 0
143    uint countLines = 1 ;
144 
145    outArr.isize = sizeof( lexitem )
146    if !( fileexist( namefile ) )
147    {
148       print( "File not found \n" )
149       return 0 ;
150    } 
151    inBuffer.read( namefile )
152    lex = lex_init( 0, lexfgentee.ptr( ) )
153    gentee_lex( inBuffer -> buf, lex, outArr )
154    //print("------------------------ddd--\n") 
155    //
156    off = outArr.data.ptr( )
157    str stemp1
158    fornum i = 0, * outArr
159    {
160       uint li
161 
162       li as off -> lexitem
163 
164       stemp1.clear( )
165 
166       //print( "type=\( hex2stru( "", li.ltype ) ) pos = \( li.pos ) len=\( li.len ) \( hex2stru( "", li.value ) ) \n" )
167       if( li.ltype == $FG_NAME )
168       {
169          uint uKod
170          if( li.value == $KEY_INCLUDE || li.value == $KEY_FUNC || li.value == $KEY_GLOBAL
171              || li.value == $KEY_DEFINE || li.value == $KEY_IMPORT || li.value == $KEY_METHOD
172              || li.value == $KEY_OPERATOR || li.value == $KEY_TYPE || li.value == $KEY_IFDEF 
173 			    || li.value == $KEY_EXTERN)
174          {
175             startPos = * strLine
176             sMainValue = li.value
177             bNewLine = 0
178             strLine.fillspacer( startPos )
179             strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + "" + tags_css [ 2 ] +stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
180          } 
181          elif ( li.value == $KEY_ARR || li.value == $KEY_BUF || li.value == $KEY_BYTE || li.value == $KEY_DOUBLE ||
182               li.value == $KEY_FLOAT || li.value == $KEY_HASH || li.value == $KEY_INT || li.value == $KEY_LONG ||
183               li.value == $KEY_SHORT || li.value == $KEY_STR || li.value == $KEY_UBYTE || li.value == $KEY_UINT ||
184               li.value == $KEY_ULONG || li.value == $KEY_USHORT )
185          {
186             uKod = 10
187             if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ uKod ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS ; bNewLine = 0
188             else : strLine += tags_css [ uKod ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
189          }
190          elif ( li.value == $KEY_AS || li.value == $KEY_BREAK || li.value == $KEY_CASE || li.value == $KEY_CONTINUE ||
191               li.value == $KEY_DEFAULT || li.value == $KEY_DO || li.value == $KEY_ELIF || li.value == $KEY_ELSE ||
192               li.value == $KEY_FOR || li.value == $KEY_FOREACH || li.value == $KEY_GOTO || li.value == $KEY_IF ||
193               li.value == $KEY_LABEL || li.value == $KEY_OF || li.value == $KEY_RETURN  || li.value == $KEY_SWITCH ||
194 			     li.value == $KEY_SUBFUNC || li.value == $KEY_WHILE || li.value == $KEY_FORNUM)
195          {
196             uKod = 3
197             if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ uKod ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS ; bNewLine = 0
198             else : strLine += tags_css [ uKod ] + "<B>"+stemp.substr( inBuffer, li.pos, li.len ) + "</B>"+$END_TAGS_CSS
199          }
200          else
201          {
202             if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + stemp.substr( inBuffer, li.pos, li.len ); bNewLine = 0
203             else : strLine += stemp.substr( inBuffer, li.pos, li.len )
204          } 
205       } 
206       elif( li.ltype == $FG_STRING || li.ltype == $FG_MACROSTR )
207       {
208          if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ 4 ] + detag( stemp.substr( inBuffer, li.pos, li.len ) ) + $END_TAGS_CSS ; bNewLine = 0
209          else : strLine += tags_css [ 4 ] + detag( stemp.substr( inBuffer, li.pos, li.len ) ) + $END_TAGS_CSS
210       }
211       elif( li.ltype == $FG_BINARY)
212       {
213          if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ 7 ] + stemp.substr( inBuffer, li.pos, li.len )  + $END_TAGS_CSS ; bNewLine = 0
214          else : strLine += tags_css [ 7 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
215       }
216       elif( li.ltype == $FG_COMMENT )
217       {
218          //strLine += stemp.substr( inBuffer, li.pos, li.len )
219          str commentBuf = stemp.substr( inBuffer, li.pos, li.len )
220          arr commentArr of str ;
221          commentBuf.lines( commentArr, 0 )
222          //uint cur
223          foreach cur, commentArr
224          {
225             strLine += tags_css [ 8 ] + num2str( countLines ++ ) + $END_TAGS_CSS + tags_css [ 1 ] + cur + $END_TAGS_CSS
226          } 
227          strLine += "\n"
228          //if (bNewLine) : bNewLine=0
229       } 
230       elif( li.ltype == $FG_LINECOMMENT )
231       {
232          if( bNewLine )
233          {
234             strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ 1 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
235             bNewLine = 0
236          } 
237          else : strLine += tags_css [ 1 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
238       } 
239       elif( li.ltype == $FG_SPACE || li.ltype == $FG_TAB )
240       {
241          //off += sizeof( lexitem )
242          if( bNewLine )
243          {
244             strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + "" + stemp.substr( inBuffer, li.pos, li.len )
245             bNewLine = 0
246          } 
247          else : strLine += stemp.substr( inBuffer, li.pos, li.len )
248          //continue
249       } 
250       elif( li.ltype == $FG_NUMBER || li.ltype == $FG_MACRO )
251       {
252          if( bNewLine )
253          {
254             bNewLine = 0
255             strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ 9 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
256          } 
257          else : strLine += tags_css [ 9 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
258       } 
259       elif( li.ltype == $FG_OPERCHAR )
260       {
261          if( bNewLine )
262          {
263             strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ 6 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
264             bNewLine = 0
265          } 
266          else : strLine += tags_css [ 5 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
267       } 
268       elif( li.ltype == $FG_UNKNOWN )
269       {
270          if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + stemp.substr( inBuffer, li.pos, li.len );bNewLine=0
271          else : strLine += stemp.substr( inBuffer, li.pos, li.len )
272       } 
273       elif( li.ltype == $FG_SYSCHAR )
274       {
275          str cTmp = ""
276          if( li.value == 0x29 ) : cTmp = ""
277          if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + tags_css [ 5 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS ; bNewLine = 0
278          else : strLine += cTmp + tags_css [ 5 ] + stemp.substr( inBuffer, li.pos, li.len ) + $END_TAGS_CSS
279       } 
280       elif( li.ltype == $FG_LINE )
281       {
282          //strLine += stemp.substr( inBuffer, li.pos, li.len )
283          if( bNewLine ) : strLine += tags_css [ 8 ] + num2str( countLines ) + $END_TAGS_CSS + "" + stemp.substr( inBuffer, li.pos, li.len )
284          else : strLine += stemp.substr( inBuffer, li.pos, li.len )
285 
286          strOutFile += strLine
287          //print(strLine+"----111111 \n")
288          bNewLine = 1
289          countLines ++ ;
290          strLine.clear( )
291       } 
292       stemp.clear( )
293       off += sizeof( lexitem )
294    } 
295    outToFile = strOutFile
296    lex_delete( lex )
297    return 1
298 } 
299 
300 
301 func uint process_file( str namefile )
302 {
303    uint loadFile, writeFile
304    str strtoFile, outData, snewfile
305 
306    strtoFile += $HEADER_CSS
307    if( ! htmlcodegentee( namefile, outData ) ) : return 0 ;
308    strtoFile += outData + $FOOTER
309    snewfile.fsetext( namefile, "html" )
310    if !( writeFile = open( snewfile, $OP_CREATE ) ) : return 0
311    strtoFile.write( writeFile )
312    close( writeFile )
313    return 1
314 } 
315 
Редактировать