1.自定義命名設置界面(Tool -> Custom Commands...)
Command
顯示當前選中命令的名字. 下拉列表中包含了所有的自定義命令.
Run
命令行,當調用自定義命令時,這個命令行就會被執行. 命令行中可以包含特殊的元字符. 詳見 “The 'Run' Field Format”.
Dir
設定命令行執行時的工作目錄.
Source Insight 會在命令行執行前將當前工作目錄設置為此處設定的值.
如果是空的,那么Source Insight 會將當前工作目錄設置為工程源碼目錄.
Output Group
這組選項控制命令輸出.
Iconic Window(窗口顯示模式)
啟動此項, 命令執行產生的窗口是最小化的,Source InSight仍是當前活動窗口;
不啟動此項, 命令執行產生的窗口取代Source InSight成為當前活動窗口.
舉例來說,比如命令是打開Windows資源管理器,
啟用此項后,Windows資源管理器被打開,但是窗口是最小化的;
不啟動此項, Windows資源管理器正常打開,窗口顯示Source InSight前面.
Capture Output
啟用此項后,當命令執行完成后,命令的標准輸入會被捕捉並且顯示在一個新的命令輸入窗口中,這個窗口的標題是自定義命令的名字.
不啟動此項, 不會捕捉標准輸出.
Paste Output
啟用此項后,命令的標准輸出會被粘貼到當前的選擇區域.
Control Group
這組選項控制Source Insight在命令執行前后做什么處理
Save Files First
啟用此項后,Source Insight 會在命令執行前 執行'Save All'(Ctrl+Shift+S)命令.
'Save All' 命令會提示你每一個被更改的文件來讓你確認是否要保存.
不啟動此項, 命令執行時不會保存任何改動過的文件. 未保存的‘變化’在命令結束后仍然保留 .
如果命令導致Source Insight崩潰,Source Insight可以恢復,未保存的‘變化’也是完好的.
Pause When Done
啟用此項后, 當命令結束后,Source Insight 會在DOS窗口中顯示下面的消息:
Press any key to return to Source Insight...
不啟動此項, DOS窗口會在命令結束后關閉.
Beep When Done
啟用此項后, Source Insight 會在命令結束后發出beep音.
Wait Until Done
啟用此項后,Source Insight 會掛起(suspend)直到命令結束.
不啟動此項, 你可以切換回Source Insight窗口繼續工作,命令會在后台繼續執行 .
Exit Source Insight
命令執行后Source Insight 會關閉.
Source Links in Output
你可以使用這些選項來處理命令結束后的輸出.
你可以讓Source Insight 分析捕捉到的輸出,從中找出你指定的內容,例如某些警告或者錯誤信息.
Parse Source Links
The command output will be searched for source link patterns. The patterns typically will match warning and error messages. If a pattern match is found, Source Insight inserts a source link at that line. The source link is used to link the warning or error message to its target source line. If Parse Source Links is enabled, you must have a valid search expression in the Pattern text box.
Pattern contains
File, then Line and Line, then File. This indicates the order of the groups in the pattern expression.
Select File, then Line if the first group in the pattern expression is the file name and the second group is the line number. With this setting, the second group, (i.e. the line number), is optional.
Select Line, then File if the first group in the pattern expression is the line number and the second group is the file name.
Pattern
Contains the regular expression used to search the command output for file names and line numbers.
如果 Parse Source Links 選項未啟用,Source Insight會忽略Pattern;
如果 Parse Source Links 選項啟用了,那么Pattern處必須填入一個有限的正則表達式(that contains “groups” for the file name and the line number.
Add…
添加一個自定義命令.
Remove
刪除當前自定義命令.
Close
退出設定.
Help
查看自定義命令的幫助文檔,即本文.
Run
運行當前自定義命令.
Menu…
將自定義命令導入Source Insight菜單.
Keys…
給當前命令設定快捷鍵.
可以包含多個命令,命令之間使用分號分割, 例如:
cat make.log;echotime
This string causes “cat make.log” to execute, followed by “echotime”.
3.Running the Command Shell
如果你想運行windows的DOS命令, 例如 “type”、 “dir”, 或者你想運行一個批處理文件,
那么你必須使用cmd.exe來運行他們. 請看下面的例子:
cmd /c mybat.bat cmd /c type foo.txt
Note: 如果你是用的是 Windows 9x/Me, 你應該使用command.com 代替 cmd.exe.
If the Run string contains more than one command, separated by semi-colons, you don’t need to run cmd.exe because Source Insight creates a batch file from the run string commands and runs command.com automatically in that case. For example,
cat readme.txt;dir
This works fine because it is already running in a batch file inside a shell.
You may find that the shell you spawned by cmd.exe does not have enough environment space. If that happens, use the /e switch with cmd.exe. For example,
cmd /e:1024 /c mybat.bat
This allocates 1K bytes of environment space to the new sub shell spawned by command.com.
4.Command Line Substitutions
The Run text box can contain meta-characters that cause the following items to be substituted in the string.
Table 1: Custom Command Meta-Characters
Character |
Expands to |
Example |
%f |
當前文件的完整路徑名 【*】 |
c:\myproj\file.c |
%r |
當前文件相對於工程源碼目錄的相對路徑名 【*】 |
file.c |
%n |
leaf name of the current file 【*】 |
file.c |
%d |
當前文件所在的完整路徑名 |
c:\myproj |
%h |
當前文件的路徑名(無磁盤驅動器字符) |
\myproj |
%b |
當前文件名(無后綴名) 【*】 |
file |
%e |
當前文件的后綴名 |
c (file.c 的文件后綴名為 c) |
%c |
當前文件所在的磁盤驅動器字符 |
c: (表示當前文件在磁盤驅動器C:下) |
%p |
當前項目名稱(包含完整路徑) |
c:\myproj\myproj |
%j |
當前項目的源碼路徑 |
c:\myproj |
%J |
當前項目的數據路徑 |
C:\Documents and Settings\Jim Smith\My Documents\Source Insight\Projects\Base |
%v |
當前項目源碼所在的磁盤驅動器字符 |
c: |
%o |
當前項目的名稱(不包含路徑) |
myproj |
%l |
當前行號 |
行號 |
%w |
選擇區域的第一個單詞,或者光標處的單詞 |
任何單詞 |
%s |
自定義命令運行時,保存當前選擇的臨時文件名. |
d:\tmp\vt0004. |
%a |
當前日期 |
05-12-02 |
%t |
當前時間 |
08:23 |
%1 - %9 |
提示用戶輸入參數 |
any strings |
You can also postfix any of the above characters marked with * with either of the following modifier characters.
Character |
Expands to |
Example |
%o |
所有打開的文件 |
%f%o |
%m |
所有修改的文件 |
%f%m |
5.ShellExecute 命令
自定義命令支持 “ShellExecute” 函數, 可以通過他告知 Windows shell 去如果操作一個文件.
ShellExecute的一個優點是你不必知道何種應用被注冊去處理某種類型的文件.
詳細技術資料見Windows Shell API 文檔中的 “ShellExecute” .
“ShellExecute” 的使用方法如下:
ShellExecute <verb> <filespec> <optional parameters>
例如使用瀏覽器打開一個網站:
ShellExecute open https://www.baidu.com
verb 是一個單詞, 可以是下列其中一個:
• edit 打開一個編輯器來編輯指定的文件.只能是文檔文件(document file)
• explore 使用資源管理器打開指定的文件夾.
• open 打開指定的文件. 文件類型可以是可執行文件、 文檔文件(document file) 或者是文件夾.
• print 打印指定的文件,如果文件類型不是文檔文件(document file),函數會失敗.
• properties 顯示文件或者文件夾的屬性.
• find 加載windows的文件查找功能.
• "" (空字符串) 跳過此參數.
參數 filespec 可以是任意有效的路徑.
如果路徑中有空格,使用雙引號將路徑括起來 你可以使用元字符,例如 %f (當前文件). .
The optional parameters list is anything to the right of the filespec. It specifies the parameters to be passed to the application that ultimately runs. The format is determined by the verb that is to be invoked, and the application that runs. You can use custom command meta-characters here as well.
The working directory text box of the custom command is applied before the ShellExecute is invoked. However, output cannot be captured or parsed when using ShellExecute.
下面是幾個使用 ShellExecute 的例子.
想要完成的動作 |
執行命令例子 |
打開一個網站 |
ShellExecute open http://www.somewebsite.com |
To explore your Windows 2000 documents file folder: |
ShellExecute explore “C:\Documents and Settings” |
To explore your Windows 98 documents file folder: |
ShellExecute explore “C:\My Documents” |
打開瀏覽器 |
ShellExecute “” iexplore |
在IE瀏覽器中預覽一個文件 |
ShellExecute “” iexplore %f |
在當前項目目錄搜索文件 |
ShellExecute find %j |
When Source Insight spawns a Custom Command shell program, it actually runs a program called Sihook3.exe.
Sihook3.exe in turn spawns the command and performs the output capturing.
You can run a custom command and click back on the Source Insight window to continue editing with Source Insight while the custom command runs in the background.