#define ccRW '<font color=blue>' #define ccCOMMENT '<font color=green>' #define ccCLOSE '</font>' #define cnRWLEN 17 #define cnCLOSELEN 7 *Collect out parameters and check 'em lparameters tcCode, tcPath local lcCode lcCode = tcCode if empty(lcCode) return '' endif wait wind nowai &&This is to test partial words *The words table holds all of the words that will turn color local llCloseWords if not used('words') llCloseWords = .T. use (iif(empty(tcPath), '', tcPath) + 'words') in 0 endif *Start the clock lnSec = Seconds() *Setup two simple variables for speed local leCR, leLF leCR = chr(13) leLF = chr(10) leTab = chr(9) *Do some basic HTML intializing lcCode = strtran(lcCode, '&', '&amp;') lcCode = strtran(lcCode, '<', '&lt;') lcCode = strtran(lcCode, '>', '&gt;') lcCode = strtran(chrtran(lcCode, leLF, ''), leCR, leCR + leLF) *Create an array element for each line and start to proccess local laLines[1], lcReturn, lnI, lcLine lnLines = alines(laLines, lcCode) lcReturn = '<pre>' *Proccess each line for lnI = 1 to lnLines lcLine = laLines[lnI] *Don't even bother the blank ones if empty(alltrim(lcLine)) lcReturn = lcReturn + leCR + leLF loop endif *Full Line Comments, first local lcNoTabLine lcNoTabLine = upper(ltrim(chrtran(lcLine, leTab, ''))) if lcNoTabLine = '*' or ; lcNoTabLine = 'NOTE' lcLine = ccCOMMENT + lcLine + ccCLOSE *And move on lcReturn = lcReturn + leCR + leLF + lcLine loop endif *Now end of the line comments local lnStartComment, lcComment lnStartComment = at('&amp;&amp;', lcLine) if lnStartComment > 0 lcComment = ccCOMMENT + substr(lcLine, lnStartComment) + ccCLOSE lcLine = substr(lcLine, 1, lnStartComment - 1) else lcComment = '' endif *Lets loop through every word in our line local laWords[1], ; lcTempLine, ; lnOffSet, ; lnWords, ; lnWord, ; lnWordLen lcTempLine = ' ' + ltrim(chrtran(upper(lcLine), ; '~! #$%^&*()-+=|\{}[]:;,./\<>' + leTab, space(29))) + ' ' lnOffset = len(lcLine) - len(lcTempLine) + 1 lnWords = occurs(' ', lcTempLine) - 1 lnRWs = 0 dime laWords[lnWords, 2] for lnWord = 1 to lnWords lnWordStart = at(' ', lcTempLine, lnWord) + 1 + lnOffset lcWord = substr(lcTempLine, ; lnWordStart - lnOffSet, ; at(' ', lcTempLine, lnWord + 1) - lnWordStart + lnOffSet) lnWordLen = len(lcWord) *Now, see if our word is a color changer if not empty(lcWord) and seek(iif(lnWordLen < 4, ; padr(lcWord, 4), lcWord), 'words', 'revword') *It is, insert the tags and bump the counter lcLine = stuff(lcLine, lnWordStart + ; ((cnRWLEN + cnCLOSELEN) * lnRWs), 0, ccRW) lcLine = stuff(lcLine, lnWordStart + ; ((cnRWLEN + cnCLOSELEN) * lnRWs) + cnRWLEN + lnWordLen, 0, ccCLOSE) lnRWs = lnRWs + 1 endif endfor lcReturn = lcReturn + leCR + leLF + lcLine + lcComment endfor *Return the orginal value so we can pass by ref if we want tcCode = lcReturn + '</pre>' lcSec = alltrim(str(seconds() - lnSec, 10, 6)) wait window nowait alltrim(str(lnLines)) + ; ' lines in ' + lcSec + ' seconds' *Finish out if llCloseWords use in words endif return tcCode