如何从 C/C++ 中提取特定函数 源代码文件,供后续处理
我正在寻找一种简单的方法来从某些 C/C++ 源代码中打印出特定函数。 例如,假设 test.c 中定义了多个函数。 我希望能够打印出仅与这些函数之一相关的源代码。
编辑:抱歉,我应该更清楚我的最终目标。 我希望将该函数打印到屏幕上,以便我可以使用 wc
来获取该特定函数的字数。 另外,我希望它成为命令行工具链的一部分,因此它不是手动输入文件和选择文本的选项。
I am looking for an easy way to print out a specific function from within some C/C++ source code. For example, assume that test.c has several functions defined within it. I want to be able to print out the source code associated with only one of those functions.
Edit: Sorry, I should be a bit more clear about my end goal. I want the function printed to the screen so I can use wc
to grab the word count of this specific function. Also, I want this be part of a command line tool-chain so it isn't an option to manually enter files and select the text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过 doxygen 运行您的项目。 它将索引您的所有函数(以及类、结构等),并可以使它们以多种格式< /a> (包括 PDF 和 HTML,两者都易于打印)。
You can run your project through doxygen. It will index all your functions (and classes, structs etc) and can make them available in multiple formats (including PDF and HTML, both easily printable).
打印函数的最终目标是什么?
你想这样使用它吗:
有更简单的方法来输出错误所在的位置。 如果我对您试图解决的问题有更好的了解,我也许可以提供更多帮助。
有关如何实现此类 PrintFunction() 的想法:
这有一个恼人的陷阱,需要更新函数在文件中所在位置的行号。 但这也许可以通过宏来解决。
What is your end goal with printing out a function?
Do you want to use this as such:
There are easier ways to output where errors are. I could maybe help more if I had a better idea of the problem you are trying to solve with this.
For a idea of how to implement such a PrintFunction():
This has an annoying pitfall of needing to update the line numbers of where your function lies in the file. But this could maybe be solved with a macro.
我通常在
emacs
中使用print-region
(或者最好是print-region-with-faces
)。 但是,它不是自动化的,我必须手动选择区域。也适用于其他语言。
以下内容来自评论中的 Tom Smith:
如果您喜欢此内容,请点击链接到 Tom 的用户页面,然后看看他是否值得你投票......
制作这个CW,所以我不会从人们投票支持汤姆的好想法中受益。 干杯。
澄清后编辑:这似乎没有指出OP的实际问题。 唉。
I generally use the
print-region
(or preferablyprint-region-with-faces
) from withinemacs
. However, it is not automated, I have to select the region by hand.Works in other languages as well.
The following due to Tom Smith in the comments:
If you liked this, follow the link to Tom's user-page and see if he deserves your vote...
Making this CW, so I won't benefit from people voting up Tom's good thinking. Cheers.
Edit after clarification: This doesn't seem to be pointed at the OP's actual question. Alas.