libbb: nuke BB_GETOPT_ERROR, always die if there are mutually exclusive options

find_pair                                            164     180     +16
passwd_main                                         1222    1230      +8
display_speed                                         91      96      +5
msh_main                                            1335    1339      +4
qrealloc                                              38      36      -2
refresh                                             1190    1182      -8
cut_main                                             543     532     -11
sendCgi                                             1807    1794     -13
getopt32                                            1063    1045     -18
arith                                               2077    2030     -47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/6 up/down: 33/-99)            Total: -66 bytes
   text    data     bss     dec     hex filename
 781548    1168   11900  794616   c1ff8 busybox_old
 781452    1168   11900  794520   c1f98 busybox_unstripped
This commit is contained in:
Denis Vlasenko
2007-07-21 13:27:44 +00:00
parent 557fb713e0
commit 091965768d
18 changed files with 28 additions and 45 deletions

View File

@@ -44,7 +44,7 @@ int cp_main(int argc, char **argv)
// -P and -d are the same (-P is POSIX, -d is GNU)
// -r and -R are the same
// -a = -pdR
opt_complementary = "?:l--s:s--l:Pd:rR:apdR";
opt_complementary = "l--s:s--l:Pd:rR:apdR";
flags = getopt32(argc, argv, FILEUTILS_CP_OPTSTR "arPHL");
/* Default behavior of cp is to dereference, so we don't have to do
* anything special when we are given -L.

View File

@@ -176,8 +176,6 @@ int cut_main(int argc, char **argv)
argv += optind;
if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
if (option_mask32 & BB_GETOPT_ERROR)
bb_error_msg_and_die("only one type of list may be specified");
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
if (strlen(ltok) > 1) {

View File

@@ -51,7 +51,7 @@ int date_main(int argc, char **argv)
char *isofmt_arg;
char *hintfmt_arg;
opt_complementary = "?:d--s:s--d"
opt_complementary = "d--s:s--d"
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
opt = getopt32(argc, argv, "Rs:ud:r:"
USE_FEATURE_DATE_ISOFMT("I::D:"),

View File

@@ -20,7 +20,7 @@ enum {
};
/* if fn is NULL then input is stdin and output is stdout */
static int convert(char *fn, int ConvType)
static int convert(char *fn, int conv_type)
{
FILE *in, *out;
int i;
@@ -52,7 +52,7 @@ static int convert(char *fn, int ConvType)
if (i == '\r')
continue;
if (i == '\n') {
if (ConvType == CT_UNIX2DOS)
if (conv_type == CT_UNIX2DOS)
fputc('\r', out);
fputc('\n', out);
continue;
@@ -81,29 +81,27 @@ static int convert(char *fn, int ConvType)
int dos2unix_main(int argc, char **argv);
int dos2unix_main(int argc, char **argv)
{
int o, ConvType;
int o, conv_type;
/* See if we are supposed to be doing dos2unix or unix2dos */
if (applet_name[0] == 'd') {
ConvType = CT_DOS2UNIX; /* 2 */
conv_type = CT_DOS2UNIX; /* 2 */
} else {
ConvType = CT_UNIX2DOS; /* 1 */
conv_type = CT_UNIX2DOS; /* 1 */
}
/* -u and -d are mutally exclusive */
opt_complementary = "?:u--d:d--u";
/* process parameters */
/* -u convert to unix */
/* -d convert to dos */
/* -u convert to unix, -d convert to dos */
opt_complementary = "u--d:d--u"; /* mutally exclusive */
o = getopt32(argc, argv, "du");
/* Do the conversion requested by an argument else do the default
* conversion depending on our name. */
if (o)
ConvType = o;
conv_type = o;
do {
/* might be convert(NULL) if there is no filename given */
o = convert(argv[optind], ConvType);
o = convert(argv[optind], conv_type);
if (o < 0)
break;
optind++;

View File

@@ -49,7 +49,7 @@ int id_main(int argc, char **argv)
#endif
/* Don't allow -n -r -nr -ug -rug -nug -rnug */
/* Don't allow more than one username */
opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
opt_complementary = "?1:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z"));
/* This values could be overwritten later */

View File

@@ -99,7 +99,7 @@ int install_main(int argc, char **argv)
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
applet_long_options = install_long_options;
#endif
opt_complementary = "?:s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
/* -c exists for backwards compatibility, it's needed */
flags = getopt32(argc, argv, "cdpsg:m:o:" USE_SELINUX("Z:"),

View File

@@ -288,7 +288,7 @@ int sort_main(int argc, char **argv)
/* Parse command line options */
/* -o and -t can be given at most once */
opt_complementary = "?:o--o:t--t:" /* -t, -o: maximum one of each */
opt_complementary = "o--o:t--t:" /* -t, -o: maximum one of each */
"k::"; /* -k takes list */
getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
#if ENABLE_FEATURE_SORT_BIG