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_NOUSAGE
#if defined(PROTOTYPES)
#define APPLET(a,b,c) \
extern int b(int argc, char **argv);
#define APPLET_ODDNAME(a,b,c,d,e) APPLET(a,b,c)
#define APPLET_NOUSAGE(a,b,c) \
extern int b(int argc, char **argv);
#elif defined(MAKE_LINKS)
#define APPLET(a,b,c) LINK c #a
#define APPLET_ODDNAME(a,b,c,d,e) LINK c a
#define APPLET_NOUSAGE(a,b,c) LINK c #a
#elif defined(APPLET_ENUM)
#define APPLET(a,b,c) a##_applet_number,
#define APPLET_ODDNAME(a,b,c,d,e) e##_applet_number,
#define APPLET_NOUSAGE(a,b,c) a##applet_number,
#define APPLET(a,b,c) 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) extern int b(int argc, char **argv);
extern const char usage_messages[];
#elif defined(MAKE_USAGE)
#ifdef BB_FEATURE_TRIVIAL_HELP
#define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#else
#define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
#endif
#else
#define USAGE_ENUM
#include "usage.h"
const struct BB_applet applets[] = {
#define APPLET(a,b,c) {#a,b,c,a##_usage_index},
#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
const struct BB_applet applets[] = {
#define APPLET(a,b,c) {#a,b,c},
#define APPLET_NOUSAGE(a,b,c) {a,b,c},
#define APPLET_ODDNAME(a,b,c,d) {a,b,c},
#endif
#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
#ifdef BB_AR
APPLET(ar, ar_main, _BB_DIR_USR_BIN)
@ -48,7 +48,7 @@ const struct BB_applet applets[] = {
#ifdef BB_BASENAME
APPLET(basename, basename_main, _BB_DIR_USR_BIN)
#endif
APPLET_NOUSAGE(busybox, busybox_main, _BB_DIR_BIN)
APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
#ifdef BB_CAT
APPLET(cat, cat_main, _BB_DIR_BIN)
#endif
@ -107,7 +107,7 @@ const struct BB_applet applets[] = {
APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN)
#endif
#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
#ifdef BB_DU
APPLET(du, du_main, _BB_DIR_USR_BIN)
@ -128,7 +128,7 @@ const struct BB_applet applets[] = {
APPLET(false, false_main, _BB_DIR_BIN)
#endif
#ifdef BB_FBSET
APPLET_NOUSAGE(fbset, fbset_main, _BB_DIR_USR_SBIN)
APPLET_NOUSAGE("fbset", fbset_main, _BB_DIR_USR_SBIN)
#endif
#ifdef BB_FDFLUSH
APPLET(fdflush, fdflush_main, _BB_DIR_BIN)
@ -143,7 +143,7 @@ const struct BB_applet applets[] = {
APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN)
#endif
#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
#ifdef BB_GETOPT
APPLET(getopt, getopt_main, _BB_DIR_BIN)
@ -191,7 +191,7 @@ const struct BB_applet applets[] = {
APPLET(length, length_main, _BB_DIR_USR_BIN)
#endif
#ifdef BB_LINUXRC
APPLET_NOUSAGE(linuxrc, init_main, _BB_DIR_ROOT)
APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT)
#endif
#ifdef BB_LN
APPLET(ln, ln_main, _BB_DIR_BIN)
@ -230,7 +230,7 @@ const struct BB_applet applets[] = {
APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN)
#endif
#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
#ifdef BB_MKNOD
APPLET(mknod, mknod_main, _BB_DIR_BIN)
@ -416,8 +416,8 @@ const struct BB_applet applets[] = {
APPLET(zcat, gunzip_main, _BB_DIR_BIN)
#endif
#if !defined(PROTOTYPES) && !defined(MAKE_LINKS) && !defined(APPLET_ENUM)
{ 0,NULL,0,-1}
#if !defined(PROTOTYPES) && !defined(MAKE_USAGE)
{ 0,NULL,0 }
};
/* 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 "applets.h"
;

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

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