Hi,
this is the (nearly) finished script of my "VariableScanner". Its purpose is to scan kixfiles for all used variables, print the lines in which they are used and (most important) print orphans.
I thinks it runs fine, but i'm not 100% sure. So, if anyone sees obvious errors or has any other helpful suggestions i would appreciate the input.
Thanks, therob
Code:
; ===========================================================================================
;
; Script Information
;
; Title: VarScan 0.9
; Author: therob (with help of the kixtart.org-community)
; Description: Scans kixfiles for Variables and writes a reportfile
; Syntax of the reportfile: [variable] - [linenumbers in which the variable is used]
;
; ===========================================================================================
Break On
;.. Variablen
$match = 0
$Var = "$"
$stopchars = " <>()+-.,'#;:?=/&\}][{*!@@"
$dictAllVars = CreateObject ("Scripting.Dictionary")
$VarNames = $dictAllVars.Keys
$allLines = "none"
$VarCount = 0
$orphans = ""
;... Datei auswählen / select source
$System = CreateObject("Kixtart.System")
$openFile = $System.openFileDialog()
$openFile.Title = "Open a script to scan"
$openFile.InitialDirectory = @CURDIR
$openFile.Filter = "All files (*.*)|*.*"
$openFile.Title = "open"
$openFile.DefaultExt = "kix"
$openFile.ShowDialog()
$input = $OpenFile.FileName
$report = $input + "report.txt"
$ = Open (1,$FileName,2)
If $input = ""
$rc = MessageBox("No file selected.", "Whoo", 64, 5)
Quit
EndIf
;.. Datei scannen / scan file
$=Open (1,$input,2)
While NOT @error
$Line = ReadLine(1)
$linecount = $linecount + 1
For $c = 0 to Len($Line)
$Char = SubStr($Line, $c, 1)
If $Char = "$"
$match = 1
EndIf
If $match = 1 AND NOT $char ="$"
If InStr ($stopchars,$char) <> 0 OR Asc ($char) = 34
; .. add to AllVars
If $dictAllVars.Exists($var)
$tempLines = $dictAllVars.Item ($var)
$allLines = $tempLines + ", " + $linecount
DictionarySet ($dictAllVars,"$var","$allLines")
Else
$allLines = $linecount
DictionarySet ($dictAllVars,"$var","$allLines")
EndIf
$Match = 0 $Var = "$"
Else
$Var = $var + $char
EndIf
EndIf
Next
Loop
; ... Reportdatei schreiben / write report
If Exist ($report) Del $report EndIf
$ = Open (2,$report,5)
$ = WriteLine (2,"File: "+$input+ @CRLF+@CRLF)
For Each $VarName In $dictAllVars.Keys
$VarCount = $VarCount + 1
$VarLines = $dictAllVars.Item ($VarName)
If NOT InStr ($Varlines,",")
$orphans = $orphans + $varname + @CRLF
$orphcount = $orphcount +1
EndIf
$reportline = $Varname + " " + $VarLines + @CRLF
$ = WriteLine (2,$reportline)
Next
$ = WriteLine (2, "-----------------------"+@CRLF+ @CRLF+ "Variables: "+ $VarCount )
$ = WriteLine (2, @CRLF+ @CRLF+ "Orphans: " + $orphcount + @CRLF+ @CRLF+ $orphans)
$=Close (1)
$=Close (2)
Quit 0
Function DictionarySet ($DictionaryObject, $key, $value)
If VarTypeName($key) = "Empty"
? " Fehler: Dictionary Keyname leer!" Quit 13
EndIf
If $DictionaryObject.Exists($key)
$DictionaryObject.Remove($key)
EndIf
$DictionaryObject.Add($key, $value)
Exit @error
EndFunction