Another update to the way usage messages are done by Evin Robertson

<nitfol@my-deja.com>, which makes things just a little bit smaller, but makes
usage.h more readable/maintainable IMHO.
 -Erik
This commit is contained in:
Eric Andersen 2001-02-22 01:15:47 +00:00
parent 8fc300976f
commit 7e9276b50a
10 changed files with 2977 additions and 5629 deletions

View File

@ -14,33 +14,33 @@
#undef APPLET_ODDNAME #undef APPLET_ODDNAME
#undef APPLET_NOUSAGE #undef APPLET_NOUSAGE
#if defined(PROTOTYPES) #if defined(PROTOTYPES)
#define APPLET(a,b,c) \ #define APPLET(a,b,c) extern int b(int argc, char **argv);
extern int b(int argc, char **argv); #define APPLET_NOUSAGE(a,b,c) extern int b(int argc, char **argv);
#define APPLET_ODDNAME(a,b,c,d,e) APPLET(a,b,c) #define APPLET_ODDNAME(a,b,c,d) extern int b(int argc, char **argv);
#define APPLET_NOUSAGE(a,b,c) \ extern const char usage_messages[];
extern int b(int argc, char **argv); #elif defined(MAKE_USAGE)
#elif defined(MAKE_LINKS) #ifdef BB_FEATURE_TRIVIAL_HELP
#define APPLET(a,b,c) LINK c #a #define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_ODDNAME(a,b,c,d,e) LINK c a #define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_NOUSAGE(a,b,c) LINK c #a #define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#elif defined(APPLET_ENUM) #else
#define APPLET(a,b,c) a##_applet_number, #define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_ODDNAME(a,b,c,d,e) e##_applet_number, #define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_NOUSAGE(a,b,c) a##applet_number, #define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
#endif
#else #else
#define USAGE_ENUM const struct BB_applet applets[] = {
#include "usage.h" #define APPLET(a,b,c) {#a,b,c},
const struct BB_applet applets[] = { #define APPLET_NOUSAGE(a,b,c) {a,b,c},
#define APPLET(a,b,c) {#a,b,c,a##_usage_index}, #define APPLET_ODDNAME(a,b,c,d) {a,b,c},
#define APPLET_ODDNAME(a,b,c,d,e) {a,b,c,d},
#define APPLET_NOUSAGE(a,b,c) {#a,b,c,-1},
#define zcat_usage_index gunzip_usage_index
#define sh_usage_index shell_usage_index
#endif #endif
#ifdef BB_TEST #ifdef BB_TEST
APPLET_ODDNAME("[", test_main, _BB_DIR_USR_BIN, test_usage_index, open_bracket) APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_AR #ifdef BB_AR
APPLET(ar, ar_main, _BB_DIR_USR_BIN) APPLET(ar, ar_main, _BB_DIR_USR_BIN)
@ -48,7 +48,7 @@ const struct BB_applet applets[] = {
#ifdef BB_BASENAME #ifdef BB_BASENAME
APPLET(basename, basename_main, _BB_DIR_USR_BIN) APPLET(basename, basename_main, _BB_DIR_USR_BIN)
#endif #endif
APPLET_NOUSAGE(busybox, busybox_main, _BB_DIR_BIN) APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
#ifdef BB_CAT #ifdef BB_CAT
APPLET(cat, cat_main, _BB_DIR_BIN) APPLET(cat, cat_main, _BB_DIR_BIN)
#endif #endif
@ -107,7 +107,7 @@ const struct BB_applet applets[] = {
APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN) APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_DPKG_DEB #ifdef BB_DPKG_DEB
APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, dpkg_deb_usage_index, dpkg_deb) APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, dpkg_deb)
#endif #endif
#ifdef BB_DU #ifdef BB_DU
APPLET(du, du_main, _BB_DIR_USR_BIN) APPLET(du, du_main, _BB_DIR_USR_BIN)
@ -128,7 +128,7 @@ const struct BB_applet applets[] = {
APPLET(false, false_main, _BB_DIR_BIN) APPLET(false, false_main, _BB_DIR_BIN)
#endif #endif
#ifdef BB_FBSET #ifdef BB_FBSET
APPLET_NOUSAGE(fbset, fbset_main, _BB_DIR_USR_SBIN) APPLET_NOUSAGE("fbset", fbset_main, _BB_DIR_USR_SBIN)
#endif #endif
#ifdef BB_FDFLUSH #ifdef BB_FDFLUSH
APPLET(fdflush, fdflush_main, _BB_DIR_BIN) APPLET(fdflush, fdflush_main, _BB_DIR_BIN)
@ -143,7 +143,7 @@ const struct BB_applet applets[] = {
APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN) APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN)
#endif #endif
#ifdef BB_FSCK_MINIX #ifdef BB_FSCK_MINIX
APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage_index, fsck_minix) APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix)
#endif #endif
#ifdef BB_GETOPT #ifdef BB_GETOPT
APPLET(getopt, getopt_main, _BB_DIR_BIN) APPLET(getopt, getopt_main, _BB_DIR_BIN)
@ -191,7 +191,7 @@ const struct BB_applet applets[] = {
APPLET(length, length_main, _BB_DIR_USR_BIN) APPLET(length, length_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_LINUXRC #ifdef BB_LINUXRC
APPLET_NOUSAGE(linuxrc, init_main, _BB_DIR_ROOT) APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT)
#endif #endif
#ifdef BB_LN #ifdef BB_LN
APPLET(ln, ln_main, _BB_DIR_BIN) APPLET(ln, ln_main, _BB_DIR_BIN)
@ -230,7 +230,7 @@ const struct BB_applet applets[] = {
APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN) APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_MKFS_MINIX #ifdef BB_MKFS_MINIX
APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage_index, mkfs_minix) APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix)
#endif #endif
#ifdef BB_MKNOD #ifdef BB_MKNOD
APPLET(mknod, mknod_main, _BB_DIR_BIN) APPLET(mknod, mknod_main, _BB_DIR_BIN)
@ -416,8 +416,8 @@ const struct BB_applet applets[] = {
APPLET(zcat, gunzip_main, _BB_DIR_BIN) APPLET(zcat, gunzip_main, _BB_DIR_BIN)
#endif #endif
#if !defined(PROTOTYPES) && !defined(MAKE_LINKS) && !defined(APPLET_ENUM) #if !defined(PROTOTYPES) && !defined(MAKE_USAGE)
{ 0,NULL,0,-1} { 0,NULL,0 }
}; };
/* The -1 arises because of the {0,NULL,0,-1} entry above. */ /* The -1 arises because of the {0,NULL,0,-1} entry above. */

View File

@ -1,2 +1,10 @@
#define USAGE_MESSAGES #include "busybox.h"
const char usage_messages[] =
#define MAKE_USAGE
#include "usage.h" #include "usage.h"
#include "applets.h"
;

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,6 @@ struct BB_applet {
const char* name; const char* name;
int (*main)(int argc, char** argv); int (*main)(int argc, char** argv);
enum Location location; enum Location location;
int usage_index;
}; };
/* From busybox.c */ /* From busybox.c */
extern const struct BB_applet applets[]; extern const struct BB_applet applets[];
@ -87,12 +86,6 @@ extern const struct BB_applet applets[];
#include "applets.h" #include "applets.h"
#undef PROTOTYPES #undef PROTOTYPES
#define APPLET_ENUM
enum APPLET_INDEX_NUMBERS {
#include "applets.h"
};
#undef APPLET_ENUM
extern const char *applet_name; extern const char *applet_name;
extern void show_usage(void) __attribute__ ((noreturn)); extern void show_usage(void) __attribute__ ((noreturn));

View File

@ -14,33 +14,33 @@
#undef APPLET_ODDNAME #undef APPLET_ODDNAME
#undef APPLET_NOUSAGE #undef APPLET_NOUSAGE
#if defined(PROTOTYPES) #if defined(PROTOTYPES)
#define APPLET(a,b,c) \ #define APPLET(a,b,c) extern int b(int argc, char **argv);
extern int b(int argc, char **argv); #define APPLET_NOUSAGE(a,b,c) extern int b(int argc, char **argv);
#define APPLET_ODDNAME(a,b,c,d,e) APPLET(a,b,c) #define APPLET_ODDNAME(a,b,c,d) extern int b(int argc, char **argv);
#define APPLET_NOUSAGE(a,b,c) \ extern const char usage_messages[];
extern int b(int argc, char **argv); #elif defined(MAKE_USAGE)
#elif defined(MAKE_LINKS) #ifdef BB_FEATURE_TRIVIAL_HELP
#define APPLET(a,b,c) LINK c #a #define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_ODDNAME(a,b,c,d,e) LINK c a #define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_NOUSAGE(a,b,c) LINK c #a #define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#elif defined(APPLET_ENUM) #else
#define APPLET(a,b,c) a##_applet_number, #define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_ODDNAME(a,b,c,d,e) e##_applet_number, #define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_NOUSAGE(a,b,c) a##applet_number, #define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
#endif
#else #else
#define USAGE_ENUM const struct BB_applet applets[] = {
#include "usage.h" #define APPLET(a,b,c) {#a,b,c},
const struct BB_applet applets[] = { #define APPLET_NOUSAGE(a,b,c) {a,b,c},
#define APPLET(a,b,c) {#a,b,c,a##_usage_index}, #define APPLET_ODDNAME(a,b,c,d) {a,b,c},
#define APPLET_ODDNAME(a,b,c,d,e) {a,b,c,d},
#define APPLET_NOUSAGE(a,b,c) {#a,b,c,-1},
#define zcat_usage_index gunzip_usage_index
#define sh_usage_index shell_usage_index
#endif #endif
#ifdef BB_TEST #ifdef BB_TEST
APPLET_ODDNAME("[", test_main, _BB_DIR_USR_BIN, test_usage_index, open_bracket) APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_AR #ifdef BB_AR
APPLET(ar, ar_main, _BB_DIR_USR_BIN) APPLET(ar, ar_main, _BB_DIR_USR_BIN)
@ -48,7 +48,7 @@ const struct BB_applet applets[] = {
#ifdef BB_BASENAME #ifdef BB_BASENAME
APPLET(basename, basename_main, _BB_DIR_USR_BIN) APPLET(basename, basename_main, _BB_DIR_USR_BIN)
#endif #endif
APPLET_NOUSAGE(busybox, busybox_main, _BB_DIR_BIN) APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
#ifdef BB_CAT #ifdef BB_CAT
APPLET(cat, cat_main, _BB_DIR_BIN) APPLET(cat, cat_main, _BB_DIR_BIN)
#endif #endif
@ -107,7 +107,7 @@ const struct BB_applet applets[] = {
APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN) APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_DPKG_DEB #ifdef BB_DPKG_DEB
APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, dpkg_deb_usage_index, dpkg_deb) APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, dpkg_deb)
#endif #endif
#ifdef BB_DU #ifdef BB_DU
APPLET(du, du_main, _BB_DIR_USR_BIN) APPLET(du, du_main, _BB_DIR_USR_BIN)
@ -128,7 +128,7 @@ const struct BB_applet applets[] = {
APPLET(false, false_main, _BB_DIR_BIN) APPLET(false, false_main, _BB_DIR_BIN)
#endif #endif
#ifdef BB_FBSET #ifdef BB_FBSET
APPLET_NOUSAGE(fbset, fbset_main, _BB_DIR_USR_SBIN) APPLET_NOUSAGE("fbset", fbset_main, _BB_DIR_USR_SBIN)
#endif #endif
#ifdef BB_FDFLUSH #ifdef BB_FDFLUSH
APPLET(fdflush, fdflush_main, _BB_DIR_BIN) APPLET(fdflush, fdflush_main, _BB_DIR_BIN)
@ -143,7 +143,7 @@ const struct BB_applet applets[] = {
APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN) APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN)
#endif #endif
#ifdef BB_FSCK_MINIX #ifdef BB_FSCK_MINIX
APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage_index, fsck_minix) APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix)
#endif #endif
#ifdef BB_GETOPT #ifdef BB_GETOPT
APPLET(getopt, getopt_main, _BB_DIR_BIN) APPLET(getopt, getopt_main, _BB_DIR_BIN)
@ -191,7 +191,7 @@ const struct BB_applet applets[] = {
APPLET(length, length_main, _BB_DIR_USR_BIN) APPLET(length, length_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_LINUXRC #ifdef BB_LINUXRC
APPLET_NOUSAGE(linuxrc, init_main, _BB_DIR_ROOT) APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT)
#endif #endif
#ifdef BB_LN #ifdef BB_LN
APPLET(ln, ln_main, _BB_DIR_BIN) APPLET(ln, ln_main, _BB_DIR_BIN)
@ -230,7 +230,7 @@ const struct BB_applet applets[] = {
APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN) APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN)
#endif #endif
#ifdef BB_MKFS_MINIX #ifdef BB_MKFS_MINIX
APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage_index, mkfs_minix) APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix)
#endif #endif
#ifdef BB_MKNOD #ifdef BB_MKNOD
APPLET(mknod, mknod_main, _BB_DIR_BIN) APPLET(mknod, mknod_main, _BB_DIR_BIN)
@ -416,8 +416,8 @@ const struct BB_applet applets[] = {
APPLET(zcat, gunzip_main, _BB_DIR_BIN) APPLET(zcat, gunzip_main, _BB_DIR_BIN)
#endif #endif
#if !defined(PROTOTYPES) && !defined(MAKE_LINKS) && !defined(APPLET_ENUM) #if !defined(PROTOTYPES) && !defined(MAKE_USAGE)
{ 0,NULL,0,-1} { 0,NULL,0 }
}; };
/* The -1 arises because of the {0,NULL,0,-1} entry above. */ /* The -1 arises because of the {0,NULL,0,-1} entry above. */

View File

@ -72,7 +72,6 @@ struct BB_applet {
const char* name; const char* name;
int (*main)(int argc, char** argv); int (*main)(int argc, char** argv);
enum Location location; enum Location location;
int usage_index;
}; };
/* From busybox.c */ /* From busybox.c */
extern const struct BB_applet applets[]; extern const struct BB_applet applets[];
@ -87,12 +86,6 @@ extern const struct BB_applet applets[];
#include "applets.h" #include "applets.h"
#undef PROTOTYPES #undef PROTOTYPES
#define APPLET_ENUM
enum APPLET_INDEX_NUMBERS {
#include "applets.h"
};
#undef APPLET_ENUM
extern const char *applet_name; extern const char *applet_name;
extern void show_usage(void) __attribute__ ((noreturn)); extern void show_usage(void) __attribute__ ((noreturn));

File diff suppressed because it is too large Load Diff

10
usage.c
View File

@ -1,2 +1,10 @@
#define USAGE_MESSAGES #include "busybox.h"
const char usage_messages[] =
#define MAKE_USAGE
#include "usage.h" #include "usage.h"
#include "applets.h"
;

2810
usage.h

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,6 @@
#define bb_need_full_version #define bb_need_full_version
#define BB_DECLARE_EXTERN #define BB_DECLARE_EXTERN
#include "messages.c" #include "messages.c"
#include "usage.h"
#include "pwd_grp/pwd.h" #include "pwd_grp/pwd.h"
#include "pwd_grp/grp.h" #include "pwd_grp/grp.h"
@ -81,21 +80,20 @@ static struct BB_applet *applet_using;
extern void show_usage(void) extern void show_usage(void)
{ {
static const char no_help[] = "No help available.\n"; const char *format_string;
const char *usage_string = usage_messages;
const char *usage_string = no_help;
int i; int i;
if (applet_using->usage_index >= 0) { for (i = applet_using - applets; i > 0; ) {
usage_string = usage_messages; if (!*usage_string++) {
for (i=applet_using->usage_index ; i>0 ; ) { --i;
if (!*usage_string++) {
--i;
}
} }
} }
fprintf(stderr, "%s\n\nUsage: %s %s\n\n", full_version, format_string = "%s\n\nUsage: %s %s\n\n";
applet_using->name, usage_string); if(*usage_string == 0)
format_string = "%s\n\nNo help available.\n\n";
fprintf(stderr, format_string,
full_version, applet_using->name, usage_string);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }