We have most of Gnu C Library Headers in /usr/include
I’m looking for a way to open and read an include file and parse it to print all the declared functions which are located inside it.
and can any one explain or provide a link talking about this headers formatting.
I doing this because I’m trying to do an C Auto completion plug-in which if I include a file.h the plug-in will give me all functions are located in the file.h.
We have most of Gnu C Library Headers in /usr/include I’m looking for a
Share
Everyone eventually asks for a tool like this at least once in their careers; something that will scan C source code and print out a listing of function/variable names or a cross-reference of function calls between various modules.
To adequately do what you’re asking, you’re going to have to write what is basically a C compiler front end; no amount of regular expression magic is going to give you what you want. Grab a
yaccable version of the C language grammar and womp up a parser usinglexandyacc(orflexandbison, or your tools of choice). However, when you match a function declaration, instead of generating machine instructions you’ll just print it out (or save it to a database, or something like that).Run the header of interest through the existing C preprocessor (e.g.
gcc -E) to strip out comments and do any macro expansion, then feed the resulting file into your parser.EDIT
And now that I actually go read the
gccman page, there’s an option-aux-infothat will write the prototype declarations of all functions declared/defined within the translation unit, including the ones declared in the included header files. Even better, the output is somewhat nicely formatted and regular and should be reasonably easy to parse.So, lesson learned: check your compiler documentation and ignore old farts like me who still think in terms of ’80s-vintage tools.