aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-02 01:10:32 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-02 01:10:32 +0200
commitacabf8fcb86302e55e01f0a20d5ff9914791416a (patch)
treeb1eff7768689d003f5c72a1ab175b1af52019012
parent3a7034c27b7fa8f3f08e2ace769f165f46afa0e3 (diff)
downloadbusybox-w32-acabf8fcb86302e55e01f0a20d5ff9914791416a.tar.gz
busybox-w32-acabf8fcb86302e55e01f0a20d5ff9914791416a.tar.bz2
busybox-w32-acabf8fcb86302e55e01f0a20d5ff9914791416a.zip
Update documentation generator so that it sucks less
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--Makefile.custom18
-rw-r--r--applets/Kbuild9
-rw-r--r--applets/applet_tables.c21
-rw-r--r--applets/usage.c14
-rw-r--r--applets/usage_pod.c97
-rwxr-xr-xdocs/autodocifier.pl307
-rw-r--r--docs/busybox_header.pod2
7 files changed, 132 insertions, 336 deletions
diff --git a/Makefile.custom b/Makefile.custom
index d9a2367ab..b0ef05627 100644
--- a/Makefile.custom
+++ b/Makefile.custom
@@ -111,15 +111,19 @@ doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
111silent_cmd_doc = 111silent_cmd_doc =
112disp_doc = $($(quiet)cmd_doc) 112disp_doc = $($(quiet)cmd_doc)
113 113
114# sed adds newlines after "Options:" etc,
115# this is needed in order to get good BusyBox.{1,txt,html}
114docs/busybox.pod: $(srctree)/docs/busybox_header.pod \ 116docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
115 $(srctree)/include/usage.h \ 117 $(srctree)/include/usage.h \
116 $(srctree)/docs/busybox_footer.pod \ 118 $(srctree)/docs/busybox_footer.pod \
117 $(srctree)/docs/autodocifier.pl 119 applets/usage_pod
118 $(disp_doc) 120 $(disp_doc)
119 $(Q)-mkdir -p docs 121 $(Q)-mkdir -p docs
120 $(Q)-( cat $(srctree)/docs/busybox_header.pod ; \ 122 $(Q)-( \
121 $(srctree)/docs/autodocifier.pl $(srctree)/include/usage.h ; \ 123 cat $(srctree)/docs/busybox_header.pod; \
122 cat $(srctree)/docs/busybox_footer.pod ; ) > docs/busybox.pod 124 applets/usage_pod | sed 's/^[A-Za-z][A-Za-z ]*[a-z]:$$/&\n/'; \
125 cat $(srctree)/docs/busybox_footer.pod; \
126 ) > docs/busybox.pod
123 127
124docs/BusyBox.txt: docs/busybox.pod 128docs/BusyBox.txt: docs/busybox.pod
125 $(disp_doc) 129 $(disp_doc)
@@ -129,8 +133,7 @@ docs/BusyBox.txt: docs/busybox.pod
129docs/BusyBox.1: docs/busybox.pod 133docs/BusyBox.1: docs/busybox.pod
130 $(disp_doc) 134 $(disp_doc)
131 $(Q)-mkdir -p docs 135 $(Q)-mkdir -p docs
132 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \ 136 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" $< > $@
133 $< > $@
134 137
135docs/BusyBox.html: docs/busybox.net/BusyBox.html 138docs/BusyBox.html: docs/busybox.net/BusyBox.html
136 $(disp_doc) 139 $(disp_doc)
@@ -140,8 +143,7 @@ docs/BusyBox.html: docs/busybox.net/BusyBox.html
140 143
141docs/busybox.net/BusyBox.html: docs/busybox.pod 144docs/busybox.net/BusyBox.html: docs/busybox.pod
142 $(Q)-mkdir -p docs/busybox.net 145 $(Q)-mkdir -p docs/busybox.net
143 $(Q)-pod2html --noindex $< > \ 146 $(Q)-pod2html --noindex $< > $@
144 docs/busybox.net/BusyBox.html
145 $(Q)-rm -f pod2htm* 147 $(Q)-rm -f pod2htm*
146 148
147# documentation, cross-reference 149# documentation, cross-reference
diff --git a/applets/Kbuild b/applets/Kbuild
index 983037987..a966f6e5b 100644
--- a/applets/Kbuild
+++ b/applets/Kbuild
@@ -8,7 +8,7 @@ obj-y :=
8obj-y += applets.o 8obj-y += applets.o
9 9
10hostprogs-y:= 10hostprogs-y:=
11hostprogs-y += usage applet_tables 11hostprogs-y += usage usage_pod applet_tables
12 12
13always:= $(hostprogs-y) 13always:= $(hostprogs-y)
14 14
@@ -22,13 +22,14 @@ else
22srctree_slash = $(srctree)/ 22srctree_slash = $(srctree)/
23endif 23endif
24 24
25 25HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude
26HOSTCFLAGS_usage.o = -I$(srctree_slash)include 26HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude
27 27
28applets/applets.o: include/usage_compressed.h include/applet_tables.h 28applets/applets.o: include/usage_compressed.h include/applet_tables.h
29 29
30applets/usage: .config $(srctree_slash)applets/usage_compressed
31applets/applet_tables: .config 30applets/applet_tables: .config
31applets/usage: .config
32applets/usage_pod: .config include/applet_tables.h
32 33
33quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h 34quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
34 cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets 35 cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
index 17135ddc1..e67f017e7 100644
--- a/applets/applet_tables.c
+++ b/applets/applet_tables.c
@@ -70,29 +70,32 @@ int main(int argc, char **argv)
70 70
71 /* Keep in sync with include/busybox.h! */ 71 /* Keep in sync with include/busybox.h! */
72 72
73 puts("/* This is a generated file, don't edit */\n"); 73 printf("/* This is a generated file, don't edit */\n\n");
74 74
75 printf("#define NUM_APPLETS %u\n", NUM_APPLETS); 75 printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
76 if (NUM_APPLETS == 1) { 76 if (NUM_APPLETS == 1) {
77 printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name); 77 printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
78 printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name); 78 printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
79 } 79 }
80 printf("\n");
80 81
81 puts("\nconst char applet_names[] ALIGN1 = \"\""); 82 printf("const char applet_names[] ALIGN1 = \"\"\n");
82 for (i = 0; i < NUM_APPLETS; i++) { 83 for (i = 0; i < NUM_APPLETS; i++) {
83 printf("\"%s\" \"\\0\"\n", applets[i].name); 84 printf("\"%s\" \"\\0\"\n", applets[i].name);
84 if (MAX_APPLET_NAME_LEN < strlen(applets[i].name)) 85 if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
85 MAX_APPLET_NAME_LEN = strlen(applets[i].name); 86 MAX_APPLET_NAME_LEN = strlen(applets[i].name);
86 } 87 }
87 puts(";"); 88 printf(";\n\n");
88 89
89 puts("\nint (*const applet_main[])(int argc, char **argv) = {"); 90 printf("#ifndef SKIP_applet_main\n");
91 printf("int (*const applet_main[])(int argc, char **argv) = {\n");
90 for (i = 0; i < NUM_APPLETS; i++) { 92 for (i = 0; i < NUM_APPLETS; i++) {
91 printf("%s_main,\n", applets[i].main); 93 printf("%s_main,\n", applets[i].main);
92 } 94 }
93 puts("};"); 95 printf("};\n");
96 printf("#endif\n\n");
94 97
95 puts("const uint16_t applet_nameofs[] ALIGN2 = {"); 98 printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
96 for (i = 0; i < NUM_APPLETS; i++) { 99 for (i = 0; i < NUM_APPLETS; i++) {
97 printf("0x%04x,\n", 100 printf("0x%04x,\n",
98 offset[i] 101 offset[i]
@@ -105,10 +108,10 @@ int main(int argc, char **argv)
105#endif 108#endif
106 ); 109 );
107 } 110 }
108 puts("};"); 111 printf("};\n\n");
109 112
110#if ENABLE_FEATURE_INSTALLER 113#if ENABLE_FEATURE_INSTALLER
111 puts("const uint8_t applet_install_loc[] ALIGN1 = {"); 114 printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
112 i = 0; 115 i = 0;
113 while (i < NUM_APPLETS) { 116 while (i < NUM_APPLETS) {
114 int v = applets[i].install_loc; /* 3 bits */ 117 int v = applets[i].install_loc; /* 3 bits */
@@ -117,7 +120,7 @@ int main(int argc, char **argv)
117 printf("0x%02x,\n", v); 120 printf("0x%02x,\n", v);
118 i++; 121 i++;
119 } 122 }
120 puts("};\n"); 123 printf("};\n\n");
121#endif 124#endif
122 125
123 printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN); 126 printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
diff --git a/applets/usage.c b/applets/usage.c
index 1e038b367..d4fd12f9b 100644
--- a/applets/usage.c
+++ b/applets/usage.c
@@ -8,17 +8,17 @@
8 8
9/* Just #include "autoconf.h" doesn't work for builds in separate 9/* Just #include "autoconf.h" doesn't work for builds in separate
10 * object directory */ 10 * object directory */
11#include "../include/autoconf.h" 11#include "autoconf.h"
12 12
13/* Since we can't use platform.h, have to do this again by hand: */ 13/* Since we can't use platform.h, have to do this again by hand: */
14#if ENABLE_NOMMU 14#if ENABLE_NOMMU
15#define BB_MMU 0 15# define BB_MMU 0
16#define USE_FOR_NOMMU(...) __VA_ARGS__ 16# define USE_FOR_NOMMU(...) __VA_ARGS__
17#define USE_FOR_MMU(...) 17# define USE_FOR_MMU(...)
18#else 18#else
19#define BB_MMU 1 19# define BB_MMU 1
20#define USE_FOR_NOMMU(...) 20# define USE_FOR_NOMMU(...)
21#define USE_FOR_MMU(...) __VA_ARGS__ 21# define USE_FOR_MMU(...) __VA_ARGS__
22#endif 22#endif
23 23
24static const char usage_messages[] = "" 24static const char usage_messages[] = ""
diff --git a/applets/usage_pod.c b/applets/usage_pod.c
new file mode 100644
index 000000000..058e0c842
--- /dev/null
+++ b/applets/usage_pod.c
@@ -0,0 +1,97 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Copyright (C) 2009 Denys Vlasenko.
4 *
5 * Licensed under GPLv2, see file LICENSE in this tarball for details.
6 */
7#include <unistd.h>
8#include <stdint.h>
9#include <string.h>
10#include <stdio.h>
11
12/* Just #include "autoconf.h" doesn't work for builds in separate
13 * object directory */
14#include "autoconf.h"
15
16#define SKIP_applet_main
17#define ALIGN1 /* nothing, just to placate applet_tables.h */
18#define ALIGN2 /* nothing, just to placate applet_tables.h */
19#include "applet_tables.h"
20
21/* Since we can't use platform.h, have to do this again by hand: */
22#if ENABLE_NOMMU
23# define BB_MMU 0
24# define USE_FOR_NOMMU(...) __VA_ARGS__
25# define USE_FOR_MMU(...)
26#else
27# define BB_MMU 1
28# define USE_FOR_NOMMU(...)
29# define USE_FOR_MMU(...) __VA_ARGS__
30#endif
31
32static const char usage_messages[] = ""
33#define MAKE_USAGE
34#include "usage.h"
35#include "applets.h"
36;
37
38int main(void)
39{
40 const char *names;
41 const char *usage;
42 int col, len2;
43
44 col = 0;
45 names = applet_names;
46 while (*names) {
47 len2 = strlen(names) + 2;
48 if (col >= 76 - len2) {
49 printf(",\n");
50 col = 0;
51 }
52 if (col == 0) {
53 col = 6;
54 printf("\t");
55 } else {
56 printf(", ");
57 }
58 printf(names);
59 col += len2;
60 names += len2 - 1;
61 }
62 printf("\n\n");
63
64 printf("=head1 COMMAND DESCRIPTIONS\n\n");
65 printf("=over 4\n\n");
66
67 names = applet_names;
68 usage = usage_messages;
69 while (*names && usage) {
70 if (*names >= 'a' && *names <= 'z'
71 && *usage != NOUSAGE_STR[0]
72 ) {
73 printf("=item B<%s>\n\n", names);
74 printf("%s %s\n\n", names, usage);
75 }
76 names += strlen(names) + 1;
77 usage += strlen(usage) + 1;
78 }
79 return 0;
80}
81
82/* TODO: we used to make options bold with B<> and output an example too:
83
84=item B<cat>
85
86cat [B<-u>] [FILE]...
87
88Concatenate FILE(s) and print them to stdout
89
90Options:
91 -u Use unbuffered i/o (ignored)
92
93Example:
94 $ cat /proc/uptime
95 110716.72 17.67
96
97*/
diff --git a/docs/autodocifier.pl b/docs/autodocifier.pl
deleted file mode 100755
index e3ba5c94b..000000000
--- a/docs/autodocifier.pl
+++ /dev/null
@@ -1,307 +0,0 @@
1#!/usr/bin/perl -w
2# vi: set sw=4 ts=4:
3
4use strict;
5use Getopt::Long;
6
7# collect lines continued with a '\' into an array
8sub continuation {
9 my $fh = shift;
10 my @line;
11
12 while (<$fh>) {
13 my $s = $_;
14 $s =~ s/\\\s*$//;
15 #$s =~ s/#.*$//;
16 push @line, $s;
17 last unless (/\\\s*$/);
18 }
19 return @line;
20}
21
22# regex && eval away unwanted strings from documentation
23sub beautify {
24 my $text = shift;
25 for (;;) {
26 my $text2 = $text;
27 $text =~ s/IF_NOT_\w+\(.*?"\s*\)//sxg;
28 $text =~ s/IF_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
29 $text =~ s/USAGE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
30 last if ( $text2 eq $text );
31 }
32 $text =~ s/"\s*"//sg;
33 my @line = split("\n", $text);
34 $text = join('',
35 map {
36 s/^\s*"//;
37 s/"\s*$//;
38 s/%/%%/g;
39 s/\$/\\\$/g;
40 s/\@/\\\@/g;
41 eval qq[ sprintf(qq{$_}) ]
42 } @line
43 );
44 return $text;
45}
46
47# generate POD for an applet
48sub pod_for_usage {
49 my $name = shift;
50 my $usage = shift;
51
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;
60
61 # make options bold
62 my $trivial = $usage->{trivial};
63 if (!defined $usage->{trivial}) {
64 $trivial = "";
65 } else {
66 $trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
67 }
68 my @f0 =
69 map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
70 split("\n", (defined $usage->{full} ? $usage->{full} : ""));
71
72 # add "\n" prior to certain lines to make indented
73 # lines look right
74 my @f1;
75 my $len = @f0;
76 for (my $i = 0; $i < $len; $i++) {
77 push @f1, $f0[$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);
81 }
82 }
83 my $full = join("\n", @f1);
84
85 # prepare notes if they exist
86 my $notes = (defined $usage->{notes})
87 ? "$usage->{notes}\n\n"
88 : "";
89
90 # prepare examples if they exist
91 my $example = (defined $usage->{example})
92 ?
93 "Example:\n\n" .
94 join ("\n",
95 map { "\t$_" }
96 split("\n", $usage->{example})) . "\n\n"
97 : "";
98
99 # Pad the name so that the applet name gets a line
100 # by itself in BusyBox.txt
101 my $spaces = 10 - length($name);
102 if ($spaces > 0) {
103 $name .= " " x $spaces;
104 }
105
106 return
107 "=item B<$name>".
108 "\n\n$name $trivial\n\n".
109 "$full\n\n" .
110 "$notes" .
111 "$example" .
112 "\n\n"
113 ;
114}
115
116# the keys are applet names, and
117# the values will contain hashrefs of the form:
118#
119# {
120# trivial => "...",
121# full => "...",
122# notes => "...",
123# example => "...",
124# }
125my %docs;
126
127
128# get command-line options
129
130my %opt;
131
132GetOptions(
133 \%opt,
134 "help|h",
135 "pod|p",
136 "verbose|v",
137);
138
139if (defined $opt{help}) {
140 print
141 "$0 [OPTION]... [FILE]...\n",
142 "\t--help\n",
143 "\t--pod\n",
144 "\t--verbose\n",
145 ;
146 exit 1;
147}
148
149
150# collect documenation into %docs
151
152foreach (@ARGV) {
153 open(USAGE, $_) || die("$0: $_: $!");
154 my $fh = *USAGE;
155 my ($applet, $type, @line);
156 while (<$fh>) {
157 if (/^#define (\w+)_(\w+)_usage/) {
158 $applet = $1;
159 $type = $2;
160 @line = continuation($fh);
161 my $doc = $docs{$applet} ||= { };
162 my $text = join("\n", @line);
163 $doc->{$type} = beautify($text);
164 }
165 }
166}
167
168
169# generate structured documentation
170
171my $generator = \&pod_for_usage;
172
173my @names = sort keys %docs;
174my $line = "\t[, [[, ";
175for (my $i = 0; $i < $#names; $i++) {
176 if (length ($line.$names[$i]) >= 65) {
177 print "$line\n\t";
178 $line = "";
179 }
180 $line .= "$names[$i], ";
181}
182print $line . $names[-1];
183
184print "\n\n=head1 COMMAND DESCRIPTIONS\n";
185print "\n=over 4\n\n";
186
187foreach my $applet (@names) {
188 print $generator->($applet, $docs{$applet});
189}
190
191exit 0;
192
193__END__
194
195=head1 NAME
196
197autodocifier.pl - generate docs for busybox based on usage.h
198
199=head1 SYNOPSIS
200
201autodocifier.pl [OPTION]... [FILE]...
202
203Example:
204
205 ( cat docs/busybox_header.pod; \
206 docs/autodocifier.pl usage.h; \
207 cat docs/busybox_footer.pod ) > docs/busybox.pod
208
209=head1 DESCRIPTION
210
211The purpose of this script is to automagically generate
212documentation for busybox using its usage.h as the original source
213for content. It used to be that same content has to be duplicated
214in 3 places in slightly different formats -- F<usage.h>,
215F<docs/busybox.pod>. This was tedious and error-prone, so it was
216decided that F<usage.h> would contain all the text in a
217machine-readable form, and scripts could be used to transform this
218text into other forms if necessary.
219
220F<autodocifier.pl> is one such script. It is based on a script by
221Erik Andersen <andersen@codepoet.org> which was in turn based on a
222script by Mark Whitley <markw@codepoet.org>
223
224=head1 OPTIONS
225
226=over 4
227
228=item B<--help>
229
230This displays the help message.
231
232=item B<--pod>
233
234Generate POD (this is the default)
235
236=item B<--verbose>
237
238Be verbose (not implemented)
239
240=back
241
242=head1 FORMAT
243
244The following is an example of some data this script might parse.
245
246 #define length_trivial_usage \
247 "STRING"
248 #define length_full_usage \
249 "Prints out the length of the specified STRING."
250 #define length_example_usage \
251 "$ length Hello\n" \
252 "5\n"
253
254Each entry is a cpp macro that defines a string. The macros are
255named systematically in the form:
256
257 $name_$type_usage
258
259$name is the name of the applet. $type can be "trivial", "full", "notes",
260or "example". Every documentation macro must end with "_usage".
261
262The definition of the types is as follows:
263
264=over 4
265
266=item B<trivial>
267
268This should be a brief, one-line description of parameters that
269the command expects. This will be displayed when B<-h> is issued to
270a command. I<REQUIRED>
271
272=item B<full>
273
274This should contain descriptions of each option. This will also
275be displayed along with the trivial help if CONFIG_FEATURE_TRIVIAL_HELP
276is disabled. I<REQUIRED>
277
278=item B<notes>
279
280This is documentation that is intended to go in the POD or SGML, but
281not be printed when a B<-h> is given to a command. To see an example
282of notes being used, see init_notes_usage in F<usage.h>. I<OPTIONAL>
283
284=item B<example>
285
286This should be an example of how the command is actually used.
287This will not be printed when a B<-h> is given to a command -- it
288will only be included in the POD or SGML documentation. I<OPTIONAL>
289
290=back
291
292=head1 FILES
293
294F<usage.h>
295
296=head1 COPYRIGHT
297
298Copyright (c) 2001 John BEPPU. All rights reserved. This program is
299free software; you can redistribute it and/or modify it under the same
300terms as Perl itself.
301
302=head1 AUTHOR
303
304John BEPPU <b@ax9.org>
305
306=cut
307
diff --git a/docs/busybox_header.pod b/docs/busybox_header.pod
index 9f2ffc48d..2a99636b1 100644
--- a/docs/busybox_header.pod
+++ b/docs/busybox_header.pod
@@ -8,7 +8,7 @@ BusyBox - The Swiss Army Knife of Embedded Linux
8 8
9 busybox <applet> [arguments...] # or 9 busybox <applet> [arguments...] # or
10 10
11 <applet> [arguments...] # if symlinked 11 <applet> [arguments...] # if symlinked
12 12
13=head1 DESCRIPTION 13=head1 DESCRIPTION
14 14