1
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21
@EXPORT = ('say', 'sayFile', 'tmpdir', 'safe_exit',
22
'osWindows', 'osLinux', 'osSolaris', 'osMac',
23
'isoTimestamp', 'isoUTCTimestamp', 'rqg_debug', 'unix2winPath');
36
foreach my $tmp ($ENV{TMP}, $ENV{TEMP}, $ENV{TMPDIR}, '/tmp', '/var/tmp', cwd()."/tmp" ) {
46
if (defined $tmpdir) {
51
$tmpdir = $tmpdir.'\\';
53
$tmpdir = $tmpdir.'/';
57
croak("Unable to locate suitable temporary directory.") if not defined $tmpdir;
66
my $obj = bless ([], $class);
68
my $max_arg = (scalar(@_) / 2) - 1;
70
foreach my $i (0..$max_arg) {
71
if (exists $args->{$_[$i * 2]}) {
72
if (defined $obj->[$args->{$_[$i * 2]}]) {
73
carp("Argument '$_[$i * 2]' passed twice to ".$class.'->new()');
75
$obj->[$args->{$_[$i * 2]}] = $_[$i * 2 + 1];
78
carp("Unkown argument '$_[$i * 2]' to ".$class.'->new()');
88
if ($text =~ m{[\r\n]}sio) {
89
foreach my $line (split (m{[\r\n]}, $text)) {
90
print "# ".isoTimestamp()." $line\n";
93
print "# ".isoTimestamp()." $text\n";
100
say("--------- Contents of $file -------------");
106
say("----------------------------------");
114
my $exit_status = shift;
115
POSIX::_exit($exit_status);
120
($^O eq 'MSWin32') ||
130
if ($^O eq 'linux') {
138
if ($^O eq 'solaris') {
146
if ($^O eq 'darwin') {
154
my $datetime = shift;
156
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = defined $datetime ? localtime($datetime) : localtime();
157
return sprintf("%04d-%02d-%02dT%02d:%02d:%02d", $year+1900, $mon+1 ,$mday ,$hour, $min, $sec);
161
sub isoUTCTimestamp {
162
my $datetime = shift;
164
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = defined $datetime ? gmtime($datetime) : gmtime();
165
return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year+1900, $mon+1 ,$mday ,$hour, $min, $sec);
170
# Converts the given file path from unix style to windows native style
171
# by replacing all forward slashes to backslashes.
174
$path =~ s/\//\\/g; # replace "/" with "\"
179
if ($ENV{RQG_DEBUG}) {