'*****************************************************************************
'** Syntax Converter
'**
Option Explicit
'*****************************************************************************
'** Globl Varibles
'**
Dim WSHargv, WSHargc, strLine
Dim inFile, outFile
WSHargc = WScript.Arguments.Count
WSHmain()
Function WSHmain()
ForceConsole()
Hello()
WSHargs()
End Function 'WSHmain
Function ForceConsole()
Dim wshShell, vbsInterpreter, i
Set wshShell = CreateObject("WScript.Shell")
vbsInterpreter = "cscript.exe"
If InStr(LCase(WScript.FullName), vbsInterpreter) = 0 Then
For i=0 To WSHargc-1
WSHargv = WSHargv & chr(32) & chr(34) & WScript.Arguments.Item(i) & chr(34)
Next
wshShell.Run vbsInterpreter & " //Nologo " & chr(34) & WScript.ScriptFullName & chr(34) & WSHargv
WScript.Quit
End If
End Function 'ForceConsole
Function WSHargs()
Dim i, strLen
For i=0 To WSHargc-1
WSHargv = LCase(WScript.Arguments.Item(i))
strLen = Len(WSHargv)
If Left(WSHargv, 1) = "-" Then
If Right(WSHargv, 1) = "i" Then
i=i+1
inFile = WScript.Arguments.Item(i)
If LCase(Right(inFile,3)) = "hrc" Then
outFile= Left(inFile,Len(inFile)-3) + "syntax"
convert inFile, outFile
Else
Usage()
End If
End If
End If
Next
If IsEmpty(inFile) = True Then
Usage()
End If
End Function 'WSHargs
Function printf(txt)
WScript.StdOut.WriteLine txt
End Function 'printf
Function printl(txt)
WScript.StdOut.Write txt
End Function 'printl
Function scanf()
scanf = LCase(WScript.StdIn.ReadLine)
End Function
Function wait(n)
WScript.Sleep Int(n * 1000)
End Function 'wait
Function convert(inFile, outFile)
Dim objFSO, objWFile, objRFile
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objRFile = objFSO.OpenTextFile(inFile)
Set objWFile = objFSO.CreateTextFile(outFile,True)
objWFile.WriteLine("file vbs\script \*.vbs")
objWFile.WriteLine("context default")
objWFile.WriteLine(" keyword " & chr(34) & " yellow")
Do Until objRFile.AtEndOfStream
strLine = objRFile.ReadLine
StrFind objWFile, "<scheme name="& chr(34), chr(34) & ">", 2
StrFind objWFile, "<word name="& chr(34), chr(34) & "/>", 1
StrFind objWFile, "<symb name="& chr(34), chr(34) & "/>", 3
Loop
objRFile.Close
objWFile.Close
End Function 'convert
Function StrFind(objWFile, CaseStart, CaseEnd, strUpds)
Dim strLineM, strLineL, strLineR
strLineL = InStr(1,strLine,CaseStart,vbTextCompare)
strLineR = InStr(1,strLine,CaseEnd,vbTextCompare)
If ( strLineR <> 0 ) And ( strLineL <> 0 ) And ( strLineL+strLineR <> Empty ) Then
strLineM = Mid(strLine, strLineL, strLineR)
strLine = Mid(strLineM,Len(CaseStart)+1,Len(strLineM)-Len(CaseStart)-Len(CaseEnd))
If strUpds = 1 Then
strUpd strLine, Len(strLine)
objWFile.WriteLine (" keyword whole " & strLine & " white")
ElseIf strUpds = 2 Then
objWFile.WriteLine ("#" & strLine)
Else
charUpd strLine, Len(strLine)
objWFile.WriteLine (" keyword " & strLine & " green")
End If
End If
End Function 'FindParse
Function strUpd(txt,StrLen)
Dim txtout, i, inChar, newChar, objRegExp
txt = LCase(txt)
Set objRegExp = New RegExp
objRegExp.Pattern = "[^a-z^0-9]"
For i=1 To StrLen
inChar = Mid(txt,i,1)
If objRegExp.Test(inChar) = True Then
txtout = txtout & inChar
ElseIf newChar = inChar Then
txtout = Left(txtout,Len(txtout)-1)
txtout = txtout & "{2,2}/"
Else
txtout = txtout & "/[" & UCase(inChar) & inChar & "]/"
End If
newChar = inChar
Next
strLine = txtout
End Function 'strUpd
Function charUpd(txt,StrLen)
Dim txtout, i, inChar
For i=1 To StrLen
inChar = Mid(txt,i,1)
If ( Mid(txt,i,1) = "&" ) Then
If ( Mid(txt,i,5) = "&" ) Then
txtout = txtout & "&"
i=i+4
End If
If ( Mid(txt,i,4) = "<" ) Then
txtout = txtout & "<"
i=i+3
End If
If ( Mid(txt,i,4) = ">" ) Then
txtout = txtout & ">"
i=i+3
End If
Else
txtout = txtout & inChar
End If
Next
strLine = txtout
End Function 'charUpd
Function Hello()
printf "==============================================================================="
printf ",---. | ,---. | "
printf "`---., .,---.|--- ,---.. , | ,---.,---.. ,,---.,---.|--- ,---.,---."
printf " || || || ,---| >< | | || | \ / |---'| | |---'| "
printf "`---'`---|` '`---'`---^' ` `---'`---'` ' `' `---'` `---'`---'` "
printf " `---' v.1.1"
printf "==============================================================================="
' wait(1)
End Function 'Hello
Function Usage()
printf "Correct Usage:"
printf WScript.ScriptName + " -i file.hrc"
wait(3)
WScript.Quit
End Function 'Usage