7 # collect lines continued with a '\' into an array
17 last unless (/\\\s*$/);
22 # regex && eval away unwanted strings from documentation
27 $text =~ s/SKIP_\w+\(.*?"\s*\)//sxg;
28 $text =~ s/USE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
29 $text =~ s/USAGE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
30 last if ( $text2 eq $text );
33 my @line = split("\n", $text);
41 eval qq[ sprintf(qq{$_}) ]
47 # generate POD for an applet
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;
62 my $trivial = $usage->{trivial};
63 if (!defined $usage->{trivial}) {
66 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
69 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
70 split("\n", (defined $usage->{full} ? $usage->{full} : ""));
72 # add "\n" prior to certain lines to make indented
76 for (my $i = 0; $i < $len; $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);
83 my $full = join("\n", @f1);
85 # prepare notes if they exist
86 my $notes = (defined $usage->{notes})
87 ? "$usage->{notes}\n\n"
90 # prepare examples if they exist
91 my $example = (defined $usage->{example})
96 split("\n", $usage->{example})) . "\n\n"
99 # Pad the name so that the applet name gets a line
100 # by itself in BusyBox.txt
101 my $spaces = 10 - length($name);
103 $name .= " " x $spaces;
108 "\n\n$name $trivial\n\n".
116 # the keys are applet names, and
117 # the values will contain hashrefs of the form:
128 # get command-line options
139 if (defined $opt{help}) {
141 "$0 [OPTION]... [FILE]...\n",
150 # collect documenation into %docs
153 open(USAGE, $_) || die("$0: $_: $!");
155 my ($applet, $type, @line);
157 if (/^#define (\w+)_(\w+)_usage/) {
160 @line = continuation($fh);
161 my $doc = $docs{$applet} ||= { };
162 my $text = join("\n", @line);
163 $doc->{$type} = beautify($text);
169 # generate structured documentation
171 my $generator = \&pod_for_usage;
173 my @names = sort keys %docs;
174 my $line = "\t[, [[, ";
175 for (my $i = 0; $i < $#names; $i++) {
176 if (length ($line.$names[$i]) >= 65) {
180 $line .= "$names[$i], ";
182 print $line . $names[-1];
184 print "\n\n=head1 COMMAND DESCRIPTIONS\n";
185 print "\n=over 4\n\n";
187 foreach my $applet (@names) {
188 print $generator->($applet, $docs{$applet});
197 autodocifier.pl - generate docs for busybox based on usage.h
201 autodocifier.pl [OPTION]... [FILE]...
205 ( cat docs/busybox_header.pod; \
206 docs/autodocifier.pl usage.h; \
207 cat docs/busybox_footer.pod ) > docs/busybox.pod
211 The purpose of this script is to automagically generate
212 documentation for busybox using its usage.h as the original source
213 for content. It used to be that same content has to be duplicated
214 in 3 places in slightly different formats -- F<usage.h>,
215 F<docs/busybox.pod>. This was tedious and error-prone, so it was
216 decided that F<usage.h> would contain all the text in a
217 machine-readable form, and scripts could be used to transform this
218 text into other forms if necessary.
220 F<autodocifier.pl> is one such script. It is based on a script by
221 Erik Andersen <andersen@codepoet.org> which was in turn based on a
222 script by Mark Whitley <markw@codepoet.org>
230 This displays the help message.
234 Generate POD (this is the default)
238 Be verbose (not implemented)
244 The following is an example of some data this script might parse.
246 #define length_trivial_usage \
248 #define length_full_usage \
249 "Prints out the length of the specified STRING."
250 #define length_example_usage \
254 Each entry is a cpp macro that defines a string. The macros are
255 named systematically in the form:
259 $name is the name of the applet. $type can be "trivial", "full", "notes",
260 or "example". Every documentation macro must end with "_usage".
262 The definition of the types is as follows:
268 This should be a brief, one-line description of parameters that
269 the command expects. This will be displayed when B<-h> is issued to
270 a command. I<REQUIRED>
274 This should contain descriptions of each option. This will also
275 be displayed along with the trivial help if CONFIG_FEATURE_TRIVIAL_HELP
276 is disabled. I<REQUIRED>
280 This is documentation that is intended to go in the POD or SGML, but
281 not be printed when a B<-h> is given to a command. To see an example
282 of notes being used, see init_notes_usage in F<usage.h>. I<OPTIONAL>
286 This should be an example of how the command is actually used.
287 This will not be printed when a B<-h> is given to a command -- it
288 will only be included in the POD or SGML documentation. I<OPTIONAL>
298 Copyright (c) 2001 John BEPPU. All rights reserved. This program is
299 free software; you can redistribute it and/or modify it under the same
300 terms as Perl itself.
304 John BEPPU <b@ax9.org>