diff options
Diffstat (limited to 'applets/usage_pod.c')
-rw-r--r-- | applets/usage_pod.c | 57 |
1 files changed, 34 insertions, 23 deletions
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 | } |