Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Syntax Coloring in HTML
Message
From
03/03/2000 03:42:53
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Internet applications
Title:
VFP Syntax Coloring in HTML
Miscellaneous
Thread ID:
00341120
Message ID:
00341120
Views:
68
Hi Folks,

There may already be ways to do this, but if you ever want to presenet VFP code on the Web, it looks pretty dry, so here's a simple program that I use.

This is a VFP Program that accpets a character string gives it VFP syntax coloring through HTML. As you can see the Program's contents was run through itself.

If you know of one, or are interested in helping build a table of all the reserved words that I can use to make stuff blue, that would be awesome.

I think it would be even cooler to see this built into the UT parser.

I already know about most of the issues (like Reserved Words in quotes are still black), but lemme know if this is useful, or its been done. And the way it actually prints the output is left open (I just put it on the clippboard), so you can use it in ASP or WWWC, whatever.



lparameters lcCode
clear
_cliptext = "<b><pre>"
*MH     lcCode = ;
*MH     "*Make sure we have something" + chr(13) + ;
*MH     "if llVal"  + chr(13) + ;
*MH     "     ?lcString " + chr(38) + "&Bug" + chr(13) + ;
*MH     "endif.if"

local laRWs[23]
laRWs[1] = ' IF '
laRWs[2] = ' ENDIF '
laRWs[3] = ' LOCAL '
laRWs[4] = ' CLEAR '
laRWs[5] = ' _CLIPTEXT '
laRWs[6] = ' CHR '
laRWs[7] = ' ALINES '
laRWs[8] = ' FOR '
laRWs[9] = ' EACH '
laRWs[10] = ' IN '
laRWs[11] = ' UPPER '
laRWs[12] = ' ALLTRIM '
laRWs[13] = ' LOOP '
laRWs[14] = ' STUFF '
laRWs[15] = ' TO '
laRWs[16] = ' OCCURS '
laRWs[17] = ' AT '
laRWs[18] = ' ENDFOR '
laRWs[19] = ' LPARAMETERS '
laRWs[20] = ' TRIM '
laRWs[21] = ' LEN '
laRWs[22] = ' CHRTRAN '
laRWs[23] = ' STRTRAN '

lcCode = strtran(lcCode, chr(9), space(5))
lcCode = strtran(lcCode, '<', '<')
lcCode = strtran(lcCode, '>', '>')
local laLines[1]
alines(laLines, lcCode)
*suspend

for each lcLine in laLines

     *Full Line Comments, first
     if upper(alltrim(lcLine)) = '*' or;
          upper(alltrim(lcLine)) = 'NOTE'
          lcLine = '<font color=green>' + ;
               lcLine + '</font>'

          *Print line here
          ?lcLine
          _cliptext = _cliptext + chr(13) + chr(10) + lcLine
          loop
     endif

     *Now end of the line comments
     local lcDoubleAmp, lnStartComment
     lcDoubleAmp = chr(38) + chr(38)
     lnStartComment = at(lcDoubleAmp, lcLine)
     if lnStartComment > 0
          lcLine = stuff(lcLine, lnStartComment, 0, '<font color=green>') + ;
               '</font>'
     endif

     *Define vars ahead of time
     *So they do not always need to be
     *Calculated in the loops
     local lcFormat, lnFormatLength, lcFL, ;
          lcRW, lnRWLength, lnStartRW, lnOccurance
     lcFormat = '<font color=blue>'
     lnFormatLength = len(lcFormat)
     lcFL = ' '+ upper(trim(chrtran(lcLine, ':;./\<>+=-}]()', space(14)))) + ' '

     for each lcRW in laRWs
          lnRWLength = len(lcRW) - 2

          *For each occurance of an RW ...
*MH               for lnX = 1 to occurs(lcRW, lcFL)
          lnOccurance = 1
          lnStartRW = at(lcRW, lcFL, 1)
          do while lnStartRW > 0

               *Put in the format tags
               lcLine = stuff(lcLine, lnStartRW, 0, lcFormat)
               lcLine = stuff(lcLine, lnStartRW + lnFormatLength + lnRWLength, 0, '</font>')
               lcFL = ' '+ upper(trim(chrtran(lcLine, ':;./\<>+=-}]()', space(14)))) + ' '
*MH                    lcFL = stuff(lcFL, lnStartRW, 0, lcFormat)
*MH                    lcFL = stuff(lcFL, lnStartRW + lnFormatLength + lnRWLength, 0, '</font>')

               lnOccurance = lnOccurance + 1
               lnStartRW = at(lcRW, lcFL, lnOccurance)
          enddo
     endfor
     ?lcLine
     _cliptext = _cliptext + chr(13) + chr(10) + lcLine
endfor
_cliptext = _cliptext + '</pre><b>'
Next
Reply
Map
View

Click here to load this message in the networking platform