ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/res2pm
Revision: 1.13
Committed: Fri Mar 19 21:38:14 2010 UTC (14 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.12: +2 -1 lines
Log Message:
added broken connected field.

File Contents

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