3 #*************************************************************************
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 # Copyright 2000, 2010 Oracle and/or its affiliates.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # This file is part of OpenOffice.org.
13 # OpenOffice.org is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License version 3
15 # only, as published by the Free Software Foundation.
17 # OpenOffice.org is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Lesser General Public License version 3 for more details
21 # (a copy is included in the LICENSE file that accompanied this code).
23 # You should have received a copy of the GNU Lesser General Public License
24 # version 3 along with OpenOffice.org. If not, see
25 # <http://www.openoffice.org/license.html>
26 # for a copy of the LGPLv3 License.
28 #*************************************************************************
37 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
40 # if using RCS/CVS, this may be preferred
41 $VERSION = do { my @r = (q
$Revision: 1.29 $ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r }; # must be all one line, for MakeMaker
43 @EXPORT = qw(&callphp &getPHPExecutable &ExecSQL &callperl &getPerlExecutable &calljava &setJavaExecutable &getJavaExecutable &setToolsPath "e "eIfNeed &set_logfile &close_logfile );
44 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
45 # your exported package globals go here,
46 # as well as any optionally exported functions
47 @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3);
50 # ------------------------------------------------------------------------------
51 # small helper, which replaces the return code
57 $error = $error / 256;
61 $error = $error - 256;
65 # ------------------------------------------------------------------------------
66 # helper to call external php with popen
71 my $phpprogram = shift;
77 # print "Will send: $phpexe $sParams\n";
78 # log_print("CALLPHP: $phpexe $phpprogram $sParams\n");
79 # if (open(IN_FILE, "$phpexe $sParams 2>&1 |"))
80 if (open(IN_FILE
, "$phpexe $phpprogram $sParams |"))
82 while ($line = <IN_FILE
>)
87 # print "callphp output: $line\n";
90 $error = errorAdaption
($?
);
94 print "callphp(): Can't popen '$phpexe' with parameter: '$sParams'\n";
97 return $error, @result;
100 # ------------------------------------------------------------------------------
101 sub getPHPExecutable
()
104 if ($OSNAME eq "solaris")
108 elsif ($OSNAME eq "linux")
110 if ( -e
"/usr/bin/php5") # Suse :-(
114 elsif ( -e
"/usr/bin/php") # Gentoo
120 print "getPHPExecutable(): no php exec found.\n";
123 elsif ( $OSNAME eq "MSWin32" )
125 $phpexe = "C:/programme/php/php.exe";
126 # add second try (xampp)
129 $phpexe = "C:/xampp/php/php.exe";
132 elsif ( $OSNAME eq "cygwin" )
134 $phpexe = "/cygdrive/c/programme/php/php";
138 print "getPHPExecutable(): unknown environment. ($OSNAME)\n";
142 print "getPHPExecutable(): ERROR: php executable not found.\n";
147 # ------------------------------------------------------------------------------
148 # helper to call external java with popen
160 log_print
("ERROR: javaexe not set.\n");
167 $javaexe = quoteIfNeed
($javaexe);
168 log_print
("CALLJAVA: $javaexe $sDebug $sParams\n");
169 if (open(IN_FILE
, "$javaexe $sDebug $sParams 2>&1 |"))
171 while ($line = <IN_FILE
>)
174 log_print
("- $line\n");
177 $error = errorAdaption
($?
);
181 log_print
("calljava(): Can't popen '$javaexe' with parameter '$sParams'\n");
187 # ------------------------------------------------------------------------------
188 sub getPerlExecutable
()
193 $perlexe = $ENV{PERL
};
195 elsif ( $ENV{PERLEXE
} )
197 $perlexe = $ENV{PERLEXE
};
201 if ($OSNAME eq "MSWin32")
203 $perlexe="C:/xampp/perl/bin/perl.exe";
206 $perlexe="r:/btw/perl/bin/perl";
210 $perlexe="C:/Programme/Perl/bin/perl.exe";
213 elsif ($OSNAME eq "cygwin")
217 elsif ($OSNAME eq "solaris")
219 $perlexe="/so/env/bt_solaris_intel/bin/perl";
221 elsif ($OSNAME eq "linux")
223 $perlexe="/so/env/bt_linux_libc2.32/DEV300/bin/perl";
227 log_print
"WARNING: Use only the fallback of perl executable.\n";
228 $perlexe = "perl"; # FALLBACK
233 log_print
"getPerlExecutable(): There exist no perl executable.\n";
238 # ------------------------------------------------------------------------------
239 # helper to call external perl with popen
244 my $perlprogram = shift;
249 log_print
("CALLPERL: $perlexe $perlprogram $sParams\n");
250 # if (open(IN_FILE, "$perlexe $sParams 2>&1 |"))
251 if (open(IN_FILE
, "$perlexe $perlprogram $sParams |"))
253 while ($line = <IN_FILE
>)
256 log_print
("- $line\n");
259 $error = errorAdaption
($?
);
263 log_print
("Can't popen '$perlexe' with parameter: '$sParams'\n");
268 # ------------------------------------------------------------------------------
269 our $sJavaExecutable;
270 sub setJavaExecutable
($)
272 $sJavaExecutable = shift;
278 # if ($OSNAME eq "MSWin32")
280 # if ($sJavaExecutable)
282 # $sJava14 = $sJavaExecutable;
287 # $sJava14 = "C:\\Programme\\Java\\j2re1.4.2_10\\bin\\java.exe";
292 # if ($sJavaExecutable)
294 # $sJava14 = $sJavaExecutable;
299 # $sJava14 = "/opt/java14/bin/java";
302 # if ( ! -e $sJava14 )
304 # log_print ("Java14 not found. Is searched in '$sJava14'\n");
310 # ------------------------------------------------------------------------------
314 if ($sJavaExecutable)
316 $sJava15 = $sJavaExecutable;
320 if ($OSNAME eq "MSWin32")
323 $sJava15 = "C:\\Programme\\Java\\jre1.5.0_22\\bin\\java.exe";
326 $sJava15 = "C:\\Program Files\\Java\\jre6\\bin\\java.exe";
330 $sJava15 = "C:\\Java\\jdk1.6\\bin\\java.exe";
333 elsif ($OSNAME eq "cygwin")
340 if ($OSNAME eq "solaris")
342 $sJava15 = "/usr/bin/java";
346 $sJava15 = "/usr/bin/java";
349 $sJava15 = "/opt/java15/bin/java";
355 log_print
("Java15 not found. Is searched in '$sJava15'\n");
362 # ------------------------------------------------------------------------------
366 if ($sJavaExecutable)
368 $sJava16 = $sJavaExecutable;
372 if ($OSNAME eq "MSWin32")
375 $sJava16 = "C:\\Programme\\Java\\jre1.6.0_16\\bin\\java.exe";
378 $sJava16 = "C:\\Program Files\\Java\\jre6\\bin\\java.exe";
382 $sJava16 = "C:\\Java\\jdk1.6\\bin\\java.exe";
386 elsif ($OSNAME eq "cygwin")
389 $sJava16 = "C:/Program Files/Java/jdk1.6.0_16/bin/java.exe";
394 if ($OSNAME eq "solaris")
396 $sJava16 = "/usr/bin/java";
400 $sJava16 = "/usr/bin/java";
403 $sJava16 = "/opt/java16/bin/java";
409 log_print
("Java16 not found. Is searched in '$sJava16'\n");
417 # ------------------------------------------------------------------------------
418 sub getJavaExecutable
()
423 # ------------------------------------------------------------------------------
424 # this function is a helper for parameters
425 # if quotes the whole string with 'STR' or "STR" and replace quotes in it's content for the right.
429 if ( $OSNAME eq "MSWin32")
431 # we are MSWin32 (quote \" stronger)
432 # $sStr =~ s/\'/\"/g;
433 $sStr =~ s/\'/\\\"/g;
434 return "\"" . $sStr . "\"";
438 if (index($sStr, "'") >= 0)
440 # replace all single quotes ("'") by "\""
444 return "'" . $sStr . "'";
450 return "\"" . $sName . "\"";
456 if (-1 != index($sName, " "))
458 return quote
($sName);
464 # ------------------------------------------------------------------------------
468 my $sNewPath = shift;
469 $sToolsPath = $sNewPath;
481 $sSQLDirect = $sToolsPath;
484 $sSQLDirect .= "sql_direct.php";
486 # select(undef, undef, undef, 0.060);
487 # log_print("ExecSQL: $sSQL\n");
489 ($error, @aResult) = callphp
(getPHPExecutable
(), $sSQLDirect, singleQuote
($sSQL));
492 log_print
("ExecSQL: An Error occured.\n");
493 log_print
("PHP: " . getPHPExecutable
() . "\n");
494 log_print
("SQL Statement: " . singleQuote
($sSQL) . "\n");
497 # select(undef, undef, undef, 0.125);
502 # ------------------------------------------------------------------------------
503 # helper to call external php with popen
508 # my $program = shift;
509 # my $sParams = shift;
514 # $exe = quoteIfNeed($exe);
515 # $program = quoteIfNeed($program);
517 # # print "Will send: $exe $sParams\n";
518 # # log_print("CALLEXE: $exe $program $sParams\n");
519 # if (open(IN_FILE, "$exe $program $sParams |"))
521 # while ($line = <IN_FILE>)
525 # push(@result, $line);
526 # # print "callphp output: $line\n";
529 # $error = errorAdaption($?);
533 # print "Can't popen '$exe' with parameter: '$sParams'\n";
536 # return $error, @result;