1:
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4#**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26#### script id #####
27
28( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
29
30$id_str = ' $Revision: 1.4.108.1 $ ';
31$id_str =~ /Revision:\s+(\S+)\s+\$/
32  ? ($script_rev = $1) : ($script_rev = "-");
33
34#########################
35#                       #
36#   Globale Variablen   #
37#                       #
38#########################
39
40use Encode;
41use Encode::Alias;
42
43
44my ($in_name, $ID, $new_ID);
45my ($help);
46
47print STDERR "$script_name -- Version: $script_rev\n" ;
48
49&get_options;
50
51if ( $help ) {
52    &usage();
53    exit 0;
54};
55
56
57open IN, "<$in_name" or die "Could not open $in_name for reading $! $^E";
58
59foreach $lang ( keys %files )
60{
61    open "F_$lang",">$files{$lang}" or die "Could not open $files{$lang} for writing $! $^E";
62    binmode "F_$lang";
63    $files{$lang} = "F_$lang";
64}
65
66%transunit = ();
67
68while ( <IN> )
69{
70    chomp;
71    $line = $_;
72    $line =~ s/\r$//;
73    # [RID_RESXLS_COST_Print_Area]
74    if ( $line =~ /^\[(.*)\]$/ )
75    {
76        $new_ID = $1;
77
78        write_transunit();
79        $ID = $new_ID;
80        %transunit = ();
81    }
82    # de = "Druckbereich"
83    elsif ( $line =~ /^(\S*)\s*=\s*\"(.*)\"$/ )
84    {
85        $lang = $1;
86        $string = $2;
87        $transunit{ $lang } = $string;
88    }
89    elsif ( $line !~ /^\s*$/ )
90    {
91        die "unknown lineformat in $in_name: $line\n";
92    }
93}
94write_transunit();
95
96
97sub write_transunit
98{
99    if ( ! $ID )
100    {
101        return;
102    }
103	foreach $lang ( keys %files )
104	{
105	    my $string;
106	    if ( defined $transunit{ $lang } )
107	    {
108	        $string = $transunit{ $lang };
109	    }
110	    else
111	    {
112	        $string = $transunit{ "en-US" };
113	    }
114
115        my $dat_line = "$ID=$string";
116        Encode::from_to( $dat_line, "utf8", "UTF-16LE");
117		print { $files{$lang} } "$dat_line\015\000\012\000";
118	}
119}
120
121
122sub get_options {
123	my ($arg,$lang);
124
125	while ($arg = shift @ARGV) {
126		$arg =~ /^-i$/  and $in_name = shift @ARGV and next;
127		$arg =~ /^-help$/  and $help = 1 and next; #show help
128
129		$arg =~ /.*[\/\\]([^\/\\]*)\.dat$/;
130#		$arg =~ /.*[/\]([^/\]*)\.dat$/;
131		$lang = $1;
132		print "got $lang = $arg\n";
133		$files{ $lang } = $arg;
134	}
135}
136
137
138
139sub usage {
140	print STDERR "\n\n";
141    print STDERR "Syntax:   $script_name [-help|-i <ulf-filename>] <dat-filename> ... \n";
142    print STDERR "Example:  $script_name -i strings.ulf en-US.dat de.dat\n";
143    print STDERR "Options:\n\n";
144    print STDERR "    -i      input ulf file\n";
145    print STDERR "    -help   print this help info\n\n";
146};
147
148