source: osm/applications/editors/josm/i18n/convpreset.pl@ 28773

Last change on this file since 28773 was 28252, checked in by simon04, 13 years ago

JOSM/i18n: correct number of newlines in convpreset, test for existing URL in convwms

File size: 4.8 KB
RevLine 
[11529]1#! /usr/bin/perl -w
2
3# Written by Dirk Stöcker <openstreetmap@dstoecker.de>
4# Public domain, no rights reserved.
5
6use strict;
7
8my $item = "";
9my $group;
[24764]10my $combo_n;
[28250]11my $combo_type;
[25155]12my $result = 0;
[11529]13my $comment = 0;
[28250]14my $vctx;
[11529]15
16# This is a simple conversion and in no way a complete XML parser
17# but it works with a default Perl installation
18
[13392]19# Print a header to write valid Java code. No line break,
20# so that the input and output line numbers will match.
21print "class trans_preset { void tr(String s){} void f() {";
22
[26180]23sub fix($)
24{
25 my ($val) = @_;
26 $val =~ s/'/''/g;
27 return $val;
28}
29
[11529]30while(my $line = <>)
31{
32 chomp($line);
33 if($line =~ /<item\s+name=(".*?")/)
34 {
[26180]35 my $val = fix($1);
[17969]36 $item = $group ? "$group$val" : $val;
[11529]37 $item =~ s/""/\//;
[17969]38 if($line =~ /name_context=(".*?")/)
39 {
[23091]40 print "/* item $item */ trc($1, $val);\n";
[17969]41 }
42 else
43 {
[23091]44 print "/* item $item */ tr($val);\n";
[17969]45 }
[11529]46 }
[17969]47 elsif($line =~ /<group.*\s+name=(".*?")/)
[11529]48 {
[26180]49 my $gr = fix($1);
[17973]50 $group = $group ? "$group$gr" : $gr;
[17969]51 $group =~ s/\"\"/\//;
52 if($line =~ /name_context=(".*?")/)
53 {
[23091]54 print "/* group $group */ trc($1,$gr);\n";
[17969]55 }
56 else
57 {
[23091]58 print "/* group $group */ tr($gr);\n";
[17969]59 }
[11529]60 }
[17969]61 elsif($line =~ /<label.*\s+text=" "/)
[11529]62 {
63 print "/* item $item empty label */\n";
64 }
[17969]65 elsif($line =~ /<label.*\s+text=(".*?")/)
[11529]66 {
[26180]67 my $text = fix($1);
[17969]68 if($line =~ /text_context=(".*?")/)
69 {
[23091]70 print "/* item $item label $text */ trc($1,$text);\n";
[17969]71 }
72 else
73 {
[23091]74 print "/* item $item label $text */ tr($text);\n";
[17969]75 }
[11529]76 }
[17969]77 elsif($line =~ /<text.*\s+text=(".*?")/)
[11529]78 {
[26180]79 my $n = fix($1);
[17969]80 if($line =~ /text_context=(".*?")/)
81 {
[23091]82 print "/* item $item text $n */ trc($1,$n);\n";
[17969]83 }
84 else
85 {
[23091]86 print "/* item $item text $n */ tr($n);\n";
[17969]87 }
[11529]88 }
[17969]89 elsif($line =~ /<check.*\s+text=(".*?")/)
[11529]90 {
[26180]91 my $n = fix($1);
[17969]92 if($line =~ /text_context=(".*?")/)
93 {
[23091]94 print "/* item $item check $n */ trc($1,$n);\n";
[17969]95 }
96 else
97 {
[23091]98 print "/* item $item check $n */ tr($n);\n";
[17969]99 }
[11529]100 }
[17969]101 elsif($line =~ /<role.*\s+text=(".*?")/)
[13469]102 {
[26180]103 my $n = fix($1);
[17969]104 if($line =~ /text_context=(".*?")/)
105 {
[23091]106 print "/* item $item role $n */ trc($1,$n);\n";
[17969]107 }
108 else
109 {
[23091]110 print "/* item $item role $n */ tr($n);\n";
[17969]111 }
[13469]112 }
[28250]113 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?")/)
[11529]114 {
[28250]115 my ($type,$n) = ($1,fix($2));
116 $combo_n = $n;
117 $combo_type = $type;
118 $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
119 # text
120 my $tctx = ($line =~ /text_context=(".*?")/) ? $1 : undef;
121 print "/* item $item $type $n */" . ($tctx ? " trc($tctx, $n);" : " tr($n);");
122 # display_values / values
[25155]123 my $sp = ($type eq "combo" ? ",":";");
[28250]124 my $vals = ($line =~ /display_values="(.*?)"/) ? $1 : ($line =~ /values="(.*?)"/) ? $1 : undef;
125 if($vals)
[17969]126 {
[28250]127 my @combo_values = split $sp,$vals;
128 foreach my $val (@combo_values)
129 {
130 next if $val =~ /^[0-9-]+$/; # search for non-numbers
131 $val = fix($val);
132 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");");
133 }
[17969]134 }
[11529]135 print "\n";
136 }
[28250]137 elsif(!$comment && $line =~ /<list_entry/)
[11529]138 {
[28250]139 my $vctxi = ($line =~ /value_context=(".*?")/) ? $1 : $vctx;
140 my $value = ($line =~ /value=(".*?")/) ? $1 : undef;
141 if($line =~ /display_value=(".*?")/)
[17969]142 {
[28250]143 my $val = fix($1);
[28252]144 print "/* item $item $combo_type $combo_n entry $value display value */" . ($vctxi ? " trc($vctxi, $val);" : " tr($val);");
[17969]145 }
146 else
147 {
[28250]148 my $val = fix($value);
[28252]149 print "/* item $item $combo_type $combo_n entry $value display value */" . ($vctxi ? " trc($vctxi, $val);" : " tr($val);");
[17969]150 }
[28250]151 if($line =~ /short_description=(".*?")/)
[11529]152 {
[28250]153 my $val = fix($1);
[28252]154 print "/* item $item $combo_type $combo_n entry $value short description */ tr($val);";
[11529]155 }
[28252]156 print "\n";
[11529]157 }
158 elsif($line =~ /<\/group>/)
159 {
[17969]160 $group = 0 if !($group =~ s/(.*\/).*?$//);
[11529]161 print "\n";
162 }
163 elsif($line =~ /<\/item>/)
164 {
165 $item = "";
166 print "\n";
167 }
[24764]168 elsif($line =~ /<\/combo/)
169 {
170 $combo_n = "";
171 }
[13469]172 elsif(!$line)
173 {
174 print "\n";
175 }
[11529]176 elsif($line =~ /^\s*$/
[13140]177 || $line =~ /<separator *\/>/
178 || $line =~ /<space *\/>/
179 || $line =~ /<\/?optional>/
[11529]180 || $line =~ /<key/
[25155]181 || $line =~ /<presets/
182 || $line =~ /<\/presets/
[13469]183 || $line =~ /roles/
184 || $line =~ /href=/
[11529]185 || $line =~ /<!--/
[25155]186 || $line =~ /<\?xml/
[11529]187 || $line =~ /-->/
188 || $comment)
189 {
[13469]190 print "// $line\n";
[11529]191 }
192 else
193 {
194 print "/* unparsed line $line */\n";
[25155]195 $result = 20
[11529]196 }
197
198 # note, these two must be in this order ore oneliners aren't handled
199 $comment = 1 if($line =~ /<!--/);
200 $comment = 0 if($line =~ /-->/);
201}
[13392]202
203print "}}\n";
[25155]204return $result if $result;
Note: See TracBrowser for help on using the repository browser.