-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddcomment
More file actions
executable file
·38 lines (30 loc) · 1.25 KB
/
addcomment
File metadata and controls
executable file
·38 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/local/bin/perl5 -0777 -i
# Author: Jason Eisner, University of Pennsylvania
# Usage: addcomment [-c comment] [files ...]
#
# Modifies the files listed on the command line by prepending the same
# set of user comments to all of them. If no files are specified, then
# stdin is filtered.
#
# The comments are read from stdin or (quoted) following -c, and "#
# addcomment:" is prefixed to them.
require("stamp.inc"); &fixprog; # fix $0, but don't timestamp just yet -- we'll timestamp the individual files below.
die "$0: can't use stdin for both input files and comments (specify some args!); aborting\n" unless @ARGV;
if ($ARGV[0] =~ /^-c/) {
shift(@ARGV);
$comments = $';
$comments = shift(@ARGV) if $comment eq "";
}
@saveargv = @ARGV; # make sure that stamp mentions all files in @ARGV (so we know what else got stamped) but not the -c argument if any.
unless (defined $comments) {
$comments = <STDIN>;
print STDERR "$0: modifying file(s) ...\n";
}
$comments .= "\n" unless substr($comments,-1) eq "\n"; # add final newline if not already present
$comments =~ s/^/\# $0: /gm; # insert prefix at the start of each line
while (<>) {
{ local(@ARGV)=@saveargv; &stamp; }
print $comments;
print;
}
print STDERR "$0: done\n";