| 1 | #! /usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 |
|
|---|
| 5 | my $item;
|
|---|
| 6 | my $line = 1;
|
|---|
| 7 | my $comment = 0;
|
|---|
| 8 |
|
|---|
| 9 | # this is a simple conversion and in no way a complete XML parser
|
|---|
| 10 | # but it works with a default Perl installation
|
|---|
| 11 |
|
|---|
| 12 | while(my $line = <>)
|
|---|
| 13 | {
|
|---|
| 14 | chomp($line);
|
|---|
| 15 | if($line =~ /<item\s+name="(.*?)\/ ".*<\/item>/)
|
|---|
| 16 | {
|
|---|
| 17 | print "tr(\"$1/ \") /* empty item \"$1\" */\n";
|
|---|
| 18 | }
|
|---|
| 19 | elsif($line =~ /<item\s+name=(".*?")/)
|
|---|
| 20 | {
|
|---|
| 21 | $item = $1;
|
|---|
| 22 | print "tr($item) /* item $item */\n";
|
|---|
| 23 | }
|
|---|
| 24 | elsif($line =~ /<label\s+text=" "/)
|
|---|
| 25 | {
|
|---|
| 26 | print "/* item $item empty label */\n";
|
|---|
| 27 | }
|
|---|
| 28 | elsif($line =~ /<label\s+text=(".*?")/)
|
|---|
| 29 | {
|
|---|
| 30 | print "tr($1) /* item $item label $1 */\n";
|
|---|
| 31 | }
|
|---|
| 32 | elsif($line =~ /<text.*text=(".*?")/)
|
|---|
| 33 | {
|
|---|
| 34 | print "tr($1) /* item $item text $1 */\n";
|
|---|
| 35 | }
|
|---|
| 36 | elsif($line =~ /<check.*text=(".*?")/)
|
|---|
| 37 | {
|
|---|
| 38 | print "tr($1) /* item $item check $1 */\n";
|
|---|
| 39 | }
|
|---|
| 40 | elsif($line =~ /<combo.*text=(".*?").*values="(.*?)"/)
|
|---|
| 41 | {
|
|---|
| 42 | print "tr($1) /* item $item combo $1 */";
|
|---|
| 43 | foreach my $val (split ",",$2)
|
|---|
| 44 | {
|
|---|
| 45 | next if $val =~ /^[0-9-]+$/; # search for non-numbers
|
|---|
| 46 | print " tr(\"$val\")";
|
|---|
| 47 | }
|
|---|
| 48 | print "\n";
|
|---|
| 49 | }
|
|---|
| 50 | elsif($line =~ /^\s*$/
|
|---|
| 51 | || $line =~ /<\/item>/
|
|---|
| 52 | || $line =~ /<key/
|
|---|
| 53 | || $line =~ /annotations/
|
|---|
| 54 | || $line =~ /<!--/
|
|---|
| 55 | || $line =~ /-->/
|
|---|
| 56 | || $comment)
|
|---|
| 57 | {
|
|---|
| 58 | print "\n";
|
|---|
| 59 | }
|
|---|
| 60 | else
|
|---|
| 61 | {
|
|---|
| 62 | print "/* unparsed line $line */\n";
|
|---|
| 63 | print STDERR "Unparsed line $line\n";
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | # note, these two must be in this order ore oneliners aren't handled
|
|---|
| 67 | $comment = 1 if($line =~ /<!--/);
|
|---|
| 68 | $comment = 0 if($line =~ /-->/);
|
|---|
| 69 | }
|
|---|