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.2 $ }; $version =~ s/^[^\d]+([\d.]+).*/$1/;
25 # These are marked as disabled by default in the .ad file.
65 open (IN, "<$file") || error ("$file: $!");
66 while (<IN>) { $body .= $_; }
70 my ($top, $mid, $bot) = ($body =~ m/^(.*?\n)(\*hacks\..*?\n)(\n.*)$/s);
76 # Update the "*hacks.foo.name" section of the file based on the contents
81 my @counts = (0,0,0,0,0,0);
82 foreach my $xml (sort (glob ("$dir/../hacks/config/*.xml"))) {
84 open (IN, "<$xml") || error ("$xml: $!");
85 while (<IN>) { $b .= $_; }
87 my ($name) = ($b =~ m@<screensaver[^<>]*\b_label=\"([^<>\"]+)\">@s);
88 error ("$xml: no name") unless $name;
90 my $name2 = lc($name);
91 $name2 =~ s/^((x|gl)?[a-z])/\U$1/s; # what prefs.c (make_hack_name) does
93 $xml =~ s@^.*/([^/]+)\.xml$@$1@s;
94 if ($name ne $name2) {
95 my $s = sprintf("*hacks.%s.name:", $xml);
96 $mid2 .= sprintf ("%-28s%s\n", $s, $name);
102 ($b =~ m/<_description>.*Written by.*?;\s+(19[6-9]\d|20\d\d)\b/si);
103 error ("no year in $xml.xml") unless $year;
104 $hacks{$xml} = $year;
108 # Splice in new names.
109 $body = $top . $mid2 . $bot;
112 # Replace the "programs" section.
113 # Sort hacks by creation date, but put the OpenGL ones at the end.
115 my $segregate_p = 0; # whether to put the GL hacks at the end.
118 foreach my $hack (sort { $hacks{$a} == $hacks{$b}
120 : $hacks{$a} <=> $hacks{$b}}
122 my $cmd = "$hack -root";
123 my $ts = (length($cmd) / 8) * 8;
124 while ($ts < 40) { $cmd .= "\t"; $ts += 8; }
125 next if ($hack eq 'ant' || $hack eq 'rdbomb');
128 my $glep = ($hack eq 'extrusion');
129 if (-f "$hack.c" || -f "$hack") { $glp = 0; }
130 elsif (-f "glx/$hack.c") { $glp = 1; }
131 else { error ("is $hack X or GL?"); }
133 my $dis = ($disable{$hack} ? '-' : '');
135 ? (($dis ? '' : $glep ? '@GLE_KLUDGE@' : '@GL_KLUDGE@') .
138 $cmd = "$dis$vis\t\t\t\t$cmd \\n\\\n";
141 ($segregate_p ? $ghacks : $xhacks) .= $cmd;
142 $counts[4+defined($disable{$hack})]++;
145 $counts[2+defined($disable{$hack})]++;
149 # Splice in new programs list.
152 ($segregate_p ? "\t\t\t\t\t\t\t\t\t \\\n" : "") .
156 ($body =~ m/^(.*?\n\*programs:\s+\\\n)(.*?\n)(\n.*)$/s);
157 error ("unparsable") unless $mid;
158 $body = $top . $mid2 . $bot;
160 print STDERR "$progname: Total: $counts[0]; " .
161 "X11: $counts[2]+$counts[3]; GL: $counts[4]+$counts[5]; " .
162 "Names: $counts[1]\n"
165 # Write file if changed.
167 if ($body ne $obody) {
169 open (OUT, ">$file") || error ("$file: $!");
172 print STDERR "$progname: wrote $file\n";
174 print STDERR "$progname: $file unchanged\n";
181 print STDERR "$progname: $err\n";
186 print STDERR "usage: $progname [--verbose] ad-file\n";
192 while ($#ARGV >= 0) {
194 if (m/^--?verbose$/) { $verbose++; }
195 elsif (m/^-v+$/) { $verbose += length($_)-1; }
196 elsif (m/^-./) { usage; }
197 elsif (!$file) { $file = $_; }
201 usage unless ($file);