2009年3月25日 星期三

multi tabbed ssh client

常用shh or telnet,但是卻不喜歡有多個視窗,覺得很混亂嗎?
可以try下面這個multi-tabbed plug-in for putty。

PuTTY Connection Manager
http://puttycm.free.fr/

PuTTY Connection Manager需要先安裝,然後在指定putty路徑,就可以運作。0.6.0.4822beta 的版本在我的電腦上,並不能正確運作,會出現下面的錯誤訊息

=============================
An unexpected error occured :
Object reference not set to an instance of an object..

Check log for further informations.
(c:\......\puttycm.log)
=============================

改用Alpha version 0.7.0.4780就可以正確運作

參考圖(reference:http://puttycm.free.fr/images/puttycm.JPG)


參考:
http://www.tsmexpert.org/2008/03/tabbed-sshtelnet-client.html

2009年3月23日 星期一

multi-projects of vim using cscope plugin

我在 Linux 上都是用 vim 在 trace source code,可是以前都是用 grep 的笨方法,並不知道 cscope 這個好東西,他可以直接在 vi 裡面直接連結到 function 的定義或是哪邊的 code 有用到這個 function 。
這像是在 windows 上的 source insight,也許用很多人認為 source insight 非常好用(也許是學習曲線較快),vi 相對來說,就需要花點時間去習慣,不過習慣後,就會討厭在寫 code 的時候要去動到滑鼠。:)

下面的安裝,我做了些改良(cscope_maps.vim),讓 vim 自動尋找正確的 cscope 產生出來的 CSCOPE_DB(通常為 cscope.out ),這邊透過絕對路徑的方式讓 vim 可以在任何子目錄中跳到另外幾個目錄下的某個檔案,原本的機制是不行的。

1. Install cscope and ctags
sudo apt-get install cscope ctags

2. download and modify cscope_maps.vim

這邊預設的目錄深度為 20 層,所以如果你的 source code 的目錄深度大於 20 請自行修正 i 的值
if has("cscope")
......

" add the database pointed to by environment variable 

" Search database for each project, you can switch different projects easily, :)

let i = 1
  while i < 20
    if filereadable("cscope.out")
      let db = getcwd() . "/cscope.out"
      "echo db
      let $CSCOPE_DB = db
      cs add $CSCOPE_DB
      let i = 20
    else
      cd ..
    let i += 1
  endif
endwhile

" show msg when any other cscope db added

.......
3. put cscope_maps.vim into ~/.vim/plugin
(目錄不存在請自行建立)

4. Create goproj.sh and put it in ~/bin
這是為了方便建立 cscope.out (CSCOPE_DB)而寫的 goproj.sh,內容如下,為了方便起見可放在 ~/bin 下面。
Content of goproj.sh
#!/bin/bash
CSCOPE_FILE=cscope.out
if [ -n "$1" ]; then
  echo "Source code directory: " $1
  echo "Create file map : " $CSCOPE_FILE
  find $1 -name "*.h" -o -name "*.c" -o -name "*.cpp" > $CSCOPE_FILE
  cscope -bkq -i $CSCOPE_FILE
  # cscope -Rbkq
  ctags -R
else
  echo "Please key-in path of project"
fi 

5. 使用範例,以 kernel source
# tar zxvf kernel-2.6.29.tar.gz
# cd kernel-2.6.29
# goproj.sh `pwd`
# vim xxx.c


[ Ctrl + \ + s ] : 搜尋游標上的 function 哪邊參考到
[ Ctrl + \ + c ] : 搜尋游標上的 function 哪邊呼叫到
[ Ctrl + \ + g ] : 搜尋游標上的 function 是在哪邊定義的

[ Ctrl + \ + t ] : 跳回下一個位置
[ Ctrl + \ + o ] : 跳回上一個位置

另外由於 cscope_maps.vim 中有定義 Ctrl + ] 的作用,會取代原本 TAG 裡面的定義,所以如果不喜歡的話可以把 cscope_maps.vim 中的這行 (set cscopetag) 移除 。

6. 請用力使用。謝謝!