2 # Copyright © 2008-2012 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.8 $ }; $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.
52 'rdbomb' => 2, # alternate name
63 # Parse the RETIRED_EXES variable from the Makefiles to populate %disable.
65 sub parse_makefiles() {
66 foreach my $mf ( "Makefile.in", "glx/Makefile.in" ) {
69 open (IN, "<$mf") || error ("$mf: $!");
70 while (<IN>) { $body .= $_; }
74 my ($var) = ($body =~ m/^RETIRED_EXES\s*=\s*(.*)$/mi);
75 my ($var2) = ($body =~ m/^RETIRED_GL_EXES\s*=\s*(.*)$/mi);
76 error ("no RETIRED_EXES in $mf") unless $var;
77 $var .= " $var2" if $var2;
78 foreach my $hack (split (/\s+/, $var)) {
92 open (IN, "<$file") || error ("$file: $!");
93 while (<IN>) { $body .= $_; }
97 my ($top, $mid, $bot) = ($body =~ m/^(.*?\n)(\*hacks\..*?\n)(\n.*)$/s);
103 # Update the "*hacks.foo.name" section of the file based on the contents
107 $dir =~ s@/[^/]*$@@s;
108 my @counts = (0,0,0,0,0,0,0,0,0,0);
109 foreach my $xml (sort (glob ("$dir/../hacks/config/*.xml"))) {
111 open (IN, "<$xml") || error ("$xml: $!");
112 while (<IN>) { $b .= $_; }
114 my ($name) = ($b =~ m@<screensaver[^<>]*\b_label=\"([^<>\"]+)\"@s);
115 error ("$xml: no name") unless $name;
117 my $name2 = lc($name);
118 $name2 =~ s/^((x|gl)?[a-z])/\U$1/s; # what prefs.c (make_hack_name) does
120 $xml =~ s@^.*/([^/]+)\.xml$@$1@s;
121 if ($name ne $name2) {
122 my $s = sprintf("*hacks.%s.name:", $xml);
123 $mid2 .= sprintf ("%-28s%s\n", $s, $name);
129 ($b =~ m/<_description>.*Written by.*?;\s+(19[6-9]\d|20\d\d)\b/si);
130 error ("no year in $xml.xml") unless $year;
131 $hacks{$xml} = $year;
134 # Splice in new names.
135 $body = $top . $mid2 . $bot;
138 # Replace the "programs" section.
139 # Sort hacks by creation date, but put the OpenGL ones at the end.
141 my $segregate_p = 0; # whether to put the GL hacks at the end.
144 foreach my $hack (sort { $hacks{$a} == $hacks{$b}
146 : $hacks{$a} <=> $hacks{$b}}
148 my $cmd = "$hack -root";
149 my $ts = (length($cmd) / 8) * 8;
150 while ($ts < 40) { $cmd .= "\t"; $ts += 8; }
152 my $dis = $disable{$hack} || 0;
155 my $glep = ($hack eq 'extrusion');
156 if (-f "$hack.c" || -f "$hack") { $glp = 0; }
157 elsif (-f "glx/$hack.c") { $glp = 1; }
158 elsif ($hack eq 'companioncube') { $glp = 1; } # kludge
159 elsif ($dis != 2) { error ("is $hack X or GL?"); }
161 $counts[($disable{$hack} || 0)]++;
163 $counts[6+($disable{$hack} || 0)]++;
165 $counts[3+($disable{$hack} || 0)]++;
170 $dis = ($dis ? '-' : '');
172 ? (($dis ? '' : $glep ? '@GLE_KLUDGE@' : '@GL_KLUDGE@') .
175 $cmd = "$dis$vis\t\t\t\t$cmd \\n\\\n";
178 ($segregate_p ? $ghacks : $xhacks) .= $cmd;
184 # Splice in new programs list.
187 ($segregate_p ? "\t\t\t\t\t\t\t\t\t \\\n" : "") .
191 ($body =~ m/^(.*?\n\*programs:\s+\\\n)(.*?\n)(\n.*)$/s);
192 error ("unparsable") unless $mid;
193 $body = $top . $mid2 . $bot;
195 print STDERR "$progname: " .
196 "Total: $counts[0]+$counts[1]+$counts[2]; " .
197 "X11: $counts[3]+$counts[4]+$counts[5]; " .
198 "GL: $counts[6]+$counts[7]+$counts[8]; " .
199 "Names: $counts[9]\n"
202 # Write file if changed.
204 if ($body ne $obody) {
206 open (OUT, ">$file") || error ("$file: $!");
209 print STDERR "$progname: wrote $file\n";
211 print STDERR "$progname: $file unchanged\n";
218 print STDERR "$progname: $err\n";
223 print STDERR "usage: $progname [--verbose] ad-file\n";
229 while ($#ARGV >= 0) {
231 if (m/^--?verbose$/) { $verbose++; }
232 elsif (m/^-v+$/) { $verbose += length($_)-1; }
233 elsif (m/^-./) { usage; }
234 elsif (!$file) { $file = $_; }
238 usage unless ($file);