2011-07-25 29 views
9

ctags是否有辦法在C中處理多行函數原型?ctags多行C函數原型

我已搜索周圍和--fields=+S是應該做多的原型,但我不能得到它的工作:

ctags -x --c-kinds=pf --fields=+S file 

文件:

int 
foo(int 
    x, int y 
    ); 

的ctags只返回:

foo(int 

(注意返回類型也是缺失)

最後,我想獲得類似

int foo(int x, int y); 

int foo(int x, int y 

的輸出爲--fields=+S不正確的方法是什麼? 是否有部分我缺少的ctags字段? 任何指針一般?

如果沒有辦法在ctags中做任何推薦的程序? (我目前正在尋找uncrustify)

回答

0

我無法找到任何的ctags所以我寫了一個python腳本重新安排我的文件,這樣的ctags可以捕捉原型。

注意:我的代碼有註釋,所以需要注意刪除它們(否則它們會妨礙ctags)。

操作在這個順序進行:

# concat to one line 
file_str = '' 
for line in read_from.readlines(): 
    file_str += line 

# remove all /* */ comments 
file_str = re.sub('/\*(.|[\r\n])*?\*/', '', file_str) 

# remove '//' comments 
file_str = re.sub('//.*', '', file_str) 

# split on '\n' 
file_as_list = file_str.splitlines(True) 

# strip everything 
for index in range(len(file_as_list)): 
    file_as_list[index] = file_as_list[index].strip() 

# add in newlines where appropriate 
for line in file_as_list: 
    # if the line ends in ';' or '}' 
    if line.endswith(';') or line.endswith('}'): 
     # append a newline to the stripped line 
     write_to.write(line.strip() + '\n') 
    else: 
     # append a space to the stripped line 
     write_to.write(line.strip() + ' ') 
-1

你可以用一個簡單的過濾器刪除不需要的換行符,例如:

tr '\n' ' ' | sed 's/\([{};]\)/\1\n/g' 
1

我有同樣的問題,我的代碼,但我不能修改它。 當我使用--fields = + S參數時,它似乎工作,因爲我在標記文件中獲得了一行。簽名:部分包含該函數的所有參數。

CopyToTX26 d:\ BiseL \我的Dropbox \工作\ 0_BSW \ PKG_CMD \ Memory.c/^無效CopyToTX26(UINT16 memory_ID,UINT32 ** pt_data_address,UINT32 nb_recover,$ /;」 F簽名:(UINT16 memory_ID,UINT32 ** pt_data_address,UINT32 nb_recover,UINT32 * nb_copied,UINT32 MAX_LENGTH)

0

--_ xformat選項可以幫助你。

[[email protected] ~]$ cat /tmp/foo.h 
int 
foo(int 
    x, int y 
    ); 
[[email protected] ~]$ ~/var/ctags/ctags -x --c-kinds=pf --_xformat="%-16N %4n %-16F %C %S" /tmp/foo.h 
foo     2 /tmp/foo.h  foo(int (int x,int y)