shells: do not frocibly enable test, echo and kill _applets_,

just build relevant source and use xxx_main functions.
build system: add a special case when we have exactly one applet enabled
(makes "true", "false", "basename" REALLY tiny).
getopt32: do not use stdio.

function                                             old     new   delta
getopt32                                            1385    1412     +27
make_device                                         1187    1200     +13
basename_main                                        120     127      +7
tcpudpsvd_main                                      1922    1926      +4
testcmd                                                5       -      -5
echocmd                                                5       -      -5
fuser_main                                          1243    1231     -12
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 4/1 up/down: 51/-22)             Total: 29 bytes
This commit is contained in:
Denis Vlasenko
2008-04-01 14:47:57 +00:00
parent 165f5b394f
commit 468aea2d88
14 changed files with 84 additions and 91 deletions

View File

@@ -285,6 +285,10 @@ const char *const bb_argv_dash[] = { "-", NULL };
const char *opt_complementary;
/* Many small applets don't want to suck in stdio.h only because
* they need to parse options by calling us */
#define DONT_USE_PRINTF 1
enum {
PARAM_STRING,
PARAM_LIST,
@@ -335,7 +339,8 @@ getopt32(char **argv, const char *applet_opts, ...)
#define SHOW_USAGE_IF_ERROR 1
#define ALL_ARGV_IS_OPTS 2
#define FIRST_ARGV_IS_OPT 4
#define FREE_FIRST_ARGV_IS_OPT 8
#define FREE_FIRST_ARGV_IS_OPT (8 * !DONT_USE_PRINTF)
int spec_flgs = 0;
argc = 0;
@@ -489,10 +494,16 @@ getopt32(char **argv, const char *applet_opts, ...)
va_end(p);
if (spec_flgs & FIRST_ARGV_IS_OPT) {
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
if (argv[1] && argv[1][0] != '-' && argv[1][1] != '\0') {
#if DONT_USE_PRINTF
char *pp = alloca(strlen(argv[1]) + 2);
*pp++ = '-';
argv[1] = strcpy(pp, argv[1]);
#else
argv[1] = xasprintf("-%s", argv[1]);
if (ENABLE_FEATURE_CLEAN_UP)
spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
#endif
}
}
@@ -573,7 +584,7 @@ getopt32(char **argv, const char *applet_opts, ...)
}
}
#if (ENABLE_AR || ENABLE_TAR) && ENABLE_FEATURE_CLEAN_UP
#if ENABLE_FEATURE_CLEAN_UP
if (spec_flgs & FREE_FIRST_ARGV_IS_OPT)
free(argv[1]);
#endif