From a329682e064a34ffecc83f5018e86015fd71989f Mon Sep 17 00:00:00 2001 From: Neil Moore Date: Sun, 30 Mar 2014 12:33:46 -0400 Subject: Improvements to checkwhite and unbrace. Give both programs a -n option to do a dry run (that is, check for problems without correcting them). Exit with a nonzero status if the dry run detected problems, to make it easier to use these in scripts. However, in order to avoid breaking existing scripts, we do not give an exit status if things *were* changed. Also allow unbrace to take a list of files like checkwhite can. --- crawl-ref/source/util/checkwhite | 17 +++++++++++++---- crawl-ref/source/util/unbrace | 26 ++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source/util') diff --git a/crawl-ref/source/util/checkwhite b/crawl-ref/source/util/checkwhite index e6397cdc41..a93ef6763f 100755 --- a/crawl-ref/source/util/checkwhite +++ b/crawl-ref/source/util/checkwhite @@ -3,8 +3,11 @@ use Encode; use Text::Tabs; use Getopt::Std; -getopt('t'); # this removes -t from @ARGV; +our ($opt_n, $opt_t); +getopts('t:n'); # this removes -t and -n from @ARGV; $tabstop = $opt_t if ($opt_t); +my $dry_run = $opt_n; +my $any_bad = 0; my @files = @ARGV; unless (@files) @@ -56,8 +59,14 @@ for (@files) if ($_ ne $cont) { - open F, ">$file" or die; - print F; - close F; + $any_bad = 1; + if (!$dry_run) + { + open F, ">$file" or die; + print F; + close F; + } } } + +exit 1 if ($dry_run and $any_bad); diff --git a/crawl-ref/source/util/unbrace b/crawl-ref/source/util/unbrace index 7cff755dde..ac73a24fa2 100755 --- a/crawl-ref/source/util/unbrace +++ b/crawl-ref/source/util/unbrace @@ -1,7 +1,19 @@ #!/usr/bin/perl -w +use Getopt::Std; +our ($opt_n); +getopts('n'); +my $dry_run = $opt_n; +my $any_bad = 0; + +my @files = @ARGV; undef $/; -for $f (grep /\.(cc|h)$/, split /\n/, `git ls-files`) +unless (@files) +{ + @files = (grep /\.(cc|h)$/, split /\n/, `git ls-files`); +} + +for $f (@files) { open F, "<", $f or die "Can't read $f\n"; my $old = $_ = ; @@ -47,8 +59,14 @@ for $f (grep /\.(cc|h)$/, split /\n/, `git ls-files`) if ($old ne $_) { print "$f\n"; - open F, ">", $f or die "Can't write $f\n"; - print F; - close F; + $any_bad = 1; + if (!$dry_run) + { + open F, ">", $f or die "Can't write $f\n"; + print F; + close F; + } } } + +exit 1 if ($dry_run and $any_bad); -- cgit v1.2.3-54-g00ecf