[英]How to get the range (i.e., the line number) of all functions in a file in C?
我想得到C中文件中所有函数的开始和结束行号。是否有人知道Linux中是否有一个易于使用的工具用于此目的?
$ ctags -x --c-kinds=f filename.c
This only gives the starting line of each function, but perhaps that is good enough. 这只给出了每个函数的起始行,但也许这就足够了。
If the code was written using fairly common conventions, the function should end with a single line containing }
in the first column, so it is fairly easy to get the last line given the first: 如果代码是使用相当常见的约定编写的,那么函数应该在第一列中以包含
}
的单行结束,因此在第一行中给出最后一行是相当容易的:
awk 'NR > first && /^}$/ { print NR; exit }' first=$FIRST_LINE filename.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.