要做个调查,要从一堆C程序源代码中grep到一些特殊行,然后判断其所在的函数名。
源代码tree下几千个文件,当然得用脚本来做。
如何取函列表?
想到自己用脚本分析,最不靠谱。
想到cflow可以生成函数调用关系,再做一些加工,结果测试下来,发现会漏掉一些函数,找得结果不全。
后来在想还有哪工具可堪当此任,于是不觉觉得ctags比较可疑。
man 了一下
-x Print a tabular, human-readable cross reference (xref) file to standard output instead of generating a tag file.
The information contained in the output includes: the tag name; the kind of tag; the line number, file name, and
source line (with extra white space condensed) of the file which defines the tag. No tag file is written and all
options affecting tag file output will be ignored. Example applications for this feature are generating a listing
of all functions located in a source file (e.g. ctags -x --c-kinds=f file), or generating a list of all externally
visible global variables located in a source file (e.g. ctags -x --c-kinds=v --file-scope=no file). This option
must appear before the first file name.
发现了亮点
结果就大概是这个样子了
# make function list (line_no-func_name pair) for source file
# line_no asc sorted
list_functions()
{
local file_path=${1:?source file required}
ctags -x --c-kinds=f $file_path | sort -k3n | awk '{print $3,$1}'
}
⇄
侦测语言 » Afrikaans
⇄
侦测语言 » Afrikaans
⇄
侦测语言 » Afrikaans