Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 C 中获取文件中所有函数的开始行号和结束行号。有谁知道 Linux 中是否有一个易于使用的工具用于此目的?
$ ctags -x --c-kinds=f 文件名.c
这只给出了每个函数的起点,但也许这已经足够了。
如果代码是使用相当普遍的约定编写的,则函数应该以包含第一列的单行结尾},因此很容易得到第一行的最后一行:
}
awk 'NR > first && /^}$/ { print NR; exit }' first=$FIRST_LINE filename.c