2 # Copyright © 2002 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.2 $ }; $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 2002 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/;
122 if ($arg && $arg =~ m/^-no(-.*)/) {
123 $arg = "$1 | \\$arg";
124 } elsif ($boolp && $arg) {
125 $arg = "$arg | \\-no$arg";
128 if ($carg && $carg =~ m/colors/) {
133 } elsif ($carg eq '-move' || $carg eq '-no-move' ||
134 $carg eq '-wander' || $carg eq '-no-wander') {
135 $label = "Whether the object should wander around the screen.";
136 } elsif ($boolp && ($carg eq '-spin' || $carg eq '-no-spin')) {
137 $label = "Whether the object should spin.";
138 } elsif ($carg eq '-spin X') {
139 $carg = '-spin \fI[XYZ]\fP';
141 $label = "Around which axes should the object spin?";
142 } elsif ($carg eq '-fps' || $carg eq '-no-fps') {
143 $label = "Whether to show a frames-per-second display " .
144 "at the bottom of the screen.";
145 } elsif ($carg eq '-wireframe' || $carg eq '-wire') {
146 $label = "Render in wireframe instead of solid.";
147 } elsif ($carg =~ m/^-delay/ && $hi && $hi >= 10000) {
148 $label = "Per-frame delay, in microseconds.";
149 $def = sprintf ("%d (%0.2f seconds.)", $def, ($def/1000000.0));
152 $label .= ". Boolean.";
157 if (m/^<(number|boolean|option)/) {
159 next if (!$arg && m/<option/);
161 print STDERR "$progname: ERROR: no label: $_\n";
165 $args .= "[\\$carg]\n";
167 $label .= " $low - $hi." if (defined($low) && defined($hi));
168 $label .= " Default: $def." if (defined ($def));
169 $label = wrap ("", "", $label);
171 $body .= ".TP 8\n.B \\$arg\n$label";
174 } elsif (m@^<_description>\s*(.*)\s*</_description>@) {
177 print STDERR "$progname: ERROR: UNKNOWN: $_\n";
181 $desc = "Something pretty." unless $desc;
184 if ($desc =~ m@^(.*?)\s*(Written by|By) ([^.]+\.?\s*)$@s) {
187 $author =~ s/\s*[.]\s*$//;
191 print STDERR "$progname: $exe: WARNING: unknown author\n";
195 $desc = wrap ("", "", $desc);
197 $body = (".TH XScreenSaver 1 \"\" \"X Version 11\"\n" .
199 "$exe - screen saver.\n" .
204 ".SH DESCRIPTION\n" .
211 $body =~ s/%AUTHOR%/$author/g;
213 #print $body; exit 0;
216 open (OUT, ">$man") || error ("$man: $!");
217 print OUT $body || error ("$man: $!");
218 close OUT || error ("$man: $!");
219 print STDERR "$progname: wrote $man\n";
225 print STDERR "$progname: $_\n";
230 print STDERR "usage: $progname [--verbose] programs...\n";
236 while ($_ = $ARGV[0]) {
238 if ($_ eq "--verbose") { $verbose++; }
239 elsif (m/^-v+$/) { $verbose += length($_)-1; }
240 elsif (m/^-./) { usage; }
241 else { push @progs, $_; }
244 usage() if ($#progs < 0);
246 foreach (@progs) { xml2man($_); }