1 |
root |
1.1 |
#!/opt/bin/perl |
2 |
|
|
|
3 |
root |
1.2 |
# usage: res2pm |
4 |
|
|
|
5 |
|
|
open STDOUT, ">:utf8", "Crossfire/Data.pm" |
6 |
|
|
or die "Crossfire/Data.pm: $!"; |
7 |
root |
1.1 |
|
8 |
|
|
print <<EOF; |
9 |
|
|
=head1 NAME |
10 |
|
|
|
11 |
|
|
Crossfire::Data - various data structures useful for understanding archs and objects |
12 |
|
|
|
13 |
|
|
=head1 |
14 |
|
|
|
15 |
|
|
THIS FILE IS AUTOGENERATED, DO NOT EDIT! |
16 |
|
|
|
17 |
|
|
It's a translation of the following files: |
18 |
|
|
|
19 |
|
|
res/spells.xml |
20 |
|
|
res/types.xml |
21 |
|
|
res/typenumbers.xml |
22 |
|
|
|
23 |
|
|
See F<res/README> for more info. |
24 |
|
|
|
25 |
|
|
=cut |
26 |
|
|
|
27 |
|
|
EOF |
28 |
|
|
|
29 |
|
|
use Data::Dumper; |
30 |
|
|
use XML::Parser::Grove; |
31 |
|
|
|
32 |
|
|
sub dump_hash { |
33 |
root |
1.3 |
my ($names, $refs) = @_; |
34 |
|
|
|
35 |
|
|
$d = new Data::Dumper ($refs, [map "*$_", @$names]); |
36 |
root |
1.1 |
$d->Terse (1); |
37 |
|
|
$d->Indent (1); |
38 |
|
|
$d->Quotekeys (0); |
39 |
root |
1.3 |
$d->Useqq (0); |
40 |
|
|
$d->Useperl(1); |
41 |
root |
1.1 |
$d->Sortkeys (sub { |
42 |
|
|
[sort { |
43 |
|
|
$a > 0 && $b > 0 ? $a <=> $b |
44 |
|
|
: $a cmp $b |
45 |
|
|
} keys %{+shift}] |
46 |
|
|
}); |
47 |
root |
1.3 |
|
48 |
|
|
my @vals = $d->Dump; |
49 |
|
|
|
50 |
|
|
while (@vals) { |
51 |
|
|
my $v = shift @vals; |
52 |
|
|
$v =~ s/^ /\t\t/gm; |
53 |
|
|
$v =~ s/^ /\t/gm; |
54 |
|
|
$v =~ s/\s+$//; |
55 |
|
|
|
56 |
|
|
my $name = shift @$names; |
57 |
|
|
my $ref = shift @$refs; |
58 |
|
|
|
59 |
|
|
my $sigil = ref $ref eq "ARRAY" ? '@' : '%'; |
60 |
|
|
|
61 |
|
|
print "our $sigil$name = $v;\n\n"; |
62 |
|
|
} |
63 |
root |
1.1 |
} |
64 |
|
|
|
65 |
|
|
my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml"); |
66 |
|
|
|
67 |
|
|
my %bitmask; |
68 |
|
|
my %list; |
69 |
|
|
my %type; |
70 |
root |
1.3 |
my %typename; |
71 |
|
|
my @attr0; |
72 |
|
|
my %attr; |
73 |
root |
1.1 |
my %ignore_list; |
74 |
|
|
my %default_attr; |
75 |
root |
1.3 |
my %spell; |
76 |
root |
1.1 |
|
77 |
|
|
sub string($) { |
78 |
|
|
local $_ = join "", @{shift->contents}; |
79 |
|
|
$_ =~ s/^\s+//; |
80 |
|
|
$_ =~ s/\s+$//; |
81 |
|
|
$_ =~ s/\s+/ /g; |
82 |
|
|
$_ |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
sub parse_attr { |
86 |
|
|
my ($e, $sect) = @_; |
87 |
|
|
|
88 |
root |
1.2 |
my $arch = { |
89 |
root |
1.3 |
type => $e->attr ("type"), |
90 |
root |
1.1 |
name => $e->attr ("editor"), |
91 |
|
|
desc => string $e, |
92 |
|
|
$e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), |
93 |
|
|
}; |
94 |
root |
1.2 |
|
95 |
root |
1.3 |
delete $arch->{name} unless defined $arch->{name}; |
96 |
|
|
delete $arch->{desc} unless length $arch->{desc}; |
97 |
|
|
|
98 |
root |
1.2 |
if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) { |
99 |
root |
1.3 |
$arch->{value} = $bitmask{$2} ||= {}; |
100 |
|
|
} elsif ($arch->{type} =~ s/^(list)_(.*)/$1/) { |
101 |
|
|
$arch->{value} = $list{$2} ||= {}; |
102 |
|
|
} elsif ($arch->{type} =~ s/^bool_special$/bool/) { |
103 |
|
|
$arch->{value} = [$e->attr ("false"), $e->attr ("true")]; |
104 |
root |
1.2 |
} |
105 |
|
|
|
106 |
|
|
$sect->{$e->attr ("arch") || $e->attr("arch_begin")} = $arch; |
107 |
root |
1.1 |
} |
108 |
|
|
|
109 |
|
|
sub parse_type { |
110 |
|
|
my ($e, $type) = @_; |
111 |
|
|
|
112 |
|
|
for my $e (grep ref, @{$e->contents}) { |
113 |
|
|
if ($e->name eq "required") { |
114 |
|
|
for my $i (grep ref, @{$e->contents}) { |
115 |
|
|
$type->{required}{$i->attr ("arch")} = $i->attr ("value"); |
116 |
|
|
} |
117 |
|
|
} elsif ($e->name eq "attribute") { |
118 |
|
|
parse_attr $e, $type->{attr}{Main} ||= {}; |
119 |
|
|
} elsif ($e->name eq "ignore") { |
120 |
|
|
for my $i (grep ref, @{$e->contents}) { |
121 |
|
|
if ($i->name eq "ignore_list") { |
122 |
|
|
push @{$type->{ignore}}, $ignore_list{$i->attr ("name")} ||= []; |
123 |
|
|
} elsif ($i->name eq "attribute") { |
124 |
|
|
push @{$type->{ignore}}, $i->attr ("arch"); |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
} elsif ($e->name eq "import_type") { |
128 |
root |
1.3 |
push @{$type->{import}}, $type{$e->attr ("name")} ||= {}; |
129 |
root |
1.1 |
} elsif ($e->name eq "use") { |
130 |
|
|
$type->{use} = string $e; |
131 |
|
|
} elsif ($e->name eq "description") { |
132 |
|
|
$type->{desc} = string $e; |
133 |
|
|
} elsif ($e->name eq "section") { |
134 |
|
|
for my $i (grep ref, @{$e->contents}) { |
135 |
|
|
parse_attr $i, $type->{attr}{$e->attr ("name")} ||= {}; |
136 |
|
|
} |
137 |
|
|
# $type->{desc} = string $e; |
138 |
|
|
} else { |
139 |
|
|
warn "unknown types subelement ", $e->name; |
140 |
|
|
} |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
$type |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
for my $e (grep ref, @{$type->root->contents}) { |
147 |
|
|
if ($e->name eq "bitmask") { |
148 |
root |
1.2 |
my $bm = $bitmask{$e->attr ("name")} ||= {}; |
149 |
root |
1.1 |
for my $b (grep ref, @{$e->contents}) { |
150 |
|
|
$bm->{$b->attr ("bit")} = $b->attr ("name"); |
151 |
|
|
} |
152 |
|
|
} elsif ($e->name eq "list") { |
153 |
root |
1.2 |
my $list = $list{$e->attr ("name")} ||= {}; |
154 |
root |
1.1 |
for my $b (grep ref, @{$e->contents}) { |
155 |
|
|
$list->{$b->attr ("value")} = $b->attr ("name"); |
156 |
|
|
} |
157 |
|
|
} elsif ($e->name eq "ignore_list") { |
158 |
|
|
my $list = $ignore_list{$e->attr ("name")} ||= []; |
159 |
|
|
for my $b (grep ref, @{$e->contents}) { |
160 |
|
|
push @$list, $b->attr ("arch"); |
161 |
|
|
} |
162 |
|
|
} elsif ($e->name eq "default_type") { |
163 |
|
|
parse_type $e, \%default_attr; |
164 |
|
|
} elsif ($e->name eq "type") { |
165 |
root |
1.3 |
my $type = $type{$e->attr ("name")} ||= {}; |
166 |
root |
1.1 |
parse_type $e, $type; |
167 |
root |
1.3 |
#unshift @{$type->{import}}, \%default_attr; |
168 |
|
|
|
169 |
|
|
if ($e->attr ("number") > 0) { |
170 |
|
|
$attr{$e->attr ("number")} = $type; |
171 |
|
|
} elsif ($e->attr ("name") eq "Misc") { |
172 |
|
|
delete $type->{required}; |
173 |
|
|
} else { |
174 |
|
|
push @attr0, $type; |
175 |
|
|
} |
176 |
root |
1.1 |
|
177 |
|
|
} else { |
178 |
|
|
warn "unknown types element ", $e->name; |
179 |
|
|
} |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml"); |
183 |
|
|
|
184 |
|
|
for (grep ref, @{$type->root->contents}) { |
185 |
root |
1.3 |
$typename{$_->attr ("number")} = $_->attr ("name"); |
186 |
root |
1.1 |
} |
187 |
|
|
|
188 |
|
|
my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") |
189 |
|
|
or die; |
190 |
|
|
|
191 |
|
|
for (grep ref, @{$spell->root->contents}) { |
192 |
|
|
$spell{$_->attr ("id")} = $_->attr ("name"); |
193 |
|
|
} |
194 |
|
|
|
195 |
root |
1.3 |
dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR0", "ATTR", "TYPENAME", "SPELL"], |
196 |
|
|
[\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \@attr0, \%attr, \%typename, \%spell]; |
197 |
root |
1.1 |
|
198 |
|
|
print <<EOF; |
199 |
|
|
|
200 |
|
|
=head1 AUTHOR |
201 |
|
|
|
202 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
203 |
|
|
http://home.schmorp.de/ |
204 |
|
|
|
205 |
|
|
The source files are part of the CFJavaEditor. |
206 |
|
|
|
207 |
|
|
=cut |
208 |
|
|
|
209 |
|
|
1 |
210 |
|
|
EOF |
211 |
|
|
|