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

Last change on this file since 17708 was 13469, checked in by stoecker, 16 years ago

added relations stuff

File size: 2.6 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 print "tr($1); /* item $item */\n";
25 $item = $group ? "$group$1" : $1;
26 $item =~ s/""/\//;
27 }
28 elsif($line =~ /<group\s+name=(".*?")/)
29 {
30 $group = $1;
31 print "tr($1); /* group $group */\n";
32 }
33 elsif($line =~ /<label\s+text=" "/)
34 {
35 print "/* item $item empty label */\n";
36 }
37 elsif($line =~ /<label\s+text=(".*?")/)
38 {
39 print "tr($1); /* item $item label $1 */\n";
40 }
41 elsif($line =~ /<text.*text=(".*?")/)
42 {
43 my $n = $1;
44 print "tr($n); /* item $item text $n */\n";
45 }
46 elsif($line =~ /<check.*text=(".*?")/)
47 {
48 my $n = $1;
49 print "tr($n); /* item $item check $n */\n";
50 }
51 elsif($line =~ /<role.*text=(".*?")/)
52 {
53 my $n = $1;
54 print "tr($n); /* item $item role $n */\n";
55 }
56 # first handle display values
57 elsif($line =~ /<combo.*text=(".*?").*display_values="(.*?)"/)
58 {
59 my ($n,$vals) = ($1,$2);
60 print "tr($n); /* item $item combo $n */";
61 foreach my $val (split ",",$vals)
62 {
63 next if $val =~ /^[0-9-]+$/; # search for non-numbers
64 print " tr(\"$val\");";
65 }
66 print "\n";
67 }
68 elsif($line =~ /<combo.*text=(".*?").*values="(.*?)"/)
69 {
70 my ($n,$vals) = ($1,$2);
71 print "tr($n); /* item $item combo $n */";
72 foreach my $val (split ",",$vals)
73 {
74 next if $val =~ /^[0-9-]+$/; # search for non-numbers
75 print " tr(\"$val\");";
76 }
77 print "\n";
78 }
79 elsif($line =~ /<\/group>/)
80 {
81 $group = 0;
82 print "\n";
83 }
84 elsif($line =~ /<\/item>/)
85 {
86 $item = "";
87 print "\n";
88 }
89 elsif(!$line)
90 {
91 print "\n";
92 }
93 elsif($line =~ /^\s*$/
94 || $line =~ /<separator *\/>/
95 || $line =~ /<space *\/>/
96 || $line =~ /<\/?optional>/
97 || $line =~ /<key/
98 || $line =~ /annotations/
99 || $line =~ /roles/
100 || $line =~ /href=/
101 || $line =~ /<!--/
102 || $line =~ /-->/
103 || $comment)
104 {
105 print "// $line\n";
106 }
107 else
108 {
109 print "/* unparsed line $line */\n";
110# print STDERR "Unparsed line $line\n";
111 }
112
113 # note, these two must be in this order ore oneliners aren't handled
114 $comment = 1 if($line =~ /<!--/);
115 $comment = 0 if($line =~ /-->/);
116}
117
118print "}}\n";
Note: See TracBrowser for help on using the repository browser.