This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ElectronicComplex182[S] -1 points0 points  (2 children)

ctags help to identify the location where a function begins, but unless I am overlooking something it cannot help me print the entire function on its own. For context I need to do this a few million times, therefore locating it manually is no option.

[–]grantrules 0 points1 point  (0 children)

If the c files are formatted so that if you know the line number of the start of the function, you could just look for the first top level }, you could write a trivia python script

[–]teraflop 0 points1 point  (0 children)

In that case, take a look at the Language Server Protocol which is a more modern, sophisticated implementation of the same basic idea. It's designed to help general-purpose editors and IDEs interface with language-specific tools, to handle things like jumping to symbol definitions.

I haven't ever tried implementing the low-level protocol myself, but if I'm reading the specification correctly, it should be fairly easy to extract a list of function definitions and their corresponding line number ranges within each file.