我有许多cmake头文件,我想将其中的注释和cmakedefine
提取到CSV(或TSV)文件中.
典型的输入如下所示:
/**
* 1st Multi-line brief description of what the following
* cmakedefine does.
*
* Second more complicated multi-line full description, of <c>SOMETHING</c> to be enabled in the
* configuration.
*
* Possibly additional lines of full description.
*/
#cmakedefine SOMETHING
第一步要得到的输出如下:
SOMETHING
1st Multi-line brief description of what the following cmakedefine does.
Second more complicated multi-line full description , of <c>SOMETHING</c> to be enabled in the configuration. Possibly additional lines of full description.
...
最终,我希望得到的结果是:
SOMETHING, "1st Multi-line brief description of what the following cmakedefine does.", "Second more complicated multi-line full description, of <c>SOMETHING</c> to be enabled in the configuration. Possibly additional lines of full description."
SOMETHING_ELSE, "Brief description", "Long Description"
(列标题可以隐含为:cmakedefine, Brief_Description, Long_Description
.)
我曾try 在sed分钟内做到这一点,但没有成功,这不是一种消磨时间的好方法.我也try 过awk,但没有成功.在这一点上,我并不关心使用什么工具,我只想完成工作.但我认为也许可以更好地使用Python来实现这一点.
注意事项:
- 所有 comments 都以空的
/**
开头. - 所有
Brief
条 comments 都以\ * \
开头,可能在多行. -
Brief
和Long
comments 用空的注释行\ *
分隔. - 所有
Long
条 comments 都可以有多个段落(如图所示),方式类似. - 相关的
cmakedefine
人正在关注 comments .