小编piy*_*ush的帖子

仅提取函数名称及其来自C代码的注释

我想提取注释,并想知道它们是哪些函数.我有很多这样的C文件如下:

输入:

void main()
{
    //sdgs
    call A;
    /*
    sdfgs
    dfhdfh
    */
    call b;
    some code;
}

/* this function adds
 something */
int add()
{
    //sgsd
    some code;
    //more comments
    some code;
}
Run Code Online (Sandbox Code Playgroud)

输出应该是:

void main()
{
    //sdgs

    /*
    sdfgs
    dfhdfh
    */

}

/* this function adds
 something */
int add()
{
    //sgsd

    //more comments

}
Run Code Online (Sandbox Code Playgroud)

输入代码格式整齐,"功能代码" {在下一行后开始.基本上,我只需要知道哪个"评论"来自哪个函数.此外,它还应包括功能名称或其他地方的任何其他注释.注意:这是不同的,因为顶层的函数名称应该在那里.

为了简化我的要求:

  1. 打印所有评论
  2. 检测包含(在第一行上的块,其中一行仅包含{一到三行后的第一列,并打印上面的行.

c perl awk comments sed

2
推荐指数
1
解决办法
818
查看次数

标签 统计

awk ×1

c ×1

comments ×1

perl ×1

sed ×1