#! /usr/bin/perl -w # Written by Dirk Stöcker # Public domain, no rights reserved. use strict; my $item = ""; my $chunk = ""; my $group; my $combo_n; my $combo_type; my $result = 0; my $comment = 0; my $vctx; # 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() {"; sub fix($) { my ($val) = @_; $val =~ s/'/''/g; $val =~ s/<//g; $val =~ s/&/&/g; return $val; } sub infoblock { my $r = ""; $r .= " item $item" if $item; $r .= " chunk $chunk" if $chunk; $r .= " group $group" if $group; $r .= " $_[0]" if $_[0]; return $r ? "/* $r */ " : ""; } my $linenr = 0; while(my $line = <>) { ++$linenr; chomp($line); print "tr(\"---DUMMY-MARKER---\"); "; if($line =~ //) { $group = 0 if !($group =~ s/(.*\/).*?$//); print "\n"; } elsif($line =~ /<\/item>/) { $item = ""; print "\n"; } elsif($line =~ /<\/chunk>/) { $chunk = ""; } elsif($line =~ /<\/(combo|multiselect)/) { $combo_n = ""; print "\n"; } elsif(!$line) { print "\n"; } elsif($line =~ /^\s*$/ || $line =~ // || $line =~ // || $line =~ /<\/?optional>/ || $line =~ // || $line =~ /<\/?chunk/ || $line =~ // || $comment) { $line =~ s/[ \t]+((?:short)?description) *= *"([^"]+)/*\/ \/* $1 *\/ tr("$2"); \/*/g; print "/* $line */\n"; } else { print "/* unparsed line $line */\n"; print STDERR "/* unparsed line $linenr $line */\n"; $result = 20 } # note, these two must be in this order ore oneliners aren't handled $comment = 1 if($line =~ //); } print "}}\n"; exit($result) if $result;