parse sections and create dump files with DEBUG=1
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 10 May 2011 20:08:49 +0000 (22:08 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 10 May 2011 20:08:49 +0000 (22:08 +0200)
lib/H1/ZTEMSAN.pm

index 316acad..0a45155 100755 (executable)
@@ -44,24 +44,39 @@ sub command {
                my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/');
                $out .= $prematch;
                last if $match eq '#';
-               $t->put(" ");
+#              $t->put(" ");
+               $t->print('');
        }
 
        warn "## out = [$out]";
 
        my $hash;
+       my $section = '';
+       my $last_line;
        foreach my $line ( split(/[\n\r]+/, $out) ) {
                warn "# $line\n";
                if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) {
                        my ($n,$v) = ($1,$2);
                        $n =~ s/\(.+\)//;
-                       $hash->{$n} = $v;
+                       $hash->{ $section . $n } = $v;
                        warn "## $n = $v\n";
+               } elsif ( $line =~ m/^-+$/ ) {
+                       $section = $last_line . '.'
                }
-
+               $last_line = $line;
        }
 
-       warn dump $hash;
+       warn "## hash = ",dump $hash;
+
+       if ( $ENV{DEBUG} ) {
+               my $path = $command;
+               $path =~ s{\W+}{_}g;
+               $path = "/tmp/dump.$path";
+               open( my $fh, '>', $path ) || die "$path: $!";
+               print $fh $out;
+               close $fh;
+               warn "DEBUG ",$path, " ", -s $path, " bytes\n";
+       }
 
        return $hash;
 }