aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rwxr-xr-xdocs/autodocifier.pl307
-rw-r--r--docs/busybox_header.pod2
2 files changed, 1 insertions, 308 deletions
diff --git a/docs/autodocifier.pl b/docs/autodocifier.pl
deleted file mode 100755
index e3ba5c94b..000000000
--- a/docs/autodocifier.pl
+++ /dev/null
@@ -1,307 +0,0 @@
1#!/usr/bin/perl -w
2# vi: set sw=4 ts=4:
3
4use strict;
5use Getopt::Long;
6
7# collect lines continued with a '\' into an array
8sub continuation {
9 my $fh = shift;
10 my @line;
11
12 while (<$fh>) {
13 my $s = $_;
14 $s =~ s/\\\s*$//;
15 #$s =~ s/#.*$//;
16 push @line, $s;
17 last unless (/\\\s*$/);
18 }
19 return @line;
20}
21
22# regex && eval away unwanted strings from documentation
23sub beautify {
24 my $text = shift;
25 for (;;) {
26 my $text2 = $text;
27 $text =~ s/IF_NOT_\w+\(.*?"\s*\)//sxg;
28 $text =~ s/IF_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
29 $text =~ s/USAGE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
30 last if ( $text2 eq $text );
31 }
32 $text =~ s/"\s*"//sg;
33 my @line = split("\n", $text);
34 $text = join('',
35 map {
36 s/^\s*"//;
37 s/"\s*$//;
38 s/%/%%/g;
39 s/\$/\\\$/g;
40 s/\@/\\\@/g;
41 eval qq[ sprintf(qq{$_}) ]
42 } @line
43 );
44 return $text;
45}
46
47# generate POD for an applet
48sub pod_for_usage {
49 my $name = shift;
50 my $usage = shift;
51
52 # Sigh. Fixup the known odd-name applets.
53# Perhaps we can use some of APPLET_ODDNAME from include/applets.h ?
54 $name =~ s/dpkg_deb/dpkg-deb/g;
55 $name =~ s/fsck_minix/fsck.minix/g;
56 $name =~ s/mkfs_minix/mkfs.minix/g;
57 $name =~ s/run_parts/run-parts/g;
58 $name =~ s/start_stop_daemon/start-stop-daemon/g;
59 $name =~ s/ether_wake/ether-wake/g;
60
61 # make options bold
62 my $trivial = $usage->{trivial};
63 if (!defined $usage->{trivial}) {
64 $trivial = "";
65 } else {
66 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
67 }
68 my @f0 =
69 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
70 split("\n", (defined $usage->{full} ? $usage->{full} : ""));
71
72 # add "\n" prior to certain lines to make indented
73 # lines look right
74 my @f1;
75 my $len = @f0;
76 for (my $i = 0; $i < $len; $i++) {
77 push @f1, $f0[$i];
78 if (($i+1) != $len && $f0[$i] !~ /^\s/ && $f0[$i+1] =~ /^\s/) {
79 next if ($f0[$i] =~ /^$/);
80 push(@f1, "") unless ($f0[$i+1] =~ /^\s*$/s);
81 }
82 }
83 my $full = join("\n", @f1);
84
85 # prepare notes if they exist
86 my $notes = (defined $usage->{notes})
87 ? "$usage->{notes}\n\n"
88 : "";
89
90 # prepare examples if they exist
91 my $example = (defined $usage->{example})
92 ?
93 "Example:\n\n" .
94 join ("\n",
95 map { "\t$_" }
96 split("\n", $usage->{example})) . "\n\n"
97 : "";
98
99 # Pad the name so that the applet name gets a line
100 # by itself in BusyBox.txt
101 my $spaces = 10 - length($name);
102 if ($spaces > 0) {
103 $name .= " " x $spaces;
104 }
105
106 return
107 "=item B<$name>".
108 "\n\n$name $trivial\n\n".
109 "$full\n\n" .
110 "$notes" .
111 "$example" .
112 "\n\n"
113 ;
114}
115
116# the keys are applet names, and
117# the values will contain hashrefs of the form:
118#
119# {
120# trivial => "...",
121# full => "...",
122# notes => "...",
123# example => "...",
124# }
125my %docs;
126
127
128# get command-line options
129
130my %opt;
131
132GetOptions(
133 \%opt,
134 "help|h",
135 "pod|p",
136 "verbose|v",
137);
138
139if (defined $opt{help}) {
140 print
141 "$0 [OPTION]... [FILE]...\n",
142 "\t--help\n",
143 "\t--pod\n",
144 "\t--verbose\n",
145 ;
146 exit 1;
147}
148
149
150# collect documenation into %docs
151
152foreach (@ARGV) {
153 open(USAGE, $_) || die("$0: $_: $!");
154 my $fh = *USAGE;
155 my ($applet, $type, @line);
156 while (<$fh>) {
157 if (/^#define (\w+)_(\w+)_usage/) {
158 $applet = $1;
159 $type = $2;
160 @line = continuation($fh);
161 my $doc = $docs{$applet} ||= { };
162 my $text = join("\n", @line);
163 $doc->{$type} = beautify($text);
164 }
165 }
166}
167
168
169# generate structured documentation
170
171my $generator = \&pod_for_usage;
172
173my @names = sort keys %docs;
174my $line = "\t[, [[, ";
175for (my $i = 0; $i < $#names; $i++) {
176 if (length ($line.$names[$i]) >= 65) {
177 print "$line\n\t";
178 $line = "";
179 }
180 $line .= "$names[$i], ";
181}
182print $line . $names[-1];
183
184print "\n\n=head1 COMMAND DESCRIPTIONS\n";
185print "\n=over 4\n\n";
186
187foreach my $applet (@names) {
188 print $generator->($applet, $docs{$applet});
189}
190
191exit 0;
192
193__END__
194
195=head1 NAME
196
197autodocifier.pl - generate docs for busybox based on usage.h
198
199=head1 SYNOPSIS
200
201autodocifier.pl [OPTION]... [FILE]...
202
203Example:
204
205 ( cat docs/busybox_header.pod; \
206 docs/autodocifier.pl usage.h; \
207 cat docs/busybox_footer.pod ) > docs/busybox.pod
208
209=head1 DESCRIPTION
210
211The purpose of this script is to automagically generate
212documentation for busybox using its usage.h as the original source
213for content. It used to be that same content has to be duplicated
214in 3 places in slightly different formats -- F<usage.h>,
215F<docs/busybox.pod>. This was tedious and error-prone, so it was
216decided that F<usage.h> would contain all the text in a
217machine-readable form, and scripts could be used to transform this
218text into other forms if necessary.
219
220F<autodocifier.pl> is one such script. It is based on a script by
221Erik Andersen <andersen@codepoet.org> which was in turn based on a
222script by Mark Whitley <markw@codepoet.org>
223
224=head1 OPTIONS
225
226=over 4
227
228=item B<--help>
229
230This displays the help message.
231
232=item B<--pod>
233
234Generate POD (this is the default)
235
236=item B<--verbose>
237
238Be verbose (not implemented)
239
240=back
241
242=head1 FORMAT
243
244The following is an example of some data this script might parse.
245
246 #define length_trivial_usage \
247 "STRING"
248 #define length_full_usage \
249 "Prints out the length of the specified STRING."
250 #define length_example_usage \
251 "$ length Hello\n" \
252 "5\n"
253
254Each entry is a cpp macro that defines a string. The macros are
255named systematically in the form:
256
257 $name_$type_usage
258
259$name is the name of the applet. $type can be "trivial", "full", "notes",
260or "example". Every documentation macro must end with "_usage".
261
262The definition of the types is as follows:
263
264=over 4
265
266=item B<trivial>
267
268This should be a brief, one-line description of parameters that
269the command expects. This will be displayed when B<-h> is issued to
270a command. I<REQUIRED>
271
272=item B<full>
273
274This should contain descriptions of each option. This will also
275be displayed along with the trivial help if CONFIG_FEATURE_TRIVIAL_HELP
276is disabled. I<REQUIRED>
277
278=item B<notes>
279
280This is documentation that is intended to go in the POD or SGML, but
281not be printed when a B<-h> is given to a command. To see an example
282of notes being used, see init_notes_usage in F<usage.h>. I<OPTIONAL>
283
284=item B<example>
285
286This should be an example of how the command is actually used.
287This will not be printed when a B<-h> is given to a command -- it
288will only be included in the POD or SGML documentation. I<OPTIONAL>
289
290=back
291
292=head1 FILES
293
294F<usage.h>
295
296=head1 COPYRIGHT
297
298Copyright (c) 2001 John BEPPU. All rights reserved. This program is
299free software; you can redistribute it and/or modify it under the same
300terms as Perl itself.
301
302=head1 AUTHOR
303
304John BEPPU <b@ax9.org>
305
306=cut
307
diff --git a/docs/busybox_header.pod b/docs/busybox_header.pod
index 9f2ffc48d..2a99636b1 100644
--- a/docs/busybox_header.pod
+++ b/docs/busybox_header.pod
@@ -8,7 +8,7 @@ BusyBox - The Swiss Army Knife of Embedded Linux
8 8
9 busybox <applet> [arguments...] # or 9 busybox <applet> [arguments...] # or
10 10
11 <applet> [arguments...] # if symlinked 11 <applet> [arguments...] # if symlinked
12 12
13=head1 DESCRIPTION 13=head1 DESCRIPTION
14 14