diff options
Diffstat (limited to 'applets')
-rw-r--r-- | applets/Kbuild | 9 | ||||
-rw-r--r-- | applets/applet_tables.c | 21 | ||||
-rw-r--r-- | applets/usage.c | 14 | ||||
-rw-r--r-- | applets/usage_pod.c | 97 |
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 := | |||
8 | obj-y += applets.o | 8 | obj-y += applets.o |
9 | 9 | ||
10 | hostprogs-y:= | 10 | hostprogs-y:= |
11 | hostprogs-y += usage applet_tables | 11 | hostprogs-y += usage usage_pod applet_tables |
12 | 12 | ||
13 | always:= $(hostprogs-y) | 13 | always:= $(hostprogs-y) |
14 | 14 | ||
@@ -22,13 +22,14 @@ else | |||
22 | srctree_slash = $(srctree)/ | 22 | srctree_slash = $(srctree)/ |
23 | endif | 23 | endif |
24 | 24 | ||
25 | 25 | HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude | |
26 | HOSTCFLAGS_usage.o = -I$(srctree_slash)include | 26 | HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude |
27 | 27 | ||
28 | applets/applets.o: include/usage_compressed.h include/applet_tables.h | 28 | applets/applets.o: include/usage_compressed.h include/applet_tables.h |
29 | 29 | ||
30 | applets/usage: .config $(srctree_slash)applets/usage_compressed | ||
31 | applets/applet_tables: .config | 30 | applets/applet_tables: .config |
31 | applets/usage: .config | ||
32 | applets/usage_pod: .config include/applet_tables.h | ||
32 | 33 | ||
33 | quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h | 34 | quiet_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 | ||
24 | static const char usage_messages[] = "" | 24 | 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 @@ | |||
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 | |||
32 | static const char usage_messages[] = "" | ||
33 | #define MAKE_USAGE | ||
34 | #include "usage.h" | ||
35 | #include "applets.h" | ||
36 | ; | ||
37 | |||
38 | int 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 | |||
86 | cat [B<-u>] [FILE]... | ||
87 | |||
88 | Concatenate FILE(s) and print them to stdout | ||
89 | |||
90 | Options: | ||
91 | -u Use unbuffered i/o (ignored) | ||
92 | |||
93 | Example: | ||
94 | $ cat /proc/uptime | ||
95 | 110716.72 17.67 | ||
96 | |||
97 | */ | ||