diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-08-15 12:59:30 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-08-15 12:59:30 +0000 |
commit | 4b21d1d60d5d7623ba938a57a4741d8e2d0caf9b (patch) | |
tree | 7ecdb7999066cfcf21acd7ed4ea02f5a51dd2943 /crawl-ref/source/util/descript-sort.pl | |
parent | 474793c7638ec859494caef26d03f6e1ce731f87 (diff) | |
download | crawl-ref-4b21d1d60d5d7623ba938a57a4741d8e2d0caf9b.tar.gz crawl-ref-4b21d1d60d5d7623ba938a57a4741d8e2d0caf9b.zip |
[1773753] Split and sort the description db input file (zelgadis).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2003 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/util/descript-sort.pl')
-rwxr-xr-x | crawl-ref/source/util/descript-sort.pl | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crawl-ref/source/util/descript-sort.pl b/crawl-ref/source/util/descript-sort.pl new file mode 100755 index 0000000000..130a465760 --- /dev/null +++ b/crawl-ref/source/util/descript-sort.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl -w + +use strict; + +if (@ARGV != 2) { + die "usage: descript-sort.pl infile outfile\n"; +} + +my $INNAME = $ARGV[0]; +my $OUTNAME = $ARGV[1]; + +unless (open(INFILE, "$INNAME")) { + die "Couldn't open input file '$INNAME' for reading: $!\n"; +} + +unless (open(OUTFILE, ">$OUTNAME")) { + die "Couldn't open output file '$OUTNAME' for writing: $!\n"; +} + +undef $/; + +my $content = <INFILE>; +close(INFILE); + +my @entries = split(/\n?%%%%\s*\n?/m, $content); + +my($entry, %entry_table); + +foreach $entry (@entries) { + chomp(my @lines = split(/\n/m, $entry)); + next if (@lines < 1); + + s/\s+$// for @lines; + + my $key = shift(@lines); + + shift(@lines) while (@lines && length($lines[0]) == 0); + + if (@lines == 0) { + print "'$key' has no definition\n"; + $entry_table{$key} = ""; + next; + } + + $entry_table{$key} = join("\n", @lines); +} + +my @entry_order = sort keys(%entry_table); + +foreach $entry (@entry_order) { + print OUTFILE "%%%%\n"; + print OUTFILE "$entry\n\n"; + + if ($entry_table{$entry} ne "") { + print OUTFILE "$entry_table{$entry}\n"; + } +} + +print OUTFILE "%%%%\n"; +close(OUTFILE); |