Hello every one I Want to parse a header file to print all the function names (only name) in header file. Is there an way to do that like can I do it with any other language and embed that code in my c program? Or do I have to read the file from the start and parse it in some way to find the function name? Any better way?
-
Why do you ask? Why are you concerned only by function names and not their signature? What about inlined functions? – Basile Starynkevitch Feb 02 '12 at 12:09
-
actually I want to find the function name then i will search that function name in the .c file to find function definition – mainajaved Feb 02 '12 at 12:42
-
But why are you asking? What is the overall goal? Who will search the found function name (you, some program or script)? What is the real goal??? How gig is your source code?? – Basile Starynkevitch Feb 02 '12 at 12:59
3 Answers
If you are only concerned with names of the functions in the *.h file a simple regex rule to extract them. So yeah you could do it from pretty much any language that supports regex.
There was topic about it here some time ago. Regex to pull out C function prototype declarations?

- 1
- 1

- 4,387
- 5
- 27
- 47
You might consider extending GCC with a plugin or a MELT extension for that purpose. Except that it would probably cost you more work than copy-pasting the names or some ugly textual solution.
You could also use the nm
command to discover the defined functions in object files.
If you are concerned by glue code between C and some other language, you might look into SWIG

- 223,805
- 18
- 296
- 547
Of course you have to read the file from the start and parse it, that is generally how you extract information from files.
Not sure what other methods for other languages you're referencing, this is of course the way it works for all languages that represent programs as sequences of characters.
Parsing C is not trivial either, you typically need to pre-process the code first, which can require quite a lot of configuration management.

- 391,730
- 64
- 469
- 606