summaryrefslogtreecommitdiffstats
path: root/convert
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2005-06-24 06:16:06 +0000
committerPascal Rigaux <pixel@mandriva.com>2005-06-24 06:16:06 +0000
commitd4f5186be207b197bda2d491308c722ce42450ea (patch)
tree59b933eb9cb79ecb8b089957e8bf3a3623d2e082 /convert
parentd7087fd086d19060269a07d9d3e2ab124ab3212f (diff)
downloadldetect-lst-d4f5186be207b197bda2d491308c722ce42450ea.tar
ldetect-lst-d4f5186be207b197bda2d491308c722ce42450ea.tar.gz
ldetect-lst-d4f5186be207b197bda2d491308c722ce42450ea.tar.bz2
ldetect-lst-d4f5186be207b197bda2d491308c722ce42450ea.tar.xz
ldetect-lst-d4f5186be207b197bda2d491308c722ce42450ea.zip
- new code to merge in MonitorsDB entries (esp. coming from monitor-parse-edid --MonitorsDB)
- verify_MonitorsDB has been merged in merge_MonitorsDB
Diffstat (limited to 'convert')
-rw-r--r--convert/Makefile3
-rwxr-xr-xconvert/merge_MonitorsDB.pl132
-rw-r--r--convert/verify_MonitorsDB16
3 files changed, 133 insertions, 18 deletions
diff --git a/convert/Makefile b/convert/Makefile
index 60372817..3553a905 100644
--- a/convert/Makefile
+++ b/convert/Makefile
@@ -8,5 +8,4 @@ verif:
./verify_Cards.pl
clean:
- rm -f $(FILES) modules.pcimap modules.usbmap vendors.txt pcitable.new usbtable.new
-
+ rm -f $(FILES) modules.pcimap modules.usbmap vendors.txt *.new
diff --git a/convert/merge_MonitorsDB.pl b/convert/merge_MonitorsDB.pl
new file mode 100755
index 00000000..7a24cfe3
--- /dev/null
+++ b/convert/merge_MonitorsDB.pl
@@ -0,0 +1,132 @@
+#!/usr/bin/perl
+
+# ./merge_MonitorsDB.pl ../../monitor-edid/test/new_MonitorsDB ../lst/MonitorsDB > MonitorsDB.new
+# diff -u ../lst/MonitorsDB MonitorsDB.new
+
+@ARGV == 2 or die "usage: $0 [--verif | <entries to add>] <mdk MonitorsDB>\n";
+
+my ($to_add, $MonitorsDB) = @ARGV;
+my $verif = $to_add eq '--verif';
+
+
+use MDK::Common;
+
+my $monitors_db = readMonitorsDB($MonitorsDB);
+
+if ($verif) {
+ verif($monitors_db);
+} else {
+ my $to_add = readMonitorsDB($to_add);
+
+ rationalize_EISA_ID($_) foreach @$to_add, @$monitors_db;
+
+ my %EISA_ID_to_VendorName = EISA_ID_to_VendorName($monitors_db);
+ foreach (@$to_add) {
+ my $VendorName = $_->{EISA_ID} =~ /(...)/ && $EISA_ID_to_VendorName{$1} or next;
+
+ $_->{ModelName} =~ s/^(\Q$_->{VendorName}\E|\Q$VendorName\E)\s//i;
+ $_->{VendorName} = $VendorName;
+ $_->{ModelName} = "$VendorName $_->{ModelName}";
+ $_->{text} = join_line($_);
+ }
+
+ #- first see if the EISA_ID is already there
+ my %to_add = map { $_->{EISA_ID} => $_ } @$to_add;
+ foreach (@$monitors_db) {
+ $to_add{$_->{EISA_ID}} or next;
+
+ $_->{text} =~ s!.*\n$!$to_add{$_->{EISA_ID}}{text}!;
+ delete $to_add{$_->{EISA_ID}};
+ }
+
+ my @to_add = sort { lc($a->{text}) cmp lc($b->{text}) } values %to_add;
+ foreach (@$monitors_db) {
+ while (@to_add && lc("$to_add[0]{VendorName}; $to_add[0]{ModelName}") lt lc("$_->{VendorName}; $_->{ModelName}")) {
+ $_->{text} = (shift @to_add)->{text} . $_->{text};
+ }
+ }
+
+ print $_->{text} foreach (@$monitors_db, @to_add);
+}
+
+sub verif {
+ my ($monitors_db) = @_;
+
+ my %l;
+ foreach my $e (@$monitors_db) {
+ rationalize_EISA_ID($e, sub {
+ my ($previous) = @{$l{$e->{EISA_ID}} || []} or return;
+ my @vs = map {
+ $e->{$_} eq $previous->{$_} ? () : "$e->{$_} vs $previous->{$_}";
+ } 'ModelName', 'HorizSync', 'VertRefresh';
+ warn "$e->{lineno}: duplicate $e->{EISA_ID}: " . (@vs ? join(", ", @vs) : $e->{ModelName}) . "\n";
+ });
+
+ push @{$l{$e->{EISA_ID}}}, $e;
+ }
+}
+
+sub rationalize_EISA_ID {
+ my ($e, $o_verif) = @_;
+
+ if ($e->{EISA_ID} =~ /^([A-Z]{3})([0-9a-f]{4})$/i) {
+ # perfect!
+ $e->{EISA_ID} = uc($1) . lc($2);
+ $o_verif and $o_verif->();
+ } elsif ($e->{EISA_ID} eq '0') {
+ # ok
+ } elsif ($e->{EISA_ID} =~ /^([a-z]{3})([0-9a-f]{0,3})$/i) {
+ # we can correct this (?)
+ warn sprintf("$e->{lineno}: $e->{EISA_ID} should be %s%04x\n", $1, hex($2)) if $verif;
+ } else {
+ warn "$e->{lineno}: bad EISA_ID $e->{EISA_ID}\n" if $o_verif;
+ }
+}
+
+sub EISA_ID_to_VendorName {
+ my ($monitors_db) = @_;
+
+ my %l;
+ foreach (@$monitors_db) {
+ $_->{EISA_ID} =~ /(...)/ and $l{$1}{$_->{VendorName}}++;
+ }
+ map {
+ my $v = $l{$_};
+ my @l = sort { $v->{$b} <=> $v->{$a} } keys %$v;
+ $_ => $l[0];
+ } keys %l;
+}
+
+BEGIN {
+ our @fields = qw(VendorName ModelName EISA_ID HorizSync VertRefresh dpms);
+}
+
+sub join_line {
+ my ($e) = @_;
+ join('; ', @$e{@fields}) . "\n";
+}
+sub split_line {
+ my ($s) = @_;
+ my %l; @l{@fields} = split(/\s*;\s*/, $s);
+ \%l;
+}
+
+sub readMonitorsDB {
+ my ($f) = @_;
+ my $s = '';
+ my @monitors_db;
+ my $lineno = 0;
+ foreach (cat_($f)) {
+ $lineno++;
+ $s .= $_;
+ s/\s+$//;
+ /^#/ and next;
+ /^$/ and next;
+
+ my $e = split_line($_);
+ ($e->{text}, $s) = ($s, '');
+ $e->{lineno} = $lineno;
+ push @monitors_db, $e;
+ }
+ \@monitors_db;
+}
diff --git a/convert/verify_MonitorsDB b/convert/verify_MonitorsDB
deleted file mode 100644
index 9da8ec6f..00000000
--- a/convert/verify_MonitorsDB
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/perl
-
-use lib qw(/usr/lib/libDrakX);
-use Xconfig::monitor;
-
-my $monitors_db = Xconfig::monitor::readMonitorsDB("../lst/MonitorsDB");
-foreach (@$monitors_db) {
- if ($_->{EISA_ID} =~ /^\w{3}[0-9a-f]{4}$/i) {
- # perfect!
- } elsif ($_->{EISA_ID} =~ /^([a-z]{3})([0-9a-f]{0,3})$/i) {
- # we can correct this
- printf "$_->{EISA_ID} should be %s%04x\n", $1, hex($2);
- } else {
- print "bad EISA_ID $_->{EISA_ID}\n";
- }
-}