chiark / gitweb /
emacs: set vm-legacy-key-bindings so "a" works
[ian-dotfiles.git] / from-cvs / files / _.configs_checkconfig
1 #!/usr/bin/perl
2 # New configuration script
3
4 $ENV{'PATH'}.= ':/usr/openwin/bin';
5
6 $_= $ENV{'DISPLAY'};
7 $_= $ENV{'HOST'}.':0' if m/^:/ || m/^unix:/; 
8 s/:.*$//;
9 s/\.[^0-9].*$//;
10
11 $pfx= shift @ARGV;
12 @ARGV && warn "arguments beyond the first ignored\n";
13
14 if ($_) {
15     $c{'display'}= $_;
16     $_= `xauth -i extract /dev/null $c{'display'}:0 2>&1`;
17     $c{'xauth'}= length($_) ? 'false' : 'true';
18     $_= `xdpyinfo`;
19     $c{'keycodes'}="$1-$2" if m/range:\s+minimum (\d+), maximum (\d+)\s/;
20     if (m/default screen number:\s+(\d+)\s/) {
21         $defscreen= $1;
22         $_=$' if m/\nscreen \#$defscreen:/;
23         $_="$`\n" if m/\n\S/;
24     }
25     ($c{'pixels_x'}, $c{'pixels_y'}) = ($1,$2)
26                 if m/dimensions:\s+(\d+)x(\d+) pixels/;
27     ($c{'mm_x'}, $c{'mm_y'}) = ($1,$2)
28                 if m/dimensions:.*\D(\d+)x(\d+) millimeters/;
29     ($c{'dpi_x'}, $c{'dpi_y'}) = ($1,$2)
30         if m/resolution:\s+(\d+)x(\d+) dots per inch/;
31     $c{'depth'} = $1 if m/depth of root window:\s+(\d+) planes/;
32     if (m/default visual id:\s+(\w+)\s/) {
33         $defvisual= $1;
34         $_=$' if m/\n  visual:\s+visual id:\s+$defvisual\s/;
35         $_="$`\n" if m/\n  visual:/;
36     }
37     $c{'visual'} = $1 if m/class:\s+(\w+)\s/;
38     $c{'depth'} = $1 if m/depth:\s+(\d+) planes/;
39 }
40
41 $c{'host'}= $ENV{'HOST'};
42 #$c{'arch'}= $ENV{'ARCH'};
43 $_= `uname -sr`; s/\s(\d+)\.\S*/$1/;
44 $c{'arch'}= $_;
45
46 chdir($ENV{'HOME'});
47 chdir('.configs');
48
49 open(L, "list") || die "$0: list: $!\n";
50
51 while(<L>) {
52     s/\s*$//;
53     next if m/^#/ || m/^$/;
54     $ol= $l= $_;
55     $true=0;
56     while ($l =~ s/\s*(\S+)// && $1 ne ':') {
57         next if $true;
58         $_= $1;
59         if (m/^default$/) {
60             $true= 1;
61         } elsif (m/[<>]=?/) {
62             $lhs= $`;
63             $rhs= $';
64             $op= $&;
65             next unless defined($c{$lhs});
66             $true= eval '$c{$lhs} '.$op.' $rhs';
67         } elsif (m/=/) {
68             $lhs= $`;
69             $rhs= $';
70             next unless defined($c{$lhs});
71             $true= $c{$lhs} eq $rhs;
72         } else {
73             warn "condition `$_' in line $. not understood\n";
74         }
75     }
76     next unless $true;
77     while ($l =~ s/\s*(\S+)//) {
78         unless ($1 =~ m/=/) {
79             warn "consequence `$1' in line $. not understood\n";
80             next;
81         }
82         $c{$`}= $';
83     }
84 }
85
86 close(L);
87
88 while (($k,$v) = each %c) {
89     print " $pfx$k=$v";
90 }
91 print "\n";