Petr Schreiber
07-11-2009, 22:59
Hi guys,
I managed to generate CodeTips for 99% of ThinBASIC commands :D.
I did it completely by hand ... ok, just joking.
I first decompiled all the help files using HTML Help Workshop, and then ran the following script on them (warning, dirty code):
' -- HTML help 2 code tips
Uses "file", "console"
Dim Files() As String
Dim nFiles As Long
' -- Where HTML files are
Dim SearchPath As String = APP_SourcePath
' -- Filter them
nFiles = DIR_ListArray(Files, SearchPath, "*.htm", %FILE_NORMAL Or %FILE_ADDPATH)
Dim i As Long
Dim sBuffer, sSyntax, sDescription As String
Dim sCodeTips As String
Dim sLineFinal As String
PrintL nFiles, "found"
Dim found As Long
Dim fSpace As Long
For i = 1 To nFiles
' -- Load file
sBuffer = FILE_Load(Files(i))
If InStr(sBuffer, ">Syntax") = 0 Then Iterate For
' -- Extract and postprocess description
sDescription = GRAB$(sBuffer, ">Description", "Syntax<")
sDescription = Replace$(sDescription, " ", " ")
sDescription = Replace$(sDescription, $CRLF, "|")
sDescription = BirdBracketPurge(sDescription)
sDescription = Trim$(sDescription, Any $CRLF+$SPC)
sDescription = TrimFull$(sDescription)
While InStr(sDescription, "||")
sDescription = Replace$(sDescription, "||", "|")
Wend
sDescription = Trim$(sDescription, Any " |")
' -- Extract and postprocess syntax
If InStr(sBuffer, "Returns<") Then
sSyntax = GRAB$(sBuffer, ">Syntax", "Returns<")
Else
sSyntax = GRAB$(sBuffer, ">Syntax", "Return value<")
End If
sSyntax = Replace$(sSyntax, " ", " ")
If InStr(sSyntax, "= ") Then sSyntax = Remain$(sSyntax, "= ")
If InStr(sSyntax, " =") Then sSyntax = Remain$(sSyntax, " =")
If InStr(sSyntax, "Type") Then Iterate For
If InStr(sSyntax, "expression1") Then Iterate For
sSyntax = Replace$(sSyntax, $CRLF, "|")
sSyntax = BirdBracketPurge(sSyntax)
sSyntax = Trim$(sSyntax, Any $CRLF+$SPC)
sSyntax = TrimFull$(sSyntax)
While InStr(sSyntax, "||")
sSyntax = Replace$(sSyntax, "||", "|")
Wend
sSyntax = Trim$(sSyntax, Any " |")
' -- Silly bad syntax detection
If InStr(sSyntax, "2005") > 0 Then Iterate For
If InStr(sSyntax, "2006") > 0 Then Iterate For
If InStr(sSyntax, "2007") > 0 Then Iterate For
If InStr(sSyntax, "2008") > 0 Then Iterate For
If InStr(sSyntax, "2009") > 0 Then Iterate For
' -- Build final description
sLineFinal = sSyntax+"|"+sDescription+$CRLF
' -- Silly test if it is really what we want
If sLineFinal = "||.|"+$CRLF Then Iterate For
If InStr(sLineFinal, "( ...|... )") Then Iterate For
If sLineFinal = "FTP_(, )||.|"+$CRLF Then Iterate For
If LEFT$(sLineFinal, 1) = "|" Then Iterate For
If LEFT$(sLineFinal, 1) = "'" Then Iterate For
If LEFT$(sLineFinal, 1) = "%" Then Iterate For
If LEFT$(sLineFinal, 3) = "|||" Then Iterate For
If LEFT$(sLineFinal, 2) = "1|" Then Iterate For
If LEFT$(sLineFinal, 4) = "see(" Then Iterate For
If LEFT$(sLineFinal, 4) = "see " Then Iterate For
If LEFT$(sLineFinal, 7) = "number^" Then Iterate For
If LEFT$(sLineFinal, 6) = "for( C" Then Iterate For
If LEFT$(sLineFinal, 6) = "b Site" Then Iterate For
If LEFT$(sLineFinal, 5) = "TYPE(" Then Iterate For
If LEFT$(sLineFinal, 6) = "There(" Then Iterate For
If LEFT$(sLineFinal, 7) = "String(" Then Iterate For
If LEFT$(sLineFinal, 7) = "nStart(" Then Iterate For
If LEFT$(sLineFinal, 7) = "nStart " Then Iterate For
If LEFT$(sLineFinal,16) = "StringExpression" Then Iterate For
If LEFT$(sLineFinal, 9) = "There are" Then Iterate For
sCodeTips += sLineFinal
PrintL "--", Files(i)
Incr found
Next
Dim LinesOfClips() As String
Parse(sCodeTips, LinesOfClips, $CRLF)
Array Sort LinesOfClips
sCodeTips = Join$(LinesOfClips, $CRLF)
PrintL "END OF PROCESSING"
' -- Put it to clipboard
ClipBoard_SetText(sCodeTips)
WaitKey
' -- Removes anything bird brackets ( purging text from HTML tags )
Function BirdBracketPurge(sString As String) As String
Dim i As Long
Dim char, result As String
Dim inBracket As Long
For i = 1 To Len(sString)
char = Mid$(sString, i, 1)
If char = "<" Then Incr inBracket
If inBracket = 0 Then result += char
If char = ">" Then Decr inBracket
Next
Return result
End Function
To use it, just copy the contents of attached file to thinBasic_Codetips_Usr.ini
Petr
I managed to generate CodeTips for 99% of ThinBASIC commands :D.
I did it completely by hand ... ok, just joking.
I first decompiled all the help files using HTML Help Workshop, and then ran the following script on them (warning, dirty code):
' -- HTML help 2 code tips
Uses "file", "console"
Dim Files() As String
Dim nFiles As Long
' -- Where HTML files are
Dim SearchPath As String = APP_SourcePath
' -- Filter them
nFiles = DIR_ListArray(Files, SearchPath, "*.htm", %FILE_NORMAL Or %FILE_ADDPATH)
Dim i As Long
Dim sBuffer, sSyntax, sDescription As String
Dim sCodeTips As String
Dim sLineFinal As String
PrintL nFiles, "found"
Dim found As Long
Dim fSpace As Long
For i = 1 To nFiles
' -- Load file
sBuffer = FILE_Load(Files(i))
If InStr(sBuffer, ">Syntax") = 0 Then Iterate For
' -- Extract and postprocess description
sDescription = GRAB$(sBuffer, ">Description", "Syntax<")
sDescription = Replace$(sDescription, " ", " ")
sDescription = Replace$(sDescription, $CRLF, "|")
sDescription = BirdBracketPurge(sDescription)
sDescription = Trim$(sDescription, Any $CRLF+$SPC)
sDescription = TrimFull$(sDescription)
While InStr(sDescription, "||")
sDescription = Replace$(sDescription, "||", "|")
Wend
sDescription = Trim$(sDescription, Any " |")
' -- Extract and postprocess syntax
If InStr(sBuffer, "Returns<") Then
sSyntax = GRAB$(sBuffer, ">Syntax", "Returns<")
Else
sSyntax = GRAB$(sBuffer, ">Syntax", "Return value<")
End If
sSyntax = Replace$(sSyntax, " ", " ")
If InStr(sSyntax, "= ") Then sSyntax = Remain$(sSyntax, "= ")
If InStr(sSyntax, " =") Then sSyntax = Remain$(sSyntax, " =")
If InStr(sSyntax, "Type") Then Iterate For
If InStr(sSyntax, "expression1") Then Iterate For
sSyntax = Replace$(sSyntax, $CRLF, "|")
sSyntax = BirdBracketPurge(sSyntax)
sSyntax = Trim$(sSyntax, Any $CRLF+$SPC)
sSyntax = TrimFull$(sSyntax)
While InStr(sSyntax, "||")
sSyntax = Replace$(sSyntax, "||", "|")
Wend
sSyntax = Trim$(sSyntax, Any " |")
' -- Silly bad syntax detection
If InStr(sSyntax, "2005") > 0 Then Iterate For
If InStr(sSyntax, "2006") > 0 Then Iterate For
If InStr(sSyntax, "2007") > 0 Then Iterate For
If InStr(sSyntax, "2008") > 0 Then Iterate For
If InStr(sSyntax, "2009") > 0 Then Iterate For
' -- Build final description
sLineFinal = sSyntax+"|"+sDescription+$CRLF
' -- Silly test if it is really what we want
If sLineFinal = "||.|"+$CRLF Then Iterate For
If InStr(sLineFinal, "( ...|... )") Then Iterate For
If sLineFinal = "FTP_(, )||.|"+$CRLF Then Iterate For
If LEFT$(sLineFinal, 1) = "|" Then Iterate For
If LEFT$(sLineFinal, 1) = "'" Then Iterate For
If LEFT$(sLineFinal, 1) = "%" Then Iterate For
If LEFT$(sLineFinal, 3) = "|||" Then Iterate For
If LEFT$(sLineFinal, 2) = "1|" Then Iterate For
If LEFT$(sLineFinal, 4) = "see(" Then Iterate For
If LEFT$(sLineFinal, 4) = "see " Then Iterate For
If LEFT$(sLineFinal, 7) = "number^" Then Iterate For
If LEFT$(sLineFinal, 6) = "for( C" Then Iterate For
If LEFT$(sLineFinal, 6) = "b Site" Then Iterate For
If LEFT$(sLineFinal, 5) = "TYPE(" Then Iterate For
If LEFT$(sLineFinal, 6) = "There(" Then Iterate For
If LEFT$(sLineFinal, 7) = "String(" Then Iterate For
If LEFT$(sLineFinal, 7) = "nStart(" Then Iterate For
If LEFT$(sLineFinal, 7) = "nStart " Then Iterate For
If LEFT$(sLineFinal,16) = "StringExpression" Then Iterate For
If LEFT$(sLineFinal, 9) = "There are" Then Iterate For
sCodeTips += sLineFinal
PrintL "--", Files(i)
Incr found
Next
Dim LinesOfClips() As String
Parse(sCodeTips, LinesOfClips, $CRLF)
Array Sort LinesOfClips
sCodeTips = Join$(LinesOfClips, $CRLF)
PrintL "END OF PROCESSING"
' -- Put it to clipboard
ClipBoard_SetText(sCodeTips)
WaitKey
' -- Removes anything bird brackets ( purging text from HTML tags )
Function BirdBracketPurge(sString As String) As String
Dim i As Long
Dim char, result As String
Dim inBracket As Long
For i = 1 To Len(sString)
char = Mid$(sString, i, 1)
If char = "<" Then Incr inBracket
If inBracket = 0 Then result += char
If char = ">" Then Decr inBracket
Next
Return result
End Function
To use it, just copy the contents of attached file to thinBasic_Codetips_Usr.ini
Petr