Yes. Me me. 
Code:
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
;$RC = SetOption("Explicit","On")
$RC = SetOption("NoVarsInStrings","On")
$RC = SetOption("NoMacrosInStrings","On")
$RC = SetOption("WrapAtEOL","On")
Include "D:\scripts\udf\combsort.udf"
; ===========================================================================================
;
; Script Information
;
$Title = "VarScan 1.1b"
; Author: therob / Function combsort () by Shawn Tassie
; Description: Scans kixfiles for Variables and missing quotes and writes a reportfile
; -> Syntax of the reportfile: [variable] - [linenumbers in which the variable is used]
;
; ===========================================================================================
Break On
;.. variables
$match = 0
$Var = "$"
$stopchars = " <>()+-.,'#;:?=/&\}][{*!@@"+'"'
$TextMode = 1
$dictAllVars = CreateObject ("Scripting.Dictionary")
$dictAllVars.CompareMode = $TextMode
$VarNames = $dictAllVars.Keys
$allLines = "none"
$VarCount = 0
$orphans = ""
$orphcount = 0
$linecount = 0
$quote1 = 0
$quote2 = 0
;... select source
$System = CreateObject("Kixtart.System")
$openFile = $System.openFileDialog()
$openFile.Title = "Open a script to scan"
$openFile.InitialDirectory = @curDIR
$openFile.Filter = "KiX Files(*.kix;*.udf;*.scr)|*.kix;*.udf;*.scr|All files (*.*)|*.*"
$openFile.Title = "Select a kixfile to scan..."
$openFile.DefaultExt = "kix"
$ = $openFile.ShowDialog()
$input = $OpenFile.FileName
$report = $input + "-VarScanReport.txt"
$ = Open (1,$FileName,2)
If $input = ""
$rc = MessageBox("No file selected.", "Whoo", 262208, 5)
Quit
EndIf
; ..
; ... scan file
$=Open (1,$input,2)
$Line = ReadLine(1)
While NOT @error
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 = 1 to Len($Line)
$Char = SubStr ($Line, $c, 1)
If $Char = ";" AND NOT ($quote1 = 1 OR $quote2 = 1)
$c = Len($Line);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,CStr($var),CStr($allLines)) ;"$var","$allLines")
Else
$allLines = $linecount
DictionarySet ($dictAllVars,CStr($var),CStr($allLines)) ;"$var","$allLines")
EndIf
$Match = 0 $Var = "$"
Else
$Var = $var + $char
EndIf
EndIf
Select ;look for --> "
Case $Char = '"' AND $quote1 = 1
$quote1 = 0
Case $Char = '"'
$quote1 = 1
$curline = $line
EndSelect
Select ;look for --> '
Case $Char = "'" AND $quote2 = 1
$quote2 = 0
Case $Char = "'"
$quote2 = 1
$curline = $line
EndSelect
Next
;:readAline
Select
Case Len ($linecount) = 1 $wslinecount = "000" + $linecount
Case Len ($linecount) = 2 $wslinecount = "00" + $linecount
Case Len ($linecount) = 3 $wslinecount = "0" + $linecount
Case 1 $wslinecount = $linecount
EndSelect
$wholescript = $wholescript + $wslinecount + " " + $line + @CRLF
If $match = 1
; .. add to Dict
If $dictAllVars.Exists($var)
$tempLines = $dictAllVars.Item ($var)
$allLines = $tempLines + ", " + $linecount
DictionarySet ($dictAllVars,CStr($var),CStr($allLines))
Else
$allLines = $linecount
DictionarySet ($dictAllVars,CStr($var),CStr($allLines))
EndIf
$Match = 0 $Var = "$"
EndIf
$Line = ReadLine(1)
Loop
; ..
; ... sort and write report
If Exist ($report) Del $report EndIf
$ = Open (2,$report,5)
$ = WriteLine (2, $Title + " / Scanned file: "+$input+ @CRLF+ @CRLF)
; ..Sort Dict
For Each $VarNameA In $dictAllVars.Keys
$VarCount = $VarCount + 1
$VarString = $VarString + "," + $VarNameA
Next
$varArray = combsort (Split (SubStr ($VarString,2),","))
;... search for orphans and export the variables
For Each $VarName In $varArray
$VarLines = $dictAllVars.Item ($VarName)
If NOT InStr ($Varlines,",")
$orphans = $orphans + $varname + " " + $Varlines + @CRLF
$orphcount = $orphcount + 1
EndIf
$reportline = $Varname + " " + $VarLines + @CRLF
$ = WriteLine (2,$reportline)
Next
;... export rest
$ = WriteLine (2, "-----------------------"+@CRLF+ "All Variables: "+ $VarCount )
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Orphans: " + $orphcount + @CRLF+ "-----------------------"+ @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
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Scanned script:"+ @CRLF+ "-------------------------"+ @CRLF + $wholescript)
$=Close (1)
$=Close (2)
Run "%COMSPEC% /c " + $report ;Run "%COMSPEC% /c $report"
Quit 0
; ..
;... functions
Function DictionarySet ($DictionaryObject, $key, $value)
If VarTypeName($key) = "Empty"
Quit 13
EndIf
If $DictionaryObject.Exists($key)
$DictionaryObject.Remove($key)
EndIf
$DictionaryObject.Add($key, $value)
Exit @error
EndFunction
What have I been doing?
I (almost) implemented my favorite header (except for SetOption)
I put combsort in a reusable scriptfile
You do not have to do these things if you don't want. It is personal preference.
Code:
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
;$RC = SetOption("Explicit","On")
$RC = SetOption("NoVarsInStrings","On")
$RC = SetOption("NoMacrosInStrings","On")
$RC = SetOption("WrapAtEOL","On")
Include "D:\scripts\udf\combsort.udf"
Show KiX files only in dialog box
Code:
$openFile.Filter = "KiX Files(*.kix;*.udf;*.scr)|*.kix;*.udf;*.scr|All files (*.*)|*.*"
I presume a double quote can also be a stopchar?
Code:
$stopchars = " <>()+-.,'#;:?=/&\}][{*!@@"+'"'
If InStr ($stopchars,$char) <> 0; OR Asc ($char) = 34
I love silence if nothing meaningfull can be said (will I shut up now?
)
Code:
$ = $openFile.ShowDialog() ;$openFile.ShowDialog()
Got rid of that Goto
Code:
If $Char = ";" AND NOT ($quote1 = 1 OR $quote2 = 1)
$c = Len($Line) ;GoTo readAline
EndIf
...
;:readAline
Kicked some vars out of strings (because of SetOption("NoVarsInStrings","On"))
Code:
DictionarySet ($dictAllVars,CStr($var),CStr($allLines)) ;"$var","$allLines")
...
Run "%COMSPEC% /c " + $report ;Run "%COMSPEC% /c $report"
If var found at end of line, nothing counted or resetted
Code:
If $match = 1
; .. add to Dict
If $dictAllVars.Exists($var)
$tempLines = $dictAllVars.Item ($var)
$allLines = $tempLines + ", " + $linecount
DictionarySet ($dictAllVars,CStr($var),CStr($allLines))
Else
$allLines = $linecount
DictionarySet ($dictAllVars,CStr($var),CStr($allLines))
EndIf
$Match = 0 $Var = "$"
This is the output file
Code:
VarScan 1.1b / Scanned file: d:\Scripts\test\VarScan.kix
$ 29, 53, 58, 68, 87, 91, 104, 148, 160, 161, 183, 189, 190, 193, 195, 198, 199, 200
$allLines 35, 97, 98, 100, 101, 141, 142, 144, 145
$c 80, 81, 84
$Char 81, 83, 87, 91, 92, 106, 111, 113, 119, 121
$curline 74, 115, 123
$dictAllVars 32, 33, 34, 95, 96, 98, 101, 139, 140, 142, 145, 165, 175
$DictionaryObject 210, 215, 216, 219
$FileName 58
$input 55, 56, 59, 68, 161
$key 210, 211, 215, 216, 219
$Line 69, 80, 81, 84, 115, 123, 135, 152
$linecount 39, 74, 78, 78, 97, 100, 130, 130, 131, 131, 132, 132, 133, 141, 144
$Match 28, 88, 91, 104, 137, 148
$OpenFile 47, 48, 49, 50, 51, 52, 53, 55
$orphans 37, 178, 178, 190
$orphcount 38, 179, 179, 190
$quote1 40, 73, 77, 83, 111, 112, 114
$quote2 41, 73, 77, 83, 119, 120, 122
$quoteErrCount 75, 75, 192, 193
$quoterror 74, 74, 193
$rc 6, 8, 9, 10, 60
$report 56, 159, 159, 160
$report 203
$reportline 182, 183
$stopchars 30, 92
$System 45, 47
$tempLines 96, 97, 140, 141
$TextMode 31, 33
$Title 16, 161
$value 210, 219
$Var 29, 95, 96, 98, 101, 104, 106, 106, 139, 140, 142, 145, 148
$varArray 169, 173
$VarCount 36, 166, 166, 189
$VarLines 175, 177, 178, 182
$Varname 173, 175, 178, 182
$VarNameA 165, 167
$VarNames 34
$VarString 167, 167, 169
$wholescript 135, 135, 198
$wslinecount 130, 131, 132, 133, 135
-----------------------
All Variables: 40
Orphans: 3
-----------------------
$FileName 58
$report 203
$VarNames 34
Possible Quote-Errors: 5
-----------------------
Attention: Presumably a missing quotation mark in:
30 $stopchars = " <>()+-.,'#;:?=/&\}][{*!@@"+'"'
Attention: Presumably a missing quotation mark in:
111 Case $Char = '"' AND $quote1 = 1
Attention: Presumably a missing quotation mark in:
113 Case $Char = '"'
Attention: Presumably a missing quotation mark in:
119 Case $Char = "'" AND $quote2 = 1
Attention: Presumably a missing quotation mark in:
121 Case $Char = "'"
Scanned script:
-------------------------
0001 ...
Questions:
- I do not get the Possible Quote-Errors.
If a string starts with ", it ends with " (you can use any number of the ' quote in between)
If a string starts with ', it ends with ' (you can use any number of the " quote in between)
It does not matter what is between the quotes (except maybe vars and macros)
- If you skip the line after a ";", you will also want to skip block quotes?