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

Last change on this file since 20244 was 17973, checked in by stoecker, 15 years ago

fixed typos

File size: 4.0 KB
Line 
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;
10my $comment = 0;
11
12# This is a simple conversion and in no way a complete XML parser
13# but it works with a default Perl installation
14
15# Print a header to write valid Java code. No line break,
16# so that the input and output line numbers will match.
17print "class trans_preset { void tr(String s){} void f() {";
18
19while(my $line = <>)
20{
21 chomp($line);
22 if($line =~ /<item\s+name=(".*?")/)
23 {
24 my $val = $1;
25 $item = $group ? "$group$val" : $val;
26 $item =~ s/""/\//;
27 if($line =~ /name_context=(".*?")/)
28 {
29 print "trc($1, $val); /* item $item */\n";
30 }
31 else
32 {
33 print "tr($val); /* item $item */\n";
34 }
35 }
36 elsif($line =~ /<group.*\s+name=(".*?")/)
37 {
38 my $gr = $1;
39 $group = $group ? "$group$gr" : $gr;
40 $group =~ s/\"\"/\//;
41 if($line =~ /name_context=(".*?")/)
42 {
43 print "trc($1,$gr); /* group $group */\n";
44 }
45 else
46 {
47 print "tr($gr); /* group $group */\n";
48 }
49 }
50 elsif($line =~ /<label.*\s+text=" "/)
51 {
52 print "/* item $item empty label */\n";
53 }
54 elsif($line =~ /<label.*\s+text=(".*?")/)
55 {
56 my $text = $1;
57 if($line =~ /text_context=(".*?")/)
58 {
59 print "trc($1,$text); /* item $item label $text */\n";
60 }
61 else
62 {
63 print "tr($text); /* item $item label $text */\n";
64 }
65 }
66 elsif($line =~ /<text.*\s+text=(".*?")/)
67 {
68 my $n = $1;
69 if($line =~ /text_context=(".*?")/)
70 {
71 print "trc($1,$n); /* item $item text $n */\n";
72 }
73 else
74 {
75 print "tr($n); /* item $item text $n */\n";
76 }
77 }
78 elsif($line =~ /<check.*\s+text=(".*?")/)
79 {
80 my $n = $1;
81 if($line =~ /text_context=(".*?")/)
82 {
83 print "trc($1,$n); /* item $item check $n */\n";
84 }
85 else
86 {
87 print "tr($n); /* item $item check $n */\n";
88 }
89 }
90 elsif($line =~ /<role.*\s+text=(".*?")/)
91 {
92 my $n = $1;
93 if($line =~ /text_context=(".*?")/)
94 {
95 print "trc($1,$n); /* item $item role $n */\n";
96 }
97 else
98 {
99 print "tr($n); /* item $item role $n */\n";
100 }
101 }
102 # first handle display values
103 elsif($line =~ /<combo.*\s+text=(".*?").*\s+display_values="(.*?)"/)
104 {
105 my ($n,$vals) = ($1,$2);
106 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
107 if($line =~ /text_context=(".*?")/)
108 {
109 print "trc($1,$n); /* item $item combo $n */";
110 }
111 else
112 {
113 print "tr($n); /* item $item combo $n */";
114 }
115 foreach my $val (split ",",$vals)
116 {
117 next if $val =~ /^[0-9-]+$/; # search for non-numbers
118 print $vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");";
119 }
120 print "\n";
121 }
122 elsif($line =~ /<combo.*\s+text=(".*?").*\s+values="(.*?)"/)
123 {
124 my ($n,$vals) = ($1,$2);
125 my $vctx = ($line =~ /values_context=(".*?")/) ? $1 : undef;
126 if($line =~ /text_context=(".*?")/)
127 {
128 print "trc($1,$n); /* item $item combo $n */";
129 }
130 else
131 {
132 print "tr($n); /* item $item combo $n */";
133 }
134 foreach my $val (split ",",$vals)
135 {
136 next if $val =~ /^[0-9-]+$/; # search for non-numbers
137 print $vctx ? " trc($vctx, \"$val\");" : " tr(\"$val\");";
138 }
139 print "\n";
140 }
141 elsif($line =~ /<\/group>/)
142 {
143 $group = 0 if !($group =~ s/(.*\/).*?$//);
144 print "\n";
145 }
146 elsif($line =~ /<\/item>/)
147 {
148 $item = "";
149 print "\n";
150 }
151 elsif(!$line)
152 {
153 print "\n";
154 }
155 elsif($line =~ /^\s*$/
156 || $line =~ /<separator *\/>/
157 || $line =~ /<space *\/>/
158 || $line =~ /<\/?optional>/
159 || $line =~ /<key/
160 || $line =~ /annotations/
161 || $line =~ /roles/
162 || $line =~ /href=/
163 || $line =~ /<!--/
164 || $line =~ /-->/
165 || $comment)
166 {
167 print "// $line\n";
168 }
169 else
170 {
171 print "/* unparsed line $line */\n";
172# print STDERR "Unparsed line $line\n";
173 }
174
175 # note, these two must be in this order ore oneliners aren't handled
176 $comment = 1 if($line =~ /<!--/);
177 $comment = 0 if($line =~ /-->/);
178}
179
180print "}}\n";
Note: See TracBrowser for help on using the repository browser.