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 /applets | |
| 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>
Diffstat (limited to 'applets')
| -rw-r--r-- | applets/usage.c | 33 | ||||
| -rwxr-xr-x | applets/usage_compressed | 22 | ||||
| -rw-r--r-- | applets/usage_pod.c | 57 |
3 files changed, 75 insertions, 37 deletions
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 | } |
