6 # collect lines continued with a '\' into an array
16 last unless (/\\\s*$/);
21 # regex && eval away unwanted strings from documentation
24 $text =~ s/USAGE_NOT\w+\(.*?"\s*\)//sxg;
25 $text =~ s/USAGE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
27 my @line = split("\n", $text);
34 eval qq[ sprintf(qq{$_}) ]
40 # generate POD for an applet
45 # Sigh. Fixup the known odd-name applets.
46 $name =~ s/dpkg_deb/dpkg-deb/g;
47 $name =~ s/fsck_minix/fsck.minix/g;
48 $name =~ s/mkfs_minix/mkfs.minix/g;
49 $name =~ s/run_parts/run-parts/g;
50 $name =~ s/start_stop_daemon/start-stop-daemon/g;
53 my $trivial = $usage->{trivial};
54 if (!defined $usage->{trivial}) {
57 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
60 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
61 split("\n", (defined $usage->{full} ? $usage->{full} : ""));
63 # add "\n" prior to certain lines to make indented
67 for (my $i = 0; $i < $len; $i++) {
69 if (($i+1) != $len && $f0[$i] !~ /^\s/ && $f0[$i+1] =~ /^\s/) {
70 next if ($f0[$i] =~ /^$/);
71 push(@f1, "") unless ($f0[$i+1] =~ /^\s*$/s);
74 my $full = join("\n", @f1);
76 # prepare notes if they exist
77 my $notes = (defined $usage->{notes})
78 ? "$usage->{notes}\n\n"
81 # prepare examples if they exist
82 my $example = (defined $usage->{example})
87 split("\n", $usage->{example})) . "\n\n"
92 "\n\n$name $trivial\n\n".
100 # the keys are applet names, and
101 # the values will contain hashrefs of the form:
112 # get command-line options
123 if (defined $opt{help}) {
125 "$0 [OPTION]... [FILE]...\n",
134 # collect documenation into %docs
137 open(USAGE, $_) || die("$0: $_: $!");
139 my ($applet, $type, @line);
141 if (/^#define (\w+)_(\w+)_usage/) {
144 @line = continuation($fh);
145 my $doc = $docs{$applet} ||= { };
146 my $text = join("\n", @line);
147 $doc->{$type} = beautify($text);
153 # generate structured documentation
155 my $generator = \&pod_for_usage;
157 my @names = sort keys %docs;
159 for (my $i = 0; $i < $#names; $i++) {
160 if (($i + 2) % 8 == 0) {
163 print "$names[$i], ";
167 print "\n\n=head1 COMMAND DESCRIPTIONS\n";
168 print "\n=over 4\n\n";
170 foreach my $applet (@names) {
171 print $generator->($applet, $docs{$applet});
180 autodocifier.pl - generate docs for busybox based on usage.h
184 autodocifier.pl [OPTION]... [FILE]...
188 ( cat docs/busybox_header.pod; \
189 docs/autodocifier.pl usage.h; \
190 cat docs/busybox_footer.pod ) > docs/busybox.pod
194 The purpose of this script is to automagically generate
195 documentation for busybox using its usage.h as the original source
196 for content. It used to be that same content has to be duplicated
197 in 3 places in slightly different formats -- F<usage.h>,
198 F<docs/busybox.pod>. This was tedious and error-prone, so it was
199 decided that F<usage.h> would contain all the text in a
200 machine-readable form, and scripts could be used to transform this
201 text into other forms if necessary.
203 F<autodocifier.pl> is one such script. It is based on a script by
204 Erik Andersen <andersen@codepoet.org> which was in turn based on a
205 script by Mark Whitley <markw@codepoet.org>
213 This displays the help message.
217 Generate POD (this is the default)
221 Be verbose (not implemented)
227 The following is an example of some data this script might parse.
229 #define length_trivial_usage \
231 #define length_full_usage \
232 "Prints out the length of the specified STRING."
233 #define length_example_usage \
237 Each entry is a cpp macro that defines a string. The macros are
238 named systematically in the form:
242 $name is the name of the applet. $type can be "trivial", "full", "notes",
243 or "example". Every documentation macro must end with "_usage".
245 The definition of the types is as follows:
251 This should be a brief, one-line description of parameters that
252 the command expects. This will be displayed when B<-h> is issued to
253 a command. I<REQUIRED>
257 This should contain descriptions of each option. This will also
258 be displayed along with the trivial help if CONFIG_FEATURE_TRIVIAL_HELP
259 is disabled. I<REQUIRED>
263 This is documentation that is intended to go in the POD or SGML, but
264 not be printed when a B<-h> is given to a command. To see an example
265 of notes being used, see init_notes_usage in F<usage.h>. I<OPTIONAL>
269 This should be an example of how the command is actually used.
270 This will not be printed when a B<-h> is given to a command -- it
271 will only be included in the POD or SGML documentation. I<OPTIONAL>
281 Copyright (c) 2001 John BEPPU. All rights reserved. This program is
282 free software; you can redistribute it and/or modify it under the same
283 terms as Perl itself.
287 John BEPPU <b@ax9.org>
291 # $Id: autodocifier.pl,v 1.26 2004/04/06 15:26:25 andersen Exp $