2 # Copyright © 2002-2013 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 # Created: 30-May-2002.
14 # This creates man pages from the XML program descriptions in
15 # xscreensaver/hacks/config/.
17 # They aren't necessarily the most accurate or well-written man pages,
18 # but at least they exist.
26 my $progname = $0; $progname =~ s@.*/@@g;
27 my $version = q{ $Revision: 1.4 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
31 my $default_args = ("[\\-display \\fIhost:display.screen\\fP]\n" .
32 "[\\-visual \\fIvisual\\fP]\n" .
35 my $default_options = (".TP 8\n" .
36 ".B \\-visual \\fIvisual\\fP\n" .
37 "Specify which visual to use. Legal values " .
38 "are the name of a visual class,\n" .
39 "or the id number (decimal or hex) of a " .
40 "specific visual.\n" .
43 "Draw on a newly-created window. " .
44 "This is the default.\n" .
47 "Draw on the root window.\n");
49 my $man_suffix = (".SH ENVIRONMENT\n" .
53 "to get the default host and display number.\n" .
56 "to get the name of a resource file that overrides " .
57 "the global resources\n" .
58 "stored in the RESOURCE_MANAGER property.\n" .
61 ".BR xscreensaver (1)\n" .
63 "Copyright \\(co %YEAR% by %AUTHOR%. " .
64 "Permission to use, copy, modify, \n" .
65 "distribute, and sell this software and its " .
66 "documentation for any purpose is \n" .
67 "hereby granted without fee, provided that " .
68 "the above copyright notice appear \n" .
69 "in all copies and that both that copyright " .
70 "notice and this permission notice\n" .
71 "appear in supporting documentation. No " .
72 "representations are made about the \n" .
73 "suitability of this software for any purpose. " .
74 "It is provided \"as is\" without\n" .
75 "express or implied warranty.\n" .
81 my $cfgdir = (-d "config" ? "config" : "../config");
82 my $xml = "$cfgdir/$exe.xml";
85 error ("$exe does not exist") if (! -f $exe);
86 error ("$xml does not exist") if (! -f $xml);
87 error ("$man already exists") if (-f $man);
90 open (IN, "<$xml") || error ("$xml: $!");
92 while (<IN>) { $xmltxt .= $_; }
99 $xmltxt =~ s/\s+/ /gs;
100 $xmltxt =~ s/<!--.*?-->//g;
101 $xmltxt =~ s@(<[^/])@\n$1@gs;
103 foreach (split ('\n', $xmltxt)) {
105 next if m/^<\?xml\b/;
106 next if m/^<screensaver\b/;
107 next if m/^<command\b/;
108 next if m/^<[hv]group\b/;
109 next if m/^<select\b/;
111 my ($x,$arg) = m@\barg(|-unset|-set)=\"([^\"]+)\"@;
112 my ($label) = m@\b_?label=\"([^\"]+)\"@;
113 my ($low) = m@\blow=\"([^\"]+)\"@;
114 my ($hi) = m@\bhigh=\"([^\"]+)\"@;
115 my ($def) = m@\bdefault=\"([^\"]+)\"@;
117 $arg =~ s@\s*\%\s*@ \\fInumber\\fP@g if ($arg);
120 my $boolp = m/^<boolean/;
123 if ($arg && $arg =~ m/^-no(-.*)/) {
124 $arg = "$1 | \\$arg";
125 } elsif ($boolp && $arg) {
126 $arg = "$arg | \\-no$arg";
129 if ($carg && $carg =~ m/colors/) {
134 } elsif ($carg eq '-move' || $carg eq '-no-move' ||
135 $carg eq '-wander' || $carg eq '-no-wander') {
136 $label = "Whether the object should wander around the screen.";
137 } elsif ($boolp && ($carg eq '-spin' || $carg eq '-no-spin')) {
138 $label = "Whether the object should spin.";
139 } elsif ($carg eq '-spin X') {
140 $carg = '-spin \fI[XYZ]\fP';
142 $label = "Around which axes should the object spin?";
143 } elsif ($carg eq '-fps' || $carg eq '-no-fps') {
144 $label = "Whether to show a frames-per-second display " .
145 "at the bottom of the screen.";
146 } elsif ($carg eq '-wireframe' || $carg eq '-wire') {
147 $label = "Render in wireframe instead of solid.";
148 } elsif ($carg =~ m/^-delay/ && $hi && $hi >= 10000) {
149 $label = "Per-frame delay, in microseconds.";
150 $def = sprintf ("%d (%0.2f seconds)", $def, ($def/1000000.0));
152 } elsif ($carg eq '-speed \fInumber\fP') {
153 $label = "Animation speed. 2.0 means twice as fast, " .
154 "0.5 means half as fast.";
157 $label .= ". Boolean.";
162 if (m/^<(number|boolean|option)/) {
164 next if (!$arg && m/<option/);
166 print STDERR "$progname: ERROR: no label: $_\n";
170 $args .= "[\\$carg]\n";
173 $label .= " $low - $hi." if (defined($low) && defined($hi));
174 $label .= " Default: $def." if (defined ($def));
176 $label = wrap ("", "", $label);
178 $body .= ".TP 8\n.B \\$arg\n$label";
181 } elsif (m@^<_description>\s*(.*)\s*</_description>@) {
184 print STDERR "$progname: ERROR: UNKNOWN: $_\n";
188 $desc = "Something pretty." unless $desc;
191 if ($desc =~ m@^(.*?)\s*(Written by|By) ([^.]+\.?\s*)$@s) {
194 $author =~ s/\s*[.]\s*$//;
198 print STDERR "$progname: $exe: WARNING: unknown author\n";
202 $desc =~ s@http://en\.wikipedia\.org/[^\s]+@@gs;
204 $desc = wrap ("", "", $desc);
206 $body = (".TH XScreenSaver 1 \"\" \"X Version 11\"\n" .
208 "$exe - screen saver.\n" .
213 ".SH DESCRIPTION\n" .
220 my $year = $1 if ($author =~ s/; (\d{4})$//s);
221 $year = (localtime)[5] + 1900 unless $year;
223 $body =~ s/%AUTHOR%/$author/g;
224 $body =~ s/%YEAR%/$year/g;
226 #print $body; exit 0;
229 open (OUT, ">$man") || error ("$man: $!");
230 print OUT $body || error ("$man: $!");
231 close OUT || error ("$man: $!");
232 print STDERR "$progname: wrote $man\n";
238 print STDERR "$progname: $err\n";
243 print STDERR "usage: $progname [--verbose] programs...\n";
249 while ($_ = $ARGV[0]) {
251 if ($_ eq "--verbose") { $verbose++; }
252 elsif (m/^-v+$/) { $verbose += length($_)-1; }
253 elsif (m/^-./) { usage; }
254 else { push @progs, $_; }
257 usage() if ($#progs < 0);
259 foreach (@progs) { xml2man($_); }