diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-07-07 18:05:47 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-07-07 18:05:47 +0000 |
commit | a346bb966a66953049e2089625550f167ba3f7c7 (patch) | |
tree | 1aecef41e268e3be194ab5145691bdd534c4a06b /monitor-parse-edid | |
parent | 17fc9d38c90a8d2abc1115b1b0ba2537baf679d0 (diff) | |
download | monitor-edid-a346bb966a66953049e2089625550f167ba3f7c7.tar monitor-edid-a346bb966a66953049e2089625550f167ba3f7c7.tar.gz monitor-edid-a346bb966a66953049e2089625550f167ba3f7c7.tar.bz2 monitor-edid-a346bb966a66953049e2089625550f167ba3f7c7.tar.xz monitor-edid-a346bb966a66953049e2089625550f167ba3f7c7.zip |
- monitor-parse-edid:
o handle parsing of EDIDs found in "xrandr --prop" or Xorg.log
Diffstat (limited to 'monitor-parse-edid')
-rwxr-xr-x | monitor-parse-edid | 72 |
1 files changed, 51 insertions, 21 deletions
diff --git a/monitor-parse-edid b/monitor-parse-edid index e976814..c6e158c 100755 --- a/monitor-parse-edid +++ b/monitor-parse-edid @@ -457,8 +457,31 @@ sub print_edid { } } +sub edid_from_lines { + my (@l) = @_; + my $edid_str = join('', map { /\s+([0-9a-f]{32})$/ && $1 } @l); + length($edid_str) == 256 or return (); + pack("C*", map { hex($_) } $edid_str =~ /(..)/g); +} + +sub find_edid_in_string { + my ($input) = @_; + + my @edids; + while ($input =~ /(?:EDID_DATA|: EDID \(in hex\)):\n((.*\n){8})/g) { + push @edids, edid_from_lines(split '\n', $1); + } + if (!@edids) { + @edids = edid_from_lines(split '\n', $input); + } + @edids; +} + sub usage() { - die "usage: monitor-parse-edid [-v] [--perl] [<edid file>]\n"; + die <<'EOF'; +usage: monitor-parse-edid [-v] [--perl] [<edid file>] +You can also do "xrandr --prop | monitor-parse-edid" +EOF } use Getopt::Long; @@ -477,7 +500,7 @@ if (@ARGV == 0) { usage(); } -my $raw_edid = join('', <$F>); +my $input = join('', <$F>); sub error { my ($msg) = @_; @@ -485,26 +508,33 @@ sub error { exit 1; } -length($raw_edid) == 128 || length($raw_edid) == 256 or error("bad edid"); - -my $edid = parse_edid($raw_edid, $verbose); -if (my $err = check_parsed_edid($edid)) { - die "$err\n"; -} -$edid->{file} = $file if $file; - -if ($raw_perl) { - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - my $s = Dumper($edid); - $s =~ s/.*? = {/+{/; # remove variable name we don't want - $s =~ s/};$/}/m; - print $s; -} elsif ($MonitorsDB) { - my $s = to_MonitorsDB($edid); - print "$s\n" if $s; +my @raw_edids; +if (length($input) == 128 || length($input) == 256) { + @raw_edids = $input; } else { - print_edid($edid, $verbose); + @raw_edids = find_edid_in_string($input) or error("bad edid"); +} + +foreach my $raw_edid (@raw_edids) { + my $edid = parse_edid($raw_edid, $verbose); + if (my $err = check_parsed_edid($edid)) { + die "$err\n"; + } + $edid->{file} = $file if $file; + + if ($raw_perl) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + my $s = Dumper($edid); + $s =~ s/.*? = {/+{/; # remove variable name we don't want + $s =~ s/};$/}/m; + print $s; + } elsif ($MonitorsDB) { + my $s = to_MonitorsDB($edid); + print "$s\n" if $s; + } else { + print_edid($edid, $verbose); + } } |