external tool to remove embedded filenames

Joe Perches joe at perches.com
Thu Oct 1 14:47:06 EDT 2020


It's rather unnecessary for files to contain their
path/filename in source code comments.

Here's a trivial little script that can remove
embedded filenames in c90 style comments from files.

This requires git.

It does the following types of removals:

remove individual lines like /* filename */ completely
remove filename from /* filename -- comment */, leave /* comment */
remove filename and any trailing ' *\n' from /* filename, leave /*
remove filename from /* filename, leave /*
remove filename from continuation ' * filename -- comment' leave ' * comment'
remove filename and any trailing ' *\n' from continuation ' * filename\n *\n'

It seems to work well enough.

It does not handle c99 comments.
No // filename variants are removed.

Running it on today's -next gives:

$ perl remove_embedded_filenames.pl
$ git diff --shortstat
 2310 files changed, 354 insertions(+), 4239 deletions(-)

It's also possible to give any filename or path
as an argument to the script

For instance:

$ perl remove_embedded_filenames.pl drivers/net

-------------- next part --------------
A non-text attachment was scrubbed...
Name: remove_embedded_filenames.pl
Type: application/x-perl
Size: 2615 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20201001/d04a768b/attachment.pl>


More information about the Kernelnewbies mailing list