I added shawn's sort-function for the variables, it ignores variables in comments now and i added a simple check for missing quotes. I'm happy with the outcome, but one odd thing though:

After adding the sort-udf, i had to read the dict into an array for sorting. Since then, the first output is an empty dict-object. I doesnt create an error, but the orphan-counter was wrong, so i had to set it to -1 to get the right count.
Any idea why there is this empty object suddenly?

cu, therob



Code:

; ===========================================================================================
;
; Script Information
;
$Title = "VarScan 1.0"
; Author: therob (with help of the kixtart.org-community) / UDF: COMBSORT() by Shawn Tassie
; 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 = " <>()+-.,'#;:?=/&\}][{*!@@"
$TextMode = 1
$dictAllVars = CreateObject ("Scripting.Dictionary")
$dictAllVars.CompareMode = $TextMode
$VarNames = $dictAllVars.Keys
$allLines = "none"
$VarCount = 0
$orphans = ""
$orphcount = -1
$linecount = 0
$quote1 = 0
$quote2 = 0

;... 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 = "Select a kixfile to scan..."
$openFile.DefaultExt = "kix"
$openFile.ShowDialog()

$input = $OpenFile.FileName
$report = $input + "report.txt"

$ = Open (1,$FileName,2)
If $input = ""
$rc = MessageBox("No file selected.", "Whoo", 262208, 5)
Quit
EndIf


;.. Datei scannen / scan file

$=Open (1,$input,2)

While Not @error
:readAline
$Line = ReadLine(1)

If $quote1 = 1 Or $quote2 =1
$quoterror = $quoterror + "Attention: Presumably a missing quotation mark in: "+ @CRLF + $linecount + " " + $curline + @crlf +@crlf
$quoteErrCount = $quoteErrCount + 1
EndIf
$quote1 = 0 $quote2 = 0
$linecount = $linecount + 1

For $c = 0 to Len($Line)
$Char = SubStr($Line, $c, 1)

If $Char = ";" And Not ($quote1 = 1 Or $quote2 = 1)
Goto readAline
EndIf

If $Char = "$"
$match = 1
EndIf

If $match = 1 And Not $char ="$"
If InStr ($stopchars,$char) <> 0 Or Asc ($char) = 34

; .. add to Dict
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

Select ;look for --> "
Case $Char = '"' And $quote1 = 1
$quote1 = 0 ; $quote1
Case $Char = '"'
$quote1 = 1 ; $quote1
$curline = $line
EndSelect

Select ;look for --> '
Case $Char = "'" And $quote2 = 1
$quote2 = 0 ; $quote1
Case $Char = "'"
$quote2 = 1 ; $quote1
$curline = $line
EndSelect
Next
Loop


; ... Reportdatei schreiben / write report

If Exist ($report) Del $report EndIf
$ = Open (2,$report,5)
$ = WriteLine (2, $Title + " / Scanned file: "+$input+ @CRLF)

; ..Sort Dict

For Each $VarNameA in $dictAllVars.Keys
$VarCount = $VarCount + 1
$VarString = $VarString + $VarNameA + ","
Next
$varArray = combsort (Split ($VarString,","))

;... export

For Each $VarName in $varArray

$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+ "Variables: "+ $VarCount )
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Orphans: " + $orphcount + @CRLF+ "-----------------------"+ $orphans)

If $quoteErrCount > 0
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Possible Quote-Errors: " + $quoteErrCount + @CRLF+ "-----------------------"+ @CRLF+ $quoterror)
Else
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "No Quote-Errors found.")
EndIf
$=Close (1)
$=Close (2)


Run "%COMSPEC% /c $report"
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

Function combsort($v, optional $o)
Dim $i,$j,$m,$s,$g
$n=Ubound($v)
$g=$n
If $g
While $g > 1 Or Not $s
$g=($g*1000)/1279
If $g < 1
$g=1
EndIf
$s=1
For $i = 0 to $n-$g
$j=$i+$g
If ($v[$i] > $v[$j] And Not $o) Or ($v[$i] < $v[$j] And $o)
$m = $v[$i]
$v[$i] = $v[$j]
$v[$j] = $m
$s=0
EndIf
Next
Loop
$combsort = $v
Else
$combsort = 0
EndIf
EndFunction



Edited by therob (2006-09-15 03:46 PM)
_________________________
Eternity is a long time, especially towards the end. - W.Allan