update dev300-m58
[ooovba.git] / migrationanalysis / src / driver_docs / ulf2dat.pl
blob4468350307039c575b98035dcf6626a2c3ff4062
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: ulf2dat.pl,v $
13 # $Revision: 1.4.108.1 $
15 # This file is part of OpenOffice.org.
17 # OpenOffice.org is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU Lesser General Public License version 3
19 # only, as published by the Free Software Foundation.
21 # OpenOffice.org is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU Lesser General Public License version 3 for more details
25 # (a copy is included in the LICENSE file that accompanied this code).
27 # You should have received a copy of the GNU Lesser General Public License
28 # version 3 along with OpenOffice.org. If not, see
29 # <http://www.openoffice.org/license.html>
30 # for a copy of the LGPLv3 License.
32 #***********************************************************************/
35 #### script id #####
37 ( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
39 $id_str = ' $Revision: 1.4.108.1 $ ';
40 $id_str =~ /Revision:\s+(\S+)\s+\$/
41 ? ($script_rev = $1) : ($script_rev = "-");
43 #########################
44 # #
45 # Globale Variablen #
46 # #
47 #########################
49 use Encode;
50 use Encode::Alias;
53 my ($in_name, $ID, $new_ID);
54 my ($help);
56 print STDERR "$script_name -- Version: $script_rev\n" ;
58 &get_options;
60 if ( $help ) {
61 &usage();
62 exit 0;
66 open IN, "<$in_name" or die "Could not open $in_name for reading $! $^E";
68 foreach $lang ( keys %files )
70 open "F_$lang",">$files{$lang}" or die "Could not open $files{$lang} for writing $! $^E";
71 binmode "F_$lang";
72 $files{$lang} = "F_$lang";
75 %transunit = ();
77 while ( <IN> )
79 chomp;
80 $line = $_;
81 $line =~ s/\r$//;
82 # [RID_RESXLS_COST_Print_Area]
83 if ( $line =~ /^\[(.*)\]$/ )
85 $new_ID = $1;
87 write_transunit();
88 $ID = $new_ID;
89 %transunit = ();
91 # de = "Druckbereich"
92 elsif ( $line =~ /^(\S*)\s*=\s*\"(.*)\"$/ )
94 $lang = $1;
95 $string = $2;
96 $transunit{ $lang } = $string;
98 elsif ( $line !~ /^\s*$/ )
100 die "unknown lineformat in $in_name: $line\n";
103 write_transunit();
106 sub write_transunit
108 if ( ! $ID )
110 return;
112 foreach $lang ( keys %files )
114 my $string;
115 if ( defined $transunit{ $lang } )
117 $string = $transunit{ $lang };
119 else
121 $string = $transunit{ "en-US" };
124 my $dat_line = "$ID=$string";
125 Encode::from_to( $dat_line, "utf8", "UTF-16LE");
126 print { $files{$lang} } "$dat_line\015\000\012\000";
131 sub get_options {
132 my ($arg,$lang);
134 while ($arg = shift @ARGV) {
135 $arg =~ /^-i$/ and $in_name = shift @ARGV and next;
136 $arg =~ /^-help$/ and $help = 1 and next; #show help
138 $arg =~ /.*[\/\\]([^\/\\]*)\.dat$/;
139 # $arg =~ /.*[/\]([^/\]*)\.dat$/;
140 $lang = $1;
141 print "got $lang = $arg\n";
142 $files{ $lang } = $arg;
148 sub usage {
149 print STDERR "\n\n";
150 print STDERR "Syntax: $script_name [-help|-i <ulf-filename>] <dat-filename> ... \n";
151 print STDERR "Example: $script_name -i strings.ulf en-US.dat de.dat\n";
152 print STDERR "Options:\n\n";
153 print STDERR " -i input ulf file\n";
154 print STDERR " -help print this help info\n\n";