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 $text =~ s/USAGE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
29 last if ( $text2 eq $text );
32 my @line = split("\n", $text);
39 eval qq[ sprintf(qq{$_}) ]
45 # generate POD for an applet
50 # Sigh. Fixup the known odd-name applets.
51 $name =~ s/dpkg_deb/dpkg-deb/g;
52 $name =~ s/fsck_minix/fsck.minix/g;
53 $name =~ s/mkfs_minix/mkfs.minix/g;
54 $name =~ s/run_parts/run-parts/g;
55 $name =~ s/start_stop_daemon/start-stop-daemon/g;
58 my $trivial = $usage->{trivial};
59 if (!defined $usage->{trivial}) {
62 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
65 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
66 split("\n", (defined $usage->{full} ? $usage->{full} : ""));
68 # add "\n" prior to certain lines to make indented
72 for (my $i = 0; $i < $len; $i++) {
74 if (($i+1) != $len && $f0[$i] !~ /^\s/ && $f0[$i+1] =~ /^\s/) {
75 next if ($f0[$i] =~ /^$/);
76 push(@f1, "") unless ($f0[$i+1] =~ /^\s*$/s);
79 my $full = join("\n", @f1);
81 # prepare notes if they exist
82 my $notes = (defined $usage->{notes})
83 ? "$usage->{notes}\n\n"
86 # prepare examples if they exist
87 my $example = (defined $usage->{example})
92 split("\n", $usage->{example})) . "\n\n"
95 # Pad the name so that the applet name gets a line
96 # by itself in BusyBox.txt
97 my $spaces = 10 - length($name);
99 $name .= " " x $spaces;
104 "\n\n$name $trivial\n\n".
112 # the keys are applet names, and
113 # the values will contain hashrefs of the form:
124 # get command-line options
135 if (defined $opt{help}) {
137 "$0 [OPTION]... [FILE]...\n",
146 # collect documenation into %docs
149 open(USAGE, $_) || die("$0: $_: $!");
151 my ($applet, $type, @line);
153 if (/^#define (\w+)_(\w+)_usage/) {
156 @line = continuation($fh);
157 my $doc = $docs{$applet} ||= { };
158 my $text = join("\n", @line);
159 $doc->{$type} = beautify($text);
165 # generate structured documentation
167 my $generator = \&pod_for_usage;
169 my @names = sort keys %docs;
170 my $line = "\t[, [[, ";
171 for (my $i = 0; $i < $#names; $i++) {
172 if (length ($line.$names[$i]) >= 65) {
176 $line .= "$names[$i], ";
178 print $line . $names[-1];
180 print "\n\n=head1 COMMAND DESCRIPTIONS\n";
181 print "\n=over 4\n\n";
183 foreach my $applet (@names) {
184 print $generator->($applet, $docs{$applet});
193 autodocifier.pl - generate docs for busybox based on usage.h
197 autodocifier.pl [OPTION]... [FILE]...
201 ( cat docs/busybox_header.pod; \
202 docs/autodocifier.pl usage.h; \
203 cat docs/busybox_footer.pod ) > docs/busybox.pod
207 The purpose of this script is to automagically generate
208 documentation for busybox using its usage.h as the original source
209 for content. It used to be that same content has to be duplicated
210 in 3 places in slightly different formats -- F<usage.h>,
211 F<docs/busybox.pod>. This was tedious and error-prone, so it was
212 decided that F<usage.h> would contain all the text in a
213 machine-readable form, and scripts could be used to transform this
214 text into other forms if necessary.
216 F<autodocifier.pl> is one such script. It is based on a script by
217 Erik Andersen <andersen@codepoet.org> which was in turn based on a
218 script by Mark Whitley <markw@codepoet.org>
226 This displays the help message.
230 Generate POD (this is the default)
234 Be verbose (not implemented)
240 The following is an example of some data this script might parse.
242 #define length_trivial_usage \
244 #define length_full_usage \
245 "Prints out the length of the specified STRING."
246 #define length_example_usage \
250 Each entry is a cpp macro that defines a string. The macros are
251 named systematically in the form:
255 $name is the name of the applet. $type can be "trivial", "full", "notes",
256 or "example". Every documentation macro must end with "_usage".
258 The definition of the types is as follows:
264 This should be a brief, one-line description of parameters that
265 the command expects. This will be displayed when B<-h> is issued to
266 a command. I<REQUIRED>
270 This should contain descriptions of each option. This will also
271 be displayed along with the trivial help if CONFIG_FEATURE_TRIVIAL_HELP
272 is disabled. I<REQUIRED>
276 This is documentation that is intended to go in the POD or SGML, but
277 not be printed when a B<-h> is given to a command. To see an example
278 of notes being used, see init_notes_usage in F<usage.h>. I<OPTIONAL>
282 This should be an example of how the command is actually used.
283 This will not be printed when a B<-h> is given to a command -- it
284 will only be included in the POD or SGML documentation. I<OPTIONAL>
294 Copyright (c) 2001 John BEPPU. All rights reserved. This program is
295 free software; you can redistribute it and/or modify it under the same
296 terms as Perl itself.
300 John BEPPU <b@ax9.org>