ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/res2pm
(Generate patch)

Comparing deliantra/Deliantra/res2pm (file contents):
Revision 1.8 by root, Sun Mar 12 23:21:11 2006 UTC vs.
Revision 1.13 by elmex, Fri Mar 19 21:38:14 2010 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3# usage: res2pm 3# usage: res2pm
4 4
5open STDOUT, ">:utf8", "Crossfire/Data.pm" 5open STDOUT, ">:utf8", "Deliantra/Data.pm"
6 or die "Crossfire/Data.pm: $!"; 6 or die "Deliantra/Data.pm: $!";
7 7
8print <<EOF; 8print <<EOF;
9=head1 NAME 9=head1 NAME
10 10
11Crossfire::Data - various data structures useful for understanding archs and objects 11Deliantra::Data - various data structures useful for understanding archs and objects
12 12
13=head1 13=head1
14 14
15THIS FILE IS AUTOGENERATED, DO NOT EDIT! 15THIS FILE IS AUTOGENERATED, DO NOT EDIT!
16 16
22 22
23See F<res/README> for more info. 23See F<res/README> for more info.
24 24
25=cut 25=cut
26 26
27package Crossfire::Data; 27package Deliantra::Data;
28 28
29EOF 29EOF
30 30
31use Data::Dumper; 31use Data::Dumper;
32use XML::Grove::Builder;
32use XML::Parser::Grove; 33use XML::Parser::PerlSAX;
34
33 35
34sub dump_hash { 36sub dump_hash {
35 my ($names, $refs) = @_; 37 my ($names, $refs) = @_;
36 38
37 $d = new Data::Dumper ($refs, [map "*$_", @$names]); 39 $d = new Data::Dumper ($refs, [map "*$_", @$names]);
62 64
63 print "our $sigil$name = $v;\n\n"; 65 print "our $sigil$name = $v;\n\n";
64 } 66 }
65} 67}
66 68
67my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml"); 69my $grove_builder = XML::Grove::Builder->new;
70my $parser = XML::Parser::PerlSAX->new ( Handler => $grove_builder );
71my $type = $parser->parse ( Source => { SystemId => "res/types.xml" } );
68 72
69my %bitmask; 73my %bitmask;
70my %list; 74my %list;
71my %type; 75my %type;
72my %typename; 76my %typename;
75my %ignore_list; 79my %ignore_list;
76my %default_attr; 80my %default_attr;
77my %spell; 81my %spell;
78 82
79sub string($) { 83sub string($) {
80 local $_ = join "", @{shift->contents}; 84 local $_ = join "", map $_->{Data}, @{shift->{Contents}};
81 $_ =~ s/^\s+//; 85 $_ =~ s/^\s+//;
82 $_ =~ s/\s+$//; 86 $_ =~ s/\s+$//;
83 $_ =~ s/\s+/ /g; 87 $_ =~ s/\s+/ /g;
84 $_ 88 $_
85} 89}
86 90
87sub parse_attr { 91sub parse_attr {
88 my ($e, $sect) = @_; 92 my ($e, $sect) = @_;
89 93
90 my $arch = { 94 my $arch = {
91 type => $e->attr ("type"), 95 type => $e->{Attributes}->{type},
92 name => $e->attr ("editor"), 96 name => $e->{Attributes}->{editor},
93 desc => string $e, 97 desc => string $e,
94 $e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), 98 $e->{Attributes}->{arch_begin} ? (end => $e->{Attributes}->{arch_end}) : (),
95 }; 99 };
96 100
97 delete $arch->{name} unless defined $arch->{name}; 101 delete $arch->{name} unless defined $arch->{name};
98 delete $arch->{desc} unless length $arch->{desc}; 102 delete $arch->{desc} unless length $arch->{desc};
99 103
100 if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) { 104 if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) {
101 $arch->{value} = $bitmask{$2} ||= {}; 105 $arch->{value} = $bitmask{$2} ||= {};
102 } elsif ($arch->{type} =~ s/^(list)_(.*)/$1/) { 106 } elsif ($arch->{type} =~ s/^(list)_(.*)/$1/) {
103 $arch->{value} = $list{$2} ||= {}; 107 $arch->{value} = $list{$2} ||= {};
104 } elsif ($arch->{type} eq "fixed") { 108 } elsif ($arch->{type} eq "fixed") {
105 $arch->{value} = $e->attr ("value"); 109 $arch->{value} = $e->{Attributes}->{value};
106 } elsif ($arch->{type} =~ s/^bool_special$/bool/) { 110 } elsif ($arch->{type} =~ s/^bool_special$/bool/) {
107 $arch->{value} = [$e->attr ("false"), $e->attr ("true")]; 111 $arch->{value} = [$e->{Attributes}->{false}, $e->{Attributes}->{true}];
108 } 112 }
109 113
110 push @$sect, [$e->attr ("arch") || $e->attr("arch_begin"), $arch]; 114 push @$sect, [$e->{Attributes}->{arch} || $e->{Attributes}->{arch_begin}, $arch];
111} 115}
112 116
113sub parse_type { 117sub parse_type {
114 my ($e, $type) = @_; 118 my ($e, $type) = @_;
115 119
116 my %main; 120 my %main;
117 121
118 for my $e (grep ref, @{$e->contents}) { 122 for my $e (grep { $_->isa ('XML::Grove::Element') } @{$e->{Contents}}) {
119 if ($e->name eq "required") { 123 if ($e->{Name} eq "required") {
120 for my $i (grep ref, @{$e->contents}) { 124 # not used
121 $type->{required}{$i->attr ("arch")} = $i->attr ("value"); 125 #for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
126 # $type->{required}{$i->{Attributes}->{arch}} = $i->{Attributes}->{value};
122 } 127 #}
123 } elsif ($e->name eq "attribute") { 128 } elsif ($e->{Name} eq "attribute") {
124 parse_attr $e, $type->{attr} ||= []; 129 parse_attr $e, $type->{attr} ||= [];
125 } elsif ($e->name eq "ignore") { 130 } elsif ($e->{Name} eq "ignore") {
126 for my $i (grep ref, @{$e->contents}) { 131 for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
127 if ($i->name eq "ignore_list") { 132 if ($i->{Name} eq "ignore_list") {
128 push @{$type->{ignore}}, $ignore_list{$i->attr ("name")} ||= []; 133 push @{$type->{ignore}}, $ignore_list{$i->{Attributes}->{name}} ||= [];
129 } elsif ($i->name eq "attribute") { 134 } elsif ($i->{Name} eq "attribute") {
135 warn "ACDD $i->{Attributes}->{arch}\n";
130 push @{$type->{ignore}}, $i->attr ("arch"); 136 push @{$type->{ignore}}, [$i->{Attributes}->{arch}];
131 } 137 }
132 } 138 }
133 } elsif ($e->name eq "import_type") { 139 } elsif ($e->{Name} eq "import_type") {
134 push @{$type->{import}}, $type{$e->attr ("name")} ||= {}; 140 #push @{$type->{import}}, $type{$e->{Attributes}->{name}} ||= {};
141 push @{$type->{import}}, $e->{Attributes}->{name};
135 } elsif ($e->name eq "use") { 142 } elsif ($e->{Name} eq "use") {
136 $type->{use} = string $e; 143 $type->{use} = string $e;
137 } elsif ($e->name eq "description") { 144 } elsif ($e->{Name} eq "description") {
138 $type->{desc} = string $e; 145 $type->{desc} = string $e;
139 } elsif ($e->name eq "section") { 146 } elsif ($e->{Name} eq "section") {
140 my @attr; 147 my @attr;
141 for my $i (grep ref, @{$e->contents}) { 148 for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
142 parse_attr $i, \@attr; 149 parse_attr $i, \@attr;
143 } 150 }
144 push @{ $type->{section} }, [$e->attr ("name") => \@attr]; 151 push @{ $type->{section} }, [$e->{Attributes}->{name} => \@attr];
145 } else { 152 } else {
146 warn "unknown types subelement ", $e->name; 153 warn "unknown types subelement ", $e->{Name};
147 } 154 }
148 } 155 }
149 156
150 $type 157 $type
151} 158}
152 159
153for my $e (grep ref, @{$type->root->contents}) { 160for my $e (grep $_->isa ('XML::Grove::Element'), @{$type->root->{Contents}}) {
154 if ($e->name eq "bitmask") { 161 if ($e->{Name} eq "bitmask") {
155 my $bm = $bitmask{$e->attr ("name")} ||= {}; 162 my $bm = $bitmask{$e->{Attributes}->{name}} ||= {};
156 for my $b (grep ref, @{$e->contents}) { 163 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
157 $bm->{$b->attr ("bit")} = $b->attr ("name"); 164 $bm->{$b->{Attributes}->{bit}} = $b->{Attributes}->{name};
158 } 165 }
159 } elsif ($e->name eq "list") { 166 } elsif ($e->{Name} eq "list") {
160 my $list = $list{$e->attr ("name")} ||= {}; 167 my $list = $list{$e->{Attributes}->{name}} ||= {};
161 for my $b (grep ref, @{$e->contents}) { 168 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
162 $list->{$b->attr ("value")} = $b->attr ("name"); 169 $list->{$b->{Attributes}->{value}} = $b->{Attributes}->{name};
163 } 170 }
164 } elsif ($e->name eq "ignore_list") { 171 } elsif ($e->{Name} eq "ignore_list") {
165 my $list = $ignore_list{$e->attr ("name")} ||= []; 172 my $list = $ignore_list{$e->{Attributes}->{name}} ||= [];
166 for my $b (grep ref, @{$e->contents}) { 173 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
167 push @$list, $b->attr ("arch"); 174 push @$list, $b->{Attributes}->{arch};
168 } 175 }
169 } elsif ($e->name eq "default_type") { 176 } elsif ($e->{Name} eq "default_type") {
170 parse_type $e, \%default_attr; 177 parse_type $e, \%default_attr;
171 } elsif ($e->name eq "type") { 178 } elsif ($e->{Name} eq "type") {
172 my $type = $type{$e->attr ("name")} ||= {}; 179 my $type = $type{$e->{Attributes}->{name}} ||= {};
173 180
174 $type->{name} = $e->attr ("name"); 181 $type->{name} = $e->{Attributes}->{name};
175 182
176 parse_type $e, $type; 183 parse_type $e, $type;
177 184
178 if ($e->attr ("number") > 0) { 185 if ($e->{Attributes}->{number} > 0) {
179 $attr{$e->attr ("number")} = $type; 186 $attr{$e->{Attributes}->{number}} = $type;
180 } elsif ($e->attr ("name") eq "Misc") { 187 } elsif ($e->{Attributes}->{name} eq "Misc") {
181 delete $type->{required}; 188 delete $type->{required};
182 } else { 189 } else {
183 push @attr0, $type; 190 push @attr0, $type;
184 } 191 }
185 192
186 } else { 193 } else {
187 warn "unknown types element ", $e->name; 194 warn "unknown types element ", $e->{Name};
188 } 195 }
189} 196}
190 197
191my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml"); 198my $type = $parser->parse ( Source => { SystemId => "res/typenumbers.xml" } );
192 199
193for (grep ref, @{$type->root->contents}) { 200for (grep $_->isa ('XML::Grove::Element'), @{$type->root->{Contents}}) {
194 $typename{$_->attr ("number")} = $_->attr ("name"); 201 $typename{$_->{Attributes}->{number}} = $_->{Attributes}->{name};
195} 202}
196 203
197my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") 204my $spell = $parser->parse ( Source => { SystemId => "res/spells.xml" } )
198 or die; 205 or die;
199 206
200for (grep ref, @{$spell->root->contents}) { 207for (grep $_->isa ('XML::Grove::Element'), @{$spell->root->{Contents}}) {
201 $spell{$_->attr ("id")} = $_->attr ("name"); 208 $spell{$_->{Attributes}->{id}} = $_->{Attributes}->{name};
202} 209}
203 210
204dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR0", "ATTR", "TYPENAME", "SPELL"], 211dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR", "TYPENAME", "SPELL"],
205 [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \@attr0, \%attr, \%typename, \%spell]; 212 [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \%attr, \%typename, \%spell];
206 213
207print <<EOF; 214print <<EOF;
208 215
209=head1 AUTHOR 216=head1 AUTHOR
210 217

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines