Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to pull out C function prototype declarations?

Tags:

c

function

regex

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 anyone know of a decent regular expression to find any and all function prototypes in a C header, while excluding everything else?

Edit: Three things that weren't clear initially:

  1. I do not care about C++, only straight C. This means no templates, etc. to worry about.
  2. The solution must work with typedefs and structs, no limiting to only basic C types.
  3. This is kind of a one-off thing. It does not need to be pretty. I do not care how much of a kludge it is as long as it works, but I don't want a complex, hard to implement solution.
like image 560
dsimcha Avatar asked Jan 24 '09 15:01

dsimcha


1 Answers

You may implement a parser using ANSI C yacc/lex grammar.

like image 123
Quassnoi Avatar answered Oct 06 '22 07:10

Quassnoi