这个脚本只满足了我要完成的工作的一部分内容,其余内容必须在公司才能完成及调试了。
脚本运行需要有如下条件:
与脚本在同一级目录下的 ctags.exe ,需要5.8以后版本的。主要是要支持正则,支持 - R选项后面带目录路径的。
同一级目录下要有logic文件夹,文件夹内要有符合语法的logic文件。
脚本如下:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 初始化一些全局变量
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim FSO
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 展示逻辑的方式
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const SW_LOGIC_IN_DLG = 0
Const INSERT_LOGIC_TO_SCRIPT = 1
Const OPEN_LOGIC_FILE = 2
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Window Style
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const SW_HIDE = 0
Const SW_SHOW = 1
Const SW_MIN = 2
Const SW_MAX = 3
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 由 Drive.DriveType 返回的常数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const DriveTypeRemovable = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDisk = 5
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 由 File.Attributes 返回的常数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const FileAttrNormal = 0
Const FileAttrReadOnly = 1
Const FileAttrHidden = 2
Const FileAttrSystem = 4
Const FileAttrVolume = 8
Const FileAttrDirectory = 16
Const FileAttrArchive = 32
Const FileAttrAlias = 64
Const FileAttrCompressed = 128
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 用来打开文件的常数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8
Function GenerateFileInformation(File)
Dim S
S = NewLine & "Path:" & TabStop & File.Path
S = S & NewLine & "Name:" & TabStop & File.Name
S = S & NewLine & "Type:" & TabStop & File.Type
S = S & NewLine & "Attribs:" & TabStop & ShowFileAttr(File)
S = S & NewLine & "Created:" & TabStop & File.DateCreated
S = S & NewLine & "Accessed:" & TabStop & File.DateLastAccessed
S = S & NewLine & "Modified:" & TabStop & File.DateLastModified
S = S & NewLine & "Size" & TabStop & File.Size & NewLine
GenerateFileInformation = S
End Function
Function GetFolderLastModifyTime (FolderPath)
If (FSO.FileExists("tags")) Then
Set File = FSO.GetFile("tags")
lastModTime = File.DateLastModified
'MsgBox lastModTime
Else
msg = filespec & " doesn't exist."
'MsgBox msg
End If
Set Folder = FSO.GetFolder(FolderPath)
folderModTime = Folder.DateLastModified
lTime = Folder.DateLastModified
Set Files = Folder.Files
For Each File In Files
If lTime < File.DateLastModified Then
lTime = File.DateLastModified
End If
Next
GetFolderLastModifyTime = lTime
End Function
Function FlashTagFile (tagFileName, FolderPath)
If (FSO.FileExists(tagFileName)) Then
Set File = FSO.GetFile(tagFileName)
lastModTime = File.DateLastModified
Else
strCmd = "ctags.exe --langdef=logic --langmap=logic:.logic --regex-logic=""/^\s*(Logic|Join)\s+(\w+)\s+\{/\2/L,Logic/"" -n -R " & FolderPath
oExec = WshShell.Run(strCmd, SW_HIDE, True)
FlashTagFile = True
Exit Function
End If
If lastModTime < GetFolderLastModifyTime(FolderPath) Then
strCmd = "ctags.exe --langdef=logic --langmap=logic:.logic --regex-logic=""/^\s*(Logic|Join)\s+(\w+)\s+\{/\2/L,Logic/"" -n -R " & FolderPath
oExec = WshShell.Run(strCmd, SW_HIDE, True)
FlashTagFile = True
Else
FlashTagFile = False
End If
End Function
Function LocationLogic (logicName, logicFileName, lineNum)
LocationLogic = "It's just a empty Function now!" & vbCrLf _
& "It will find [" & logicName & "] in file [" & logicFileName & "]. line : " & lineNum
End Function
Function GetLogicInfo (logicName, tagFileName)
Dim oRe, oMatch, oMatches
Set tagFile = FSO.GetFile(tagFileName)
Set TextStream = FSO.OpenTextFile(tagFileName, OpenFileForReading)
allLogicInfo = TextStream.ReadAll
TextStream.Close
' the format as below
'testLogic010 logic\Logic0.logic 24;" L
Set oRe = New RegExp
oRe.Pattern = logicName & "\s+(.*?)\s+(\d+);""\s+(\w)"
' 得到 Matches 集合
oRe.IgnoreCase = False ' 设置是否区分大小写。
oRe.Global = False ' 设置全程匹配。
Set oMatches = oRe.Execute(allLogicInfo)
If oMatches.Count = 0 Then
MsgBox "Can not find this logic <" & logicName & ">"
GetLogicInfo = ""
Exit Function
Else
Set oMatch = oMatches(0)
filePath = oMatch.SubMatches(0)
lineNum = oMatch.SubMatches(1)
End If
GetLogicInfo = LocationLogic(logicName, filePath, lineNum)
Set oRe = Nothing
End Function
Function GetLogicNameFromGTR ()
' It is empty now
GetLogicNameFromGTR = "testLogic99956"
End Function
Function GetLogicFilePath ()
' 这种方式能够读取的注册表有限制,功能更强的方式是采用winmgmts对象读取,但是没有这个简单
GetLogicFilePath = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Evernote\Installer")
GetLogicFilePath = "logic"
End Function
Function InsertLogicInfoToScript (logicInfo)
' It is empty now
InsertLogicInfoToScript = "It is empty now"
End Function
Function OpenLogicFileInGTR ()
' 查找逻辑文件及逻辑所在行数的方法与函数GetLogicInfo一样
InsertLogicInfoToScript = "It is empty now"
End Function
Function Main ()
Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
showMethod = objArgs(I)
End If
logicName = GetLogicNameFromGTR()
FlashTagFile "tags", GetLogicFilePath()
logicInfo = GetLogicInfo(logicName, "tags")
Select Case showMethod
' 64 means show "Information Mark" icon.
'Case SW_LOGIC_IN_DLG WshShell.popup(logicInfo, 10, "逻辑提示,10秒后消失", 64)
Case INSERT_LOGIC_TO_SCRIPT InsertLogicInfoToScript logicInfo
Case OPEN_LOGIC_FILE OpenLogicFileInGTR
Case Else WshShell.popup logicInfo, 10, "逻辑提示,10秒后消失", 64
End Select
End Function
StartTime = Timer
Main
EndTime = Timer
TimeIt = EndTime - StartTime
MsgBox "cast time " & TimeIt