EnglishРусский  

   ..

   src2html.g

Данный проект закрыт! Создан новый скриптовый язык с тем же именем. Всё доступно на GitHub.
Также попробуйте нашу open source кроссплатформенную программу для создания и управления скриптами.

Реклама

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

  1 #!gentee.exe -p default "%1"
  2 /******************************************************************************
  3 *
  4 * Copyright (C) 2007, The Gentee Group. All rights reserved. 
  5 * This file is part of the Gentee open source project - 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:  src2html 14.11.07 0.0.A.
 12 *
 13 * Author: Alexey Krivonogov ( gentee )
 14 *
 15 * Summary: 
 16 *
 17 ******************************************************************************/
 18 
 19 include
 20 {
 21    $"..\..\lib\lex\lexnew.g"
 22    $"..\autoformat\lexfgentee.g"
 23    $"..\autoformat\lexfc.g"
 24 } 
 25 
 26 define 
 27 {
 28    S2H_GENTEE = 0x0001
 29    S2H_C      = 0x0002
 30    S2H_UTF8   = 0x0010
 31    S2H_LINES  = 0x0020
 32 }
 33 
 34 text  src2html( str input, uint flags )
 35 \{
 36    arrout aout
 37    uint   lex, off, start, end, ptrlex
 38    str    out
 39         
 40    aout.isize = sizeof( lexitem )
 41    if flags & $S2H_C : ptrlex = lexfc.ptr() 
 42    else : ptrlex = lexfgentee.ptr()
 43    lex = lex_init( 0, ptrlex )
 44    
 45    if flags & $S2H_UTF8
 46    {
 47       ustr   ust = input
 48       ust.toutf8( input )
 49    }  
 50    gentee_lex( &input, lex, &aout )
 51 
 52    off = aout.data.ptr()
 53    start = input.ptr()
 54    end = aout.data.ptr() + *aout * sizeof( lexitem )
 55    while off < end
 56    {
 57       uint  li nospan 
 58       str   ok stemp
 59       
 60       li as off->lexitem
 61       // print("TYpe = \( hex2stru( li.ltype )) Off=\(li.pos) len = \(li.len)\n") 
 62       if flags & $S2H_C
 63       {      
 64       switch li.ltype
 65       {
 66          case $FC_NAME
 67          {
 68             if li.value && li.value <= 0xFF : out@"<span class=\"srk\">"
 69             elif li.value > 0xFF : out@"<span class=\"srt\">"
 70             else : nospan = 1
 71          }
 72          case $FC_STRING,$FC_BINARY : out@"<span class=\"srs\">"
 73          case $FC_COMMENT, $FC_LINECOMMENT : out@"<span class=\"src\">"
 74          case $FC_NUMBER : out@"<span class=\"srn\">"
 75          default : nospan = 1
 76       }
 77       }
 78       else
 79       {      
 80       switch li.ltype
 81       {
 82          case $FG_NAME
 83          {
 84             if li.value && li.value <= 0xFF : out@"<span class=\"srk\">"
 85             elif li.value > 0xFF : out@"<span class=\"srt\">"
 86             else : nospan = 1
 87          }
 88          case $FG_STRING,$FG_BINARY,$FG_TEXTSTR,$FG_FILENAME,$FG_MACROSTR
 89          {
 90             out@"<span class=\"srs\">"
 91          }
 92          case $FG_COMMENT, $FG_LINECOMMENT : out@"<span class=\"src\">"
 93          case $FG_MACRO : out@"<span class=\"srm\">"
 94          case $FG_NUMBER : out@"<span class=\"srn\">"
 95          default : nospan = 1
 96       }
 97       }
 98       ok.append( start + li.pos, li.len )
 99       stemp.replacech( ok, '<', "<" )
100       ok.replacech( stemp, '>', ">" )
101       out@ok
102       if !nospan : out@"</span>"
103       off += sizeof( lexitem ) 
104    }         
105    if flags & $S2H_LINES 
106    {
107       arrstr lines
108       uint   i width = 1
109       
110       lines.load( out, 0 )
111       i = *lines
112       while i /= 10 : width++
113       
114       fornum i = 0, *lines
115       {
116          @"<span class = \"line\">\( "".out4( "%\( width )i", i + 1 ))</span> \( lines[i] )\l"
117       }  
118    }
119    else : @out
120 
121 //   @input
122 }\!
123 
124 func mainsrc2html<main>
125 {
126    str in 
127    
128    in.read("c:\\temp\\calendar.g")
129    @src2html( in, $S2H_GENTEE )
130    getch()
131 }
Редактировать