* Fixed stupid last-minute change in octal size conversion in
[BackupPC.git] / bin / BackupPC_zcat
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  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.0.2, released 6 Oct 2003.
36 #
37 # See http://backuppc.sourceforge.net.
38 #
39 #========================================================================
40
41 use strict;
42 no  utf8;
43
44 use lib "/usr/local/BackupPC2.0.2/lib";
45 use Compress::Zlib;
46 use BackupPC::FileZIO;
47
48 sub zcat
49 {
50     my($fh, $fileName) = @_;
51     my($data, $r);
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     }
59     $fh->close();
60 }
61
62 if ( @ARGV ) {
63     while ( @ARGV ) {
64         if ( defined(my $fh = BackupPC::FileZIO->open($ARGV[0], 0, 1)) ) {
65             zcat($fh, $ARGV[0]);
66         } else {
67             print(STDERR "$0: can't open $ARGV[0]\n");
68             exit(1);
69         }
70         shift @ARGV;
71     }
72 } else {
73     my $fh = BackupPC::FileZIO->open(*STDIN, 0, 1);
74     zcat($fh, "stdin");
75 }