058e0c842e2061a61d75f84047a38a6d6dbee546
[platform/upstream/busybox.git] / applets / usage_pod.c
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>
9 #include <string.h>
10 #include <stdio.h>
11
12 /* Just #include "autoconf.h" doesn't work for builds in separate
13  * object directory */
14 #include "autoconf.h"
15
16 #define SKIP_applet_main
17 #define ALIGN1 /* nothing, just to placate applet_tables.h */
18 #define ALIGN2 /* nothing, just to placate applet_tables.h */
19 #include "applet_tables.h"
20
21 /* Since we can't use platform.h, have to do this again by hand: */
22 #if ENABLE_NOMMU
23 # define BB_MMU 0
24 # define USE_FOR_NOMMU(...) __VA_ARGS__
25 # define USE_FOR_MMU(...)
26 #else
27 # define BB_MMU 1
28 # define USE_FOR_NOMMU(...)
29 # define USE_FOR_MMU(...) __VA_ARGS__
30 #endif
31
32 static const char usage_messages[] = ""
33 #define MAKE_USAGE
34 #include "usage.h"
35 #include "applets.h"
36 ;
37
38 int main(void)
39 {
40         const char *names;
41         const char *usage;
42         int col, len2;
43
44         col = 0;
45         names = applet_names;
46         while (*names) {
47                 len2 = strlen(names) + 2;
48                 if (col >= 76 - len2) {
49                         printf(",\n");
50                         col = 0;
51                 }
52                 if (col == 0) {
53                         col = 6;
54                         printf("\t");
55                 } else {
56                         printf(", ");
57                 }
58                 printf(names);
59                 col += len2;
60                 names += len2 - 1;
61         }
62         printf("\n\n");
63
64         printf("=head1 COMMAND DESCRIPTIONS\n\n");
65         printf("=over 4\n\n");
66
67         names = applet_names;
68         usage = usage_messages;
69         while (*names && usage) {
70                 if (*names >= 'a' && *names <= 'z'
71                  && *usage != NOUSAGE_STR[0]
72                 ) {
73                         printf("=item B<%s>\n\n", names);
74                         printf("%s %s\n\n", names, usage);
75                 }
76                 names += strlen(names) + 1;
77                 usage += strlen(usage) + 1;
78         }
79         return 0;
80 }
81
82 /* TODO: we used to make options bold with B<> and output an example too:
83
84 =item B<cat>
85
86 cat [B<-u>] [FILE]...
87
88 Concatenate FILE(s) and print them to stdout
89
90 Options:
91         -u      Use unbuffered i/o (ignored)
92
93 Example:
94         $ cat /proc/uptime
95         110716.72 17.67
96
97 */