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

Last change on this file since 29943 was 29943, checked in by stoecker, 11 years ago

remove obsolete comments to empty string

File size: 5.2 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
[29933]30my $linenr = 0;
[11529]31while(my $line = <>)
32{
[29933]33 ++$linenr;
[11529]34 chomp($line);
[29943]35 print "tr(\"\"); ";
[11529]36 if($line =~ /<item\s+name=(".*?")/)
37 {
[26180]38 my $val = fix($1);
[17969]39 $item = $group ? "$group$val" : $val;
[11529]40 $item =~ s/""/\//;
[17969]41 if($line =~ /name_context=(".*?")/)
42 {
[23091]43 print "/* item $item */ trc($1, $val);\n";
[17969]44 }
45 else
46 {
[23091]47 print "/* item $item */ tr($val);\n";
[17969]48 }
[11529]49 }
[17969]50 elsif($line =~ /<group.*\s+name=(".*?")/)
[11529]51 {
[26180]52 my $gr = fix($1);
[17973]53 $group = $group ? "$group$gr" : $gr;
[17969]54 $group =~ s/\"\"/\//;
55 if($line =~ /name_context=(".*?")/)
56 {
[23091]57 print "/* group $group */ trc($1,$gr);\n";
[17969]58 }
59 else
60 {
[23091]61 print "/* group $group */ tr($gr);\n";
[17969]62 }
[11529]63 }
[17969]64 elsif($line =~ /<label.*\s+text=" "/)
[11529]65 {
66 print "/* item $item empty label */\n";
67 }
[17969]68 elsif($line =~ /<label.*\s+text=(".*?")/)
[11529]69 {
[26180]70 my $text = fix($1);
[17969]71 if($line =~ /text_context=(".*?")/)
72 {
[23091]73 print "/* item $item label $text */ trc($1,$text);\n";
[17969]74 }
75 else
76 {
[23091]77 print "/* item $item label $text */ tr($text);\n";
[17969]78 }
[11529]79 }
[17969]80 elsif($line =~ /<text.*\s+text=(".*?")/)
[11529]81 {
[26180]82 my $n = fix($1);
[17969]83 if($line =~ /text_context=(".*?")/)
84 {
[23091]85 print "/* item $item text $n */ trc($1,$n);\n";
[17969]86 }
87 else
88 {
[23091]89 print "/* item $item text $n */ tr($n);\n";
[17969]90 }
[11529]91 }
[17969]92 elsif($line =~ /<check.*\s+text=(".*?")/)
[11529]93 {
[26180]94 my $n = fix($1);
[17969]95 if($line =~ /text_context=(".*?")/)
96 {
[23091]97 print "/* item $item check $n */ trc($1,$n);\n";
[17969]98 }
99 else
100 {
[23091]101 print "/* item $item check $n */ tr($n);\n";
[17969]102 }
[11529]103 }
[17969]104 elsif($line =~ /<role.*\s+text=(".*?")/)
[13469]105 {
[26180]106 my $n = fix($1);
[17969]107 if($line =~ /text_context=(".*?")/)
108 {
[23091]109 print "/* item $item role $n */ trc($1,$n);\n";
[17969]110 }
111 else
112 {
[23091]113 print "/* item $item role $n */ tr($n);\n";
[17969]114 }
[13469]115 }
[29933]116 elsif($line =~ /<optional.*\s+text=(".*?")/)
117 {
118 my $n = fix($1);
119 if($line =~ /text_context=(".*?")/)
120 {
121 print "/* item $item optional $n */ trc($1,$n);\n";
122 }
123 else
124 {
125 print "/* item $item optional $n */ tr($n);\n";
126 }
127 }
[28250]128 elsif($line =~ /<(combo|multiselect).*\s+text=(".*?")/)
[11529]129 {
[28250]130 my ($type,$n) = ($1,fix($2));
131 $combo_n = $n;
132 $combo_type = $type;
133 $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
134 # text
135 my $tctx = ($line =~ /text_context=(".*?")/) ? $1 : undef;
136 print "/* item $item $type $n */" . ($tctx ? " trc($tctx, $n);" : " tr($n);");
137 # display_values / values
[25155]138 my $sp = ($type eq "combo" ? ",":";");
[28250]139 my $vals = ($line =~ /display_values="(.*?)"/) ? $1 : ($line =~ /values="(.*?)"/) ? $1 : undef;
140 if($vals)
[17969]141 {
[28250]142 my @combo_values = split $sp,$vals;
143 foreach my $val (@combo_values)
144 {
145 next if $val =~ /^[0-9-]+$/; # search for non-numbers
146 $val = fix($val);
147 print "/* item $item $type $n display value */" . ($vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");");
148 }
[17969]149 }
[11529]150 print "\n";
151 }
[28250]152 elsif(!$comment && $line =~ /<list_entry/)
[11529]153 {
[28250]154 my $vctxi = ($line =~ /value_context=(".*?")/) ? $1 : $vctx;
155 my $value = ($line =~ /value=(".*?")/) ? $1 : undef;
156 if($line =~ /display_value=(".*?")/)
[17969]157 {
[28250]158 my $val = fix($1);
[28252]159 print "/* item $item $combo_type $combo_n entry $value display value */" . ($vctxi ? " trc($vctxi, $val);" : " tr($val);");
[17969]160 }
161 else
162 {
[28250]163 my $val = fix($value);
[28252]164 print "/* item $item $combo_type $combo_n entry $value display value */" . ($vctxi ? " trc($vctxi, $val);" : " tr($val);");
[17969]165 }
[28250]166 if($line =~ /short_description=(".*?")/)
[11529]167 {
[28250]168 my $val = fix($1);
[28252]169 print "/* item $item $combo_type $combo_n entry $value short description */ tr($val);";
[11529]170 }
[28252]171 print "\n";
[11529]172 }
173 elsif($line =~ /<\/group>/)
174 {
[17969]175 $group = 0 if !($group =~ s/(.*\/).*?$//);
[11529]176 print "\n";
177 }
178 elsif($line =~ /<\/item>/)
179 {
180 $item = "";
181 print "\n";
182 }
[24764]183 elsif($line =~ /<\/combo/)
184 {
185 $combo_n = "";
186 }
[13469]187 elsif(!$line)
188 {
189 print "\n";
190 }
[11529]191 elsif($line =~ /^\s*$/
[13140]192 || $line =~ /<separator *\/>/
193 || $line =~ /<space *\/>/
194 || $line =~ /<\/?optional>/
[11529]195 || $line =~ /<key/
[25155]196 || $line =~ /<presets/
[29933]197 || $line =~ /<checkgroup/
198 || $line =~ /<\/checkgroup/
[25155]199 || $line =~ /<\/presets/
[13469]200 || $line =~ /roles/
201 || $line =~ /href=/
[11529]202 || $line =~ /<!--/
[25155]203 || $line =~ /<\?xml/
[11529]204 || $line =~ /-->/
205 || $comment)
206 {
[13469]207 print "// $line\n";
[11529]208 }
209 else
210 {
211 print "/* unparsed line $line */\n";
[29933]212 print STDERR "/* unparsed line $linenr $line */\n";
[25155]213 $result = 20
[11529]214 }
215
216 # note, these two must be in this order ore oneliners aren't handled
217 $comment = 1 if($line =~ /<!--/);
218 $comment = 0 if($line =~ /-->/);
219}
[13392]220
221print "}}\n";
[29208]222exit($result) if $result;
Note: See TracBrowser for help on using the repository browser.