开发者

How to extract code comments from a C file?

开发者 https://www.devze.com 2023-04-06 08:57 出处:网络
I have a C file which contains lots of code comments, how I can I extract the comments? Just want the comments, not the c code. Is th开发者_如何学JAVAere any tools i can use to do this. e.g Doxygen? o

I have a C file which contains lots of code comments, how I can I extract the comments? Just want the comments, not the c code. Is th开发者_如何学JAVAere any tools i can use to do this. e.g Doxygen? or need i to build a parser by myself? if needed, which language is better?

Thanks in advance.

thank you all!! i start to look into perl now, have never used this kind of language before, it seems so clever~~ and is there any suggestion for extracting xml from a file that contains xml?


Following one-liner displays all commented lines (or lines that contain comments) in main.c file:

cat main.c | awk '/\/\// {print $0}; /\/\*/ {blk=1}; {if(blk) print $0}; /\*\// {blk=0}'


I suggest you to use an scripting language, such as Perl, and parse the file looking all the possibilities:

 - "//" for single-line comments.
 - "/*" and "*/" for multi-line comments.
 - doxygen ones "///", "/**", "/*!"
0

精彩评论

暂无评论...
验证码 换一张
取 消