| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use warnings; |
| 4 |
|
| 5 |
# Run gather_features -a if you want "A pigsty" rather than "pigsty". |
| 6 |
my $art = grep /^-a$/, @ARGV; |
| 7 |
|
| 8 |
# extract(fn, start, end[, per-line) |
| 9 |
# |
| 10 |
# Gather quoted strings from the file named fn, in the region between the first |
| 11 |
# occurrence of the start string and the next line that contains only the end |
| 12 |
# string. If per_line is true, take only the first string from each line. |
| 13 |
sub extract($$$;$) |
| 14 |
{ |
| 15 |
my ($fn, $start, $end, $per_line) = @_; |
| 16 |
open my $in, "util/cpp_version $fn|" or die "Can't read $fn: $!\n"; |
| 17 |
undef local $/; |
| 18 |
my $data = <$in>; |
| 19 |
close $in; |
| 20 |
|
| 21 |
$data =~ s/.*\Q$start\E(.*?)\Q$end\E.*/$1/s |
| 22 |
or die "Can't find \"$start\" in $fn\n"; |
| 23 |
$data =~ s|//.*$||mg; |
| 24 |
my $consume = $per_line ? '.*' : ''; |
| 25 |
return grep { |
| 26 |
$_ ne "" and $_ !~ /^<.*>$/ |
| 27 |
} ($data =~ /"([^"\n]*)"$consume/g); |
| 28 |
} |
| 29 |
|
| 30 |
sub articled($) |
| 31 |
{ |
| 32 |
local $_ = $_[0]; |
| 33 |
return $_ unless $art; |
| 34 |
return $_ if /^[A-Z]/ && !/ trap$/; |
| 35 |
return "\u$_" if /^(?:the |an |a |some )/i; |
| 36 |
return "A $_" if /^one-/i; |
| 37 |
# Handle "rough-hewn floor" but not "escape hatch in the floor" |
| 38 |
return "The $_" if $_ =~ /^(\S+\s+)?floor$/; |
| 39 |
return /^[aeiou]/i ? "An $_" : "A $_"; |
| 40 |
} |
| 41 |
|
| 42 |
for (extract "directn.cc", "static string _base_feature_desc", "}") |
| 43 |
{ |
| 44 |
$features{articled($_)} = 1; |
| 45 |
} |
| 46 |
|
| 47 |
for (extract "feature-data.h", "feat_defs[] =", "};", "per-line") |
| 48 |
{ |
| 49 |
$features{articled($_)} = 1; |
| 50 |
} |
| 51 |
|
| 52 |
for (extract "describe.cc", "trap_names[] =", "};") |
| 53 |
{ |
| 54 |
$_ .= " trap" unless /^(web|shaft|passage|pressure plate)$/; |
| 55 |
$_ .= " of Golubria" if /^passage$/; |
| 56 |
|
| 57 |
$features{articled($_)} = 1; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
for (grep /\.des|\.des\.disabled|\.lua$/, `git ls-files`) |
| 62 |
{ |
| 63 |
chomp; |
| 64 |
open IN, "<", $_ or die "Can't read $_\n"; |
| 65 |
{ undef local $/; $_ = <IN>; } |
| 66 |
close IN; |
| 67 |
|
| 68 |
$features{articled($_)} = 1 |
| 69 |
for /set_feature_name\s*\(\s*"[^"\n"]+"\s*,[ \n:]*"([^"\n]+)"\s*\)/sg; |
| 70 |
|
| 71 |
$features{articled($_)} = 1 |
| 72 |
for /\bdesc\s*=\s*"([^"]*)"/g; |
| 73 |
} |
| 74 |
|
| 75 |
$features{articled("gleaming silver wall")} = 1; |
| 76 |
$features{articled("awoken tree")} = 1; |
| 77 |
for (qw(open closed runed sealed)) |
| 78 |
{ |
| 79 |
$features{articled("large $_ door")} = 1; |
| 80 |
$features{articled("$_ gate")} = 1; |
| 81 |
$features{articled("huge $_ gate")} = 1; |
| 82 |
} |
| 83 |
for (qw(haloed liquefied umbraed), "disjunction haloed") |
| 84 |
{ |
| 85 |
$features{$_} = 1; |
| 86 |
} |
| 87 |
|
| 88 |
print join("\n", sort keys %features), "\n"; |