2004-01-29 04:47:42 -06:00
|
|
|
#*************************************************************************
|
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# Copyright 2008 by Sun Microsystems, Inc.
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# OpenOffice.org - a multi-platform office productivity suite
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# $RCSfile: files.pm,v $
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# $Revision: 1.6 $
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# This file is part of OpenOffice.org.
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# only, as published by the Free Software Foundation.
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License version 3 for more details
|
|
|
|
# (a copy is included in the LICENSE file that accompanied this code).
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
2008-04-10 11:30:51 -05:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# version 3 along with OpenOffice.org. If not, see
|
|
|
|
# <http://www.openoffice.org/license.html>
|
|
|
|
# for a copy of the LGPLv3 License.
|
2004-01-29 04:47:42 -06:00
|
|
|
#
|
|
|
|
#*************************************************************************
|
|
|
|
|
|
|
|
package pre2par::files;
|
|
|
|
|
|
|
|
use pre2par::exiter;
|
|
|
|
|
|
|
|
############################################
|
|
|
|
# File Operations
|
|
|
|
############################################
|
|
|
|
|
|
|
|
sub check_file
|
|
|
|
{
|
|
|
|
my ($arg) = @_;
|
|
|
|
|
|
|
|
if(!( -f $arg ))
|
|
|
|
{
|
|
|
|
pre2par::exiter::exit_program("ERROR: Cannot find file $arg", "check_file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_file
|
|
|
|
{
|
|
|
|
my ($localfile) = @_;
|
|
|
|
|
2009-03-25 03:57:52 -05:00
|
|
|
my @localfile = ();
|
|
|
|
|
2005-01-31 03:50:59 -06:00
|
|
|
open( IN, "<$localfile" ) || pre2par::exiter::exit_program("ERROR: Cannot open file: $localfile", "read_file");
|
2009-03-25 03:57:52 -05:00
|
|
|
while ( <IN> ) { push(@localfile, $_); }
|
2004-01-29 04:47:42 -06:00
|
|
|
close( IN );
|
|
|
|
|
|
|
|
return \@localfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Saving files, arrays and hashes
|
|
|
|
###########################################
|
|
|
|
|
|
|
|
sub save_file
|
|
|
|
{
|
|
|
|
my ($savefile, $savecontent) = @_;
|
2005-02-21 05:12:49 -06:00
|
|
|
if (-f $savefile) { unlink $savefile };
|
|
|
|
if (-f $savefile) { pre2par::exiter::exit_program("ERROR: Cannot delete existing file: $savefile", "save_file"); };
|
2004-01-29 04:47:42 -06:00
|
|
|
open( OUT, ">$savefile" );
|
|
|
|
print OUT @{$savecontent};
|
|
|
|
close( OUT);
|
|
|
|
if (! -f $savefile) { pre2par::exiter::exit_program("ERROR: Cannot write file: $savefile", "save_file"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
sub save_hash
|
|
|
|
{
|
|
|
|
my ($savefile, $hashref) = @_;
|
|
|
|
|
|
|
|
my @printcontent = ();
|
|
|
|
|
|
|
|
my ($itemkey, $itemvalue, $line);
|
|
|
|
|
|
|
|
foreach $itemkey ( keys %{$hashref} )
|
|
|
|
{
|
|
|
|
$line = "";
|
|
|
|
$itemvalue = $hashref->{$itemkey};
|
|
|
|
$line = $itemkey . "=" . $itemvalue . "\n";
|
|
|
|
push(@printcontent, $line);
|
|
|
|
}
|
|
|
|
|
|
|
|
open( OUT, ">$savefile" );
|
|
|
|
print OUT @printcontent;
|
|
|
|
close( OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub save_array_of_hashes
|
|
|
|
{
|
|
|
|
my ($savefile, $arrayref) = @_;
|
|
|
|
|
|
|
|
my @printcontent = ();
|
|
|
|
|
|
|
|
my ($itemkey, $itemvalue, $line, $hashref);
|
|
|
|
|
|
|
|
for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
|
|
|
|
{
|
|
|
|
$line = "";
|
|
|
|
$hashref = ${$arrayref}[$i];
|
|
|
|
|
|
|
|
foreach $itemkey ( keys %{$hashref} )
|
|
|
|
{
|
|
|
|
$itemvalue = $hashref->{$itemkey};
|
|
|
|
|
|
|
|
$line = $line . $itemkey . "=" . $itemvalue . "\t";
|
|
|
|
}
|
|
|
|
|
|
|
|
$line = $line . "\n";
|
|
|
|
|
|
|
|
push(@printcontent, $line);
|
|
|
|
}
|
|
|
|
|
|
|
|
open( OUT, ">$savefile" );
|
|
|
|
print OUT @printcontent;
|
|
|
|
close( OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|