2 # Copyright © 2008-2014 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) = ('$Revision: 1.10 $' =~ m/\s(\d[.\d]+)\s/s);
25 # 1 means disabled: marked with "-" by default in the .ad file.
26 # 2 means retired: not mentioned in .ad at all (parsed from Makefile).
49 'rdbomb' => 2, # alternate name
59 # Parse the RETIRED_EXES variable from the Makefiles to populate %disable.
60 # Duplicated in ../OSX/build-fntable.pl.
62 sub parse_makefiles() {
63 foreach my $mf ( "Makefile.in", "glx/Makefile.in" ) {
64 open (my $in, '<', $mf) || error ("$mf: $!");
65 local $/ = undef; # read entire file
70 my ($var) = ($body =~ m/^RETIRED_EXES\s*=\s*(.*)$/mi);
71 my ($var2) = ($body =~ m/^RETIRED_GL_EXES\s*=\s*(.*)$/mi);
72 error ("no RETIRED_EXES in $mf") unless $var;
73 $var .= " $var2" if $var2;
74 foreach my $hack (split (/\s+/, $var)) {
86 open (my $in, '<', $file) || error ("$file: $!");
87 local $/ = undef; # read entire file
92 my ($top, $mid, $bot) = ($body =~ m/^(.*?\n)(\*hacks\..*?\n)(\n.*)$/s);
98 # Update the "*hacks.foo.name" section of the file based on the contents
102 $dir =~ s@/[^/]*$@@s;
103 my @counts = (0,0,0,0,0,0,0,0,0,0);
104 foreach my $xml (sort (glob ("$dir/../hacks/config/*.xml"))) {
105 open (my $in, '<', $xml) || error ("$xml: $!");
106 local $/ = undef; # read entire file
109 my ($name) = ($b =~ m@<screensaver[^<>]*\b_label=\"([^<>\"]+)\"@s);
110 error ("$xml: no name") unless $name;
112 my $name2 = lc($name);
113 $name2 =~ s/^((x|gl)?[a-z])/\U$1/s; # what prefs.c (make_hack_name) does
115 $xml =~ s@^.*/([^/]+)\.xml$@$1@s;
116 if ($name ne $name2) {
117 my $s = sprintf("*hacks.%s.name:", $xml);
118 $mid2 .= sprintf ("%-28s%s\n", $s, $name);
124 ($b =~ m/<_description>.*Written by.*?;\s+(19[6-9]\d|20\d\d)\b/si);
125 error ("no year in $xml.xml") unless $year;
126 $hacks{$xml} = $year;
129 # Splice in new names.
130 $body = $top . $mid2 . $bot;
133 # Replace the "programs" section.
134 # Sort hacks by creation date, but put the OpenGL ones at the end.
136 my $segregate_p = 0; # whether to put the GL hacks at the end.
139 foreach my $hack (sort { $hacks{$a} == $hacks{$b}
141 : $hacks{$a} <=> $hacks{$b}}
143 my $cmd = "$hack -root";
144 my $ts = (length($cmd) / 8) * 8;
145 while ($ts < 40) { $cmd .= "\t"; $ts += 8; }
147 my $dis = $disable{$hack} || 0;
150 my $glep = ($hack eq 'extrusion');
151 if (-f "$hack.c" || -f "$hack") { $glp = 0; }
152 elsif (-f "glx/$hack.c") { $glp = 1; }
153 elsif ($hack eq 'companioncube') { $glp = 1; } # kludge
154 elsif ($dis != 2) { error ("is $hack X or GL?"); }
156 $counts[($disable{$hack} || 0)]++;
158 $counts[6+($disable{$hack} || 0)]++;
160 $counts[3+($disable{$hack} || 0)]++;
165 $dis = ($dis ? '-' : '');
167 ? (($dis ? '' : $glep ? '@GLE_KLUDGE@' : '@GL_KLUDGE@') .
170 $cmd = "$dis$vis\t\t\t\t$cmd \\n\\\n";
173 ($segregate_p ? $ghacks : $xhacks) .= $cmd;
179 # Splice in new programs list.
182 ($segregate_p ? "\t\t\t\t\t\t\t\t\t \\\n" : "") .
186 ($body =~ m/^(.*?\n\*programs:\s+\\\n)(.*?\n)(\n.*)$/s);
187 error ("unparsable") unless $mid;
188 $body = $top . $mid2 . $bot;
190 print STDERR "$progname: " .
191 "Total: $counts[0]+$counts[1]+$counts[2]; " .
192 "X11: $counts[3]+$counts[4]+$counts[5]; " .
193 "GL: $counts[6]+$counts[7]+$counts[8]; " .
194 "Names: $counts[9]\n"
197 # Write file if changed.
199 if ($body ne $obody) {
200 open (my $out, '>', $file) || error ("$file: $!");
203 print STDERR "$progname: wrote $file\n";
205 print STDERR "$progname: $file unchanged\n";
212 print STDERR "$progname: $err\n";
217 print STDERR "usage: $progname [--verbose] ad-file\n";
223 while ($#ARGV >= 0) {
225 if (m/^--?verbose$/) { $verbose++; }
226 elsif (m/^-v+$/) { $verbose += length($_)-1; }
227 elsif (m/^-./) { usage; }
228 elsif (!$file) { $file = $_; }
232 usage unless ($file);