1 |
dpavlin |
1 |
#!/bin/perl |
2 |
|
|
#============================================================= -*-perl-*- |
3 |
|
|
# |
4 |
|
|
# BackupPC_zcat: uncompress files to stdout |
5 |
|
|
# |
6 |
|
|
# DESCRIPTION |
7 |
|
|
# |
8 |
|
|
# Usage: BackupPC_zcat [files...] |
9 |
|
|
# |
10 |
|
|
# BackupPC_zcat is a command-line utility for uncompressing BackupPC |
11 |
|
|
# compressed files. |
12 |
|
|
# |
13 |
|
|
# AUTHOR |
14 |
|
|
# Craig Barratt <cbarratt@users.sourceforge.net> |
15 |
|
|
# |
16 |
|
|
# COPYRIGHT |
17 |
|
|
# Copyright (C) 2001-2003 Craig Barratt |
18 |
|
|
# |
19 |
|
|
# This program is free software; you can redistribute it and/or modify |
20 |
|
|
# it under the terms of the GNU General Public License as published by |
21 |
|
|
# the Free Software Foundation; either version 2 of the License, or |
22 |
|
|
# (at your option) any later version. |
23 |
|
|
# |
24 |
|
|
# This program is distributed in the hope that it will be useful, |
25 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 |
|
|
# GNU General Public License for more details. |
28 |
|
|
# |
29 |
|
|
# You should have received a copy of the GNU General Public License |
30 |
|
|
# along with this program; if not, write to the Free Software |
31 |
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
32 |
|
|
# |
33 |
|
|
#======================================================================== |
34 |
|
|
# |
35 |
|
|
# Version 2.1.0, released 20 Jun 2004. |
36 |
|
|
# |
37 |
|
|
# See http://backuppc.sourceforge.net. |
38 |
|
|
# |
39 |
|
|
#======================================================================== |
40 |
|
|
|
41 |
|
|
use strict; |
42 |
|
|
no utf8; |
43 |
|
|
|
44 |
|
|
use lib "__INSTALLDIR__/lib"; |
45 |
|
|
use Compress::Zlib; |
46 |
|
|
use BackupPC::FileZIO; |
47 |
|
|
|
48 |
|
|
sub zcat |
49 |
|
|
{ |
50 |
|
|
my($fh, $fileName) = @_; |
51 |
|
|
my($data, $r, $ret); |
52 |
|
|
|
53 |
|
|
while ( ($r = $fh->read(\$data, 65536)) > 0 ) { |
54 |
|
|
print($data); |
55 |
|
|
} |
56 |
|
|
if ( $r < 0 ) { |
57 |
|
|
print(STDERR "$0: can't uncompress $fileName\n"); |
58 |
|
|
$ret = 1; |
59 |
|
|
} |
60 |
|
|
$fh->close(); |
61 |
|
|
return $ret; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
my $ret = 0; |
65 |
|
|
if ( @ARGV ) { |
66 |
|
|
while ( @ARGV ) { |
67 |
|
|
if ( defined(my $fh = BackupPC::FileZIO->open($ARGV[0], 0, 1)) ) { |
68 |
|
|
$ret ||= zcat($fh, $ARGV[0]); |
69 |
|
|
} else { |
70 |
|
|
print(STDERR "$0: can't open $ARGV[0]\n"); |
71 |
|
|
$ret = 1; |
72 |
|
|
last; |
73 |
|
|
} |
74 |
|
|
shift @ARGV; |
75 |
|
|
} |
76 |
|
|
} else { |
77 |
|
|
my $fh = BackupPC::FileZIO->open(*STDIN, 0, 1); |
78 |
|
|
$ret ||= zcat($fh, "stdin"); |
79 |
|
|
} |
80 |
|
|
exit($ret); |