autocorrect: non-breaking space before % in French fdo#41015
[LibreOffice.git] / oowintool
blobbc75736bef02a14ef9edba3331b5515e6005f362
1 #!/usr/bin/perl -w
3 use File::Copy;
5 my $output_format = 'u';
7 sub reg_get_value($)
9 # it is believed that the registry moves keys around
10 # depending on OS version, this will de-mangle that
11 my $key = shift;
12 my $fhandle;
13 my $value;
15 open ($fhandle, "/proc/registry/$key") || return;
16 # reg keys have 0x00 0x5c at the end
17 $value = (split /\0/, <$fhandle>)[0];
18 close ($fhandle);
20 if ( defined $value ) {
21 chomp ($value);
22 $value =~ s|\r\n||;
23 # print "Value '$value' at '$key'\n";
26 return $value;
29 sub reg_find_key($)
31 # it is believed that the registry moves keys around
32 # depending on OS version, this will de-mangle that
33 my $key = shift;
34 $key =~ s| |\\ |;
35 $key = `cd /proc/registry/ ; ls $key`;
37 return $key;
40 sub print_syntax()
42 print "oowintool [option] ...\n";
43 print " encoding options\n";
44 print " -w - windows form\n";
45 print " -u - unix form (default)\n";
46 print " commands:\n";
47 print " --msvc-ver - print version of MSVC eg. 6.0\n";
48 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
49 print " --msvc-productdir - print productdir\n";
50 print " --msvs-productdir - print productdir\n";
51 print " --dotnetsdk-dir - print .NET SDK path\n";
52 print " --csc-compilerdir - print .NET SDK compiler path\n";
53 print " --windows-sdk-home - print Windows SDK install dir\n";
54 print " --jdk-home - print the jdk install dir\n";
55 print " --nsis-dir - print NSIS path\n";
56 print " --help - print this message\n";
59 sub cygpath($$$)
61 my ($path, $input_format, $format) = @_;
63 return $path if ( ! defined $path );
64 # Strip trailing path separators
65 if ($input_format eq 'u') {
66 $path =~ s|/*\s*$||;
67 } else {
68 $path =~ s|\\*\s*$||;
71 # 'Unterminated quoted string errors' from 'ash' when
72 # forking cygpath so - reimplement cygpath in perl [ gack ]
73 if ($format eq 'u' && $input_format eq 'w') {
74 $path =~ s|\\|/|g;
75 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
77 elsif ($format eq 'w' && $input_format eq 'u') {
78 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
79 $path =~ s|/|\\|g;
82 return $path;
85 sub print_path($$)
87 my ($path, $unix) = @_;
89 $path = cygpath ($path, $unix, $output_format);
91 print $path;
94 sub print_windows_sdk_home()
96 my ($value, $key);
97 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.1/InstallationFolder');
98 if (!defined $value)
100 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
102 if (!defined $value)
104 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
106 if (!defined $value)
108 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
109 $value = reg_get_value ($key);
111 if (!defined $value)
113 my $dir = cygpath (find_msvc()->{'product_dir'}, 'w', $output_format);
114 $value = `/bin/find "$dir" -iname platformsdk | head -n 1`;
117 defined $value || die "Windows Sdk not found";
119 print cygpath ($value, 'w', $output_format);
122 my %msvs_2008 = (
123 'ver' => '9.0',
124 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
125 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
126 'dll_suffix' => '90'
128 my %msvc_2008 = (
129 'ver' => '9.0',
130 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
131 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
132 'dll_suffix' => '90'
134 my %msvs_express_2008 = (
135 'ver' => '9.0',
136 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
137 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
138 'dll_suffix' => '90'
140 my %msvc_express_2008 = (
141 'ver' => '9.0',
142 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
143 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
144 'dll_suffix' => '90'
146 my %msvs_2010 = (
147 'ver' => '10.0',
148 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
149 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
150 'dll_suffix' => '100'
152 my %msvc_2010 = (
153 'ver' => '10.0',
154 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
155 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
156 'dll_suffix' => '100'
159 sub find_msvs()
161 my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2010 );
163 for $ver (@ms_versions)
165 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
166 if (defined $install && $install ne '') {
167 $ver->{'product_dir'} = $install;
168 return $ver;
171 die "Can't find MS Visual Studio / VC++";
174 sub find_msvc()
176 my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2010 );
178 for $ver (@ms_versions)
180 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
181 if (defined $install && $install ne '') {
182 $ver->{'product_dir'} = $install;
183 return $ver;
186 die "Can't find MS Visual Studio / VC++";
189 sub print_msvc_ver()
191 my $ver = find_msvc();
192 print $ver->{'ver'};
195 sub print_msvc_product_dir()
197 my $ver = find_msvc();
198 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
201 sub print_msvs_productdir()
203 my $ver = find_msvs();
204 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
207 sub print_csc_compiler_dir()
209 my $dir = cygpath (reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
210 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
211 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
212 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
213 print `dirname $csc_exe`;
216 sub print_dotnetsdk_dir()
218 my $dir =
219 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
220 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
221 if ($dir) {
222 print cygpath ($dir, 'w', $output_format);
226 sub print_jdk_dir()
228 my $dir =
229 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
230 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
231 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
232 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
233 print cygpath($dir, 'w', $output_format);
236 sub print_nsis_dir()
238 my $dir = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/NSIS/@");
239 print cygpath ($dir, 'w', $output_format) if defined $dir;
242 sub copy_dll($$$)
244 my ($src, $fname, $dest) = @_;
246 -f "$src/$fname" || die "can't find $src";
247 -d $dest || die "no directory $dest";
249 print STDERR "Copying $src/$fname to $dest\n";
250 copy ("$src/$fname", $dest) || die "copy failed: $!";
251 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
254 sub msvc_find_version($)
256 my $checkpath = shift;
257 my $ver = find_msvc();
258 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
259 $ver->{$checkpath});
260 -d $srcdir && return $ver;
261 $ver = find_msvs();
262 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
263 $ver->{$checkpath});
264 -d $srcdir && return $ver;
265 return undef;
268 sub msvc_copy_dlls($)
270 my $dest = shift;
271 my $ver = msvc_find_version('dll_path');
272 defined $ver || return;
273 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
274 $ver->{'dll_path'});
276 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
277 $dest . $ver->{'dll_suffix'});
278 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
279 $dest . $ver->{'dll_suffix'});
280 if ($ver->{'dll_suffix'} == 90) {
281 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
282 $dest . $ver->{'dll_suffix'});
283 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
287 if (!@ARGV) {
288 print_syntax();
289 exit 1;
292 my @commands = ();
293 my $opt;
294 while (@ARGV) {
295 $opt = shift @ARGV;
297 if ($opt eq '-w' || $opt eq '-u') {
298 $output_format = substr($opt, 1, 1);
299 } else {
300 push @commands, $opt;
304 while (@commands) {
305 $opt = shift @commands;
307 if (0) {
308 } elsif ($opt eq '--msvc-ver') {
309 print_msvc_ver();
310 } elsif ($opt eq '--msvc-copy-dlls') {
311 my $dest = shift @commands;
312 defined $dest || die "copy-dlls requires a destination directory";
313 msvc_copy_dlls( $dest );
314 } elsif ($opt eq '--msvs-productdir') {
315 print_msvs_productdir();
316 } elsif ($opt eq '--msvc-productdir') {
317 print_msvc_product_dir();
318 } elsif ($opt eq '--dotnetsdk-dir') {
319 print_dotnetsdk_dir();
320 } elsif ($opt eq '--csc-compilerdir') {
321 print_csc_compiler_dir();
322 } elsif ($opt eq '--windows-sdk-home') {
323 print_windows_sdk_home();
324 } elsif ($opt eq '--jdk-home') {
325 print_jdk_dir();
326 } elsif ($opt eq '--nsis-dir') {
327 print_nsis_dir();
328 } elsif ($opt eq '--help' || $opt eq '/?') {
329 print_syntax();
330 } else {
331 print "Unknown option '$opt'\n";
332 print_syntax();
333 exit 1;