how to get the function declaration or definitions using regex

后端 未结 7 999
野的像风
野的像风 2020-12-16 06:43

I want to get only function prototypes like

int my_func(char, int, float)
void my_func1(void)
my_func2()

from C files using regex and pytho

7条回答
  •  一生所求
    2020-12-16 07:14

    I think regex isn't best solution in your case. There are many traps like comments, text in string etc., but if your function prototypes share common style:

    type fun_name(args);
    

    then \w+ \w+\(.*\); should work in most cases:

    mn> egrep "\w+ \w+\(.*\);" *.h
    md5.h:extern bool md5_hash(const void *buff, size_t len, char *hexsum);
    md5file.h:int check_md5files(const char *filewithsums, const char *filemd5sum);
    

提交回复
热议问题