linux下生成C程序函数列表

要做个调查,要从一堆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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值