source: osm/applications/editors/josm/plugins/lang/convpreset.pl@ 9949

Last change on this file since 9949 was 9913, checked in by stoecker, 16 years ago

some cleanups

  • Property svn:executable set to *
File size: 2.1 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 $comment = 0;
10
11# This is a simple conversion and in no way a complete XML parser
12# but it works with a default Perl installation
13
14while(my $line = <>)
15{
16 chomp($line);
17 if($line =~ /<item\s+name="(.*?)\/ ".*<\/item>/)
18 {
19 print "tr(\"$1/ \") /* empty item \"$1\" */\n";
20 }
21 elsif($line =~ /<item\s+name=" ".*<\/item>/)
22 {
23 print "/* empty item */\n";
24 }
25 elsif($line =~ /<item\s+name=" ".*\/>/)
26 {
27 print "/* empty item */\n";
28 }
29 elsif($line =~ /<item\s+name=(".*?")/)
30 {
31 $item = $1;
32 print "tr($item) /* item $item */\n";
33 }
34 elsif($line =~ /<label\s+text=" "/)
35 {
36 print "/* item $item empty label */\n";
37 }
38 elsif($line =~ /<label\s+text=(".*?")/)
39 {
40 print "tr($1) /* item $item label $1 */\n";
41 }
42 elsif($line =~ /<text.*text=(".*?")/)
43 {
44 my $n = $1;
45 print "tr($n) /* item $item text $n */\n";
46 }
47 elsif($line =~ /<check.*text=(".*?")/)
48 {
49 my $n = $1;
50 print "tr($n) /* item $item check $n */\n";
51 }
52 # first handle display values
53 elsif($line =~ /<combo.*text=(".*?").*display_values="(.*?)"/)
54 {
55 my ($n,$vals) = ($1,$2);
56 print "tr($n) /* item $item combo $n */";
57 foreach my $val (split ",",$vals)
58 {
59 next if $val =~ /^[0-9-]+$/; # search for non-numbers
60 print " tr(\"$val\")";
61 }
62 print "\n";
63 }
64 elsif($line =~ /<combo.*text=(".*?").*values="(.*?)"/)
65 {
66 my ($n,$vals) = ($1,$2);
67 print "tr($n) /* item $item combo $n */";
68 foreach my $val (split ",",$vals)
69 {
70 next if $val =~ /^[0-9-]+$/; # search for non-numbers
71 print " tr(\"$val\")";
72 }
73 print "\n";
74 }
75 elsif($line =~ /^\s*$/
76 || $line =~ /<\/item>/
77 || $line =~ /<key/
78 || $line =~ /annotations/
79 || $line =~ /<!--/
80 || $line =~ /-->/
81 || $comment)
82 {
83 print "\n";
84 }
85 else
86 {
87 print "/* unparsed line $line */\n";
88 print STDERR "Unparsed line $line\n";
89 }
90
91 # note, these two must be in this order ore oneliners aren't handled
92 $comment = 1 if($line =~ /<!--/);
93 $comment = 0 if($line =~ /-->/);
94}
Note: See TracBrowser for help on using the repository browser.