#! /usr/bin/perl -w # Written by Dirk Stöcker # Public domain, no rights reserved. use strict; my $item = ""; my $group; my $combo_n; my @combo_values; my $combo_idx; my $comment = 0; # This is a simple conversion and in no way a complete XML parser # but it works with a default Perl installation # Print a header to write valid Java code. No line break, # so that the input and output line numbers will match. print "class trans_preset { void tr(String s){} void f() {"; while(my $line = <>) { chomp($line); if($line =~ /(.*?)<\/short_description>/) { my $n = $1; print "/* item $item combo $combo_n item \"$combo_values[$combo_idx]\" short description */ tr(\"$n\");\n"; $combo_idx++; } elsif($line =~ /<\/group>/) { $group = 0 if !($group =~ s/(.*\/).*?$//); print "\n"; } elsif($line =~ /<\/item>/) { $item = ""; print "\n"; } elsif($line =~ /<\/combo/) { $combo_n = ""; $combo_idx = 0; } elsif(!$line) { print "\n"; } elsif($line =~ /^\s*$/ || $line =~ // || $line =~ // || $line =~ /<\/?optional>/ || $line =~ // || $comment) { print "// $line\n"; } else { print "/* unparsed line $line */\n"; # print STDERR "Unparsed line $line\n"; } # note, these two must be in this order ore oneliners aren't handled $comment = 1 if($line =~ //); } print "}}\n";