问题描述
请注意:为了更好的字,我致电源文件开始时绒毛的习惯 -
Note: For wont of a better word I call the fluff at the start of source files --
/* @(#) $Id: file.c,v 1.9 2011/01/05 11:55:00 user Exp $
**************************************************************************
* COPYRIGHT, 2005-2011 *
...
*/
- 意见,虽然我不知道这是不是只是一个颠覆的术语。
-- Keyword Substitution comments, although I do not know if this is just a subversion term.
不管怎样,现在到的问题的:我们有我们从源头code第三方供应商。这些C源代码的所有的有这些关键字SUBST意见,每一次我们从供应商的新版本的所有的(1000+)文件被更改,因为他们更新这些意见每次发布他们送我们,即使的没有源$ C $ C的变化保证责任是在这些文件所做的,这样的只有的变化是评论。现在,在我们编译和使用这些资源,我们有兴趣做一个粗略code检讨,看看已更改的区域。 (永远不要相信发行历史记录)。然而,这是相当困难的,因为做一个简单的文件夹差异显然会列出所有文件。
Anyway, now to the question: We have a 3rd party supplier that we get source code from. These c source all have these keyword subst comments, and every time we get a new version from the supplier, all (1000+) files are changed because they update these comments for every release they send us, even if no source code changes whatsover are made in these files, so the only change is the comments. Now, before we compile and use these sources, we would be interested in doing a cursory code review to see the areas that have been changed. (Never trust the release history). However, this is rather difficult, as doing a simple folder diff will obviously list all files.
我要找的是现在是否已经存在任何简单的工具来去除这些特殊的多线从源文件的注释。也许有人有一个链接到一个grep或者sed脚本会刮伤的东西从文件吗?
What I'm looking for now is whether there already exist any simple tools to strip these special multi line comments from the source files. Maybe anyone has a link to a grep or sed script that will scratch that stuff from the files?
推荐答案
是这样的:
perl -ne 'if(m+/\*.*\$Id: +) $c = 1; print unless $c; if($c && m+\*/+) $c = 0;'
请注意,这只会工作,如果
Note that this will work only if
- 这样的评论是分隔的
/*...*/
- 在第一行有
$ ID:
- 有什么的
后* /
- 没有
* /
的前/ *
- such comments are delimited with
/*...*/
- on the first line there is
$Id:
- there is nothing after the
*/
- there is no
*/
before the/*
和这将剥夺那些评论的开始和注释结束之间的所有行。
And that it will strip all lines that are between start of comment and end of comment.
我没有测试它!
这篇关于从删除源文件的关键字替换评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!