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