aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-21 13:27:44 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-21 13:27:44 +0000
commit091965768da4175d3763e61db56bba058d68ae3b (patch)
tree011719c7b70c58099641d98244ea1aad9b2a8e5d
parent557fb713e0f943ac9b87c9f3804ba24e73d55bb0 (diff)
downloadbusybox-w32-091965768da4175d3763e61db56bba058d68ae3b.tar.gz
busybox-w32-091965768da4175d3763e61db56bba058d68ae3b.tar.bz2
busybox-w32-091965768da4175d3763e61db56bba058d68ae3b.zip
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
-rw-r--r--archival/ar.c2
-rw-r--r--coreutils/cp.c2
-rw-r--r--coreutils/cut.c2
-rw-r--r--coreutils/date.c2
-rw-r--r--coreutils/dos2unix.c22
-rw-r--r--coreutils/id.c2
-rw-r--r--coreutils/install.c2
-rw-r--r--coreutils/sort.c2
-rw-r--r--debianutils/start_stop_daemon.c2
-rw-r--r--editors/cmp.c2
-rw-r--r--include/libbb.h2
-rw-r--r--ipsvd/tcpudp.c2
-rw-r--r--libbb/getopt32.c19
-rw-r--r--miscutils/eject.c2
-rw-r--r--networking/udhcp/dhcpc.c2
-rw-r--r--networking/udhcp/dumpleases.c2
-rw-r--r--util-linux/getopt.c2
-rw-r--r--util-linux/hwclock.c2
18 files changed, 28 insertions, 45 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 31e96de4f..e85ca5c6f 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -50,7 +50,7 @@ int ar_main(int argc, char **argv)
50 archive_handle = init_handle(); 50 archive_handle = init_handle();
51 51
52 /* Prepend '-' to the first argument if required */ 52 /* Prepend '-' to the first argument if required */
53 opt_complementary = "--:p:t:x:-1:?:p--tx:t--px:x--pt"; 53 opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
54 opt = getopt32(argc, argv, "ptxovcr"); 54 opt = getopt32(argc, argv, "ptxovcr");
55 55
56 if (opt & AR_CTX_PRINT) { 56 if (opt & AR_CTX_PRINT) {
diff --git a/coreutils/cp.c b/coreutils/cp.c
index f98f281b5..78bd73c0f 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -44,7 +44,7 @@ int cp_main(int argc, char **argv)
44 // -P and -d are the same (-P is POSIX, -d is GNU) 44 // -P and -d are the same (-P is POSIX, -d is GNU)
45 // -r and -R are the same 45 // -r and -R are the same
46 // -a = -pdR 46 // -a = -pdR
47 opt_complementary = "?:l--s:s--l:Pd:rR:apdR"; 47 opt_complementary = "l--s:s--l:Pd:rR:apdR";
48 flags = getopt32(argc, argv, FILEUTILS_CP_OPTSTR "arPHL"); 48 flags = getopt32(argc, argv, FILEUTILS_CP_OPTSTR "arPHL");
49 /* Default behavior of cp is to dereference, so we don't have to do 49 /* Default behavior of cp is to dereference, so we don't have to do
50 * anything special when we are given -L. 50 * anything special when we are given -L.
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 084f7be37..435b21070 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -176,8 +176,6 @@ int cut_main(int argc, char **argv)
176 argv += optind; 176 argv += optind;
177 if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) 177 if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
178 bb_error_msg_and_die("expected a list of bytes, characters, or fields"); 178 bb_error_msg_and_die("expected a list of bytes, characters, or fields");
179 if (option_mask32 & BB_GETOPT_ERROR)
180 bb_error_msg_and_die("only one type of list may be specified");
181 179
182 if (option_mask32 & CUT_OPT_DELIM_FLGS) { 180 if (option_mask32 & CUT_OPT_DELIM_FLGS) {
183 if (strlen(ltok) > 1) { 181 if (strlen(ltok) > 1) {
diff --git a/coreutils/date.c b/coreutils/date.c
index 1b20cd443..5e2bcee3b 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -51,7 +51,7 @@ int date_main(int argc, char **argv)
51 char *isofmt_arg; 51 char *isofmt_arg;
52 char *hintfmt_arg; 52 char *hintfmt_arg;
53 53
54 opt_complementary = "?:d--s:s--d" 54 opt_complementary = "d--s:s--d"
55 USE_FEATURE_DATE_ISOFMT(":R--I:I--R"); 55 USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
56 opt = getopt32(argc, argv, "Rs:ud:r:" 56 opt = getopt32(argc, argv, "Rs:ud:r:"
57 USE_FEATURE_DATE_ISOFMT("I::D:"), 57 USE_FEATURE_DATE_ISOFMT("I::D:"),
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index 86adcd91f..115632f75 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -20,7 +20,7 @@ enum {
20}; 20};
21 21
22/* if fn is NULL then input is stdin and output is stdout */ 22/* if fn is NULL then input is stdin and output is stdout */
23static int convert(char *fn, int ConvType) 23static int convert(char *fn, int conv_type)
24{ 24{
25 FILE *in, *out; 25 FILE *in, *out;
26 int i; 26 int i;
@@ -52,7 +52,7 @@ static int convert(char *fn, int ConvType)
52 if (i == '\r') 52 if (i == '\r')
53 continue; 53 continue;
54 if (i == '\n') { 54 if (i == '\n') {
55 if (ConvType == CT_UNIX2DOS) 55 if (conv_type == CT_UNIX2DOS)
56 fputc('\r', out); 56 fputc('\r', out);
57 fputc('\n', out); 57 fputc('\n', out);
58 continue; 58 continue;
@@ -81,29 +81,27 @@ static int convert(char *fn, int ConvType)
81int dos2unix_main(int argc, char **argv); 81int dos2unix_main(int argc, char **argv);
82int dos2unix_main(int argc, char **argv) 82int dos2unix_main(int argc, char **argv)
83{ 83{
84 int o, ConvType; 84 int o, conv_type;
85 85
86 /* See if we are supposed to be doing dos2unix or unix2dos */ 86 /* See if we are supposed to be doing dos2unix or unix2dos */
87 if (applet_name[0] == 'd') { 87 if (applet_name[0] == 'd') {
88 ConvType = CT_DOS2UNIX; /* 2 */ 88 conv_type = CT_DOS2UNIX; /* 2 */
89 } else { 89 } else {
90 ConvType = CT_UNIX2DOS; /* 1 */ 90 conv_type = CT_UNIX2DOS; /* 1 */
91 } 91 }
92 /* -u and -d are mutally exclusive */ 92
93 opt_complementary = "?:u--d:d--u"; 93 /* -u convert to unix, -d convert to dos */
94 /* process parameters */ 94 opt_complementary = "u--d:d--u"; /* mutally exclusive */
95 /* -u convert to unix */
96 /* -d convert to dos */
97 o = getopt32(argc, argv, "du"); 95 o = getopt32(argc, argv, "du");
98 96
99 /* Do the conversion requested by an argument else do the default 97 /* Do the conversion requested by an argument else do the default
100 * conversion depending on our name. */ 98 * conversion depending on our name. */
101 if (o) 99 if (o)
102 ConvType = o; 100 conv_type = o;
103 101
104 do { 102 do {
105 /* might be convert(NULL) if there is no filename given */ 103 /* might be convert(NULL) if there is no filename given */
106 o = convert(argv[optind], ConvType); 104 o = convert(argv[optind], conv_type);
107 if (o < 0) 105 if (o < 0)
108 break; 106 break;
109 optind++; 107 optind++;
diff --git a/coreutils/id.c b/coreutils/id.c
index 9dd5b48d3..27fb26e77 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -49,7 +49,7 @@ int id_main(int argc, char **argv)
49#endif 49#endif
50 /* Don't allow -n -r -nr -ug -rug -nug -rnug */ 50 /* Don't allow -n -r -nr -ug -rug -nug -rnug */
51 /* Don't allow more than one username */ 51 /* Don't allow more than one username */
52 opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g"); 52 opt_complementary = "?1:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
53 flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z")); 53 flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z"));
54 54
55 /* This values could be overwritten later */ 55 /* This values could be overwritten later */
diff --git a/coreutils/install.c b/coreutils/install.c
index 5503b55cd..8d71fa070 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -99,7 +99,7 @@ int install_main(int argc, char **argv)
99#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS 99#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
100 applet_long_options = install_long_options; 100 applet_long_options = install_long_options;
101#endif 101#endif
102 opt_complementary = "?:s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z"); 102 opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
103 /* -c exists for backwards compatibility, it's needed */ 103 /* -c exists for backwards compatibility, it's needed */
104 104
105 flags = getopt32(argc, argv, "cdpsg:m:o:" USE_SELINUX("Z:"), 105 flags = getopt32(argc, argv, "cdpsg:m:o:" USE_SELINUX("Z:"),
diff --git a/coreutils/sort.c b/coreutils/sort.c
index f41bd6329..6371139cb 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -288,7 +288,7 @@ int sort_main(int argc, char **argv)
288 288
289 /* Parse command line options */ 289 /* Parse command line options */
290 /* -o and -t can be given at most once */ 290 /* -o and -t can be given at most once */
291 opt_complementary = "?:o--o:t--t:" /* -t, -o: maximum one of each */ 291 opt_complementary = "o--o:t--t:" /* -t, -o: maximum one of each */
292 "k::"; /* -k takes list */ 292 "k::"; /* -k takes list */
293 getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); 293 getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
294#if ENABLE_FEATURE_SORT_BIG 294#if ENABLE_FEATURE_SORT_BIG
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 0681a085c..fd9f60ce9 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -254,7 +254,7 @@ int start_stop_daemon_main(int argc, char **argv)
254#endif 254#endif
255 255
256 /* Check required one context option was given */ 256 /* Check required one context option was given */
257 opt_complementary = "K:S:?:K--S:S--K:m?p:K?xpun:S?xa"; 257 opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa";
258 opt = getopt32(argc, argv, "KSbqma:n:s:u:c:x:p:" 258 opt = getopt32(argc, argv, "KSbqma:n:s:u:c:x:p:"
259 USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"), 259 USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"),
260// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), 260// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"),
diff --git a/editors/cmp.c b/editors/cmp.c
index e5dda80ff..da431f39b 100644
--- a/editors/cmp.c
+++ b/editors/cmp.c
@@ -57,7 +57,7 @@ int cmp_main(int argc, char **argv)
57 57
58 xfunc_error_retval = 2; /* 1 is returned if files are different. */ 58 xfunc_error_retval = 2; /* 1 is returned if files are different. */
59 59
60 opt_complementary = "?:-1" 60 opt_complementary = "-1"
61 USE_DESKTOP(":?4") 61 USE_DESKTOP(":?4")
62 SKIP_DESKTOP(":?2") 62 SKIP_DESKTOP(":?2")
63 ":l--s:s--l"; 63 ":l--s:s--l";
diff --git a/include/libbb.h b/include/libbb.h
index a8b9b5bcf..b8ec83927 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -588,8 +588,6 @@ void bb_daemonize_or_rexec(int flags, char **argv);
588void bb_sanitize_stdio(void); 588void bb_sanitize_stdio(void);
589 589
590 590
591// TODO: always error out?
592enum { BB_GETOPT_ERROR = 0x80000000 };
593extern const char *opt_complementary; 591extern const char *opt_complementary;
594#if ENABLE_GETOPT_LONG 592#if ENABLE_GETOPT_LONG
595extern const struct option *applet_long_options; 593extern const struct option *applet_long_options;
diff --git a/ipsvd/tcpudp.c b/ipsvd/tcpudp.c
index bc3d3a209..492808a6b 100644
--- a/ipsvd/tcpudp.c
+++ b/ipsvd/tcpudp.c
@@ -150,7 +150,7 @@ int tcpudpsvd_main(int argc, char **argv)
150 tcp = (applet_name[0] == 't'); 150 tcp = (applet_name[0] == 't');
151 151
152 /* 3+ args, -i at most once, -p implies -h, -v is counter */ 152 /* 3+ args, -i at most once, -p implies -h, -v is counter */
153 opt_complementary = "-3:?:i--i:ph:vv"; 153 opt_complementary = "-3:i--i:ph:vv";
154#ifdef SSLSVD 154#ifdef SSLSVD
155 getopt32(argc, argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:", 155 getopt32(argc, argv, "+c:C:i:x:u:l:Eb:hpt:vU:/:Z:K:",
156 &str_c, &str_C, &instructs, &instructs, &user, &local_hostname, 156 &str_c, &str_C, &instructs, &instructs, &user, &local_hostname,
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index d4465f899..f5aaa70df 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -217,20 +217,12 @@ Special characters:
217 -b, -c and -f are mutally exclusive and should raise an error 217 -b, -c and -f are mutally exclusive and should raise an error
218 if specified together. In this case you must set 218 if specified together. In this case you must set
219 opt_complementary = "b--cf:c--bf:f--bc". If two of the 219 opt_complementary = "b--cf:c--bf:f--bc". If two of the
220 mutually exclusive options are found, getopt32's 220 mutually exclusive options are found, getopt32 will call
221 return value will have the error flag set (BB_GETOPT_ERROR) so 221 bb_show_usage() and die.
222 that we can check for it:
223
224 if (flags & BB_GETOPT_ERROR)
225 bb_show_usage();
226 222
227 "x--x" Variation of the above, it means that -x option should occur 223 "x--x" Variation of the above, it means that -x option should occur
228 at most once. 224 at most once.
229 225
230 "?" A "?" as the first char in a opt_complementary group means:
231 if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage
232 and exit instead. Next char after '?' can't be a digit.
233
234 "::" A double colon after a char in opt_complementary means that the 226 "::" A double colon after a char in opt_complementary means that the
235 option can occur multiple times. Each occurrence will be saved as 227 option can occur multiple times. Each occurrence will be saved as
236 a llist_t element instead of char*. 228 a llist_t element instead of char*.
@@ -476,11 +468,8 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
476 if (on_off->opt == 0 && c != 0) 468 if (on_off->opt == 0 && c != 0)
477 bb_show_usage(); 469 bb_show_usage();
478 } 470 }
479 if (flags & on_off->incongruously) { 471 if (flags & on_off->incongruously)
480 if ((spec_flgs & SHOW_USAGE_IF_ERROR)) 472 bb_show_usage();
481 bb_show_usage();
482 flags |= BB_GETOPT_ERROR;
483 }
484 trigger = on_off->switch_on & on_off->switch_off; 473 trigger = on_off->switch_on & on_off->switch_off;
485 flags &= ~(on_off->switch_off ^ trigger); 474 flags &= ~(on_off->switch_off ^ trigger);
486 flags |= on_off->switch_on ^ trigger; 475 flags |= on_off->switch_on ^ trigger;
diff --git a/miscutils/eject.c b/miscutils/eject.c
index ba7da5c65..8d062d1bb 100644
--- a/miscutils/eject.c
+++ b/miscutils/eject.c
@@ -32,7 +32,7 @@ int eject_main(int argc, char **argv)
32 const char *device; 32 const char *device;
33 int dev, cmd; 33 int dev, cmd;
34 34
35 opt_complementary = "?:?1:t--T:T--t"; 35 opt_complementary = "?1:t--T:T--t";
36 flags = getopt32(argc, argv, "tT"); 36 flags = getopt32(argc, argv, "tT");
37 device = argv[optind] ? : "/dev/cdrom"; 37 device = argv[optind] ? : "/dev/cdrom";
38 38
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 6909e8489..3165c2d68 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -210,7 +210,7 @@ int udhcpc_main(int argc, char **argv)
210 client_config.timeout = 3; 210 client_config.timeout = 3;
211 211
212 /* Parse command line */ 212 /* Parse command line */
213 opt_complementary = "?:c--C:C--c" // mutually exclusive 213 opt_complementary = "c--C:C--c" // mutually exclusive
214 ":hH:Hh"; // -h and -H are the same 214 ":hH:Hh"; // -h and -H are the same
215#if ENABLE_GETOPT_LONG 215#if ENABLE_GETOPT_LONG
216 applet_long_options = arg_options; 216 applet_long_options = arg_options;
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 01c7c27e8..95df7ea36 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -33,7 +33,7 @@ int dumpleases_main(int argc, char **argv)
33 33
34 applet_long_options = options; 34 applet_long_options = options;
35#endif 35#endif
36 opt_complementary = "=0:?:a--r:r--a"; 36 opt_complementary = "=0:a--r:r--a";
37 opt = getopt32(argc, argv, "arf:", &file); 37 opt = getopt32(argc, argv, "arf:", &file);
38 38
39 fd = xopen(file, O_RDONLY); 39 fd = xopen(file, O_RDONLY);
diff --git a/util-linux/getopt.c b/util-linux/getopt.c
index 06c348895..a5e674368 100644
--- a/util-linux/getopt.c
+++ b/util-linux/getopt.c
@@ -318,7 +318,7 @@ int getopt_main(int argc, char *argv[])
318 opt = getopt32(argc, argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); 318 opt = getopt32(argc, argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg);
319#else 319#else
320 applet_long_options = longopts; 320 applet_long_options = longopts;
321 opt_complementary = "?:l::"; 321 opt_complementary = "l::";
322 opt = getopt32(argc, argv, "+o:n:qQs:Tual:", 322 opt = getopt32(argc, argv, "+o:n:qQs:Tual:",
323 &optstr, &name, &s_arg, &l_arg); 323 &optstr, &name, &s_arg, &l_arg);
324 /* Effectuate the read options for the applet itself */ 324 /* Effectuate the read options for the applet itself */
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 8b65df6a6..882a0c55a 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -189,7 +189,7 @@ int hwclock_main(int argc, char **argv)
189 }; 189 };
190 applet_long_options = hwclock_long_options; 190 applet_long_options = hwclock_long_options;
191#endif 191#endif
192 opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l"; 192 opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l";
193 opt = getopt32(argc, argv, "lurswf:", &rtcname); 193 opt = getopt32(argc, argv, "lurswf:", &rtcname);
194 194
195 /* If -u or -l wasn't given check if we are using utc */ 195 /* If -u or -l wasn't given check if we are using utc */