SUB File2Html (inTxt AS STRING, outFile AS STRING, useEscapes AS INTEGER)
DIM keyList AS QSTRINGLIST
DIM i AS LONG
DIM j AS LONG
DIM quote AS BYTE
DIM ch AS STRING * 1
DIM token AS STRING
IF FILEEXISTS("keyword.lst") = 0 THEN
SHOWMESSAGE "ERROR can't find file keyword.lst"
EXIT SUB
ELSE
keyList.LoadFromFile("keyword.lst")
END IF
IF gFStream.OPEN(outFile, fmCreate) = 0 THEN
SHOWMESSAGE "ERROR in creating file " + outFile
EXIT SUB
END IF
Stat.Panel(5).CAPTION = "converting to html > " + outFile
gFStream.writeLine("<html>")
gFStream.writeLine("<head>")
gFStream.writeLine("<title> RapidQ Code </title>")
gFStream.writeLine("</head>")
gFStream.writeLine("<body bgcolor="+Quot$+"FFFFFF"+Quot$+">")
gFStream.writeLine("<pre>")
tmpList.text = inTxt
FOR i = 0 TO tmpList.itemCount-1
quote = FALSE
token = ""
FOR j = 1 TO LEN(tmpList.item(i))
ch = tmpList.item(i)[j]
IF INSTR("+-=<>()\/^&*[]:;?, "+ Quot$ + TAB, ch) THEN
IF ch = Quot$ THEN
gFStream.write(ch)
FOR j = j+1 TO LEN(tmpList.item(i))
ch = tmpList.item(i)[j]
IF useEscapes THEN
IF ch = "\\" THEN
token = token + ch
j++
ch = tmpList.item(i)[j]
token = token + ch
ELSEIF ch = Quot$ THEN
EXIT FOR
ELSE
IF ch = "<" THEN
token = token + "<"
ELSE
token = token + ch
END IF
END IF
ELSE
IF ch = Quot$ THEN
EXIT FOR
ELSE
IF ch = "<" THEN
token = token + "<"
ELSE
token = token + ch
END IF
END IF
END IF
NEXT
gFStream.write("<font color="+Quot$+"990000"+Quot$+">"+token+"</font>")
ELSEIF ch = sQuot THEN
IF token <> "" THEN
IF keyList.find(UCASE$(token)) <> -1 THEN
gFStream.write("<font color="+Quot$+"0000AA"+Quot$+"><b>"+token+"</b></font>")
ELSE
gFStream.write(token)
END IF
END IF
token = ""
FOR j = j TO LEN(tmpList.item(i))
ch = tmpList.item(i)[j]
IF ch = "<" THEN
token = token + "<"
ELSE
token = token + ch
END IF
NEXT
gFStream.write("<font color="+Quot$+"007700"+Quot$+"><i>"+token+"</i></font>")
ch = ""
ELSEIF token <> "" THEN
IF keyList.find(UCASE$(token)) <> -1 THEN
gFStream.write("<font color="+Quot$+"0000AA"+Quot$+"><b>"+token+"</b></font>")
ELSE
gFStream.write(token)
END IF
END IF
IF ch = "<" THEN
gFStream.write("<")
ELSEIF ch = "(" OR ch = ")" THEN
gFStream.write("<b>"+ch+"</b>")
ELSE
gFStream.write(ch)
END IF
token = ""
ELSE
token = token + ch
END IF
NEXT
IF token <> "" THEN
IF keyList.find(UCASE$(token)) <> -1 THEN
gFStream.write("<font color="+Quot$+"000099"+Quot$+"><b>"+token+"</b></font>")
ELSE
gFStream.write(token)
END IF
END IF
gFStream.write(CRLF)
$IFDEF WIN32
LOCATE CSRLIN, 1
$ENDIF
NEXT
gFStream.writeLine("</pre>")
gFStream.writeLine("</body>")
gFStream.writeLine("</html>")
gFStream.CLOSE
END SUB
|