1 | #!/usr/bin/perl -w |
---|
2 | |
---|
3 | use strict; |
---|
4 | |
---|
5 | use XML::Parser; |
---|
6 | use Date::Manip; |
---|
7 | |
---|
8 | Date_Init(); |
---|
9 | |
---|
10 | if (!$ARGV[0]) |
---|
11 | { |
---|
12 | die("No exist mame xml"); |
---|
13 | } |
---|
14 | |
---|
15 | my $parser = XML::Parser->new( Handlers => |
---|
16 | { |
---|
17 | Start=>\&handle_start, |
---|
18 | Char => \&char_handler, |
---|
19 | End=>\&handle_end, |
---|
20 | }); |
---|
21 | $parser->parsefile( shift @ARGV ); |
---|
22 | |
---|
23 | my $year; |
---|
24 | my $date; |
---|
25 | my $status; |
---|
26 | my $description; |
---|
27 | my $game; |
---|
28 | my $players; |
---|
29 | my $bios; |
---|
30 | my $manufacturer; |
---|
31 | |
---|
32 | sub quote |
---|
33 | { |
---|
34 | my($str) = @_; |
---|
35 | $str =~ s/["\\]/\\$&/gmo; #" |
---|
36 | return qq{"$str"}; |
---|
37 | } |
---|
38 | |
---|
39 | sub char_handler |
---|
40 | { |
---|
41 | my ($p, $data) = @_; |
---|
42 | $year=$data if ($p->current_element eq 'year'); |
---|
43 | $manufacturer.=$data if ($p->current_element eq 'manufacturer'); |
---|
44 | $description.=$data if ($p->current_element eq 'description'); |
---|
45 | } |
---|
46 | |
---|
47 | sub handle_start { |
---|
48 | my( $expat, $element, %attrs ) = @_; |
---|
49 | |
---|
50 | if ( $element eq 'mame' ) { |
---|
51 | $attrs{'build'} =~ /\((.*?)\)/gs; |
---|
52 | |
---|
53 | $date = UnixDate(ParseDate($1), '%Y%m%d'); |
---|
54 | } |
---|
55 | |
---|
56 | if ( $element eq 'driver' ) { |
---|
57 | $status=$attrs{'status'}; |
---|
58 | } |
---|
59 | |
---|
60 | if ( $element eq 'input' ) { |
---|
61 | $players=$attrs{'players'}; |
---|
62 | } |
---|
63 | |
---|
64 | if ( $element eq 'game' ) { |
---|
65 | $manufacturer= ''; |
---|
66 | $description= ''; |
---|
67 | $game = $attrs{'name'}; |
---|
68 | if ($attrs{'isbios'} and $attrs{'isbios'} eq 'yes') { |
---|
69 | $bios=1; |
---|
70 | } |
---|
71 | else { |
---|
72 | $bios=0; |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | sub handle_end { |
---|
78 | my( $expat, $element ) = @_; |
---|
79 | |
---|
80 | if ( $element eq 'game' ) { |
---|
81 | my $category; |
---|
82 | |
---|
83 | if ($bios == 1) |
---|
84 | { |
---|
85 | $category='Bios'; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | if ($status eq 'good') |
---|
90 | { |
---|
91 | if ($players != 1) |
---|
92 | { |
---|
93 | $category="Players " . $players; |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | $category='Player 1'; |
---|
98 | } |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | $category='Imperfect'; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | print "INSERT INTO gamedb VALUES ('MAME', " . quote($game . ".zip") . "," . |
---|
107 | quote($description) . "," . quote($category) . "," . quote($year) . "," . |
---|
108 | quote($manufacturer) . ",'');\n"; |
---|
109 | } |
---|
110 | } |
---|