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
46 my $trivial = $usage->{trivial};
47 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
49 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
50 split("\n", $usage->{full});
52 # add "\n" prior to certain lines to make indented
56 for (my $i = 0; $i < $len; $i++) {
58 if (($i+1) != $len && $f0[$i] !~ /^\s/ && $f0[$i+1] =~ /^\s/) {
59 next if ($f0[$i] =~ /^$/);
60 push(@f1, "") unless ($f0[$i+1] =~ /^\s*$/s);
63 my $full = join("\n", @f1);
65 # prepare notes if they exists
66 my $notes = (defined $usage->{notes})
67 ? "$usage->{notes}\n\n"
70 # prepare example if one exists
71 my $example = (defined $usage->{example})
76 split("\n", $usage->{example})) . "\n\n"
88 "-------------------------------".
93 # FIXME | generate SGML for an applet
104 # the keys are applet names, and
105 # the values will contain hashrefs of the form:
115 # get command-line options
127 if (defined $opt{help}) {
129 "$0 [OPTION]... [FILE]...\n",
139 # collect documenation into %docs
142 open(USAGE, $_) || die("$0: $_: $!");
144 my ($applet, $type, @line);
146 if (/^#define (\w+)_(\w+)_usage/) {
149 @line = continuation($fh);
150 my $doc = $docs{$applet} ||= { };
151 my $text = join("\n", @line);
152 $doc->{$type} = beautify($text);
158 # generate structured documentation
160 my $generator = \&pod_for_usage;
161 if (defined $opt{sgml}) {
162 $generator = \&sgml_for_usage;
165 foreach my $applet (sort keys %docs) {
166 print $generator->($applet, $docs{$applet});
175 autodocifier.pl - generate docs for busybox based on usage.h
179 autodocifier.pl usage.h > something
183 The purpose of this script is to automagically generate documentation
184 for busybox using its usage.h as the original source for content.
185 Currently, the same content has to be duplicated in 3 places in
186 slightly different formats -- F<usage.h>, F<docs/busybox.pod>, and
187 F<docs/busybox.sgml>. This is tedious, so Perl has come to the rescue.
189 This script was based on a script by Erik Andersen (andersen@lineo.com).
197 This displays the help message.
201 Generate POD (this is the default)
209 Be verbose (not implemented)
215 The following is an example of some data this script might parse.
217 #define length_trivial_usage \
219 #define length_full_usage \
220 "Prints out the length of the specified STRING."
221 #define length_example_usage \
222 "$ length "Hello"\n" \
225 Each entry is a cpp macro that defines a string. The macros are
226 named systematically in the form:
230 $name is the name of the applet. $type can be "trivial", "full", "notes",
231 or "example". Every documentation macro must end with "_usage".
233 The definition of the types is as follows:
239 This should be a brief, one-line description of parameters that
240 the command expects. This will be displayed when B<-h> is issued to
241 a command. I<REQUIRED>
245 This should contain descriptions of each option. This will also
246 be displayed along with the trivial help if BB_FEATURE_TRIVIAL_HELP
247 is disabled. I<REQUIRED>
251 This is documentation that is intended to go in the POD or SGML, but
252 not be output when a B<-h> is given to a command. To see an example
253 of notes being used, see init_notes_usage. I<OPTIONAL>
257 This should be an example of how the command is acutally used.
268 Copyright (c) 2001 John BEPPU. All rights reserved. This program is
269 free software; you can redistribute it and/or modify it under the same
270 terms as Perl itself.
274 John BEPPU <beppu@lineo.com>
278 # $Id: autodocifier.pl,v 1.18 2001/04/05 19:35:17 beppu Exp $