Search code examples
cparsingctags

How can I get ctags to show the parameters for a given C function?


I'm trying to write a script that parses the functions in a file, and in particular, the parameters of each function. So for example, if file X.c has function func(int a, char b), then I want to see output like

func
    int a
    char b

ctags gets me very close:

ctags -x --c-types=f file.c

shows me:

func function    106 file.c func

which is great, because file.c has a whole bunch of goofball macros and typedefs that confuse most C parsers.

So is there a way to get ctags to show the parameters for a given function? All of the examples I've seen are for generating tag files, which I don't want to do.


Solution

  • It took me a while to find the answer, but the trick is to use ctags-universal, which is an updated version of ctags.

    ctags-universal -x --c-kinds=f --_xformat="%N %S" filename