Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 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> |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 9 | #include <stdlib.h> |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 10 | #include <string.h> |
| 11 | #include <stdio.h> |
| 12 | |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 13 | #include "autoconf.h" |
| 14 | |
| 15 | #define SKIP_applet_main |
| 16 | #define ALIGN1 /* nothing, just to placate applet_tables.h */ |
| 17 | #define ALIGN2 /* nothing, just to placate applet_tables.h */ |
| 18 | #include "applet_tables.h" |
| 19 | |
| 20 | /* Since we can't use platform.h, have to do this again by hand: */ |
| 21 | #if ENABLE_NOMMU |
| 22 | # define BB_MMU 0 |
| 23 | # define USE_FOR_NOMMU(...) __VA_ARGS__ |
| 24 | # define USE_FOR_MMU(...) |
| 25 | #else |
| 26 | # define BB_MMU 1 |
| 27 | # define USE_FOR_NOMMU(...) |
| 28 | # define USE_FOR_MMU(...) __VA_ARGS__ |
| 29 | #endif |
| 30 | |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 31 | #include "usage.h" |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 32 | #define MAKE_USAGE(aname, usage) { aname, usage }, |
| 33 | static struct usage_data { |
| 34 | const char *aname; |
| 35 | const char *usage; |
| 36 | } usage_array[] = { |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 37 | #include "applets.h" |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 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 | } |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 46 | |
| 47 | int main(void) |
| 48 | { |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 49 | int col, len2; |
| 50 | |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 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 | |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 61 | col = 0; |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 62 | for (i = 0; i < num_messages; i++) { |
| 63 | len2 = strlen(usage_array[i].aname) + 2; |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 64 | if (col >= 76 - len2) { |
| 65 | printf(",\n"); |
| 66 | col = 0; |
| 67 | } |
| 68 | if (col == 0) { |
| 69 | col = 6; |
| 70 | printf("\t"); |
| 71 | } else { |
| 72 | printf(", "); |
| 73 | } |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 74 | printf(usage_array[i].aname); |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 75 | col += len2; |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 76 | } |
| 77 | printf("\n\n"); |
| 78 | |
| 79 | printf("=head1 COMMAND DESCRIPTIONS\n\n"); |
| 80 | printf("=over 4\n\n"); |
| 81 | |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 82 | for (i = 0; i < num_messages; i++) { |
| 83 | if (usage_array[i].aname[0] >= 'a' && usage_array[i].aname[0] <= 'z' |
| 84 | && usage_array[i].usage[0] != NOUSAGE_STR[0] |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 85 | ) { |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 86 | printf("=item B<%s>\n\n", usage_array[i].aname); |
| 87 | if (usage_array[i].usage[0]) |
| 88 | printf("%s %s\n\n", usage_array[i].aname, usage_array[i].usage); |
Denys Vlasenko | f228913 | 2009-10-02 01:21:31 +0200 | [diff] [blame] | 89 | else |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 90 | printf("%s\n\n", usage_array[i].aname); |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 91 | } |
Denys Vlasenko | acabf8f | 2009-10-02 01:10:32 +0200 | [diff] [blame] | 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | /* TODO: we used to make options bold with B<> and output an example too: |
| 97 | |
| 98 | =item B<cat> |
| 99 | |
| 100 | cat [B<-u>] [FILE]... |
| 101 | |
| 102 | Concatenate FILE(s) and print them to stdout |
| 103 | |
| 104 | Options: |
| 105 | -u Use unbuffered i/o (ignored) |
| 106 | |
| 107 | Example: |
| 108 | $ cat /proc/uptime |
| 109 | 110716.72 17.67 |
| 110 | |
| 111 | */ |