Changeset 5701

Show
Ignore:
Timestamp:
03/20/09 15:30:28 (4 years ago)
Author:
khali
Message:

New side-by-side output format. Especially nice for the HTML format
but (mostly) works also with text format. Might need to be made a
little more flexible to accomodate with different memory modules.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • i2c-tools/trunk/eeprom/decode-dimms

    r5700 r5701  
    4141use POSIX qw(ceil); 
    4242use Fcntl qw(:DEFAULT :seek); 
    43 use vars qw($opt_html $opt_bodyonly $opt_igncheck $use_sysfs $use_hexdump 
     43use vars qw($opt_html $opt_bodyonly $opt_side_by_side $opt_igncheck 
     44            $use_sysfs $use_hexdump 
    4445            @vendors %decode_callback $revision @dimm $current %hexdump_cache); 
    4546 
     
    359360} 
    360361 
    361 sub real_printl($$) # print a line w/ label and value 
     362sub real_printl($$) # print a line w/ label and values 
     363{ 
     364        my ($label, @values) = @_; 
     365        local $_; 
     366 
     367        if ($opt_html) { 
     368                $label = html_encode($label); 
     369                @values = map { html_encode($_) } @values; 
     370                print "<tr><td valign=top>$label</td>"; 
     371                print "<td>$_</td>" foreach @values; 
     372                print "</tr>\n"; 
     373        } else { 
     374                my $format = "%-47s".(" %-19s" x (scalar @values - 1))." %s\n"; 
     375                my $maxl = 0; # Keep track of the max number of lines 
     376 
     377                # It's a bit tricky because each value may span over more than 
     378                # one line. We can easily extract the values per column, but 
     379                # we need them per line at printing time. So we have to 
     380                # prepare a 2D array with all the individual string fragments. 
     381                my ($col, @lines); 
     382                for ($col = 0; $col < @values; $col++) { 
     383                        my @cells = split /\n/, $values[$col]; 
     384                        $maxl = @cells if @cells > $maxl; 
     385                        for (my $l = 0; $l < @cells; $l++) { 
     386                                $lines[$l]->[$col] = $cells[$l]; 
     387                        } 
     388                } 
     389 
     390                # Also make sure there are no holes in the array 
     391                for (my $l = 0; $l < $maxl; $l++) { 
     392                        for ($col = 0; $col < @values; $col++) { 
     393                                $lines[$l]->[$col] = "" 
     394                                        if not defined $lines[$l]->[$col]; 
     395                        } 
     396                } 
     397 
     398                printf $format, $label, @{shift @lines}; 
     399                printf $format, "", @{$_} foreach (@lines); 
     400        } 
     401} 
     402 
     403sub printl2($$) # print a line w/ label and value (outside a table) 
    362404{ 
    363405        my ($label, $value) = @_; 
     
    365407                $label = html_encode($label); 
    366408                $value = html_encode($value); 
    367                 print "<tr><td valign=top>$label</td><td>$value</td></tr>\n"; 
    368         } else { 
    369                 my @values = split /\n/, $value; 
    370                 printf "%-47s %s\n", $label, shift @values; 
    371                 printf "%-47s %s\n", "", $_ foreach (@values); 
    372         } 
    373 } 
    374  
    375 sub printl2($$) # print a line w/ label and value (outside a table) 
    376 { 
    377         my ($label, $value) = @_; 
     409        } 
     410        print "$label: $value\n"; 
     411} 
     412 
     413sub real_prints($) # print separator w/ given text 
     414{ 
     415        my ($label, $ncol) = @_; 
     416        $ncol = 1 unless $ncol; 
    378417        if ($opt_html) { 
    379418                $label = html_encode($label); 
    380                 $value = html_encode($value); 
    381         } 
    382         print "$label: $value\n"; 
    383 } 
    384  
    385 sub real_prints($) # print separator w/ given text 
    386 { 
    387         my ($label) = @_; 
    388         if ($opt_html) { 
    389                 $label = html_encode($label); 
    390                 print "<tr><td align=center colspan=2><b>$label</b></td></tr>\n"; 
     419                print "<tr><td align=center colspan=".(1+$ncol)."><b>$label</b></td></tr>\n"; 
    391420        } else { 
    392421                print "\n---=== $label ===---\n"; 
     
    15661595                        "  -b, --bodyonly          Don't print html header\n", 
    15671596                        "                          (useful for postprocessing the output)\n", 
     1597                        "      --side-by-side      Display all DIMMs side-by-side if possible\n", 
    15681598                        "  -c, --checksum          Decode completely even if checksum fails\n", 
    15691599                        "  -x,                     Read data from hexdump files\n", 
     
    15901620                next; 
    15911621        } 
     1622        if ($_ eq '--side-by-side') { 
     1623                $opt_side_by_side = 1; 
     1624                next; 
     1625        } 
    15921626        if ($_ eq '-c' || $_ eq '--checksum') { 
    15931627                $opt_igncheck = 1; 
     
    16081642        } 
    16091643 
    1610         push @dimm, { file => $_ } if $use_hexdump; 
     1644        push @dimm, { eeprom => $_, file => $_ } if $use_hexdump; 
    16111645} 
    16121646 
     
    16391673                        next if $use_sysfs && $file !~ /^\d+-[\da-f]+$/i; 
    16401674                        next if !$use_sysfs && $file !~ /^eeprom-/; 
    1641                         push @files, { file => "$dir/$file" }; 
     1675                        push @files, { eeprom => "$file", 
     1676                                       file => "$dir/$file" }; 
    16421677                } 
    16431678                close(DIR); 
     
    16511686# @dimm is a list of hashes. There's one hash for each EEPROM we found. 
    16521687# Each hash has the following keys: 
     1688#  * eeprom: Name of the eeprom data file 
    16531689#  * file: Full path to the eeprom data file 
    16541690#  * bytes: The EEPROM data (array) 
     
    16901726for $current (0 .. $#dimm) { 
    16911727        my @bytes = @{$dimm[$current]->{bytes}}; 
     1728 
     1729        if ($opt_side_by_side) { 
     1730                printl("Decoding EEPROM", $dimm[$current]->{eeprom}); 
     1731        } 
    16921732 
    16931733        if (!$use_hexdump) { 
     
    17701810} 
    17711811 
     1812# Side-by-side output format is only possible if all DIMMs have a similar 
     1813# output structure 
     1814if ($opt_side_by_side) { 
     1815        for $current (1 .. $#dimm) { 
     1816                my @ref_output = @{$dimm[0]->{output}}; 
     1817                my @test_output = @{$dimm[$current]->{output}}; 
     1818                my $line; 
     1819 
     1820                if (scalar @ref_output != scalar @test_output) { 
     1821                        $opt_side_by_side = 0; 
     1822                        last; 
     1823                } 
     1824 
     1825                for ($line = 0; $line < @ref_output; $line++) { 
     1826                        my ($ref_func, $ref_label, @ref_dummy) = @{$ref_output[$line]}; 
     1827                        my ($test_func, $test_label, @test_dummy) = @{$test_output[$line]}; 
     1828 
     1829                        if ($ref_func != $test_func || $ref_label ne $test_label) { 
     1830                                $opt_side_by_side = 0; 
     1831                                last; 
     1832                        } 
     1833                } 
     1834        } 
     1835 
     1836        if (!$opt_side_by_side) { 
     1837                printc("Side-by-side output only possible if all DIMMS are similar\n"); 
     1838 
     1839                # Discard "Decoding EEPROM" entry from all outputs 
     1840                for $current (0 .. $#dimm) { 
     1841                        shift(@{$dimm[$current]->{output}}); 
     1842                } 
     1843        } 
     1844} 
     1845 
    17721846# Print the decoded information for all DIMMs 
    17731847for $current (0 .. $#dimm) { 
    1774         print "<b><u>" if $opt_html; 
    1775         printl2("\n\nDecoding EEPROM", $dimm[$current]->{file}); 
    1776         print "</u></b>" if $opt_html; 
     1848        if ($opt_side_by_side) { 
     1849                print "\n\n"; 
     1850        } else { 
     1851                print "<b><u>" if $opt_html; 
     1852                printl2("\n\nDecoding EEPROM", $dimm[$current]->{file}); 
     1853                print "</u></b>" if $opt_html; 
     1854        } 
    17771855        print "<table border=1>\n" if $opt_html; 
    17781856 
    1779         foreach (@{$dimm[$current]->{output}}) { 
    1780                 my ($func, @param) = @{$_}; 
     1857        my @output = @{$dimm[$current]->{output}}; 
     1858        for (my $line = 0; $line < @output; $line++) { 
     1859                my ($func, @param) = @{$output[$line]}; 
     1860 
     1861                if ($opt_side_by_side) { 
     1862                        foreach ($current+1 .. $#dimm) { 
     1863                                my @xoutput = @{$dimm[$_]->{output}}; 
     1864                                if (@{$xoutput[$line]} == 3) { 
     1865                                        # Line with data, stack all values 
     1866                                        push @param, @{$xoutput[$line]}[2]; 
     1867                                } else { 
     1868                                        # Separator, make it span 
     1869                                        push @param, scalar @dimm; 
     1870                                } 
     1871                        } 
     1872                } 
     1873 
    17811874                $func->(@param); 
    17821875        } 
    17831876 
    17841877        print "</table>\n" if $opt_html; 
     1878        last if $opt_side_by_side; 
    17851879} 
    17861880printl2("\n\nNumber of SDRAM DIMMs detected and decoded", scalar @dimm);