fix support for globally disabling --long-options.

(disabling them saves ~4K on fully configured bbox)
This commit is contained in:
Denis Vlasenko 2006-11-29 11:09:43 +00:00
parent 601ae1378b
commit c61852a02b
10 changed files with 54 additions and 41 deletions

View File

@ -112,13 +112,11 @@ config LOCALE_SUPPORT
busybox to support locale settings. busybox to support locale settings.
config GETOPT_LONG config GETOPT_LONG
bool bool "Enable support for --long-options"
default y default y
# bool "Enable support for --long-options" help
# default n Enable this if you want busybox applets to use the gnu --long-option
# help style, in addition to single character -a -b -c style options.
# Enable this if you want busybox applets to use the gnu --long-option
# style, in addition to single character -a -b -c style options.
config FEATURE_DEVPTS config FEATURE_DEVPTS
bool "Use the devpts filesystem for Unix98 PTYs" bool "Use the devpts filesystem for Unix98 PTYs"

View File

@ -721,8 +721,6 @@ static const struct option tar_long_options[] = {
# endif # endif
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
#else
#define tar_long_options 0
#endif #endif
int tar_main(int argc, char **argv) int tar_main(int argc, char **argv)
@ -750,8 +748,9 @@ int tar_main(int argc, char **argv)
USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
if (ENABLE_FEATURE_TAR_LONG_OPTIONS) #if ENABLE_FEATURE_TAR_LONG_OPTIONS
applet_long_options = tar_long_options; applet_long_options = tar_long_options;
#endif
opt = getopt32(argc, argv, opt = getopt32(argc, argv,
"txC:f:Opvk" "txC:f:Opvk"
USE_FEATURE_TAR_CREATE( "ch" ) USE_FEATURE_TAR_CREATE( "ch" )

View File

@ -648,10 +648,12 @@ static int list_single(struct dnode *dn)
#endif #endif
case LIST_FILENAME: case LIST_FILENAME:
errno = 0; errno = 0;
#if ENABLE_FEATURE_LS_COLOR
if (show_color && !lstat(dn->fullname, &info)) { if (show_color && !lstat(dn->fullname, &info)) {
printf("\033[%d;%dm", bgcolor(info.st_mode), printf("\033[%d;%dm", bgcolor(info.st_mode),
fgcolor(info.st_mode)); fgcolor(info.st_mode));
} }
#endif
column += printf("%s", dn->name); column += printf("%s", dn->name);
if (show_color) { if (show_color) {
printf("\033[0m"); printf("\033[0m");
@ -667,11 +669,13 @@ static int list_single(struct dnode *dn)
append = append_char(info.st_mode); append = append_char(info.st_mode);
} }
#endif #endif
#if ENABLE_FEATURE_LS_COLOR
if (show_color) { if (show_color) {
errno = 0; errno = 0;
printf("\033[%d;%dm", bgcolor(info.st_mode), printf("\033[%d;%dm", bgcolor(info.st_mode),
fgcolor(info.st_mode)); fgcolor(info.st_mode));
} }
#endif
column += printf("%s", lpath) + 4; column += printf("%s", lpath) + 4;
if (show_color) { if (show_color) {
printf("\033[0m"); printf("\033[0m");

View File

@ -858,6 +858,8 @@ format_address_std(off_t address, char c)
printf(address_fmt, address_pad_len, address); printf(address_fmt, address_pad_len, address);
} }
#if ENABLE_GETOPT_LONG
/* only used with --traditional */
static void static void
format_address_paren(off_t address, char c) format_address_paren(off_t address, char c)
{ {
@ -872,7 +874,7 @@ format_address_label(off_t address, char c)
format_address_std(address, ' '); format_address_std(address, ' ');
format_address_paren(address + pseudo_offset, c); format_address_paren(address + pseudo_offset, c);
} }
#endif
static void static void
dump_hexl_mode_trailer(size_t n_bytes, const char *block) dump_hexl_mode_trailer(size_t n_bytes, const char *block)
@ -978,6 +980,7 @@ get_lcm(void)
return l_c_m; return l_c_m;
} }
#if ENABLE_GETOPT_LONG
/* If S is a valid traditional offset specification with an optional /* If S is a valid traditional offset specification with an optional
leading '+' return nonzero and set *OFFSET to the offset it denotes. */ leading '+' return nonzero and set *OFFSET to the offset it denotes. */
@ -1011,6 +1014,7 @@ parse_old_offset(const char *s, off_t *offset)
return (*offset >= 0); return (*offset >= 0);
} }
#endif
/* Read a chunk of size BYTES_PER_BLOCK from the input files, write the /* Read a chunk of size BYTES_PER_BLOCK from the input files, write the
formatted block to standard output, and repeat until the specified formatted block to standard output, and repeat until the specified
@ -1235,8 +1239,9 @@ od_main(int argc, char **argv)
OPT_s = 1 << 15, OPT_s = 1 << 15,
OPT_S = 1 << 16, OPT_S = 1 << 16,
OPT_w = 1 << 17, OPT_w = 1 << 17,
OPT_traditional = 1 << 18, OPT_traditional = (1 << 18) * ENABLE_GETOPT_LONG,
}; };
#if ENABLE_GETOPT_LONG
static const struct option long_options[] = { static const struct option long_options[] = {
{ "skip-bytes", required_argument, NULL, 'j' }, { "skip-bytes", required_argument, NULL, 'j' },
{ "address-radix", required_argument, NULL, 'A' }, { "address-radix", required_argument, NULL, 'A' },
@ -1248,6 +1253,7 @@ od_main(int argc, char **argv)
{ "traditional", no_argument, NULL, 0xff }, { "traditional", no_argument, NULL, 0xff },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
#endif
char *str_A, *str_N, *str_j, *str_S; char *str_A, *str_N, *str_j, *str_S;
char *str_w = NULL; char *str_w = NULL;
llist_t *lst_t = NULL; llist_t *lst_t = NULL;
@ -1260,7 +1266,9 @@ od_main(int argc, char **argv)
/* Parse command line */ /* Parse command line */
opt_complementary = "t::"; // list opt_complementary = "t::"; // list
#if ENABLE_GETOPT_LONG
applet_long_options = long_options; applet_long_options = long_options;
#endif
opt = getopt32(argc, argv, "A:N:abcdfhij:lot:vxsS:" opt = getopt32(argc, argv, "A:N:abcdfhij:lot:vxsS:"
"w::", // -w with optional param "w::", // -w with optional param
// -S was -s and also had optional parameter // -S was -s and also had optional parameter
@ -1333,6 +1341,7 @@ od_main(int argc, char **argv)
* FIXME: POSIX 1003.1-2001 with XSI requires support for the * FIXME: POSIX 1003.1-2001 with XSI requires support for the
* traditional syntax even if --traditional is not given. */ * traditional syntax even if --traditional is not given. */
#if ENABLE_GETOPT_LONG
if (opt & OPT_traditional) { if (opt & OPT_traditional) {
off_t o1, o2; off_t o1, o2;
@ -1388,6 +1397,7 @@ od_main(int argc, char **argv)
} }
} }
} }
#endif
if (limit_bytes_to_format) { if (limit_bytes_to_format) {
end_offset = n_bytes_to_skip + max_bytes_to_format; end_offset = n_bytes_to_skip + max_bytes_to_format;

View File

@ -333,7 +333,9 @@ extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/);
enum { BB_GETOPT_ERROR = 0x80000000 }; enum { BB_GETOPT_ERROR = 0x80000000 };
extern const char *opt_complementary; extern const char *opt_complementary;
#if ENABLE_GETOPT_LONG
extern const struct option *applet_long_options; extern const struct option *applet_long_options;
#endif
extern uint32_t option_mask32; extern uint32_t option_mask32;
extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
@ -369,7 +371,7 @@ extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn,
extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN; extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN;
extern void bb_perror_nomsg(void); extern void bb_perror_nomsg(void);
extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
/* These two are used internally -- you shouldn't need to use them */ /* These are used internally -- you shouldn't need to use them */
extern void bb_verror_msg(const char *s, va_list p, const char *strerr); extern void bb_verror_msg(const char *s, va_list p, const char *strerr);
extern void bb_vperror_msg(const char *s, va_list p); extern void bb_vperror_msg(const char *s, va_list p);
extern void bb_vinfo_msg(const char *s, va_list p); extern void bb_vinfo_msg(const char *s, va_list p);

View File

@ -264,15 +264,13 @@ int ftp_send(ftp_host_info_t *server, FILE *control_stream,
#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
static const struct option ftpgetput_long_options[] = { static const struct option ftpgetput_long_options[] = {
{"continue", 1, NULL, 'c'}, { "continue", 1, NULL, 'c' },
{"verbose", 0, NULL, 'v'}, { "verbose", 0, NULL, 'v' },
{"username", 1, NULL, 'u'}, { "username", 1, NULL, 'u' },
{"password", 1, NULL, 'p'}, { "password", 1, NULL, 'p' },
{"port", 1, NULL, 'P'}, { "port", 1, NULL, 'P' },
{0, 0, 0, 0} { 0, 0, 0, 0 }
}; };
#else
#define ftpgetput_long_options 0
#endif #endif
int ftpgetput_main(int argc, char **argv) int ftpgetput_main(int argc, char **argv)
@ -307,9 +305,9 @@ int ftpgetput_main(int argc, char **argv)
/* /*
* Decipher the command line * Decipher the command line
*/ */
if (ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS) #if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
applet_long_options = ftpgetput_long_options; applet_long_options = ftpgetput_long_options;
#endif
opt = getopt32(argc, argv, "cvu:p:P:", &server->user, &server->password, &port); opt = getopt32(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
/* Process the non-option command line arguments */ /* Process the non-option command line arguments */

View File

@ -64,19 +64,18 @@ int get_prefix(unsigned long netmask);
#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
static const struct option long_options[] = { static const struct option long_options[] = {
{"netmask", no_argument, NULL, 'm'}, { "netmask", no_argument, NULL, 'm' },
{"broadcast", no_argument, NULL, 'b'}, { "broadcast", no_argument, NULL, 'b' },
{"network", no_argument, NULL, 'n'}, { "network", no_argument, NULL, 'n' },
#ifdef CONFIG_FEATURE_IPCALC_FANCY # if ENABLE_FEATURE_IPCALC_FANCY
{"prefix", no_argument, NULL, 'p'}, { "prefix", no_argument, NULL, 'p' },
{"hostname", no_argument, NULL, 'h'}, { "hostname", no_argument, NULL, 'h' },
{"silent", no_argument, NULL, 's'}, { "silent", no_argument, NULL, 's' },
#endif # endif
{NULL, 0, NULL, 0} { NULL, 0, NULL, 0 }
}; };
#else
#define long_options 0
#endif #endif
int ipcalc_main(int argc, char **argv) int ipcalc_main(int argc, char **argv)
{ {
unsigned opt; unsigned opt;
@ -85,9 +84,9 @@ int ipcalc_main(int argc, char **argv)
struct in_addr a; struct in_addr a;
char *ipstr; char *ipstr;
if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS) #if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
applet_long_options = long_options; applet_long_options = long_options;
#endif
opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs"));
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -160,6 +160,7 @@ int udhcpc_main(int argc, char *argv[])
OPT_t = 1 << 16, OPT_t = 1 << 16,
OPT_v = 1 << 17, OPT_v = 1 << 17,
}; };
#if ENABLE_GETOPT_LONG
static const struct option arg_options[] = { static const struct option arg_options[] = {
{ "clientid", required_argument, 0, 'c' }, { "clientid", required_argument, 0, 'c' },
{ "clientid-none", no_argument, 0, 'C' }, { "clientid-none", no_argument, 0, 'C' },
@ -181,7 +182,7 @@ int udhcpc_main(int argc, char *argv[])
{ "retries", required_argument, 0, 't' }, { "retries", required_argument, 0, 't' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
#endif
/* Default options. */ /* Default options. */
client_config.interface = "eth0"; client_config.interface = "eth0";
client_config.script = DEFAULT_SCRIPT; client_config.script = DEFAULT_SCRIPT;
@ -191,7 +192,9 @@ int udhcpc_main(int argc, char *argv[])
/* Parse command line */ /* Parse command line */
opt_complementary = "?:c--C:C--c" // mutually exclusive opt_complementary = "?:c--C:C--c" // mutually exclusive
":hH:Hh"; // -h and -H are the same ":hH:Hh"; // -h and -H are the same
#if ENABLE_GETOPT_LONG
applet_long_options = arg_options; applet_long_options = arg_options;
#endif
opt = getopt32(argc, argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:v", opt = getopt32(argc, argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:v",
&str_c, &str_V, &str_h, &str_h, &str_F, &str_c, &str_V, &str_h, &str_h, &str_F,
&client_config.interface, &client_config.pidfile, &str_r, &client_config.interface, &client_config.pidfile, &str_r,

View File

@ -1949,7 +1949,7 @@ void conf_parse(const char *name)
sym_init(); sym_init();
menu_init(); menu_init();
modules_sym = sym_lookup("MODULES", 0); modules_sym = sym_lookup("MODULES", 0);
rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); rootmenu.prompt = menu_add_prompt(P_MENU, "Busybox Configuration", NULL);
#if YYDEBUG #if YYDEBUG
if (getenv("ZCONF_DEBUG")) if (getenv("ZCONF_DEBUG"))

View File

@ -459,7 +459,7 @@ void conf_parse(const char *name)
sym_init(); sym_init();
menu_init(); menu_init();
modules_sym = sym_lookup("MODULES", 0); modules_sym = sym_lookup("MODULES", 0);
rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); rootmenu.prompt = menu_add_prompt(P_MENU, "Busybox Configuration", NULL);
#if YYDEBUG #if YYDEBUG
if (getenv("ZCONF_DEBUG")) if (getenv("ZCONF_DEBUG"))