added humanly readable unit (b k M G)
[BackupPC.git] / bin / BackupPC_zcat
index 1c7ba02..72ccecb 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/perl -T
+#!/usr/bin/perl
 #============================================================= -*-perl-*-
 #
 # BackupPC_zcat: uncompress files to stdout
 #============================================================= -*-perl-*-
 #
 # BackupPC_zcat: uncompress files to stdout
@@ -14,7 +14,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2001  Craig Barratt
+#   Copyright (C) 2001-2009  Craig Barratt
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
 #
 #========================================================================
 #
 #
 #========================================================================
 #
-# Version 2.0.0beta1, released 30 Mar 2003.
+# Version 3.2.0, released 31 Jul 2010.
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
+no  utf8;
 
 use lib "/usr/local/BackupPC/lib";
 use Compress::Zlib;
 
 use lib "/usr/local/BackupPC/lib";
 use Compress::Zlib;
@@ -47,28 +48,33 @@ use BackupPC::FileZIO;
 sub zcat
 {
     my($fh, $fileName) = @_;
 sub zcat
 {
     my($fh, $fileName) = @_;
-    my($data, $r);
+    my($data, $r, $ret);
 
     while ( ($r = $fh->read(\$data, 65536)) > 0 ) { 
         print($data);
     }
     if ( $r < 0 ) {
         print(STDERR "$0: can't uncompress $fileName\n");
 
     while ( ($r = $fh->read(\$data, 65536)) > 0 ) { 
         print($data);
     }
     if ( $r < 0 ) {
         print(STDERR "$0: can't uncompress $fileName\n");
+       $ret = 1;
     }
     $fh->close();
     }
     $fh->close();
+    return $ret;
 }
 
 }
 
+my $ret = 0;
 if ( @ARGV ) {
     while ( @ARGV ) {
         if ( defined(my $fh = BackupPC::FileZIO->open($ARGV[0], 0, 1)) ) {
 if ( @ARGV ) {
     while ( @ARGV ) {
         if ( defined(my $fh = BackupPC::FileZIO->open($ARGV[0], 0, 1)) ) {
-            zcat($fh, $ARGV[0]);
+            $ret ||= zcat($fh, $ARGV[0]);
         } else {
             print(STDERR "$0: can't open $ARGV[0]\n");
         } else {
             print(STDERR "$0: can't open $ARGV[0]\n");
-            exit(1);
+            $ret = 1;
+           last;
         }
         shift @ARGV;
     }
 } else {
     my $fh = BackupPC::FileZIO->open(*STDIN, 0, 1);
         }
         shift @ARGV;
     }
 } else {
     my $fh = BackupPC::FileZIO->open(*STDIN, 0, 1);
-    zcat($fh, "stdin");
+    $ret ||= zcat($fh, "stdin");
 }
 }
+exit($ret);