3 ms·
I dont know if this off topic but is there an utlity that can parse C files and print all the function names or local variable names for example. I know it can
by freemarketteddy 15y ago
I dont know if this off topic but is there an utlity that can parse C files and print all the function names or local variable names for example.
I know it can be done through sed,but a perfect regex for parsing functions and nothing else can be complex and I am wondering if someone has already done it.
- sequoia 15y agoperhaps https://en.wikipedia.org/wiki/Ctags https://en.wikipedia.org/wiki/Ctags
- tmhedberg 15y agoIn particular, `ctags -x` generates human-readable tabular output (instead of the normal output designed for parsing by text editors) and annotates each symbol to indicate whether it's a variable, function, macro, etc. If you want to get a list of all function names from file "foo.c", you could do something like: ctags -x foo.c | awk '$2=="function"{print $1}'
- grok2 15y agoLook at what the perl script at http://www.gson.org/egypt/ http://www.gson.org/egypt/ does -- if you are using gcc, you can compile with certain options to generate info from the source code into an intermediate file and then parse this intermediate file with a script to get the info you need. A bit complex, but useful if you are trying to read through code you are maintaining. A compiler is better than a regex for this, I think, for C. Also ctags/etags like another comment mentioned as also the cscope utility.
- freemarketteddy 15y agoI checked out Egypt.It is pretty cool but unfortunately it doesnt seem to have support for Objective C.