Regex to pull out C function prototype declarations?

前端 未结 8 647
星月不相逢
星月不相逢 2020-11-30 04:48

I\'m somewhere on the learning curve when it comes to regular expressions, and I need to use them to automatically modify function prototypes in a bunch of C headers. Does

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 05:24

    A one liner regex sounds very hard. I personally use a perl script for that. It's kind of easy. The basic aproach is> 1. Call your favorite c preprocessor to eliminate comments and get macros expanded. (so it's easier) 2. Count '{' '}' symbols. For functions in plain C they have a predictable behavior that will allow you to detect function names. 3. Look the function names into the original source (before preprocessing to get the signature that has typedefs) It is an inefficiency approach but it works quite well for me. Step 1 is not really necessary but it will make your life easier

提交回复
热议问题