summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2014-03-30 12:33:46 -0400
committerNeil Moore <neil@s-z.org>2014-03-30 12:46:37 -0400
commita329682e064a34ffecc83f5018e86015fd71989f (patch)
treef6a40fa6a60d58839cd5a5a10285294b984e0a77 /crawl-ref/source/util
parentd9c209fe7ca5f958dd014d78a85824357c8c4eb1 (diff)
downloadcrawl-ref-a329682e064a34ffecc83f5018e86015fd71989f.tar.gz
crawl-ref-a329682e064a34ffecc83f5018e86015fd71989f.zip
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.
Diffstat (limited to 'crawl-ref/source/util')
-rwxr-xr-xcrawl-ref/source/util/checkwhite17
-rwxr-xr-xcrawl-ref/source/util/unbrace26
2 files changed, 35 insertions, 8 deletions
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 = $_ = <F>;
@@ -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);