X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=applets%2Fusage.c;h=94520ff66fa581e94e48e8fc2c77836e61b425f4;hb=e32b6503e75d5bcbf8ffff69cafb09523ff2b482;hp=d4fd12f9beb14bf012e01326349c94846b42f937;hpb=acabf8fcb86302e55e01f0a20d5ff9914791416a;p=oweals%2Fbusybox.git diff --git a/applets/usage.c b/applets/usage.c index d4fd12f9b..94520ff66 100644 --- a/applets/usage.c +++ b/applets/usage.c @@ -2,12 +2,12 @@ /* * Copyright (C) 2008 Denys Vlasenko. * - * Licensed under GPLv2, see file LICENSE in this tarball for details. + * Licensed under GPLv2, see file LICENSE in this source tree. */ #include +#include +#include -/* Just #include "autoconf.h" doesn't work for builds in separate - * object directory */ #include "autoconf.h" /* Since we can't use platform.h, have to do this again by hand: */ @@ -21,14 +21,35 @@ # define USE_FOR_MMU(...) __VA_ARGS__ #endif -static const char usage_messages[] = "" -#define MAKE_USAGE #include "usage.h" +#define MAKE_USAGE(aname, usage) { aname, usage }, +static struct usage_data { + const char *aname; + const char *usage; +} usage_array[] = { #include "applets.h" -; +}; + +static int compare_func(const void *a, const void *b) +{ + const struct usage_data *ua = a; + const struct usage_data *ub = b; + return strcmp(ua->aname, ub->aname); +} int main(void) { - write(STDOUT_FILENO, usage_messages, sizeof(usage_messages)); + int i; + int num_messages = sizeof(usage_array) / sizeof(usage_array[0]); + + if (num_messages == 0) + return 0; + + qsort(usage_array, + num_messages, sizeof(usage_array[0]), + compare_func); + for (i = 0; i < num_messages; i++) + write(STDOUT_FILENO, usage_array[i].usage, strlen(usage_array[i].usage) + 1); + return 0; }