Code: Select all
Function base:TidyText(text$)
Local dictionary =
{
{ "@APPAUTHOR ", 0 },
{ "@APPCOPYRIGHT ", 0 },
{ "@APPDESCRIPTION ", 0 },
{ "@APPICON ", 0 },
{ "@APPTITLE ", 0 },
{ "@APPVERSION ", 0 },
{ "@AUTHOR ", 0 },
{ "@DESCRIPTION ", 0 },
{ "@DISPLAY ", 0 },
{ "@INCLUDE ", 0 },
{ "@OPTIONS ", 0 },
{ "@REQUIRE ", 0 },
{ "Case ", 1 },
{ "CloseFile", 2 },
{ "Const ", 1 },
{ "CtrlCQuit", 2 },
{ "DebugPrint", 2},
{ "Default", 1 },
{ "DimStr", 2 },
{ "Else", 1 },
{ "End()", 2 },
{ "EndFunction", 1 },
{ "EndIf", 1 },
{ "EndSwitch", 1 },
{ "Exists", 2 },
{ "ExitOnError", 2 },
{ "FindStr", 2 },
{ "For ", 1 },
{ "Forever", 1 },
{ "Function ", 1 },
{ "GetFileAttributes", 2 },
{ "Global ", 1 },
{ "If ", 1 },
{ "InstallEventHandler", 2 },
{ "LoadBrush", 2 },
{ "Local ", 1 },
{ "MakeDirectory", 2 },
{ "MidStr", 2 },
{ "mui.CreateGUI", 2 },
{ "mui.Get", 2 },
{ "mui.IsVersion() ", 2 },
{ "mui.Set", 2 },
{ "Next", 1 },
{ "OpenFile", 2 },
{ "PathPart", 2 },
{ "ReadLine", 2 },
{ "Repeat", 1 },
{ "ReplaceStr", 2 },
{ "Return", 1 },
{ "Seek", 2 },
{ "SendRexxCommand", 2 },
{ "SplitStr", 2 },
{ "Switch ", 1 },
{ "SystemRequest", 2 },
{ "ToNumber", 2 },
{ "ToString", 2 },
{ "TrimStr", 2 },
{ "WaitEvent()", 2 },
{ "Wend", 1 },
{ "While Not Eof", 2 },
{ "WriteLine", 2 },
}
Local lines, count = SplitStr(text$,"\n")
Local colours = {}
colours[0] = FormatStr("%.6X",Config[11]) ; Preprocessors
colours[1] = FormatStr("%.6X",Config[12]) ; Structure
colours[2] = FormatStr("%.6X",Config[13]) ; Commands
colours[3] = FormatStr("%.6X",Config[14]) ; Comments
colours[4] = FormatStr("%.6X",Config[15]) ; Default Text
Local skip = False
For Local l = 0 to count-1
If LeftStr(lines[l],2) = "/*" or LeftStr(lines[l],1) = ";" or LeftStr(lines[l],1) = "*" or LeftStr(lines[l],6) = "@BRUSH" or LeftStr(TrimStr(lines[l],"\t",False),2) = ";;"
If RightStr(lines[l],2) = "*/"
lines[l] = "\27P[" .. colours[3] .. "]" .. lines[l] .. "\27P[" .. colours[4] .. "]"
Else
lines[l] = "\27P[" .. colours[3] .. "]" .. lines[l]
EndIf
skip = True
Else
If RightStr(lines[l],2) = "*/"
lines[l] = "\27P[" .. colours[4] .. "]"
EndIf
EndIf
If skip = False
For Local d = 0 to ListItems(dictionary)-1
lines[l] = ReplaceStr(lines[l], dictionary[d][0], "\27P[" .. colours[dictionary[d][1]] .. "]" .. dictionary[d][0] .. "\27P[" .. colours[4] .. "]")
Next
EndIf
skip = False
Next
text$ = ""
For Local l = 0 to count-1
text$ = text$ .. lines[l] .. "\n"
Next
Return(text$)
EndFunction