2 # Copyright © 2008 Jamie Zawinski <jwz@jwz.org>
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation. No representations are made about the suitability of this
9 # software for any purpose. It is provided "as is" without express or
12 # This updates driver/XScreenSaver.ad.in with the current list of savers.
14 # Created: 3-Aug-2008.
20 my $progname = $0; $progname =~ s@.*/@@g;
21 my $version = q{ $Revision: 1.3 $ }; $version =~ s/^[^\d]+([\d.]+).*/$1/;
25 # 1 means disabled: marked with "-" by default in the .ad file.
26 # 2 means retired: not mentioned in .ad at all.
61 'rdbomb' => 2, # alternate name
77 # Parse the RETIRED_EXES variable from the Makefiles to populate %disable.
79 sub parse_makefiles() {
80 foreach my $mf ( "Makefile.in", "glx/Makefile.in" ) {
83 open (IN, "<$mf") || error ("$mf: $!");
84 while (<IN>) { $body .= $_; }
88 my ($var) = ($body =~ m/^RETIRED_EXES\s*=\s*(.*)$/mi);
89 error ("no RETIRED_EXES in $mf") unless $var;
90 foreach my $hack (split (/\s+/, $var)) {
104 open (IN, "<$file") || error ("$file: $!");
105 while (<IN>) { $body .= $_; }
109 my ($top, $mid, $bot) = ($body =~ m/^(.*?\n)(\*hacks\..*?\n)(\n.*)$/s);
115 # Update the "*hacks.foo.name" section of the file based on the contents
119 $dir =~ s@/[^/]*$@@s;
120 my @counts = (0,0,0,0,0,0,0,0,0,0);
121 foreach my $xml (sort (glob ("$dir/../hacks/config/*.xml"))) {
123 open (IN, "<$xml") || error ("$xml: $!");
124 while (<IN>) { $b .= $_; }
126 my ($name) = ($b =~ m@<screensaver[^<>]*\b_label=\"([^<>\"]+)\">@s);
127 error ("$xml: no name") unless $name;
129 my $name2 = lc($name);
130 $name2 =~ s/^((x|gl)?[a-z])/\U$1/s; # what prefs.c (make_hack_name) does
132 $xml =~ s@^.*/([^/]+)\.xml$@$1@s;
133 if ($name ne $name2) {
134 my $s = sprintf("*hacks.%s.name:", $xml);
135 $mid2 .= sprintf ("%-28s%s\n", $s, $name);
141 ($b =~ m/<_description>.*Written by.*?;\s+(19[6-9]\d|20\d\d)\b/si);
142 error ("no year in $xml.xml") unless $year;
143 $hacks{$xml} = $year;
146 # Splice in new names.
147 $body = $top . $mid2 . $bot;
150 # Replace the "programs" section.
151 # Sort hacks by creation date, but put the OpenGL ones at the end.
153 my $segregate_p = 0; # whether to put the GL hacks at the end.
156 foreach my $hack (sort { $hacks{$a} == $hacks{$b}
158 : $hacks{$a} <=> $hacks{$b}}
160 my $cmd = "$hack -root";
161 my $ts = (length($cmd) / 8) * 8;
162 while ($ts < 40) { $cmd .= "\t"; $ts += 8; }
164 my $dis = $disable{$hack} || 0;
167 my $glep = ($hack eq 'extrusion');
168 if (-f "$hack.c" || -f "$hack") { $glp = 0; }
169 elsif (-f "glx/$hack.c") { $glp = 1; }
170 elsif ($dis != 2) { error ("is $hack X or GL?"); }
172 $counts[($disable{$hack} || 0)]++;
174 $counts[6+($disable{$hack} || 0)]++;
176 $counts[3+($disable{$hack} || 0)]++;
181 $dis = ($dis ? '-' : '');
183 ? (($dis ? '' : $glep ? '@GLE_KLUDGE@' : '@GL_KLUDGE@') .
186 $cmd = "$dis$vis\t\t\t\t$cmd \\n\\\n";
189 ($segregate_p ? $ghacks : $xhacks) .= $cmd;
195 # Splice in new programs list.
198 ($segregate_p ? "\t\t\t\t\t\t\t\t\t \\\n" : "") .
202 ($body =~ m/^(.*?\n\*programs:\s+\\\n)(.*?\n)(\n.*)$/s);
203 error ("unparsable") unless $mid;
204 $body = $top . $mid2 . $bot;
206 print STDERR "$progname: " .
207 "Total: $counts[0]+$counts[1]+$counts[2]; " .
208 "X11: $counts[3]+$counts[4]+$counts[5]; " .
209 "GL: $counts[6]+$counts[7]+$counts[8]; " .
210 "Names: $counts[9]\n"
213 # Write file if changed.
215 if ($body ne $obody) {
217 open (OUT, ">$file") || error ("$file: $!");
220 print STDERR "$progname: wrote $file\n";
222 print STDERR "$progname: $file unchanged\n";
229 print STDERR "$progname: $err\n";
234 print STDERR "usage: $progname [--verbose] ad-file\n";
240 while ($#ARGV >= 0) {
242 if (m/^--?verbose$/) { $verbose++; }
243 elsif (m/^-v+$/) { $verbose += length($_)-1; }
244 elsif (m/^-./) { usage; }
245 elsif (!$file) { $file = $_; }
249 usage unless ($file);