2013年11月13日 星期三

vim "取代" 指令

以前在學校,提到 VI / VIM 時,老師總會說它是個強大的編輯器。其實當時只覺得它很難用(那時用的版本還是用H、J、K、L在移動游標),不知道它強大在哪?現在跟視窗化的編輯器比起來,我想是沒有強大到哪去啦,除了它可以不需要滑鼠。不過就 command line 下,它的確是具備了不少後來視窗界面下才被覺得習以為常的功能。

2013年11月7日 星期四

C 語言預設變數 備忘

這也是一個常常會混亂的東西@@,記憶力越來越差,不知道跟什麼東西都能 Google 有關?還是年紀有關?

GCC 中有事先定義了一些變數,讓我們可用,其中 Debug 時常用的就是 __FILE__,__LINE__跟我常常會弄混的 __func__。別人都是大寫,就它是小寫。其實本來是 __FUNCTION__,但後來 GNU 已經不建議使用(原因不明),所以改成了 __func__。

結果我就會搞不清到底是:
__func__,__function____FUNC__ 還是 __FUNCTION__

實際上查了一下,除了這三個還有其它的,只是比較不常用。

1.  __BASE_FILE__
完整的原始檔案路徑

2.  __cplusplus
表示該檔案由 g++ 所編譯,當成 C++ 的檔案

3.  __DATE__
編譯的日期

4.  __TIME__
編譯的時間

5.  __FILE__  
原始檔名

6. __LINE__
所在行數

7. __VERSION__  
gcc 版本

8. __func__
為了避免混淆,我就不提另一個了

2013年11月4日 星期一

diff 參數備忘

diff 是我每次用都要查的指令@@,所以寫下來備忘一下。

diff -Naur path1 path2 > project.patch
-N    In  directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.
-a    Treat  all  files as text and compare them line-by-line, even if they do not seem to be text.
-u    Use the unified output format.
-r    When comparing directories, recursively compare any subdirectories found.


如果要使用這個 patch 檔

patch -p# < project.patch
PS: "#" 表示要省略的路徑層數

man 的原文說明
-pnum or --strip=num
  Strip the smallest prefix containing num leading slashes from each file name found in the patch file.
  A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was

/u/howard/src/blurfl/blurfl.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

and not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the -d option.