6 # collect lines continued with a '\' into an array
16 last unless (/\\\s*$/);
21 # regex && eval away unwanted strings from documentation
26 $text =~ s/SKIP_\w+\(.*?"\s*\)//sxg;
27 $text =~ s/USE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
28 last if ( $text2 eq $text );
31 my @line = split("\n", $text);
38 eval qq[ sprintf(qq{$_}) ]
44 # generate POD for an applet
49 # Sigh. Fixup the known odd-name applets.
50 $name =~ s/dpkg_deb/dpkg-deb/g;
51 $name =~ s/fsck_minix/fsck.minix/g;
52 $name =~ s/mkfs_minix/mkfs.minix/g;
53 $name =~ s/run_parts/run-parts/g;
54 $name =~ s/start_stop_daemon/start-stop-daemon/g;
57 my $trivial = $usage->{trivial};
58 if (!defined $usage->{trivial}) {
61 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
64 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
65 split("\n", (defined $usage->{full} ? $usage->{full} : ""));
67 # add "\n" prior to certain lines to make indented
71 for (my $i = 0; $i < $len; $i++) {
73 if (($i+1) != $len && $f0[$i] !~ /^\s/ && $f0[$i+1] =~ /^\s/) {
74 next if ($f0[$i] =~ /^$/);
75 push(@f1, "") unless ($f0[$i+1] =~ /^\s*$/s);
78 my $full = join("\n", @f1);
80 # prepare notes if they exist
81 my $notes = (defined $usage->{notes})
82 ? "$usage->{notes}\n\n"
85 # prepare examples if they exist
86 my $example = (defined $usage->{example})
91 split("\n", $usage->{example})) . "\n\n"
94 # Pad the name so that the applet name gets a line
95 # by itself in BusyBox.txt
96 my $spaces = 10 - length($name);
98 $name .= " " x $spaces;
103 "\n\n$name $trivial\n\n".
111 # the keys are applet names, and
112 # the values will contain hashrefs of the form:
123 # get command-line options
134 if (defined $opt{help}) {
136 "$0 [OPTION]... [FILE]...\n",
145 # collect documenation into %docs
148 open(USAGE, $_) || die("$0: $_: $!");
150 my ($applet, $type, @line);
152 if (/^#define (\w+)_(\w+)_usage/) {
155 @line = continuation($fh);
156 my $doc = $docs{$applet} ||= { };
157 my $text = join("\n", @line);
158 $doc->{$type} = beautify($text);
164 # generate structured documentation
166 my $generator = \&pod_for_usage;
168 my @names = sort keys %docs;
169 my $line = "\t[, [[, ";
170 for (my $i = 0; $i < $#names; $i++) {
171 if (length ($line.$names[$i]) >= 65) {
175 $line .= "$names[$i], ";
177 print $line . $names[-1];
179 print "\n\n=head1 COMMAND DESCRIPTIONS\n";
180 print "\n=over 4\n\n";
182 foreach my $applet (@names) {
183 print $generator->($applet, $docs{$applet});
192 autodocifier.pl - generate docs for busybox based on usage.h
196 autodocifier.pl [OPTION]... [FILE]...
200 ( cat docs/busybox_header.pod; \
201 docs/autodocifier.pl usage.h; \
202 cat docs/busybox_footer.pod ) > docs/busybox.pod
206 The purpose of this script is to automagically generate
207 documentation for busybox using its usage.h as the original source
208 for content. It used to be that same content has to be duplicated
209 in 3 places in slightly different formats -- F<usage.h>,
210 F<docs/busybox.pod>. This was tedious and error-prone, so it was
211 decided that F<usage.h> would contain all the text in a
212 machine-readable form, and scripts could be used to transform this
213 text into other forms if necessary.
215 F<autodocifier.pl> is one such script. It is based on a script by
216 Erik Andersen <andersen@codepoet.org> which was in turn based on a
217 script by Mark Whitley <markw@codepoet.org>
225 This displays the help message.
229 Generate POD (this is the default)
233 Be verbose (not implemented)
239 The following is an example of some data this script might parse.
241 #define length_trivial_usage \
243 #define length_full_usage \
244 "Prints out the length of the specified STRING."
245 #define length_example_usage \
249 Each entry is a cpp macro that defines a string. The macros are
250 named systematically in the form:
254 $name is the name of the applet. $type can be "trivial", "full", "notes",
255 or "example". Every documentation macro must end with "_usage".
257 The definition of the types is as follows:
263 This should be a brief, one-line description of parameters that
264 the command expects. This will be displayed when B<-h> is issued to
265 a command. I<REQUIRED>
269 This should contain descriptions of each option. This will also
270 be displayed along with the trivial help if CONFIG_FEATURE_TRIVIAL_HELP
271 is disabled. I<REQUIRED>
275 This is documentation that is intended to go in the POD or SGML, but
276 not be printed when a B<-h> is given to a command. To see an example
277 of notes being used, see init_notes_usage in F<usage.h>. I<OPTIONAL>
281 This should be an example of how the command is actually used.
282 This will not be printed when a B<-h> is given to a command -- it
283 will only be included in the POD or SGML documentation. I<OPTIONAL>
293 Copyright (c) 2001 John BEPPU. All rights reserved. This program is
294 free software; you can redistribute it and/or modify it under the same
295 terms as Perl itself.
299 John BEPPU <b@ax9.org>
303 # $Id: autodocifier.pl,v 1.26 2004/04/06 15:26:25 andersen Exp $