Removing Keyword Substitution comments from source files?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 12:30:49

问题


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.

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.

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?


回答1:


Something like:

perl -ne 'if(m+/\*.*\$Id: +) $c = 1; print unless $c; if($c && m+\*/+) $c = 0;'

Note that this will work only if

  • 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.

I have not tested it!




回答2:


First, I would try to convince them to review either their version control system (looks as if they use RCS, still?) or if that is not possible to have them hook up to a svn or git server for submitting their changes. But perhaps you already did?

If nothing in that sense is possible, I would try to set up a git repository to hold the versions that they supply to you. Git allows you to have filters when you are importing or exporting and also has support for ignoring such tags for deltas between versions.



来源:https://stackoverflow.com/questions/5001714/removing-keyword-substitution-comments-from-source-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!