diff options
-rw-r--r-- | archival/ar.c | 4 | ||||
-rw-r--r-- | archival/dpkg_deb.c | 4 | ||||
-rw-r--r-- | archival/tar.c | 6 | ||||
-rw-r--r-- | coreutils/cut.c | 2 | ||||
-rw-r--r-- | coreutils/date.c | 4 | ||||
-rw-r--r-- | coreutils/df.c | 2 | ||||
-rw-r--r-- | coreutils/du.c | 4 | ||||
-rw-r--r-- | coreutils/env.c | 2 | ||||
-rw-r--r-- | coreutils/id.c | 5 | ||||
-rw-r--r-- | coreutils/install.c | 7 | ||||
-rw-r--r-- | coreutils/mv.c | 2 | ||||
-rw-r--r-- | coreutils/rm.c | 2 | ||||
-rw-r--r-- | debianutils/start_stop_daemon.c | 6 | ||||
-rw-r--r-- | findutils/grep.c | 4 | ||||
-rw-r--r-- | findutils/xargs.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/getopt_ulflags.c | 273 | ||||
-rw-r--r-- | miscutils/crond.c | 4 | ||||
-rw-r--r-- | networking/wget.c | 2 | ||||
-rw-r--r-- | util-linux/hwclock.c | 6 |
20 files changed, 176 insertions, 167 deletions
diff --git a/archival/ar.c b/archival/ar.c index 8326aa6de..21096d712 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -67,10 +67,10 @@ extern int ar_main(int argc, char **argv) | |||
67 | 67 | ||
68 | archive_handle = init_handle(); | 68 | archive_handle = init_handle(); |
69 | 69 | ||
70 | bb_opt_complementaly = "p~tx:t~px:x~pt"; | 70 | bb_opt_complementally = "!p~tx:t~px:x~pt"; |
71 | opt = bb_getopt_ulflags(argc, argv, "ptxovcr"); | 71 | opt = bb_getopt_ulflags(argc, argv, "ptxovcr"); |
72 | 72 | ||
73 | if ((opt & BB_GETOPT_ERROR) || (opt == 0) || (optind == argc)) { | 73 | if ((opt == 0) || (optind == argc)) { |
74 | bb_show_usage(); | 74 | bb_show_usage(); |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index b95ec2d6e..6c665e57a 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
@@ -56,7 +56,7 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
56 | control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2"); | 56 | control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2"); |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | bb_opt_complementaly = "c~efXx:e~cfXx:f~ceXx:X~cefx:x~cefX"; | 59 | bb_opt_complementally = "!c~efXx:e~cfXx:f~ceXx:X~cefx:x~cefX"; |
60 | opt = bb_getopt_ulflags(argc, argv, "cefXx"); | 60 | opt = bb_getopt_ulflags(argc, argv, "cefXx"); |
61 | 61 | ||
62 | if (opt & DPKG_DEB_OPT_CONTENTS) { | 62 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
@@ -88,7 +88,7 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
88 | argcount = 2; | 88 | argcount = 2; |
89 | } | 89 | } |
90 | 90 | ||
91 | if ((optind + argcount != argc) || (opt & BB_GETOPT_ERROR)) { | 91 | if ((optind + argcount) != argc) { |
92 | bb_show_usage(); | 92 | bb_show_usage(); |
93 | } | 93 | } |
94 | 94 | ||
diff --git a/archival/tar.c b/archival/tar.c index 585f0629f..a2623863d 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -706,7 +706,7 @@ int tar_main(int argc, char **argv) | |||
706 | tar_handle = init_handle(); | 706 | tar_handle = init_handle(); |
707 | tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL; | 707 | tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL; |
708 | 708 | ||
709 | bb_opt_complementaly = "c~tx:t~cx:x~ct:X*:T*"; | 709 | bb_opt_complementally = "!c~tx:t~cx:x~ct:X*:T*"; |
710 | #ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS | 710 | #ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS |
711 | bb_applet_long_options = tar_long_options; | 711 | bb_applet_long_options = tar_long_options; |
712 | #endif | 712 | #endif |
@@ -720,10 +720,6 @@ int tar_main(int argc, char **argv) | |||
720 | #endif | 720 | #endif |
721 | ); | 721 | ); |
722 | 722 | ||
723 | /* Check one and only one context option was given */ | ||
724 | if(opt & BB_GETOPT_ERROR) { | ||
725 | bb_show_usage(); | ||
726 | } | ||
727 | #ifdef CONFIG_FEATURE_TAR_CREATE | 723 | #ifdef CONFIG_FEATURE_TAR_CREATE |
728 | ctx_flag = opt & (CTX_CREATE | CTX_TEST | CTX_EXTRACT); | 724 | ctx_flag = opt & (CTX_CREATE | CTX_TEST | CTX_EXTRACT); |
729 | #else | 725 | #else |
diff --git a/coreutils/cut.c b/coreutils/cut.c index e5fb5aff7..f65754e63 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -295,7 +295,7 @@ extern int cut_main(int argc, char **argv) | |||
295 | unsigned long opt; | 295 | unsigned long opt; |
296 | char *sopt, *sdopt; | 296 | char *sopt, *sdopt; |
297 | 297 | ||
298 | bb_opt_complementaly = "b~bcf:c~bcf:f~bcf"; | 298 | bb_opt_complementally = "b~bcf:c~bcf:f~bcf"; |
299 | opt = bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, &sdopt); | 299 | opt = bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, &sdopt); |
300 | part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS); | 300 | part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS); |
301 | if(part == 0) | 301 | if(part == 0) |
diff --git a/coreutils/date.c b/coreutils/date.c index 70484e2cd..0488b2de3 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -152,7 +152,7 @@ int date_main(int argc, char **argv) | |||
152 | #else | 152 | #else |
153 | # define GETOPT_ISOFMT | 153 | # define GETOPT_ISOFMT |
154 | #endif | 154 | #endif |
155 | bb_opt_complementaly = "d~ds:s~ds"; | 155 | bb_opt_complementally = "!d~ds:s~ds"; |
156 | opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT, | 156 | opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT, |
157 | &date_str, &date_str, &filename | 157 | &date_str, &date_str, &filename |
158 | #ifdef CONFIG_FEATURE_DATE_ISOFMT | 158 | #ifdef CONFIG_FEATURE_DATE_ISOFMT |
@@ -165,8 +165,6 @@ int date_main(int argc, char **argv) | |||
165 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 165 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
166 | } | 166 | } |
167 | use_arg = opt & DATE_OPT_DATE; | 167 | use_arg = opt & DATE_OPT_DATE; |
168 | if(opt & BB_GETOPT_ERROR) | ||
169 | bb_show_usage(); | ||
170 | #ifdef CONFIG_FEATURE_DATE_ISOFMT | 168 | #ifdef CONFIG_FEATURE_DATE_ISOFMT |
171 | if(opt & DATE_OPT_TIMESPEC) { | 169 | if(opt & DATE_OPT_TIMESPEC) { |
172 | if (!isofmt_arg) { | 170 | if (!isofmt_arg) { |
diff --git a/coreutils/df.c b/coreutils/df.c index 9233fbbf1..51d3cc632 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -62,7 +62,7 @@ extern int df_main(int argc, char **argv) | |||
62 | const char *disp_units_hdr = hdr_1k; | 62 | const char *disp_units_hdr = hdr_1k; |
63 | 63 | ||
64 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 64 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
65 | bb_opt_complementaly = "h-km:k-hm:m-hk"; | 65 | bb_opt_complementally = "h-km:k-hm:m-hk"; |
66 | opt = bb_getopt_ulflags(argc, argv, "hmk"); | 66 | opt = bb_getopt_ulflags(argc, argv, "hmk"); |
67 | if(opt & 1) { | 67 | if(opt & 1) { |
68 | df_disp_hr = 0; | 68 | df_disp_hr = 0; |
diff --git a/coreutils/du.c b/coreutils/du.c index bfa44034a..3778f0895 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -191,7 +191,7 @@ int du_main(int argc, char **argv) | |||
191 | * ignore -a. This is consistent with -s being equivalent to -d 0. | 191 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
192 | */ | 192 | */ |
193 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 193 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
194 | bb_opt_complementaly = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; | 194 | bb_opt_complementally = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; |
195 | opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); | 195 | opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); |
196 | if((opt & (1 << 9))) { | 196 | if((opt & (1 << 9))) { |
197 | /* -h opt */ | 197 | /* -h opt */ |
@@ -206,7 +206,7 @@ int du_main(int argc, char **argv) | |||
206 | disp_hr = KILOBYTE; | 206 | disp_hr = KILOBYTE; |
207 | } | 207 | } |
208 | #else | 208 | #else |
209 | bb_opt_complementaly = "H-L:L-H:s-d:d-s"; | 209 | bb_opt_complementally = "H-L:L-H:s-d:d-s"; |
210 | opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); | 210 | opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); |
211 | #if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K | 211 | #if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K |
212 | if((opt & (1 << 2))) { | 212 | if((opt & (1 << 2))) { |
diff --git a/coreutils/env.c b/coreutils/env.c index 87ab30cdd..70cef6588 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -65,7 +65,7 @@ extern int env_main(int argc, char** argv) | |||
65 | llist_t *unset_env = NULL; | 65 | llist_t *unset_env = NULL; |
66 | extern char **environ; | 66 | extern char **environ; |
67 | 67 | ||
68 | bb_opt_complementaly = "u*"; | 68 | bb_opt_complementally = "u*"; |
69 | bb_applet_long_options = env_long_options; | 69 | bb_applet_long_options = env_long_options; |
70 | 70 | ||
71 | opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env); | 71 | opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env); |
diff --git a/coreutils/id.c b/coreutils/id.c index 636049168..03c6a6d2a 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -61,12 +61,11 @@ extern int id_main(int argc, char **argv) | |||
61 | unsigned long flags; | 61 | unsigned long flags; |
62 | short status; | 62 | short status; |
63 | 63 | ||
64 | bb_opt_complementaly = "u~g:g~u"; | 64 | bb_opt_complementally = "!u~g:g~u"; |
65 | flags = bb_getopt_ulflags(argc, argv, "rnug"); | 65 | flags = bb_getopt_ulflags(argc, argv, "rnug"); |
66 | 66 | ||
67 | if ((flags & BB_GETOPT_ERROR) | ||
68 | /* Don't allow -n -r -nr */ | 67 | /* Don't allow -n -r -nr */ |
69 | || (flags <= 3 && flags > 0) | 68 | if ((flags <= 3 && flags > 0) |
70 | /* Don't allow more than one username */ | 69 | /* Don't allow more than one username */ |
71 | || (argc > optind + 1)) | 70 | || (argc > optind + 1)) |
72 | bb_show_usage(); | 71 | bb_show_usage(); |
diff --git a/coreutils/install.c b/coreutils/install.c index 345e75af0..e22dda6f9 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
@@ -64,15 +64,10 @@ extern int install_main(int argc, char **argv) | |||
64 | int i; | 64 | int i; |
65 | 65 | ||
66 | bb_applet_long_options = install_long_options; | 66 | bb_applet_long_options = install_long_options; |
67 | bb_opt_complementaly = "s~d:d~s"; | 67 | bb_opt_complementally = "!s~d:d~s"; |
68 | /* -c exists for backwards compatability, its needed */ | 68 | /* -c exists for backwards compatability, its needed */ |
69 | flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */ | 69 | flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */ |
70 | 70 | ||
71 | /* Check valid options were given */ | ||
72 | if(flags & BB_GETOPT_ERROR) { | ||
73 | bb_show_usage(); | ||
74 | } | ||
75 | |||
76 | /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */ | 71 | /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */ |
77 | if (flags & INSTALL_OPT_PRESERVE_TIME) { | 72 | if (flags & INSTALL_OPT_PRESERVE_TIME) { |
78 | copy_flags |= FILEUTILS_PRESERVE_STATUS; | 73 | copy_flags |= FILEUTILS_PRESERVE_STATUS; |
diff --git a/coreutils/mv.c b/coreutils/mv.c index e1c4529ad..43a8e6d7d 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c | |||
@@ -56,7 +56,7 @@ extern int mv_main(int argc, char **argv) | |||
56 | int status = 0; | 56 | int status = 0; |
57 | 57 | ||
58 | bb_applet_long_options = mv_long_options; | 58 | bb_applet_long_options = mv_long_options; |
59 | bb_opt_complementaly = "f-i:i-f"; | 59 | bb_opt_complementally = "f-i:i-f"; |
60 | flags = bb_getopt_ulflags(argc, argv, "fi"); | 60 | flags = bb_getopt_ulflags(argc, argv, "fi"); |
61 | if (optind + 2 > argc) { | 61 | if (optind + 2 > argc) { |
62 | bb_show_usage(); | 62 | bb_show_usage(); |
diff --git a/coreutils/rm.c b/coreutils/rm.c index 39609e7b8..e4e9bb0be 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c | |||
@@ -38,7 +38,7 @@ extern int rm_main(int argc, char **argv) | |||
38 | int flags = 0; | 38 | int flags = 0; |
39 | unsigned long opt; | 39 | unsigned long opt; |
40 | 40 | ||
41 | bb_opt_complementaly = "f-i:i-f"; | 41 | bb_opt_complementally = "f-i:i-f"; |
42 | opt = bb_getopt_ulflags(argc, argv, "fiRr"); | 42 | opt = bb_getopt_ulflags(argc, argv, "fiRr"); |
43 | if(opt & 1) | 43 | if(opt & 1) |
44 | flags |= FILEUTILS_FORCE; | 44 | flags |= FILEUTILS_FORCE; |
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 03f49165c..4fce80dbb 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -233,12 +233,12 @@ start_stop_daemon_main(int argc, char **argv) | |||
233 | 233 | ||
234 | bb_applet_long_options = ssd_long_options; | 234 | bb_applet_long_options = ssd_long_options; |
235 | 235 | ||
236 | bb_opt_complementaly = "K~S:S~K"; | 236 | bb_opt_complementally = "!K~S:S~K"; |
237 | opt = bb_getopt_ulflags(argc, argv, "KSbqma:n:s:u:x:p:", | 237 | opt = bb_getopt_ulflags(argc, argv, "KSbqma:n:s:u:x:p:", |
238 | &startas, &cmdname, &signame, &userspec, &execname, &pidfile); | 238 | &startas, &cmdname, &signame, &userspec, &execname, &pidfile); |
239 | 239 | ||
240 | /* Check one and only one context option was given */ | 240 | /* Check required one context option was given */ |
241 | if ((opt & BB_GETOPT_ERROR) || (opt & (SSD_CTX_STOP | SSD_CTX_START)) == 0) { | 241 | if ((opt & (SSD_CTX_STOP | SSD_CTX_START)) == 0) { |
242 | bb_show_usage(); | 242 | bb_show_usage(); |
243 | } | 243 | } |
244 | 244 | ||
diff --git a/findutils/grep.c b/findutils/grep.c index a8fd2d41a..2a667e37f 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -271,7 +271,7 @@ extern int grep_main(int argc, char **argv) | |||
271 | char *slines_before; | 271 | char *slines_before; |
272 | char *Copt; | 272 | char *Copt; |
273 | 273 | ||
274 | bb_opt_complementaly = "H-h:e*:f*:C-AB"; | 274 | bb_opt_complementally = "H-h:e*:f*:C-AB"; |
275 | opt = bb_getopt_ulflags(argc, argv, | 275 | opt = bb_getopt_ulflags(argc, argv, |
276 | GREP_OPTS GREP_OPT_CONTEXT OPT_EGREP, | 276 | GREP_OPTS GREP_OPT_CONTEXT OPT_EGREP, |
277 | &pattern_head, &fopt, | 277 | &pattern_head, &fopt, |
@@ -306,7 +306,7 @@ extern int grep_main(int argc, char **argv) | |||
306 | } | 306 | } |
307 | #else | 307 | #else |
308 | /* with auto sanity checks */ | 308 | /* with auto sanity checks */ |
309 | bb_opt_complementaly = "H-h:e*:f*:c-n:q-n:l-n"; | 309 | bb_opt_complementally = "H-h:e*:f*:c-n:q-n:l-n"; |
310 | opt = bb_getopt_ulflags(argc, argv, GREP_OPTS OPT_EGREP, | 310 | opt = bb_getopt_ulflags(argc, argv, GREP_OPTS OPT_EGREP, |
311 | &pattern_head, &fopt); | 311 | &pattern_head, &fopt); |
312 | 312 | ||
diff --git a/findutils/xargs.c b/findutils/xargs.c index 1a4347828..eef7c6909 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -438,7 +438,7 @@ int xargs_main(int argc, char **argv) | |||
438 | #endif | 438 | #endif |
439 | 439 | ||
440 | #ifdef CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION | 440 | #ifdef CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION |
441 | bb_opt_complementaly = "pt"; | 441 | bb_opt_complementally = "pt"; |
442 | #endif | 442 | #endif |
443 | 443 | ||
444 | opt = bb_getopt_ulflags(argc, argv, "+trn:s:e::" | 444 | opt = bb_getopt_ulflags(argc, argv, "+trn:s:e::" |
diff --git a/include/libbb.h b/include/libbb.h index 077b310b6..15af6c463 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -152,7 +152,7 @@ extern int bb_fclose_nonstdin(FILE *f); | |||
152 | extern void bb_fflush_stdout_and_exit(int retval) __attribute__ ((noreturn)); | 152 | extern void bb_fflush_stdout_and_exit(int retval) __attribute__ ((noreturn)); |
153 | 153 | ||
154 | #define BB_GETOPT_ERROR 0x80000000UL | 154 | #define BB_GETOPT_ERROR 0x80000000UL |
155 | extern const char *bb_opt_complementaly; | 155 | extern const char *bb_opt_complementally; |
156 | extern const struct option *bb_applet_long_options; | 156 | extern const struct option *bb_applet_long_options; |
157 | extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...); | 157 | extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...); |
158 | 158 | ||
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c index 6197e8d9f..44c8e1a76 100644 --- a/libbb/getopt_ulflags.c +++ b/libbb/getopt_ulflags.c | |||
@@ -2,7 +2,7 @@ | |||
2 | /* | 2 | /* |
3 | * universal getopt_ulflags implementation for busybox | 3 | * universal getopt_ulflags implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2003 Vladimir Oleynik <dzo@simtreas.ru> | 5 | * Copyright (C) 2003-2005 Vladimir Oleynik <dzo@simtreas.ru> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -31,158 +31,152 @@ | |||
31 | unsigned long | 31 | unsigned long |
32 | bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | 32 | bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) |
33 | 33 | ||
34 | The command line options must be declared in const char | 34 | The command line options must be declared in const char |
35 | *applet_opts as a string of chars, for example: | 35 | *applet_opts as a string of chars, for example: |
36 | 36 | ||
37 | flags = bb_getopt_ulflags(argc, argv, "rnug"); | 37 | flags = bb_getopt_ulflags(argc, argv, "rnug"); |
38 | 38 | ||
39 | If one of the given options is found, a flag value is added to | 39 | If one of the given options is found, a flag value is added to |
40 | the return value (an unsigned long). | 40 | the return value (an unsigned long). |
41 | 41 | ||
42 | The flag value is determined by the position of the char in | 42 | The flag value is determined by the position of the char in |
43 | applet_opts string. For example, in the above case: | 43 | applet_opts string. For example, in the above case: |
44 | 44 | ||
45 | flags = bb_getopt_ulflags(argc, argv, "rnug"); | 45 | flags = bb_getopt_ulflags(argc, argv, "rnug"); |
46 | 46 | ||
47 | "r" will add 1 (bit 1 : 0x01) | 47 | "r" will add 1 (bit 1 : 0x01) |
48 | "n" will add 2 (bit 2 : 0x02) | 48 | "n" will add 2 (bit 2 : 0x02) |
49 | "u will add 4 (bit 3 : 0x03) | 49 | "u will add 4 (bit 3 : 0x03) |
50 | "g" will add 8 (bit 4 : 0x04) | 50 | "g" will add 8 (bit 4 : 0x04) |
51 | 51 | ||
52 | and so on. You can also look at the return value as a bit | 52 | and so on. You can also look at the return value as a bit |
53 | field and each option sets one of bits. | 53 | field and each option sets one of bits. |
54 | 54 | ||
55 | ":" If one of the options requires an argument, then add a ":" | 55 | ":" If one of the options requires an argument, then add a ":" |
56 | after the char in applet_opts and provide a pointer to store | 56 | after the char in applet_opts and provide a pointer to store |
57 | the argument. For example: | 57 | the argument. For example: |
58 | 58 | ||
59 | char *pointer_to_arg_for_a; | 59 | char *pointer_to_arg_for_a; |
60 | char *pointer_to_arg_for_b; | 60 | char *pointer_to_arg_for_b; |
61 | char *pointer_to_arg_for_c; | 61 | char *pointer_to_arg_for_c; |
62 | char *pointer_to_arg_for_d; | 62 | char *pointer_to_arg_for_d; |
63 | 63 | ||
64 | flags = bb_getopt_ulflags(argc, argv, "a:b:c:d:", | 64 | flags = bb_getopt_ulflags(argc, argv, "a:b:c:d:", |
65 | &pointer_to_arg_for_a, &pointer_to_arg_for_b, | 65 | &pointer_to_arg_for_a, &pointer_to_arg_for_b, |
66 | &pointer_to_arg_for_c, &pointer_to_arg_for_d); | 66 | &pointer_to_arg_for_c, &pointer_to_arg_for_d); |
67 | 67 | ||
68 | The type of the pointer (char* or llist_t *) may be controlled | 68 | The type of the pointer (char* or llist_t *) may be controlled |
69 | by the "*" special character that is set in the external string | 69 | by the "*" special character that is set in the external string |
70 | bb_opt_complementaly (see below for more info). | 70 | bb_opt_complementally (see below for more info). |
71 | 71 | ||
72 | static const struct option bb_default_long_options[] | 72 | static const struct option bb_default_long_options[] |
73 | 73 | ||
74 | This struct allows you to define long options. The syntax for | 74 | This struct allows you to define long options. The syntax for |
75 | declaring the array is just like that of getopt's longopts. | 75 | declaring the array is just like that of getopt's longopts. |
76 | (see getopt(3)) | ||
76 | 77 | ||
77 | static const struct option applet_long_options[] = { | 78 | static const struct option applet_long_options[] = { |
78 | { "verbose", 0, 0, "v" }, | 79 | { "verbose", 0, 0, v }, |
79 | { 0, 0, 0, 0 } | 80 | { 0, 0, 0, 0 } |
80 | }; | 81 | }; |
81 | bb_applet_long_options = applet_long_options; | 82 | bb_applet_long_options = applet_long_options; |
82 | 83 | ||
83 | The first parameter is the long option name that you would pass | 84 | The last argument (val) can undefined from applet_opts. |
84 | to the applet (without the dashes). | 85 | If you use this, then: |
86 | - return bit have next position after short options | ||
87 | - if has_arg is not "no_argument", use ptr for arg also | ||
88 | - bb_opt_complementally have effects for this too | ||
85 | 89 | ||
86 | The second field determines whether the option has an argument. | 90 | Note: a good applet will make long options configurable via the |
87 | You can set this to 0, 1, or 2, or you can use the long named | 91 | config process and not a required feature. The current standard |
88 | defines of no_argument, required_argument, and optional_argument. | 92 | is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS. |
89 | 93 | ||
90 | The third argument is used only when the long option does not | 94 | const char *bb_opt_complementally |
91 | have a corresponding short option. In that case, it should be | ||
92 | an integer pointer. Otherwise (and normally), it should just | ||
93 | bet set to NULL. | ||
94 | 95 | ||
95 | The last argument is the corresponding short option (if there | 96 | ":" The colon (":") is used to separate groups of two or more chars |
96 | is one of course). | 97 | and/or groups of chars and special characters (stating some |
98 | conditions to be checked). | ||
97 | 99 | ||
98 | Note: a good applet will make long options configurable via the | 100 | "abc" If groups of two or more chars are specified, the first char |
99 | config process and not a required feature. The current standard | 101 | is the main option and the other chars are secondary options. |
100 | is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS. | 102 | Their flags will be turned on if the main option is found even |
103 | if they are not specifed on the command line. For example: | ||
101 | 104 | ||
102 | const char *bb_opt_complementaly | 105 | bb_opt_complementally = "abc"; |
103 | 106 | ||
104 | ":" The colon (":") is used to separate groups of two or more chars | 107 | flags = bb_getopt_ulflags(argc, argv, "abcd") |
105 | and/or groups of chars and special characters (stating some | ||
106 | conditions to be checked). | ||
107 | 108 | ||
108 | "abc" If groups of two or more chars are specified, the first char | 109 | If getopt() finds "-a" on the command line, then |
109 | is the main option and the other chars are secondary options. | 110 | bb_getopt_ulflags's return value will be as if "-a -b -c" were |
110 | Their flags will be turned on if the main option is found even | 111 | found. |
111 | if they are not specifed on the command line. For example: | ||
112 | |||
113 | bb_opt_complementaly = "abc"; | ||
114 | |||
115 | flags = bb_getopt_ulflags(argc, argv, "abcd") | ||
116 | |||
117 | If getopt() finds "-a" on the command line, then | ||
118 | bb_getopt_ulflags's return value will be as if "-a -b -c" were | ||
119 | found. | ||
120 | 112 | ||
121 | Special characters: | 113 | Special characters: |
122 | 114 | ||
123 | "-" A dash between two options causes the second of the two | 115 | "-" A dash between two options causes the second of the two |
124 | to be unset (and ignored) if it is given on the command line. | 116 | to be unset (and ignored) if it is given on the command line. |
125 | 117 | ||
126 | For example: | 118 | For example: |
127 | The du applet has the options "-s" and "-d depth". If | 119 | The du applet has the options "-s" and "-d depth". If |
128 | bb_getopt_ulflags finds -s, then -d is unset or if it finds -d | 120 | bb_getopt_ulflags finds -s, then -d is unset or if it finds -d |
129 | then -s is unset. (Note: busybox implements the GNU | 121 | then -s is unset. (Note: busybox implements the GNU |
130 | "--max-depth" option as "-d".) To obtain this behavior, you | 122 | "--max-depth" option as "-d".) To obtain this behavior, you |
131 | set bb_opt_complementaly = "s-d:d-s". Only one flag value is | 123 | set bb_opt_complementally = "s-d:d-s". Only one flag value is |
132 | added to bb_getopt_ulflags's return value depending on the | 124 | added to bb_getopt_ulflags's return value depending on the |
133 | position of the options on the command line. If one of the | 125 | position of the options on the command line. If one of the |
134 | two options requires an argument pointer (":" in applet_opts | 126 | two options requires an argument pointer (":" in applet_opts |
135 | as in "d:") optarg is set accordingly. | 127 | as in "d:") optarg is set accordingly. |
136 | 128 | ||
137 | char *smax_print_depth; | 129 | char *smax_print_depth; |
138 | 130 | ||
139 | bb_opt_complementaly = "s-d:d-s"; | 131 | bb_opt_complementally = "s-d:d-s"; |
140 | opt = bb_getopt_ulflags(argc, argv, "sd:", &smax_print_depth); | 132 | opt = bb_getopt_ulflags(argc, argv, "sd:", &smax_print_depth); |
141 | 133 | ||
142 | if (opt & 2) { | 134 | if (opt & 2) { |
143 | max_print_depth = bb_xgetularg10_bnd(smax_print_depth, | 135 | max_print_depth = bb_xgetularg10_bnd(smax_print_depth, |
144 | 0, INT_MAX); | 136 | 0, INT_MAX); |
145 | } | 137 | } |
146 | 138 | ||
147 | "~" A tilde between two options, or between an option and a group | 139 | "~" A tilde between two options, or between an option and a group |
148 | of options, means that they are mutually exclusive. Unlike | 140 | of options, means that they are mutually exclusive. Unlike |
149 | the "-" case above, an error will be forced if the options | 141 | the "-" case above, an error will be forced if the options |
150 | are used together. | 142 | are used together. |
151 | 143 | ||
152 | For example: | 144 | For example: |
153 | The cut applet must have only one type of list specified, so | 145 | The cut applet must have only one type of list specified, so |
154 | -b, -c and -f are mutally exclusive and should raise an error | 146 | -b, -c and -f are mutally exclusive and should raise an error |
155 | if specified together. In this case you must set | 147 | if specified together. In this case you must set |
156 | bb_opt_complementaly = "b~cf:c~bf:f~bc". If two of the | 148 | bb_opt_complementally = "b~cf:c~bf:f~bc". If two of the |
157 | mutually exclusive options are found, bb_getopt_ulflags's | 149 | mutually exclusive options are found, bb_getopt_ulflags's |
158 | return value will have the error flag set (BB_GETOPT_ERROR) so | 150 | return value will have the error flag set (BB_GETOPT_ERROR) so |
159 | that we can check for it: | 151 | that we can check for it: |
160 | 152 | ||
161 | if (flags & BB_GETOPT_ERROR) | 153 | if (flags & BB_GETOPT_ERROR) |
162 | bb_show_usage(); | 154 | bb_show_usage(); |
163 | 155 | ||
164 | "*" A star after a char in bb_opt_complementaly means that the | 156 | "!" If previous point set BB_GETOPT_ERROR, don`t return and call |
165 | option can occur multiple times: | 157 | previous example internally |
166 | 158 | ||
167 | For example: | 159 | "*" A star after a char in bb_opt_complementally means that the |
168 | The grep applet can have one or more "-e pattern" arguments. | 160 | option can occur multiple times: |
169 | In this case you should use bb_getopt_ulflags() as follows: | ||
170 | 161 | ||
171 | llist_t *patterns = NULL; | 162 | For example: |
163 | The grep applet can have one or more "-e pattern" arguments. | ||
164 | In this case you should use bb_getopt_ulflags() as follows: | ||
172 | 165 | ||
173 | (this pointer must be initializated to NULL if the list is empty | 166 | llist_t *patterns = NULL; |
174 | as required by *llist_add_to(llist_t *old_head, char *new_item).) | ||
175 | 167 | ||
176 | bb_opt_complementaly = "e*"; | 168 | (this pointer must be initializated to NULL if the list is empty |
169 | as required by *llist_add_to(llist_t *old_head, char *new_item).) | ||
177 | 170 | ||
178 | bb_getopt_ulflags(argc, argv, "e:", &patterns); | 171 | bb_opt_complementally = "e*"; |
179 | $ grep -e user -e root /etc/passwd | ||
180 | root:x:0:0:root:/root:/bin/bash | ||
181 | user:x:500:500::/home/user:/bin/bash | ||
182 | 172 | ||
173 | bb_getopt_ulflags(argc, argv, "e:", &patterns); | ||
174 | $ grep -e user -e root /etc/passwd | ||
175 | root:x:0:0:root:/root:/bin/bash | ||
176 | user:x:500:500::/home/user:/bin/bash | ||
183 | */ | 177 | */ |
184 | 178 | ||
185 | const char *bb_opt_complementaly; | 179 | const char *bb_opt_complementally; |
186 | 180 | ||
187 | typedef struct { | 181 | typedef struct { |
188 | unsigned char opt; | 182 | unsigned char opt; |
@@ -191,12 +185,12 @@ typedef struct { | |||
191 | unsigned long switch_off; | 185 | unsigned long switch_off; |
192 | unsigned long incongruously; | 186 | unsigned long incongruously; |
193 | void **optarg; /* char **optarg or llist_t **optarg */ | 187 | void **optarg; /* char **optarg or llist_t **optarg */ |
194 | } t_complementaly; | 188 | } t_complementally; |
195 | 189 | ||
196 | /* You can set bb_applet_long_options for parse called long options */ | 190 | /* You can set bb_applet_long_options for parse called long options */ |
197 | 191 | ||
198 | static const struct option bb_default_long_options[] = { | 192 | static const struct option bb_default_long_options[] = { |
199 | /* { "help", 0, NULL, '?' }, */ | 193 | /* { "help", 0, NULL, '?' }, */ |
200 | { 0, 0, 0, 0 } | 194 | { 0, 0, 0, 0 } |
201 | }; | 195 | }; |
202 | 196 | ||
@@ -206,11 +200,13 @@ unsigned long | |||
206 | bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | 200 | bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) |
207 | { | 201 | { |
208 | unsigned long flags = 0; | 202 | unsigned long flags = 0; |
209 | t_complementaly complementaly[sizeof(flags) * 8 + 1]; | 203 | t_complementally complementally[sizeof(flags) * 8 + 1]; |
210 | int c; | 204 | int c; |
211 | const unsigned char *s; | 205 | const unsigned char *s; |
212 | t_complementaly *on_off; | 206 | t_complementally *on_off; |
213 | va_list p; | 207 | va_list p; |
208 | const struct option *l_o; | ||
209 | char flg_show_usage_if_error = 0; | ||
214 | 210 | ||
215 | va_start (p, applet_opts); | 211 | va_start (p, applet_opts); |
216 | 212 | ||
@@ -220,7 +216,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | |||
220 | s++; | 216 | s++; |
221 | 217 | ||
222 | c = 0; | 218 | c = 0; |
223 | on_off = complementaly; | 219 | on_off = complementally; |
224 | for (; *s; s++) { | 220 | for (; *s; s++) { |
225 | if(c >= (sizeof(flags)*8)) | 221 | if(c >= (sizeof(flags)*8)) |
226 | break; | 222 | break; |
@@ -240,9 +236,31 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | |||
240 | c++; | 236 | c++; |
241 | } | 237 | } |
242 | on_off->opt = 0; | 238 | on_off->opt = 0; |
239 | |||
240 | for(l_o = bb_applet_long_options; l_o->name; l_o++) { | ||
241 | for(on_off = complementally; on_off->opt != 0; on_off++) | ||
242 | if(on_off->opt == l_o->val) | ||
243 | break; | ||
244 | if(on_off->opt == 0) { | ||
245 | if(c >= (sizeof(flags)*8)) | ||
246 | break; | ||
247 | on_off->opt = l_o->val; | ||
248 | on_off->switch_on = (1 << c); | ||
249 | on_off->list_flg = 0; | ||
250 | on_off->switch_off = 0; | ||
251 | on_off->incongruously = 0; | ||
252 | if(l_o->has_arg != no_argument) | ||
253 | on_off->optarg = va_arg (p, void **); | ||
254 | else | ||
255 | on_off->optarg = NULL; | ||
256 | on_off++; | ||
257 | on_off->opt = 0; | ||
258 | c++; | ||
259 | } | ||
260 | } | ||
243 | c = 0; | 261 | c = 0; |
244 | for (s = bb_opt_complementaly; s && *s; s++) { | 262 | for (s = bb_opt_complementally; s && *s; s++) { |
245 | t_complementaly *pair; | 263 | t_complementally *pair; |
246 | 264 | ||
247 | if (*s == ':') { | 265 | if (*s == ':') { |
248 | c = 0; | 266 | c = 0; |
@@ -250,7 +268,11 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | |||
250 | } | 268 | } |
251 | if (c) | 269 | if (c) |
252 | continue; | 270 | continue; |
253 | for (on_off = complementaly; on_off->opt; on_off++) | 271 | if(*s == '!') { |
272 | flg_show_usage_if_error = '!'; | ||
273 | continue; | ||
274 | } | ||
275 | for (on_off = complementally; on_off->opt; on_off++) | ||
254 | if (on_off->opt == *s) | 276 | if (on_off->opt == *s) |
255 | break; | 277 | break; |
256 | pair = on_off; | 278 | pair = on_off; |
@@ -263,7 +285,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | |||
263 | unsigned long *pair_switch = &(pair->switch_on); | 285 | unsigned long *pair_switch = &(pair->switch_on); |
264 | if(c) | 286 | if(c) |
265 | pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously); | 287 | pair_switch = c == '-' ? &(pair->switch_off) : &(pair->incongruously); |
266 | for (on_off = complementaly; on_off->opt; on_off++) | 288 | for (on_off = complementally; on_off->opt; on_off++) |
267 | if (on_off->opt == *s) { | 289 | if (on_off->opt == *s) { |
268 | *pair_switch |= on_off->switch_on; | 290 | *pair_switch |= on_off->switch_on; |
269 | break; | 291 | break; |
@@ -274,13 +296,16 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | |||
274 | } | 296 | } |
275 | 297 | ||
276 | while ((c = getopt_long (argc, argv, applet_opts, | 298 | while ((c = getopt_long (argc, argv, applet_opts, |
277 | bb_applet_long_options, NULL)) > 0) { | 299 | bb_applet_long_options, NULL)) > 0) { |
278 | for (on_off = complementaly; on_off->opt != c; on_off++) { | 300 | for (on_off = complementally; on_off->opt != c; on_off++) { |
279 | if(!on_off->opt) | 301 | if(!on_off->opt) |
280 | bb_show_usage (); | 302 | bb_show_usage (); |
281 | } | 303 | } |
282 | if(flags & on_off->incongruously) | 304 | if(flags & on_off->incongruously) { |
305 | if(flg_show_usage_if_error) | ||
306 | bb_show_usage (); | ||
283 | flags |= BB_GETOPT_ERROR; | 307 | flags |= BB_GETOPT_ERROR; |
308 | } | ||
284 | flags &= ~on_off->switch_off; | 309 | flags &= ~on_off->switch_off; |
285 | flags |= on_off->switch_on; | 310 | flags |= on_off->switch_on; |
286 | if(on_off->list_flg) { | 311 | if(on_off->list_flg) { |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 53c255fef..257632f8f 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -157,9 +157,9 @@ int crond_main(int ac, char **av) | |||
157 | #ifdef FEATURE_DEBUG_OPT | 157 | #ifdef FEATURE_DEBUG_OPT |
158 | char *dopt; | 158 | char *dopt; |
159 | 159 | ||
160 | bb_opt_complementaly = "f-b:b-f:S-L:L-S:d-l"; | 160 | bb_opt_complementally = "f-b:b-f:S-L:L-S:d-l"; |
161 | #else | 161 | #else |
162 | bb_opt_complementaly = "f-b:b-f:S-L:L-S"; | 162 | bb_opt_complementally = "f-b:b-f:S-L:L-S"; |
163 | #endif | 163 | #endif |
164 | 164 | ||
165 | opterr = 0; /* disable getopt 'errors' message. */ | 165 | opterr = 0; /* disable getopt 'errors' message. */ |
diff --git a/networking/wget.c b/networking/wget.c index 59f30c06d..0a4ccaddd 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -191,7 +191,7 @@ int wget_main(int argc, char **argv) | |||
191 | /* | 191 | /* |
192 | * Crack command line. | 192 | * Crack command line. |
193 | */ | 193 | */ |
194 | bb_opt_complementaly = "\203*"; | 194 | bb_opt_complementally = "\203*"; |
195 | bb_applet_long_options = wget_long_options; | 195 | bb_applet_long_options = wget_long_options; |
196 | opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:", &fname_out, &headers_llist, &dir_prefix, &proxy_flag); | 196 | opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:", &fname_out, &headers_llist, &dir_prefix, &proxy_flag); |
197 | if (opt & WGET_OPT_CONTINUE) { | 197 | if (opt & WGET_OPT_CONTINUE) { |
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 3c2683953..11261f47d 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -205,12 +205,8 @@ static const struct option hwclock_long_options[] = { | |||
205 | bb_applet_long_options = hwclock_long_options; | 205 | bb_applet_long_options = hwclock_long_options; |
206 | #endif | 206 | #endif |
207 | 207 | ||
208 | bb_opt_complementaly = "r~ws:w~rs:s~wr:l~u:u~l"; | 208 | bb_opt_complementally = "!r~ws:w~rs:s~wr:l~u:u~l"; |
209 | opt = bb_getopt_ulflags(argc, argv, "lursw"); | 209 | opt = bb_getopt_ulflags(argc, argv, "lursw"); |
210 | /* Check only one mode was given */ | ||
211 | if(opt & BB_GETOPT_ERROR) { | ||
212 | bb_show_usage(); | ||
213 | } | ||
214 | 210 | ||
215 | /* If -u or -l wasn't given check if we are using utc */ | 211 | /* If -u or -l wasn't given check if we are using utc */ |
216 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) | 212 | if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) |