Dean F
Lurker
Registered: 2003-09-30
Posts: 1
Loc: Seattle
|
CJ- I thought I'd post an update to your code since I thoroughly benefited from the base code and enjoy using it.
I had to fix the following issues prior to using it in KiX 4.2x Issue 1. - An operator (i.e. "=","AND","OR","NOT","In","/","\","*","&","+","-") followed by an open bracket such as “(“ would cause the operator to not be formatted correctly. Issue 2. - Certain characters or commands were dropped if directly followed by a comment character “;” in the same line. Issue 3. - A slash (“/” or “\”) following an operator would get dropped. Issue 4. - Some text would get formatted in the light magenta color incorrectly. Light Magenta was removed. Issue 5. - Some 4.2x commands did not get converted. Updated script to have all correct 4.2x commands. Issue 6. - KiX ver 3.x OLE calls are outdated and will not work in current version of KiX. Replaced with COM functions. Issue 7. - Script could not handle converting larger KiX scripts (roughly 300+ lines) due to varriable reassignment and memory settings. Reworked with an array to dump longer variables to arrayed variables. Issue 8. - Updated commands and functions to latest version of KiX.
I'll admit that I probably made a few unconventional modifications. Additionally, to handle some of the newer KiX 4.2x code, I had to modify how it converts special characters. In doing so, it doesn't always display the output to the DOS console correctly but it will convert it correctly to HTML.
Also, it is recommended that when attempting to convert larger scripts (about 700+ lines) that one uses a "faster" machine - at least a P4 with a 512MB of RAM.
I also disabled the HTML tag conversions as that would interfere with some of the newer functionalities.
If anyone finds an error, please post it.
Enjoy!
code:
;============================================= ;Written in KiXscripts Editor ver 1.7 ;Written by CJ - February, 2001 ;Last Modified on 9/28/2003 at 11:46:34 PM by: ;Dean F. ;=============================================
Break ON CLS $ = SetOption("WrapAtEOL","On") $ = SetOption("Explicit","On") $ = SetConsole("Show")
; KiX2HTML converter - for colorful displays in HTML format ; ; This script will convert your KiX script to a colorful ; HTML page for easy reading.
;================================================ ;Variable Settings and Declarations ;================================================ ;===================================== ; Variables you can't edit ;===================================== Global $HTML,$False,$True,$CRLF,$Title,$SingleQuotes,$DblQuotes,$K2HCmdIsBlank Global $K2HCommand,$NoLinesProcessed,$Document,$Error,$Lines,$RightChar1 Global $K2HTextColor,$K2HFunctionColor,$K2HBracketColor,$K2HCommandColor,$K2HCommentColor Global $K2HHTMLTagColor,$K2HQuoteColor,$K2HHTMLColor,$K2Hfilename Global $ProcessNextLine,$SpecialChar,$K2HChar Global $Nul,$Commands,$Functions,$Operators,$HTMLTags,$Step, $CMDStep,$TagStep,$OperStep,$CMD,$Test,$TheCommand, $VariableLength,$ScreenRes,$ScreenWid,$ScreenHit,$IE, $Und,$Count,$Visible,$OperatorCheck $HTML = $HTML + $K2HTextColor $False = 0 $True = -1 $CRLF = Chr(13) + Chr(10); - OLD CARRIAGE Return AND LINE FEED $SingleQuotes = 0 $DblQuotes = 0 $K2HCmdIsBlank = 0 $K2HCommand = "" $K2HChar = "" $NoLinesProcessed = 1 $Document = "" $Error = 0 Dim $MoreHTML [5]
;===================================== ; Variables you can edit ;===================================== ;============= ; Color Table ;============= $K2HFunctionColor = "<B><font color=#0000ff>"; light blue $K2HBracketColor = "<font color=#ff0000>"; red $K2HCommandColor = "<B><font color=#0000ff>"; light blue $K2HCommentColor = "<I><font color=#008000>"; dark green $K2HHTMLTagColor = "<font color=#8b4513>"; brown $K2HQuoteColor = "<font color=#990066>"; blue violet $K2HTextColor = "<font color=#000000>"; black $K2HHTMLColor = "<font color=#ff00ff>"; light magenta
;============= $Lines = 1; 1 = lines on output HTML, 0 = no lines
;====================================== ;KiX Commands, Functions, and Variables ;====================================== $Commands = "?","ABS","Beep","Big","Break","Call","Case", "CD","CLS","Color","Cookie1","Copy","Debug","Del", "Dim","Display","Do","Each","Else","EndIf","EndSelect", "EnumIPInfo","ExistKey","Exit","FlushKB","For","FreeFileHandle", "Next","Get","Gets","Global","Go","Gosub","GoTo", "KBHit","If","Loop","MD","Password","Play","Quit", "RD","ReDim","Return","Run","Select","Set","SetL", "SetM","SetTime","Shell","Sleep","Small","Until", "Use","While" $Operators = "=","AND","OR","NOT","In","/","\","*","&","+","-" $Functions = "AddKey","AddPrinterConnection","AddProgramGroup", "AddProgramItem","Asc","AScan","At","BackupEventLog", "Box","CDbl","Chr","CInt","ClearEventLog","Close", "CompareFileTimes","CreateObject","CStr","DecToHex", "DelKey","DelPrinterConnection","DelProgramGroup", "DelProgramItem","DelTree","DelValue","Dir","EndFunction", "EnumGroup","EnumIPInfo","EnumKey","EnumLocalGroup", "EnumValue","Execute","Exist","ExpandEnvironmentVars", "Fix","FormatNumber","Function","GetDiskSpace","GetFileAttr", "GetFileSize","GetFileTime","GetFileVersion","GetObject", "IIf","InGroup","InStr","InStrRev","Int","IsDeclared", "Join","KBHit","KeyExist","Lcase","Left","Len","LoadHive", "LoadKey","LogEvent","Logoff","LTrim","MemorySize", "MessageBox","Open","ReadLine","ReadProfileString", "ReadType","ReadValue","RedirectOutput","Right","Rnd", "Round","RTrim","SaveKey","SendKeys","SendMessage", "SetASCII","SetConsole","SetDefaultPrinter","SetFileAttr", "SetFocus","SetOption","SetSystemState","SetTitle", "SetWallpaper","ShowProgramGroup","Shutdown","SIDToName", "Split","SRnd","SubStr","Trim","Ubound","Ucase","UnloadHive", "Val","VarType","VarTypeName","WriteLine","WriteProfileString","WriteValue" $HTMLTags = "A","ABBR","ACRONYM","ADDRESS","APPLET","AREA","B", "BASE","BASEFONT","BDO","BGSOUND","BIG","BLINK","BLOCKQUOTE", "BODY","BR","BUTTON","CAPTION","CENTER","CITE","CODE", "COL","COLGROUP","DD","DEL","DFN","DIR","DIV","DL", "DT","EM","EMBED","FIELDSET","FONT","FORM","FRAME", "FRAMESET","H1","H2","H3","H4","H5","H6","HEAD","HR", "HTML","I","IFRAME","ILAYER","IMG","INPUT","INS", "ISINDEX","KBD","KEYGEN","LABEL","LAYER","LEGEND", "LI","LINK","LISTING","MAP","MENU","META","MULTICOL", "NOBR","NOEMBED","NOFRAMES","NOLAYER","NOSCRIPT", "OBJECT","OL","OPTGROUP","OPTION","P","PARAM","TR", "PLAINTEXT","PRE","Q","S","SAMP","SCRIPT","SELECT", "SERVER","SMALL","SOUND","SPACER","SPAN","STRIKE", "STRONG","STYLE","SUB","SUP","TBODY","TEXTAREA","TITLE", "TT","U","UL","VAR","WBR","XMP","TABLE","TD","TFOOT","TH","THEAD"
;================================================ ;Ask for the full path to the KIX script file. ;================================================Color w + /n While $K2Hfilename = "" Color w + /n "Please enter the full path and filename of your script." ? "When typing in a long file path, " Color y+/n "QUOTES ARE NOT NECESSARY" Color w + /n "!" ? "Type " Color R + /n "EXIT" Color w + /n " to exit this program. " Color w + /n "Press ENTER when ready." ? "<Path or EXIT>" Color w/n Gets $K2Hfilename If Ucase("$K2Hfilename") = "EXIT" Exit EndIf If Exist($K2Hfilename) = 0 CLS Color y + /n "File not found! Press a key" Get $Nul CLS $K2Hfilename = "" EndIf ? Loop
;================================================ ; Parse the script - line by line and create a ; HTML sequence from the commands found ; start HTML sequence with: ;================================================ $HTML = "<html>$CRLF<head><title>KiX2HTML - $K2Hfilename</title><head>$CRLF<body>$CRLF" Gosub CheckVariableLength $HTML = $HTML + "<style><!--body{ font-family: courier, arial--></style>$CRLF" Gosub CheckVariableLength $HTML = $HTML + "$CRLF" Gosub CheckVariableLength
$Nul = Open(1,"$K2Hfilename",0) "KiX-2-HTML Converter" ? "Converting $K2Hfilename to HTML:" ? ? Color w/n "Line:" ? "1 " $ProcessNextLine = ReadLine(1) If $ProcessNextLine = ";ENDOFFILE" $Error = 1 EndIf
;================================================ ;Check each Command (Character by Character), properly format the character/command ;and convert it to HTML format and dump it to a string of variables ;================================================While $Error = 0 Gosub CheckVariableLength $OperatorCheck = 0 If $Lines = 1; draw line numbers $HTML = $HTML + $K2HTextColor $Document = $NoLinesProcessed ;Display line num in TEXT colour.. If $NoLinesProcessed < 1000 $Document = "$NoLinesProcessed" EndIf If $NoLinesProcessed < 100 $Document = "0$NoLinesProcessed" EndIf If $NoLinesProcessed < 10 $Document = "00$NoLinesProcessed" EndIf ; | this is why $HTML = $HTML + "$Document: "; V we have to.. Gosub CheckVariableLength If ($SingleQuotes = 1) OR ($DblQuotes = 1) $HTML = $HTML + $K2HQuoteColor Gosub CheckVariableLength EndIf; restore quotes color and If $K2HCmdIsBlank = 1 $HTML = $HTML + $K2HTextColor Gosub CheckVariableLength EndIf; restore html color EndIf If $ProcessNextLine = "" $HTML = $HTML + " "; blank line Gosub CheckVariableLength Else ; scan line for special chars and keywords $SpecialChar = 1 Do $K2HChar = SubStr("$ProcessNextLine",$SpecialChar,1) ; special chars Select Case $K2HChar = "<" "$K2HCommand" Color r + /n "<" $HTML = $HTML + $K2HCommand + $K2HBracketColor + "<" Gosub CheckVariableLength $K2HCommand = "" $K2HCmdIsBlank = 1 If $SingleQuotes = 1 OR $DblQuotes = 1 $HTML = $HTML + $K2HQuoteColor Gosub CheckVariableLength Else $HTML = $HTML + $K2HTextColor Gosub CheckVariableLength EndIf Case $K2HChar = ">" "$K2HCommand" Color r + /n ">" $HTML = $HTML + $K2HCommand + $K2HBracketColor + ">" Gosub CheckVariableLength $K2HCommand = "" $K2HCmdIsBlank = 0 If $SingleQuotes = 1 OR $DblQuotes = 1 $HTML = $HTML + $K2HQuoteColor Gosub CheckVariableLength Else $HTML = $HTML + $K2HTextColor Gosub CheckVariableLength EndIf ;Check For Operators and change color to RED if found Case $K2HChar = "(" OR $K2HChar = ")" OR $K2HChar = "[" OR $K2HChar = "]" OR $K2HChar = "{" OR $K2HChar = "}" OR $K2HChar = "/" OR $K2HChar = "\" Color r + /n "$K2HChar" $HTML = $HTML + $K2HCommand Gosub CheckVariableLength $K2HCommand = "" If ($SingleQuotes = 0) AND ($DblQuotes = 0) $HTML = $HTML + $K2HBracketColor Gosub CheckVariableLength EndIf $HTML = $HTML + $K2HChar Gosub CheckVariableLength If ($SingleQuotes = 0) AND ($DblQuotes = 0) $HTML = $HTML + $K2HTextColor Gosub CheckVariableLength EndIf If ($SingleQuotes = 1) OR ($DblQuotes = 1) $HTML = $HTML + $K2HQuoteColor Gosub CheckVariableLength EndIf If $K2HCmdIsBlank = 1 $HTML = $HTML + $K2HTextColor Gosub CheckVariableLength EndIf Case $K2HChar = "'" Color c/n; single quotes If $DblQuotes = 0 If $SingleQuotes = 0; turn ' on $HTML = $HTML + $K2HCommand + $K2HQuoteColor + $K2HChar "$K2HCommand" Color c/n "'" Gosub CheckVariableLength $K2HCommand = "" $SingleQuotes = 1 Else; turn ' off $HTML = $HTML + $K2HCommand + $K2HQuoteColor + $K2HChar "$K2HCommand" Color c/n "'" Gosub CheckVariableLength $K2HCommand = "" $SingleQuotes = 0 If $K2HCmdIsBlank = 1 $HTML = $HTML + $K2HTextColor Color m + /n Gosub CheckVariableLength Else $HTML = $HTML + $K2HTextColor Color w/n Gosub CheckVariableLength EndIf EndIf Else $HTML = $HTML + $K2HCommand + $K2HChar "$K2HChar" $K2HCommand = "" Gosub CheckVariableLength EndIf Case $K2HChar = '"' Color c/n; double quotes If $SingleQuotes = 0 If $DblQuotes = 0; turn " on $HTML = $HTML + $K2HCommand + $K2HQuoteColor + $K2HChar "$K2HCommand" Color c/n '"' Gosub CheckVariableLength $K2HCommand = "" $DblQuotes = 1 Else; turn " off $HTML = $HTML + $K2HCommand + $K2HQuoteColor + $K2HChar "$K2HCommand" Color c/n '"' Gosub CheckVariableLength $K2HCommand = "" $DblQuotes = 0 If $K2HCmdIsBlank = 1 Color m + /n Else $HTML = $HTML + $K2HTextColor Color w/n Gosub CheckVariableLength EndIf EndIf Else $HTML = $HTML + $K2HCommand + $K2HChar "$K2HChar" Gosub CheckVariableLength $K2HCommand = "" EndIf Case $K2HChar = Chr(9) $HTML = $HTML + " " " " $K2HChar = Chr(0); 1 tab = 5 spaces Gosub CheckVariableLength Case $K2HChar = "/" If SubStr($ProcessNextLine, $SpecialChar-1, 1) = "<" $HTML = $HTML + $K2HHTMLTagColor + $K2HHTMLTagColor + $K2HChar Color y/n "/" Gosub CheckVariableLength EndIf Case $K2HChar = ";" AND $SingleQuotes = 0 AND $DblQuotes = 0 ; comments, but not in quotes... $HTML = $HTML + $K2HTextColor + $K2HCommand ;Write out the previously read $K2HCommand Gosub CheckVariableLength Color w/n "$K2HCommand" $HTML = $HTML + $K2HCommentColor + SubStr($ProcessNextLine, $SpecialChar, Len($ProcessNextLine) - $SpecialChar + 1) + $K2HTextColor + "</I>" ;Write out the comment Gosub CheckVariableLength Color g/n SubStr($ProcessNextLine, $SpecialChar, Len($ProcessNextLine)-$SpecialChar + 1) $SpecialChar = Len("$ProcessNextLine") Case 1 $K2HCommand = $K2HCommand + $K2HChar If $SpecialChar = Len("$ProcessNextLine") $K2HChar = Chr(0) EndIf ; end of line EndSelect $RightChar1 = SubStr($ProcessNextLine, $SpecialChar+1, 1); Look at last character in current line; If $RightChar1 = '(' AND $K2HChar = ' ' ;Resolve Operator comming before an open parenthesis ; strip space for word check If $K2HChar = " " $K2HCommand = SubStr($K2HCommand, 1, Len($K2HCommand)-1) EndIf $Nul = CheckOperators Gosub CheckVariableLength EndIf If ($RightChar1 = "(" OR $RightChar1 = "[" OR $RightChar1 = "{");If last character equals one of these $K2HChar = "";delete the character. It will be picked up on the next line. EndIf ; space or EoL, but only in non quotes If ($K2HChar=" " OR $K2HChar=Chr(0) OR SubStr($ProcessNextLine, $SpecialChar+1, 1)=">" OR SubStr($ProcessNextLine, $SpecialChar+1, 1)="(") AND ($SingleQuotes=0) AND ($DblQuotes=0) If SubStr($ProcessNextLine, $SpecialChar + 1, 1) =">" $K2HChar=Chr(0) EndIf ; strip space for word check If $K2HChar = " " $K2HCommand = SubStr($K2HCommand, 1, Len($K2HCommand)-1) EndIf ;COMMANDS = BLUE TEXT $Nul = CheckCommands Gosub CheckVariableLength ;FUNCTIONS = BLUE TEXT $Nul = CheckFunctions Gosub CheckVariableLength ;OPERATORS = RED TEXT $Nul = CheckOperators Gosub CheckVariableLength ;HTML TAGS = YELLOW TEXT - This appears to have an odd affect on the Command Window Display ;$Nul = CheckHTMLTags ;Gosub CheckVariableLength If $K2HChar = " " $K2HCommand = $K2HCommand + " " EndIf; replace stripped space $HTML = $HTML + $K2HCommand + $K2HChar "$K2HCommand" $K2HCommand = "" EndIf ;=============== ;Test MessageBox ;$Nul = MessageBox("K2HChar = $K2HChar@CRLFK2HCommand = $K2HCommand","Test Results 1",16) ;=============== $SpecialChar = $SpecialChar + 1 Color w/n Until $SpecialChar = Len("$ProcessNextLine") + 1 EndIf $K2HCommand = "" $HTML = $HTML + "<br>$CRLF" Gosub CheckVariableLength $ProcessNextLine = ReadLine(1) ? If @ERROR = 0 $NoLinesProcessed = $NoLinesProcessed + 1 "$NoLinesProcessed " Else Color w + /n ? "$NoLinesProcessed lines processed." $Error = 1 EndIf Loop $Nul = Close(1)
;===================================== ;Wrap up the KIX Script HTML Code ;===================================== $HTML = $HTML + "</body>$CRLF</html>$CRLF" Gosub CheckVariableLength
? "Launching IE Window..." ?
;================================================ ;Dump output of KIX SCRIPT to Internet Explorer ;================================================
;===================================== ; Set properties and display form ... ;===================================== $Nul = ScreenRes $IE = CreateObject("InternetExplorer.Application") $IE.AddressBar = $False $IE.MenuBar = $True $IE.ToolBar = $True $IE.StatusBar = $False $IE.Resizable = $True $IE.Top = 1 $IE.Left = 1 $IE.Height = $ScreenHit $IE.Width = $ScreenWid $IE.TopMost = 1 $IE.Visible = $True $IE.Navigate("about:blank")
While $IE.Busy <> 0 AND @ERROR = 0 Loop
;===================================== ; Get a handle to the open document ... ;===================================== $Document = $IE.Document $Document.Open
For $Count = 0 to Ubound($MoreHTML) $Und = $MoreHTML[$Count] If NOT (($Und = "") OR ($Und = "undefined") OR ($Und = "undefined ")) $Document.Write($MoreHTML[$Count]) EndIf Next
;===================================== ;Create the HTML version of the KIX ;===================================== $Document.Write("$HTML") $Visible = 0 While $Visible = 0 $Visible = SetFocus('$Title') Loop
$IE = ""
;================================================ ;EXIT SCRIPT ;================================================ Exit
;================================================ ;SUBFUNCTIONS AND ROUTINES ;================================================ ;Check to see if the length of the $HTML variable is too long. If so, reassign it. :CheckVariableLength $VariableLength = Len("$HTML") If $VariableLength => 20000 $Step = $Step + 1 ReDim PRESERVE $MoreHTML[$Step] $MoreHTML[$Step] = $HTML $HTML = "" EndIf Return
;Obtain the System Screen Resolution ;Examples of the above SCREENRES Function: ;1: $Resolution=ScreenRes ; "your Screen are is " ; $Resolution[0] "x" $Resolution[1] ; ;2: "your screen resolution is:" ; join(screenres,"x") ; ;3: ScreenRes ; assigns variables $ScreenHit and $ScreenWid Function ScreenRes(optional $) If NOT "" + $ $ = "." EndIf For Each $ In GetObject("winmgmts:\\" + $ + "\root\cimv2").ExecQuery("Select * from Win32_DesktopMonitor",,48) $ScreenRes = $.ScreenWidth,$.ScreenHeight $ScreenHit = $.ScreenHeight $ScreenWid = $.ScreenWidth Next EndFunction
;Check for COMMAND WORDS in the script and change the color to BLUE if found Function CheckCommands For $CMDStep = 0 to Ubound($Commands) $CMD = $Commands[$CMDStep] If $K2HCommand = $CMD If $K2HChar = " " $K2HCommand = $K2HCommand + " " EndIf; replace stripped space Color b + /n "$K2HCommand" If $K2HChar = SubStr("$K2HCommand",Len("$K2HCommand")-0,1) $K2HCommand = SubStr("$K2HCommand",1,Len("$K2HCommand")-1) EndIf $HTML = $HTML + $K2HCommandColor + $K2HCommand + $K2HChar + $K2HTextColor + "</B>" $K2HCommand = "" $K2HChar = "" EndIf Next EndFunction
;Check for FUNCTION WORDS in the script and change the color to BLUE if found Function CheckFunctions For $CMDStep = 0 to Ubound($Functions) $CMD = $Functions[$CMDStep] If $K2HCommand = $CMD If $K2HChar = " " $K2HCommand = $K2HCommand + " " EndIf; replace stripped space Color b + /n "$K2HCommand" If $K2HChar = SubStr("$K2HCommand",Len("$K2HCommand")-0,1) $K2HCommand = SubStr("$K2HCommand",1,Len("$K2HCommand")-1) EndIf $HTML = $HTML + $K2HCommandColor + $K2HCommand + $K2HChar + $K2HTextColor + "</B>" $K2HCommand = "" $K2HChar = "" EndIf Next EndFunction
;Check for OPERATOR WORDS in the script and change the color to RED if found Function CheckOperators For $OperStep = 0 to Ubound($Operators) $CMD = $Operators[$OperStep] If $K2HCommand = $CMD If $K2HChar = " " $K2HCommand = $K2HCommand + " " EndIf; replace stripped space Color r + /n "$K2HCommand" $HTML = $HTML + $K2HBracketColor + $K2HCommand + $K2HChar + $K2HTextColor $K2HCommand = "" $K2HChar = "" $OperatorCheck = 1 EndIf Next EndFunction
;Check for HTML TAG WORDS in the script and change the color to YELLOW/BROWN if found Function CheckHTMLTags For $TagStep = 0 to Ubound($HTMLTags) $CMD = $HTMLTags[$TagStep] If $K2HCommand = $CMD AND (($DblQuotes = 1) OR ($K2HCmdIsBlank = 1)) If $K2HChar = " " $K2HCommand = $K2HCommand + " " EndIf; replace stripped space Color y/n "$K2HCommand" $HTML = $HTML + $K2HHTMLTagColor + $K2HCommand + $K2HChar + $K2HTextColor $K2HCommand = "" $K2HChar = "" EndIf Next EndFunction
My apologies on previously posting the "long lines".
I forgot to mention that PostPrep will do pretty much the same. This just does it through a DOS console.
Good Luck, [ 30. September 2003, 18:45: Message edited by: Dean F ]
_________________________
-Dean F.
|