/[soft]/ldetect-lst/trunk/convert/merge_MonitorsDB.pl
ViewVC logotype

Contents of /ldetect-lst/trunk/convert/merge_MonitorsDB.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1357 - (show annotations) (download)
Tue May 17 09:21:22 2011 UTC (10 years ago) by dmorgan
File MIME type: text/plain
File size: 3314 byte(s)
Import  ldetect
1 #!/usr/bin/perl
2
3 # ./merge_MonitorsDB.pl ../../monitor-edid/test/new_MonitorsDB ../lst/MonitorsDB > MonitorsDB.new
4 # diff -u ../lst/MonitorsDB MonitorsDB.new
5
6 @ARGV == 2 or die "usage: $0 [--verif | <entries to add>] <mdk MonitorsDB>\n";
7
8 my ($to_add, $MonitorsDB) = @ARGV;
9 my $verif = $to_add eq '--verif';
10
11
12 use MDK::Common;
13
14 my $monitors_db = readMonitorsDB($MonitorsDB);
15
16 if ($verif) {
17 verif($monitors_db);
18 } else {
19 my $to_add = readMonitorsDB($to_add);
20
21 rationalize_EISA_ID($_) foreach @$to_add, @$monitors_db;
22
23 my %EISA_ID_to_VendorName = EISA_ID_to_VendorName($monitors_db);
24 foreach (@$to_add) {
25 my $VendorName = $_->{EISA_ID} =~ /(...)/ && $EISA_ID_to_VendorName{$1} or next;
26
27 $_->{ModelName} =~ s/^(\Q$_->{VendorName}\E|\Q$VendorName\E)\s//i;
28 $_->{VendorName} = $VendorName;
29 $_->{ModelName} = "$VendorName $_->{ModelName}";
30 $_->{text} = join_line($_);
31 }
32
33 #- first see if the EISA_ID is already there
34 my %to_add = map { $_->{EISA_ID} => $_ } @$to_add;
35 foreach (@$monitors_db) {
36 $to_add{$_->{EISA_ID}} or next;
37
38 $_->{text} =~ s!.*\n$!$to_add{$_->{EISA_ID}}{text}!;
39 delete $to_add{$_->{EISA_ID}};
40 }
41
42 my @to_add = sort { lc($a->{text}) cmp lc($b->{text}) } values %to_add;
43 foreach (@$monitors_db) {
44 while (@to_add && lc("$to_add[0]{VendorName}; $to_add[0]{ModelName}") lt lc("$_->{VendorName}; $_->{ModelName}")) {
45 $_->{text} = (shift @to_add)->{text} . $_->{text};
46 }
47 }
48
49 print $_->{text} foreach (@$monitors_db, @to_add);
50 }
51
52 sub verif {
53 my ($monitors_db) = @_;
54
55 my %l;
56 foreach my $e (@$monitors_db) {
57 rationalize_EISA_ID($e, sub {
58 my ($previous) = @{$l{$e->{EISA_ID}} || []} or return;
59 my @vs = map {
60 $e->{$_} eq $previous->{$_} ? () : "$e->{$_} vs $previous->{$_}";
61 } 'ModelName', 'HorizSync', 'VertRefresh';
62 warn "$e->{lineno}: duplicate $e->{EISA_ID}: " . (@vs ? join(", ", @vs) : $e->{ModelName}) . "\n";
63 });
64
65 push @{$l{$e->{EISA_ID}}}, $e;
66 }
67 }
68
69 sub rationalize_EISA_ID {
70 my ($e, $o_verif) = @_;
71
72 if ($e->{EISA_ID} =~ /^([A-Z]{3})([0-9a-f]{4})$/i) {
73 # perfect!
74 $e->{EISA_ID} = uc($1) . lc($2);
75 $o_verif and $o_verif->();
76 } elsif ($e->{EISA_ID} eq '0') {
77 # ok
78 } elsif ($e->{EISA_ID} =~ /^([a-z]{3})([0-9a-f]{0,3})$/i) {
79 # we can correct this (?)
80 warn sprintf("$e->{lineno}: $e->{EISA_ID} should be %s%04x\n", $1, hex($2)) if $verif;
81 } else {
82 warn "$e->{lineno}: bad EISA_ID $e->{EISA_ID}\n" if $o_verif;
83 }
84 }
85
86 sub EISA_ID_to_VendorName {
87 my ($monitors_db) = @_;
88
89 my %l;
90 foreach (@$monitors_db) {
91 $_->{EISA_ID} =~ /(...)/ and $l{$1}{$_->{VendorName}}++;
92 }
93 map {
94 my $v = $l{$_};
95 my @l = sort { $v->{$b} <=> $v->{$a} } keys %$v;
96 $_ => $l[0];
97 } keys %l;
98 }
99
100 BEGIN {
101 our @fields = qw(VendorName ModelName EISA_ID HorizSync VertRefresh dpms);
102 }
103
104 sub join_line {
105 my ($e) = @_;
106 join('; ', @$e{@fields}) . "\n";
107 }
108 sub split_line {
109 my ($s) = @_;
110 my %l; @l{@fields} = split(/\s*;\s*/, $s);
111 \%l;
112 }
113
114 sub readMonitorsDB {
115 my ($f) = @_;
116 my $s = '';
117 my @monitors_db;
118 my $lineno = 0;
119 foreach (cat_($f)) {
120 $lineno++;
121 $s .= $_;
122 s/\s+$//;
123 /^#/ and next;
124 /^$/ and next;
125
126 my $e = split_line($_);
127 ($e->{text}, $s) = ($s, '');
128 $e->{lineno} = $lineno;
129 push @monitors_db, $e;
130 }
131 \@monitors_db;
132 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.28