diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-05 23:11:07 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-05 23:11:07 +0200 |
| commit | 0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e (patch) | |
| tree | 1f043ab8b4f8e1e57ddaf49e0ddf7677fedf7689 | |
| parent | 729ce473609fbe2aef656e6079d6b8a102962004 (diff) | |
| download | busybox-w32-0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e.tar.gz busybox-w32-0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e.tar.bz2 busybox-w32-0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e.zip | |
Remove requirement that include/applets.h must be sorted
First, I _again_ violated it - two xz-related applets are in wrong positions.
Second, planned in-applet help text thing will be so much easier without
this requirement...
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | Config.in | 2 | ||||
| -rw-r--r-- | applets/usage.c | 33 | ||||
| -rwxr-xr-x | applets/usage_compressed | 22 | ||||
| -rw-r--r-- | applets/usage_pod.c | 57 | ||||
| -rw-r--r-- | include/applets.h | 21 | ||||
| -rw-r--r-- | libbb/appletlib.c | 43 |
6 files changed, 103 insertions, 75 deletions
| @@ -83,7 +83,7 @@ config SHOW_USAGE | |||
| 83 | config FEATURE_VERBOSE_USAGE | 83 | config FEATURE_VERBOSE_USAGE |
| 84 | bool "Show verbose applet usage messages" | 84 | bool "Show verbose applet usage messages" |
| 85 | default n | 85 | default n |
| 86 | select SHOW_USAGE | 86 | depends on SHOW_USAGE |
| 87 | help | 87 | help |
| 88 | All BusyBox applets will show more verbose help messages when | 88 | All BusyBox applets will show more verbose help messages when |
| 89 | busybox is invoked with --help. This will add a lot of text to the | 89 | busybox is invoked with --help. This will add a lot of text to the |
diff --git a/applets/usage.c b/applets/usage.c index d4fd12f9b..46adbf475 100644 --- a/applets/usage.c +++ b/applets/usage.c | |||
| @@ -5,9 +5,9 @@ | |||
| 5 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | 5 | * Licensed under GPLv2, see file LICENSE in this tarball for details. |
| 6 | */ | 6 | */ |
| 7 | #include <unistd.h> | 7 | #include <unistd.h> |
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | ||
| 8 | 10 | ||
| 9 | /* Just #include "autoconf.h" doesn't work for builds in separate | ||
| 10 | * object directory */ | ||
| 11 | #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: */ |
| @@ -21,14 +21,35 @@ | |||
| 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[] = "" | ||
| 25 | #define MAKE_USAGE | ||
| 26 | #include "usage.h" | 24 | #include "usage.h" |
| 25 | #define MAKE_USAGE(aname, usage) { aname, usage }, | ||
| 26 | static struct usage_data { | ||
| 27 | const char *aname; | ||
| 28 | const char *usage; | ||
| 29 | } usage_array[] = { | ||
| 27 | #include "applets.h" | 30 | #include "applets.h" |
| 28 | ; | 31 | }; |
| 32 | |||
| 33 | static int compare_func(const void *a, const void *b) | ||
| 34 | { | ||
| 35 | const struct usage_data *ua = a; | ||
| 36 | const struct usage_data *ub = b; | ||
| 37 | return strcmp(ua->aname, ub->aname); | ||
| 38 | } | ||
| 29 | 39 | ||
| 30 | int main(void) | 40 | int main(void) |
| 31 | { | 41 | { |
| 32 | write(STDOUT_FILENO, usage_messages, sizeof(usage_messages)); | 42 | int i; |
| 43 | int num_messages = sizeof(usage_array) / sizeof(usage_array[0]); | ||
| 44 | |||
| 45 | if (num_messages == 0) | ||
| 46 | return 0; | ||
| 47 | |||
| 48 | qsort(usage_array, | ||
| 49 | num_messages, sizeof(usage_array[0]), | ||
| 50 | compare_func); | ||
| 51 | for (i = 0; i < num_messages; i++) | ||
| 52 | write(STDOUT_FILENO, usage_array[i].usage, strlen(usage_array[i].usage) + 1); | ||
| 53 | |||
| 33 | return 0; | 54 | return 0; |
| 34 | } | 55 | } |
diff --git a/applets/usage_compressed b/applets/usage_compressed index 8d343529d..12efd2c9c 100755 --- a/applets/usage_compressed +++ b/applets/usage_compressed | |||
| @@ -9,12 +9,19 @@ test -x "$loc/usage" || exit 1 | |||
| 9 | test "$SED" || SED=sed | 9 | test "$SED" || SED=sed |
| 10 | test "$DD" || DD=dd | 10 | test "$DD" || DD=dd |
| 11 | 11 | ||
| 12 | sz=`"$loc/usage" | wc -c` || exit 1 | ||
| 13 | |||
| 14 | exec >"$target" | 12 | exec >"$target" |
| 15 | 13 | ||
| 16 | echo 'static const char packed_usage[] ALIGN1 = {' | 14 | echo '#define UNPACKED_USAGE \' |
| 15 | "$loc/usage" | od -v -t x1 \ | ||
| 16 | | $SED -e 's/^[^ ]*//' \ | ||
| 17 | -e 's/ //g' \ | ||
| 18 | -e '/^$/d' \ | ||
| 19 | -e 's/\(..\)/\\x\1/g' \ | ||
| 20 | -e 's/^/"/' \ | ||
| 21 | -e 's/$/" \\/' | ||
| 22 | echo '' | ||
| 17 | 23 | ||
| 24 | echo '#define PACKED_USAGE \' | ||
| 18 | ## Breaks on big-endian systems! | 25 | ## Breaks on big-endian systems! |
| 19 | ## # Extra effort to avoid using "od -t x1": -t is not available | 26 | ## # Extra effort to avoid using "od -t x1": -t is not available |
| 20 | ## # in non-CONFIG_DESKTOPed busybox od | 27 | ## # in non-CONFIG_DESKTOPed busybox od |
| @@ -24,12 +31,11 @@ echo 'static const char packed_usage[] ALIGN1 = {' | |||
| 24 | ## -e 's/ //g' \ | 31 | ## -e 's/ //g' \ |
| 25 | ## -e '/^$/d' \ | 32 | ## -e '/^$/d' \ |
| 26 | ## -e 's/\(..\)\(..\)/0x\2,0x\1,/g' | 33 | ## -e 's/\(..\)\(..\)/0x\2,0x\1,/g' |
| 27 | 34 | ## -e 's/$/ \\/' | |
| 28 | "$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \ | 35 | "$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \ |
| 29 | | $SED -e 's/^[^ ]*//' \ | 36 | | $SED -e 's/^[^ ]*//' \ |
| 30 | -e 's/ //g' \ | 37 | -e 's/ //g' \ |
| 31 | -e '/^$/d' \ | 38 | -e '/^$/d' \ |
| 32 | -e 's/\(..\)/0x\1,/g' | 39 | -e 's/\(..\)/0x\1,/g' \ |
| 33 | 40 | -e 's/$/ \\/' | |
| 34 | echo '};' | 41 | echo '' |
| 35 | echo '#define SIZEOF_usage_messages' `expr 0 + $sz` | ||
diff --git a/applets/usage_pod.c b/applets/usage_pod.c index ee3729d7b..85a2a8ec4 100644 --- a/applets/usage_pod.c +++ b/applets/usage_pod.c | |||
| @@ -6,11 +6,10 @@ | |||
| 6 | */ | 6 | */ |
| 7 | #include <unistd.h> | 7 | #include <unistd.h> |
| 8 | #include <stdint.h> | 8 | #include <stdint.h> |
| 9 | #include <stdlib.h> | ||
| 9 | #include <string.h> | 10 | #include <string.h> |
| 10 | #include <stdio.h> | 11 | #include <stdio.h> |
| 11 | 12 | ||
| 12 | /* Just #include "autoconf.h" doesn't work for builds in separate | ||
| 13 | * object directory */ | ||
| 14 | #include "autoconf.h" | 13 | #include "autoconf.h" |
| 15 | 14 | ||
| 16 | #define SKIP_applet_main | 15 | #define SKIP_applet_main |
| @@ -29,22 +28,39 @@ | |||
| 29 | # define USE_FOR_MMU(...) __VA_ARGS__ | 28 | # define USE_FOR_MMU(...) __VA_ARGS__ |
| 30 | #endif | 29 | #endif |
| 31 | 30 | ||
| 32 | static const char usage_messages[] = "" | ||
| 33 | #define MAKE_USAGE | ||
| 34 | #include "usage.h" | 31 | #include "usage.h" |
| 32 | #define MAKE_USAGE(aname, usage) { aname, usage }, | ||
| 33 | static struct usage_data { | ||
| 34 | const char *aname; | ||
| 35 | const char *usage; | ||
| 36 | } usage_array[] = { | ||
| 35 | #include "applets.h" | 37 | #include "applets.h" |
| 36 | ; | 38 | }; |
| 39 | |||
| 40 | static int compare_func(const void *a, const void *b) | ||
| 41 | { | ||
| 42 | const struct usage_data *ua = a; | ||
| 43 | const struct usage_data *ub = b; | ||
| 44 | return strcmp(ua->aname, ub->aname); | ||
| 45 | } | ||
| 37 | 46 | ||
| 38 | int main(void) | 47 | int main(void) |
| 39 | { | 48 | { |
| 40 | const char *names; | ||
| 41 | const char *usage; | ||
| 42 | int col, len2; | 49 | int col, len2; |
| 43 | 50 | ||
| 51 | int i; | ||
| 52 | int num_messages = sizeof(usage_array) / sizeof(usage_array[0]); | ||
| 53 | |||
| 54 | if (num_messages == 0) | ||
| 55 | return 0; | ||
| 56 | |||
| 57 | qsort(usage_array, | ||
| 58 | num_messages, sizeof(usage_array[0]), | ||
| 59 | compare_func); | ||
| 60 | |||
| 44 | col = 0; | 61 | col = 0; |
| 45 | names = applet_names; | 62 | for (i = 0; i < num_messages; i++) { |
| 46 | while (*names) { | 63 | len2 = strlen(usage_array[i].aname) + 2; |
| 47 | len2 = strlen(names) + 2; | ||
| 48 | if (col >= 76 - len2) { | 64 | if (col >= 76 - len2) { |
| 49 | printf(",\n"); | 65 | printf(",\n"); |
| 50 | col = 0; | 66 | col = 0; |
| @@ -55,29 +71,24 @@ int main(void) | |||
| 55 | } else { | 71 | } else { |
| 56 | printf(", "); | 72 | printf(", "); |
| 57 | } | 73 | } |
| 58 | printf(names); | 74 | printf(usage_array[i].aname); |
| 59 | col += len2; | 75 | col += len2; |
| 60 | names += len2 - 1; | ||
| 61 | } | 76 | } |
| 62 | printf("\n\n"); | 77 | printf("\n\n"); |
| 63 | 78 | ||
| 64 | printf("=head1 COMMAND DESCRIPTIONS\n\n"); | 79 | printf("=head1 COMMAND DESCRIPTIONS\n\n"); |
| 65 | printf("=over 4\n\n"); | 80 | printf("=over 4\n\n"); |
| 66 | 81 | ||
| 67 | names = applet_names; | 82 | for (i = 0; i < num_messages; i++) { |
| 68 | usage = usage_messages; | 83 | if (usage_array[i].aname[0] >= 'a' && usage_array[i].aname[0] <= 'z' |
| 69 | while (*names) { | 84 | && usage_array[i].usage[0] != NOUSAGE_STR[0] |
| 70 | if (*names >= 'a' && *names <= 'z' | ||
| 71 | && *usage != NOUSAGE_STR[0] | ||
| 72 | ) { | 85 | ) { |
| 73 | printf("=item B<%s>\n\n", names); | 86 | printf("=item B<%s>\n\n", usage_array[i].aname); |
| 74 | if (*usage) | 87 | if (usage_array[i].usage[0]) |
| 75 | printf("%s %s\n\n", names, usage); | 88 | printf("%s %s\n\n", usage_array[i].aname, usage_array[i].usage); |
| 76 | else | 89 | else |
| 77 | printf("%s\n\n", names); | 90 | printf("%s\n\n", usage_array[i].aname); |
| 78 | } | 91 | } |
| 79 | names += strlen(names) + 1; | ||
| 80 | usage += strlen(usage) + 1; | ||
| 81 | } | 92 | } |
| 82 | return 0; | 93 | return 0; |
| 83 | } | 94 | } |
diff --git a/include/applets.h b/include/applets.h index d8a706b44..cf8de8eb6 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -4,11 +4,6 @@ | |||
| 4 | * | 4 | * |
| 5 | * If you write a new applet, you need to add an entry to this list to make | 5 | * If you write a new applet, you need to add an entry to this list to make |
| 6 | * busybox aware of it. | 6 | * busybox aware of it. |
| 7 | * | ||
| 8 | * It is CRUCIAL that this listing be kept in ascii order, otherwise the binary | ||
| 9 | * search lookup contributed by Gaute B Strokkenes stops working. If you value | ||
| 10 | * your kneecaps, you'll be sure to *make sure* that any changes made to this | ||
| 11 | * file result in the listing remaining in ascii order. You have been warned. | ||
| 12 | */ | 7 | */ |
| 13 | 8 | ||
| 14 | /* | 9 | /* |
| @@ -36,16 +31,16 @@ s - suid type: | |||
| 36 | # define APPLET_NOFORK(name,main,l,s,name2) name main##_main name2 | 31 | # define APPLET_NOFORK(name,main,l,s,name2) name main##_main name2 |
| 37 | 32 | ||
| 38 | #elif defined(MAKE_USAGE) && ENABLE_FEATURE_VERBOSE_USAGE | 33 | #elif defined(MAKE_USAGE) && ENABLE_FEATURE_VERBOSE_USAGE |
| 39 | # define APPLET(name,l,s) name##_trivial_usage name##_full_usage "\0" | 34 | # define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage name##_full_usage) |
| 40 | # define APPLET_ODDNAME(name,main,l,s,name2) name2##_trivial_usage name2##_full_usage "\0" | 35 | # define APPLET_ODDNAME(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage) |
| 41 | # define APPLET_NOEXEC(name,main,l,s,name2) name2##_trivial_usage name2##_full_usage "\0" | 36 | # define APPLET_NOEXEC(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage) |
| 42 | # define APPLET_NOFORK(name,main,l,s,name2) name2##_trivial_usage name2##_full_usage "\0" | 37 | # define APPLET_NOFORK(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage) |
| 43 | 38 | ||
| 44 | #elif defined(MAKE_USAGE) && !ENABLE_FEATURE_VERBOSE_USAGE | 39 | #elif defined(MAKE_USAGE) && !ENABLE_FEATURE_VERBOSE_USAGE |
| 45 | # define APPLET(name,l,s) name##_trivial_usage "\0" | 40 | # define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage) |
| 46 | # define APPLET_ODDNAME(name,main,l,s,name2) name2##_trivial_usage "\0" | 41 | # define APPLET_ODDNAME(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage) |
| 47 | # define APPLET_NOEXEC(name,main,l,s,name2) name2##_trivial_usage "\0" | 42 | # define APPLET_NOEXEC(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage) |
| 48 | # define APPLET_NOFORK(name,main,l,s,name2) name2##_trivial_usage "\0" | 43 | # define APPLET_NOFORK(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage) |
| 49 | 44 | ||
| 50 | #elif defined(MAKE_LINKS) | 45 | #elif defined(MAKE_LINKS) |
| 51 | # define APPLET(name,l,c) LINK l name | 46 | # define APPLET(name,l,c) LINK l name |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index a8cd8e65f..6267f2673 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
| @@ -43,35 +43,30 @@ | |||
| 43 | #include "applets.h" | 43 | #include "applets.h" |
| 44 | #undef PROTOTYPES | 44 | #undef PROTOTYPES |
| 45 | 45 | ||
| 46 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE | ||
| 47 | /* Define usage_messages[] */ | ||
| 48 | static const char usage_messages[] ALIGN1 = "" | ||
| 49 | # define MAKE_USAGE | ||
| 50 | # include "usage.h" | ||
| 51 | # include "applets.h" | ||
| 52 | ; | ||
| 53 | # undef MAKE_USAGE | ||
| 54 | #else | ||
| 55 | # define usage_messages 0 | ||
| 56 | #endif /* SHOW_USAGE */ | ||
| 57 | |||
| 58 | 46 | ||
| 59 | /* Include generated applet names, pointers to <applet>_main, etc */ | 47 | /* Include generated applet names, pointers to <applet>_main, etc */ |
| 60 | #include "applet_tables.h" | 48 | #include "applet_tables.h" |
| 61 | /* ...and if applet_tables generator says we have only one applet... */ | 49 | /* ...and if applet_tables generator says we have only one applet... */ |
| 62 | #ifdef SINGLE_APPLET_MAIN | 50 | #ifdef SINGLE_APPLET_MAIN |
| 63 | #undef ENABLE_FEATURE_INDIVIDUAL | 51 | # undef ENABLE_FEATURE_INDIVIDUAL |
| 64 | #define ENABLE_FEATURE_INDIVIDUAL 1 | 52 | # define ENABLE_FEATURE_INDIVIDUAL 1 |
| 65 | #undef IF_FEATURE_INDIVIDUAL | 53 | # undef IF_FEATURE_INDIVIDUAL |
| 66 | #define IF_FEATURE_INDIVIDUAL(...) __VA_ARGS__ | 54 | # define IF_FEATURE_INDIVIDUAL(...) __VA_ARGS__ |
| 67 | #endif | 55 | #endif |
| 68 | 56 | ||
| 69 | 57 | ||
| 70 | #if ENABLE_FEATURE_COMPRESS_USAGE | ||
| 71 | |||
| 72 | #include "usage_compressed.h" | 58 | #include "usage_compressed.h" |
| 73 | #include "unarchive.h" | ||
| 74 | 59 | ||
| 60 | #if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE | ||
| 61 | static const char usage_messages[] ALIGN1 = UNPACKED_USAGE; | ||
| 62 | #else | ||
| 63 | # define usage_messages 0 | ||
| 64 | #endif /* SHOW_USAGE */ | ||
| 65 | |||
| 66 | #if ENABLE_FEATURE_COMPRESS_USAGE | ||
| 67 | |||
| 68 | static const char packed_usage[] = { PACKED_USAGE }; | ||
| 69 | # include "unarchive.h" | ||
| 75 | static const char *unpack_usage_messages(void) | 70 | static const char *unpack_usage_messages(void) |
| 76 | { | 71 | { |
| 77 | char *outbuf = NULL; | 72 | char *outbuf = NULL; |
| @@ -86,19 +81,19 @@ static const char *unpack_usage_messages(void) | |||
| 86 | * end up here with i != 0 on read data errors! Not trivial */ | 81 | * end up here with i != 0 on read data errors! Not trivial */ |
| 87 | if (!i) { | 82 | if (!i) { |
| 88 | /* Cannot use xmalloc: will leak bd in NOFORK case! */ | 83 | /* Cannot use xmalloc: will leak bd in NOFORK case! */ |
| 89 | outbuf = malloc_or_warn(SIZEOF_usage_messages); | 84 | outbuf = malloc_or_warn(sizeof(UNPACKED_USAGE)); |
| 90 | if (outbuf) | 85 | if (outbuf) |
| 91 | read_bunzip(bd, outbuf, SIZEOF_usage_messages); | 86 | read_bunzip(bd, outbuf, sizeof(UNPACKED_USAGE)); |
| 92 | } | 87 | } |
| 93 | dealloc_bunzip(bd); | 88 | dealloc_bunzip(bd); |
| 94 | return outbuf; | 89 | return outbuf; |
| 95 | } | 90 | } |
| 96 | #define dealloc_usage_messages(s) free(s) | 91 | # define dealloc_usage_messages(s) free(s) |
| 97 | 92 | ||
| 98 | #else | 93 | #else |
| 99 | 94 | ||
| 100 | #define unpack_usage_messages() usage_messages | 95 | # define unpack_usage_messages() usage_messages |
| 101 | #define dealloc_usage_messages(s) ((void)(s)) | 96 | # define dealloc_usage_messages(s) ((void)(s)) |
| 102 | 97 | ||
| 103 | #endif /* FEATURE_COMPRESS_USAGE */ | 98 | #endif /* FEATURE_COMPRESS_USAGE */ |
| 104 | 99 | ||
