Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Report / human.pm
index b40890a3f438b32200ea182170066471c8bac205..1726fa1781c98a68a8c48790da6be8a9bcc72121 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2010-2012 Zmanda, Inc.  All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 as published
@@ -21,6 +21,7 @@ package Amanda::Report::human;
 
 use strict;
 use warnings;
+use Carp;
 
 use POSIX;
 use Data::Dumper;
@@ -313,7 +314,7 @@ sub print_human_amreport
     my ( $self, $fh ) = @_;
 
     $fh ||= $self->{fh}
-      || die "error: no file handle given to print_human_amreport\n";
+      || confess "error: no file handle given to print_human_amreport\n";
 
     ## collect statistics
     $self->calculate_stats();
@@ -1510,9 +1511,9 @@ sub set_col_spec
     my $disp_unit = $self->{disp_unit};
 
     $self->{col_spec} = [
-        [ "HostName", 0, 12, 12, 0, "%-*.*s", "HOSTNAME" ],
-        [ "Disk",     1, 11, 11, 0, "%-*.*s", "DISK" ],
-        [ "Level",    1, 1,  1,  0, "%*.*d",  "L" ],
+        [ "HostName", 0, 12, 12, 1, "%-*.*s", "HOSTNAME" ],
+        [ "Disk",     1, 11, 11, 1, "%-*.*s", "DISK" ],
+        [ "Level",    1, 1,  1,  1, "%*.*d",  "L" ],
         [ "OrigKB",   1, 7,  0,  1, "%*.*f",  "ORIG-" . $disp_unit . "B" ],
         [ "OutKB",    1, 7,  0,  1, "%*.*f",  "OUT-" . $disp_unit . "B" ],
         [ "Compress", 1, 6,  1,  1, "%*.*f",  "COMP%" ],
@@ -1531,11 +1532,10 @@ sub apply_col_spec_override
     my ($self) = @_;
     my $col_spec = $self->{col_spec};
 
-    my %col_spec_override = read_col_spec_override();
+    my %col_spec_override = $self->read_col_spec_override();
 
     foreach my $col (@$col_spec) {
         if ( my $col_override = $col_spec_override{ $col->[COLSPEC_NAME] } ) {
-
             my $override_col_val_if_def = sub {
                 my ( $field, $or_num ) = @_;
                 if ( defined $col_override->[$or_num]
@@ -1554,22 +1554,36 @@ sub apply_col_spec_override
 
 sub read_col_spec_override
 {
-    ## takes no arguments
+    my ($self) = @_;
+
     my $col_spec_str = getconf($CNF_COLUMNSPEC) || return;
     my %col_spec_override = ();
+    my $col_spec = $self->{col_spec};
 
     foreach (split(",", $col_spec_str)) {
 
         $_ =~ m/^(\w+)           # field name
                 =([-:\d]+)       # field values
                 $/x
-          or die "error: malformed columnspec string:$col_spec_str";
+          or confess "error: malformed columnspec string:$col_spec_str";
 
         my $field = $1;
+       my $found = 0;
+
+       foreach my $col (@$col_spec) {
+           if (lc $field eq lc $col->[0]) {
+               $field = $col->[0];
+               $found = 1;
+           }
+       }
+       if ($found == 0) {
+           die("Invalid field name: $field");
+       }
+
         my @field_values = split ':', $2;
 
         # too many values
-        die "error: malformed columnspec string:$col_spec_str"
+        confess "error: malformed columnspec string:$col_spec_str"
           if (@field_values > 3);
 
         # all values *should* be in the right place.  If not enough