aboutsummaryrefslogtreecommitdiff
path: root/applets
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 /applets
parent3a7034c27b7fa8f3f08e2ace769f165f46afa0e3 (diff)
downloadbusybox-acabf8fcb86302e55e01f0a20d5ff9914791416a.tar.gz
Update documentation generator so that it sucks less
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'applets')
-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
4 files changed, 121 insertions, 20 deletions
diff --git a/applets/Kbuild b/applets/Kbuild
index 983037987..a966f6e5b 100644
--- a/applets/Kbuild
+++ b/applets/Kbuild
@@ -8,7 +8,7 @@ obj-y :=
obj-y += applets.o
hostprogs-y:=
-hostprogs-y += usage applet_tables
+hostprogs-y += usage usage_pod applet_tables
always:= $(hostprogs-y)
@@ -22,13 +22,14 @@ else
srctree_slash = $(srctree)/
endif
-
-HOSTCFLAGS_usage.o = -I$(srctree_slash)include
+HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude
+HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude
applets/applets.o: include/usage_compressed.h include/applet_tables.h
-applets/usage: .config $(srctree_slash)applets/usage_compressed
applets/applet_tables: .config
+applets/usage: .config
+applets/usage_pod: .config include/applet_tables.h
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
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)
/* Keep in sync with include/busybox.h! */
- puts("/* This is a generated file, don't edit */\n");
+ printf("/* This is a generated file, don't edit */\n\n");
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
if (NUM_APPLETS == 1) {
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
}
+ printf("\n");
- puts("\nconst char applet_names[] ALIGN1 = \"\"");
+ printf("const char applet_names[] ALIGN1 = \"\"\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("\"%s\" \"\\0\"\n", applets[i].name);
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
}
- puts(";");
+ printf(";\n\n");
- puts("\nint (*const applet_main[])(int argc, char **argv) = {");
+ printf("#ifndef SKIP_applet_main\n");
+ printf("int (*const applet_main[])(int argc, char **argv) = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("%s_main,\n", applets[i].main);
}
- puts("};");
+ printf("};\n");
+ printf("#endif\n\n");
- puts("const uint16_t applet_nameofs[] ALIGN2 = {");
+ printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("0x%04x,\n",
offset[i]
@@ -105,10 +108,10 @@ int main(int argc, char **argv)
#endif
);
}
- puts("};");
+ printf("};\n\n");
#if ENABLE_FEATURE_INSTALLER
- puts("const uint8_t applet_install_loc[] ALIGN1 = {");
+ printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].install_loc; /* 3 bits */
@@ -117,7 +120,7 @@ int main(int argc, char **argv)
printf("0x%02x,\n", v);
i++;
}
- puts("};\n");
+ printf("};\n\n");
#endif
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 @@
/* Just #include "autoconf.h" doesn't work for builds in separate
* object directory */
-#include "../include/autoconf.h"
+#include "autoconf.h"
/* Since we can't use platform.h, have to do this again by hand: */
#if ENABLE_NOMMU
-#define BB_MMU 0
-#define USE_FOR_NOMMU(...) __VA_ARGS__
-#define USE_FOR_MMU(...)
+# define BB_MMU 0
+# define USE_FOR_NOMMU(...) __VA_ARGS__
+# define USE_FOR_MMU(...)
#else
-#define BB_MMU 1
-#define USE_FOR_NOMMU(...)
-#define USE_FOR_MMU(...) __VA_ARGS__
+# define BB_MMU 1
+# define USE_FOR_NOMMU(...)
+# define USE_FOR_MMU(...) __VA_ARGS__
#endif
static 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 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Copyright (C) 2009 Denys Vlasenko.
+ *
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ */
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+/* Just #include "autoconf.h" doesn't work for builds in separate
+ * object directory */
+#include "autoconf.h"
+
+#define SKIP_applet_main
+#define ALIGN1 /* nothing, just to placate applet_tables.h */
+#define ALIGN2 /* nothing, just to placate applet_tables.h */
+#include "applet_tables.h"
+
+/* Since we can't use platform.h, have to do this again by hand: */
+#if ENABLE_NOMMU
+# define BB_MMU 0
+# define USE_FOR_NOMMU(...) __VA_ARGS__
+# define USE_FOR_MMU(...)
+#else
+# define BB_MMU 1
+# define USE_FOR_NOMMU(...)
+# define USE_FOR_MMU(...) __VA_ARGS__
+#endif
+
+static const char usage_messages[] = ""
+#define MAKE_USAGE
+#include "usage.h"
+#include "applets.h"
+;
+
+int main(void)
+{
+ const char *names;
+ const char *usage;
+ int col, len2;
+
+ col = 0;
+ names = applet_names;
+ while (*names) {
+ len2 = strlen(names) + 2;
+ if (col >= 76 - len2) {
+ printf(",\n");
+ col = 0;
+ }
+ if (col == 0) {
+ col = 6;
+ printf("\t");
+ } else {
+ printf(", ");
+ }
+ printf(names);
+ col += len2;
+ names += len2 - 1;
+ }
+ printf("\n\n");
+
+ printf("=head1 COMMAND DESCRIPTIONS\n\n");
+ printf("=over 4\n\n");
+
+ names = applet_names;
+ usage = usage_messages;
+ while (*names && usage) {
+ if (*names >= 'a' && *names <= 'z'
+ && *usage != NOUSAGE_STR[0]
+ ) {
+ printf("=item B<%s>\n\n", names);
+ printf("%s %s\n\n", names, usage);
+ }
+ names += strlen(names) + 1;
+ usage += strlen(usage) + 1;
+ }
+ return 0;
+}
+
+/* TODO: we used to make options bold with B<> and output an example too:
+
+=item B<cat>
+
+cat [B<-u>] [FILE]...
+
+Concatenate FILE(s) and print them to stdout
+
+Options:
+ -u Use unbuffered i/o (ignored)
+
+Example:
+ $ cat /proc/uptime
+ 110716.72 17.67
+
+*/