I want to get both the beginning and ending line numbers of all functions in a file in C. Does any one know that whether there is a easy-to-use tool in Linux for this purpose?
$ ctags -x --c-kinds=f filename.c
This only gives the starting line of each function, but perhaps that is good enough.
If the code was written using fairly common conventions, the function should end with a single line containing } in the first column, so it is fairly easy to get the last line given the first:
awk 'NR > first && /^}$/ { print NR; exit }' first=$FIRST_LINE filename.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With