NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / share / renumtiles.pl
blobcbb5c5325bd1d523a5f24b9bd66038d320fcd52a
1 #!/bin/perl
3 # $ANH-Date$ $ANH-Branch$:$ANH-Revision$
6 sub bail($);
8 use Getopt::Std;
10 # TODO: switch to Getopt::Long so we can parse normal arguments too
11 $Getopt::Std::STANDARD_HELP_VERSION = TRUE;
12 $main::VERSION = 1.0;
14 my %commands = (
15 'd' => 'debug mode; parse objects.txt to stdout instead of updating',
18 getopts(join('', keys(%commands)));
20 my $debug = (defined($opt_d) && $opt_d == 1);
21 my $tilecount = 0;
22 my $outfile = $debug ? "-" : "objects.txt";
23 my $infile = $debug ? "objects.txt" : "objects.bak";
26 unless ($debug) {
27 if (-e "$infile") { die "something didn't clean up objects.bak from last time; stopping\n"; }
28 rename($outfile,$infile) or die "couldn't move objects.txt to objects.bak; stopping\n";
31 open(INFILE, "<$infile") or bail("couldn't open $infile; bailing");
32 open(OUTFILE, ">$outfile") or bail("couldn't open $outfile; bailing");
34 while (my $line = <INFILE>)
36 if (my ($tiletext) = $line =~ /^# tile \d+ (.*)/)
38 $line = "# tile $tilecount $tiletext\n";
39 $tilecount++;
42 print OUTFILE $line;
45 close(INFILE);
46 close(OUTFILE);
48 unless ($debug) { unlink $infile; }
50 exit;
52 sub main::HELP_MESSAGE()
54 print <<"STARTHELP";
55 Usage: renumtiles.pl [OPTIONS] <textfile>
57 STARTHELP
58 foreach $cmd (keys(%commands)) {
59 printf("%10s %s\n", '-'.$cmd, $commands{$cmd});
61 print <<"ENDHELP";
63 \t--help display this help message and exit
64 \t--version display version and exit
65 ENDHELP
66 exit;
69 sub main::VERSION_MESSAGE()
71 my ($objglob, $optpackage, $ver, $switches) = @_;
72 print <<"STARTHELP";
73 renumtiles $ver -- tile-renumbering utility for aNetHack
74 STARTHELP
77 sub bail($)
79 unless ($debug) {
80 unlink $outfile;
81 rename ($infile,$outfile);
83 shift;
84 die "$_\n";