1#!/usr/bin/env perl
2
3use warnings;
4
5my $db = grep /^-d$/, @ARGV;
6my %jewellery_prefixes;
7
8sub jewellery_name($$)
9{
10    my ($enum, $name) = @_;
11    my $prefix = $jewellery_prefixes{$enum} || "";
12    my $type = $enum =~ /^AMU_/ ? "amulet" : "ring";
13    return "$type of $prefix$name";
14}
15
16open IN, "util/cpp_version item-name.cc|" or die "Can't read item-name.cc\n";
17{ undef local $/; $_ = <IN>; }
18close IN;
19
20# Remove this from the input so the main jewellery pattern doesn't match.
21s/^static [^\n]*_jewellery_effect_prefix\([^\n]*\).(.*?)^}//ms;
22my $prefixes = $1;
23$jewellery_prefixes{$1} = $2
24    while $prefixes =~ /((?:RING|AMU)_[A-Z_]+): *return "([^"]+)";/g;
25
26$items{"wand of $_"} = 1 for /WAND_[A-Z_]+: *return "([^"]+)";/g;
27$items{"potion of $_"} = 1 for /POT_[A-Z_]+: *return "([^"]+)";/g;
28$items{"scroll of $_"} = 1 for /SCR_[A-Z_]+: *return "([^"]+)";/g;
29my %seen_enums;
30while (/((?:RING|AMU)_[A-Z_]+): *return "([^"]+)";/g)
31{
32    next if $seen_enums{$1}++;
33    $items{jewellery_name($1, $2)} = 1
34}
35
36unless ($db)
37{
38    $items{"$_ rune of Zot"} = 1 for /RUNE_[A-Z_]+: *return "([^"]+)";/g;
39    $items{"$_ deck of cards"} = 1 for /DECK_RARITY_[A-Z_]+: *return "([^"]+)";/g;
40}
41$items{$_} = 1 for /MISC_[A-Z_]+: *return "([^"]+)";/g;
42$items{"book of $_"} = 1 for /BOOK_[A-Z_]+: *return "([^"]+)";/g;
43$items{"staff of $_"} = 1 for /STAFF_[A-Z_]+: *return "([^"]+)";/g;
44
45open IN, "util/cpp_version item-prop.cc|" or die "Can't read item-prop.cc\n";
46{ undef local $/; $_ = <IN>; }
47close IN;
48
49s/" "//g;
50$items{$_} = 1 for /\{ *ARM_[A-Z_]+, *"([^"]+)"/mg;
51$items{"$_ dragon scales"} = 1 for /^ *DRAGON_ARMOUR\([A-Z_]+, *"([^"]+)"/mg;
52$items{$_} = 1 for /^ *\{ *WPN_[A-Z_]+, *"([^"]+)"/mg;
53$items{$_} = 1 for /^ *\{ *MI_[A-Z_]+, *"([^"]+)"/mg;
54
55open IN, "util/cpp_version decks.cc|" or die "Can't read decks.cc\n";
56{ undef local $/; $_ = <IN>; }
57close IN;
58my $data = $_;
59$data =~ s/.*all_decks =(.*?)};.*/$1/s or die "can't find all_decks\n";
60$items{"deck of $_"} = 1 for $data =~ /^\s+"([^"]+)"/mg;
61
62$items{$_} = 1 for (split /\n/, <<END);
63corpse
64eggplant
65gold piece
66manual
67orb of Zot
68pair of boots
69pair of gloves
70rune of Zot
71Young Poisoner's Handbook
72Grand Grimoire
73Necronomicon
74Fen Folio
75END
76
77$items{"decaying skeleton"} = 1 if $db;
78
79delete $items{$_} for (split /\n/, <<END);
80boots
81gloves
82END
83
84for (sort keys %items)
85{
86    next if /bugginess/i;
87    # yay consistency, all other descs use proper capitalization
88    tr/A-Z/a-z/ if $db && !/Geryon/;
89    print "$_\n";
90}
91