Not tested ...
I have not verified that
$null = SetOption ("NoVarsInStrings","On")
$null = SetOption ("Explicit","On")
are followed in the older UDFs for this example.
Code:
break on
$null = SetOption ("NoVarsInStrings","On")
$null = SetOption ("Explicit","On")
Dim $file,$filehandle,$namevalue,$line,$name,$namearray,$null,$outputfile,$outputhandle
$file = 'c:\kix\test_text.txt'
$filehandle = FreeFileHandle()
If Open ($filehandle,$file) = 0
$namevalue = 0
Dim $aText, $text, $sMatch
$aText = "DCS Application Snapshot",
"Authorization",
"Inbound communication address",
"Outbound communication address",
"Application name",
"Application status"
$line = ReadLine ($filehandle)
While @Error = 0
for each $text in $aText
$sMatch = "(" + $text + ").*?= (.*?)$"
if RegExpTest($sMatch, $line, 1)
$line = RegExpReplace($line, "^\s+|\s+$", "", 1, 1)
$line = RegExpReplace($line, "\s+=\s+", "=", 1, 1)
Writelog2('c:\kix\test_text_out.txt', $line)
else
? "-No Match found"
endif
Next
$line = ReadLine ($filehandle)
Loop
Endif
;----------- Supporting UDFs ------------
Function RegExpTest($Pattern, $String, $IgnoreCase)
Dim $regEx, $Match, $Matches ; Create variable.
$regEx = createobject("VBscript.RegExp") ; Create a regular expression.
$regEx.Pattern = $Pattern ; Set pattern.
$regEx.IgnoreCase = val($IgnoreCase) ; Set case insensitivity.
$RegExpTest = $regEx.Test($String) ; Execute test search.
EndFunction
Function RegExpReplace($String1, $Pattern, $String2, $IgnoreCase, $Global)
Dim $regEx ; Create variable.
Dim $Results[0]
$regEx = createobject("VBscript.RegExp") ; Create a regular expression.
$regEx.Pattern = $Pattern ; Set pattern.
$regEx.IgnoreCase = val($IgnoreCase) ; Set case insensitivity.
$regEx.Global = val($Global) ; Set global applicability.
$RegExpReplace = $regEx.Replace($String1, $String2) ; Execute search.
EndFunction
Function WriteLog2($File, $Text, optional $TimeStamp)
dim $RC, $FH, $nul
$FH = FreeFileHandle()
if $FH > 0
$RC=Open ($FH, $File, 5)
Select
Case $RC=0
if ($TimeStamp=1)
$TimeStamp = @Date + " " + @Time + " - "
else
$TimeStamp = ""
endif
$RC=Writeline ($FH, $TimeStamp + $Text + @CRLF)
if ($RC <> 0)
$text = "WriteLine error: " + $RC + @CRLF
+ " -4 = File not open for writing" + @CRLF
+ " -3 = File number not open" + @CRLF
+ " -2 = Invalid file number specified" + @CRLF
+ " -1 = End of file"
$nul = MessageBox ($text,"Script Error",48)
endif
$nul=Close ($FH)
exit $RC
Case $RC=-2
$text = "WriteLog2: Invalid file handle (" + $FH + ") specified when trying to Open " + $File
$nul = MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name (" + $File + ") specified for log file."
$nul = MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error(" + $RC + ") while attempting to open log file (" + $File +")."
$nul = MessageBox ($text,"Script Error",48)
Endselect
else
$text = "WriteLog2: No free file handles for opening " + $File
$nul = MessageBox ($text,"Script Error",48)
$RC = -2
endif
exit $RC
EndFunction