【发布时间】:2017-04-25 21:21:12
【问题描述】:
是否也可以通过 ctags 获取函数结束行号
"ctags -x --c-kinds=f filename.c"
上面的命令列出了函数定义的起始行号。想要一种获取函数结束行号的方法。
其他方法:
awk 'NR > first && /^}$/ { print NR; exit }' first=$FIRST_LINE filename.c
这需要正确格式化代码
示例: 文件名.c
1 #include<stdio.h>
2 #include<stdlib.h>
3 int main()
4 {
5 const char *name;
6
7 int a=0
8 printf("name");
9 printf("sssss: %s",name);
10
11 return 0;
12 }
13
14 void code()
15 {
16 printf("Code \n");
17 }
18
19 int code2()
20 {
21 printf("code2 \n");
22 return 1
23 }
24
输入:文件名和函数起始行号。
Example:
Input: filename.c 3
Output: 12
Input : filename.c 19
Output : 23
有没有更好/更简单的方法?
【问题讨论】:
-
一个示例输入文件将有助于获得更多答案。
-
@karakfa 添加了示例。在这里感谢任何帮助
标签: parsing awk tags ctags exuberant-ctags