summaryrefslogtreecommitdiff
path: root/applets/usage.c
diff options
context:
space:
mode:
authorDenys Vlasenko2010-06-05 23:11:07 +0200
committerDenys Vlasenko2010-06-05 23:11:07 +0200
commit0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e (patch)
tree1f043ab8b4f8e1e57ddaf49e0ddf7677fedf7689 /applets/usage.c
parent729ce473609fbe2aef656e6079d6b8a102962004 (diff)
downloadbusybox-0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e.zip
busybox-0e5ba0843b86a78d2d98a5fbaac8d33fe041f10e.tar.gz
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/usage.c')
-rw-r--r--applets/usage.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/applets/usage.c b/applets/usage.c
index d4fd12f..46adbf4 100644
--- a/applets/usage.c
+++ b/applets/usage.c
@@ -5,9 +5,9 @@
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
-/* 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;
}