diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-07-06 21:58:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-07-06 21:58:02 +0200 |
commit | 237bedd499c58034a1355484d6d4d906f0180308 (patch) | |
tree | 42a789f8867ba3bc6ef0cea30fb18f5553d447a0 /coreutils | |
parent | 0844b5afe2cd60d46b7f2ad0fac8c2818d0780b3 (diff) | |
download | busybox-w32-237bedd499c58034a1355484d6d4d906f0180308.tar.gz busybox-w32-237bedd499c58034a1355484d6d4d906f0180308.tar.bz2 busybox-w32-237bedd499c58034a1355484d6d4d906f0180308.zip |
getopt32: add new syntax of 'o:+' and 'o:*' for -o NUM and -o LIST
In many cases, this aqllows to drop use of opt_complementary.
Approximately -400 bytes:
function old new delta
getopt32 1423 1502 +79
opt_string 17 18 +1
OPT_STR 24 25 +1
uniq_main 416 406 -10
timeout_main 279 269 -10
sulogin_main 270 260 -10
readprofile_main 1825 1815 -10
ps_main 543 533 -10
pidof_main 245 235 -10
pgrep_main 611 601 -10
od_main 2600 2590 -10
mkfs_minix_main 2684 2674 -10
mkfs_ext2_main 2603 2593 -10
microcom_main 712 702 -10
makemime_main 315 305 -10
ionice_main 282 272 -10
inetd_main 2074 2064 -10
ifplugd_main 1144 1134 -10
halt_main 353 343 -10
getopt_main 636 626 -10
fdisk_main 2854 2844 -10
env_main 206 196 -10
dmesg_main 319 309 -10
conspy_main 1214 1204 -10
awk_main 981 971 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/22 up/down: 81/-220) Total: -139 bytes
text data bss dec hex filename
919373 906 14060 934339 e41c3 busybox_old
918969 906 14060 933935 e402f busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/du.c | 8 | ||||
-rw-r--r-- | coreutils/env.c | 3 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 3 | ||||
-rw-r--r-- | coreutils/sort.c | 5 | ||||
-rw-r--r-- | coreutils/split.c | 4 | ||||
-rw-r--r-- | coreutils/tail.c | 4 | ||||
-rw-r--r-- | coreutils/uniq.c | 3 |
7 files changed, 13 insertions, 17 deletions
diff --git a/coreutils/du.c b/coreutils/du.c index 1240bcbbc..5f104736b 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -226,8 +226,8 @@ int du_main(int argc UNUSED_PARAM, char **argv) | |||
226 | * ignore -a. This is consistent with -s being equivalent to -d 0. | 226 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
227 | */ | 227 | */ |
228 | #if ENABLE_FEATURE_HUMAN_READABLE | 228 | #if ENABLE_FEATURE_HUMAN_READABLE |
229 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+"; | 229 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; |
230 | opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth); | 230 | opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth); |
231 | argv += optind; | 231 | argv += optind; |
232 | if (opt & OPT_h_for_humans) { | 232 | if (opt & OPT_h_for_humans) { |
233 | G.disp_unit = 0; | 233 | G.disp_unit = 0; |
@@ -239,8 +239,8 @@ int du_main(int argc UNUSED_PARAM, char **argv) | |||
239 | G.disp_unit = 1024; | 239 | G.disp_unit = 1024; |
240 | } | 240 | } |
241 | #else | 241 | #else |
242 | opt_complementary = "H-L:L-H:s-d:d-s:d+"; | 242 | opt_complementary = "H-L:L-H:s-d:d-s"; |
243 | opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth); | 243 | opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth); |
244 | argv += optind; | 244 | argv += optind; |
245 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 245 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
246 | if (opt & OPT_k_kbytes) { | 246 | if (opt & OPT_k_kbytes) { |
diff --git a/coreutils/env.c b/coreutils/env.c index 807ef13e9..cdfc30e14 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -54,11 +54,10 @@ int env_main(int argc UNUSED_PARAM, char **argv) | |||
54 | unsigned opts; | 54 | unsigned opts; |
55 | llist_t *unset_env = NULL; | 55 | llist_t *unset_env = NULL; |
56 | 56 | ||
57 | opt_complementary = "u::"; | ||
58 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | 57 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS |
59 | applet_long_options = env_longopts; | 58 | applet_long_options = env_longopts; |
60 | #endif | 59 | #endif |
61 | opts = getopt32(argv, "+iu:", &unset_env); | 60 | opts = getopt32(argv, "+iu:+", &unset_env); |
62 | argv += optind; | 61 | argv += optind; |
63 | if (argv[0] && LONE_DASH(argv[0])) { | 62 | if (argv[0] && LONE_DASH(argv[0])) { |
64 | opts |= 1; | 63 | opts |= 1; |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index c8a654165..f13bdfc11 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -62,7 +62,7 @@ enum { | |||
62 | }; | 62 | }; |
63 | 63 | ||
64 | #define OD_GETOPT32() getopt32(argv, \ | 64 | #define OD_GETOPT32() getopt32(argv, \ |
65 | "A:N:abcdfhij:lot:vxsS:w::", \ | 65 | "A:N:abcdfhij:lot:*vxsS:w:+:", \ |
66 | /* -w with optional param */ \ | 66 | /* -w with optional param */ \ |
67 | /* -S was -s and also had optional parameter */ \ | 67 | /* -S was -s and also had optional parameter */ \ |
68 | /* but in coreutils 6.3 it was renamed and now has */ \ | 68 | /* but in coreutils 6.3 it was renamed and now has */ \ |
@@ -1212,7 +1212,6 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1212 | address_pad_len_char = '7'; | 1212 | address_pad_len_char = '7'; |
1213 | 1213 | ||
1214 | /* Parse command line */ | 1214 | /* Parse command line */ |
1215 | opt_complementary = "w+:t::"; /* -w N, -t is a list */ | ||
1216 | #if ENABLE_LONG_OPTS | 1215 | #if ENABLE_LONG_OPTS |
1217 | applet_long_options = od_longopts; | 1216 | applet_long_options = od_longopts; |
1218 | #endif | 1217 | #endif |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 9139d9f47..34a41999b 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -73,7 +73,7 @@ | |||
73 | */ | 73 | */ |
74 | 74 | ||
75 | /* These are sort types */ | 75 | /* These are sort types */ |
76 | static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:t:"; | 76 | static const char OPT_STR[] ALIGN1 = "ngMucszbrdfimS:T:o:k:*t:"; |
77 | enum { | 77 | enum { |
78 | FLAG_n = 1, /* Numeric sort */ | 78 | FLAG_n = 1, /* Numeric sort */ |
79 | FLAG_g = 2, /* Sort using strtod() */ | 79 | FLAG_g = 2, /* Sort using strtod() */ |
@@ -358,8 +358,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv) | |||
358 | 358 | ||
359 | /* Parse command line options */ | 359 | /* Parse command line options */ |
360 | /* -o and -t can be given at most once */ | 360 | /* -o and -t can be given at most once */ |
361 | opt_complementary = "o--o:t--t:" /* -t, -o: at most one of each */ | 361 | opt_complementary = "o--o:t--t"; /* -t, -o: at most one of each */ |
362 | "k::"; /* -k takes list */ | ||
363 | opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); | 362 | opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t); |
364 | /* global b strips leading and trailing spaces */ | 363 | /* global b strips leading and trailing spaces */ |
365 | if (opts & FLAG_b) | 364 | if (opts & FLAG_b) |
diff --git a/coreutils/split.c b/coreutils/split.c index e67c3de66..19d58a21b 100644 --- a/coreutils/split.c +++ b/coreutils/split.c | |||
@@ -81,8 +81,8 @@ int split_main(int argc UNUSED_PARAM, char **argv) | |||
81 | 81 | ||
82 | setup_common_bufsiz(); | 82 | setup_common_bufsiz(); |
83 | 83 | ||
84 | opt_complementary = "?2:a+"; /* max 2 args; -a N */ | 84 | opt_complementary = "?2"; /* max 2 args; -a N */ |
85 | opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); | 85 | opt = getopt32(argv, "l:b:a:+", &count_p, &count_p, &suffix_len); |
86 | 86 | ||
87 | if (opt & SPLIT_OPT_l) | 87 | if (opt & SPLIT_OPT_l) |
88 | cnt = XATOOFF(count_p); | 88 | cnt = XATOOFF(count_p); |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 39f87679e..57ad0f3b7 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -121,8 +121,8 @@ int tail_main(int argc, char **argv) | |||
121 | #endif | 121 | #endif |
122 | 122 | ||
123 | /* -s NUM, -F imlies -f */ | 123 | /* -s NUM, -F imlies -f */ |
124 | IF_FEATURE_FANCY_TAIL(opt_complementary = "s+:Ff";) | 124 | IF_FEATURE_FANCY_TAIL(opt_complementary = "Ff";) |
125 | opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:vF"), | 125 | opt = getopt32(argv, "fc:n:" IF_FEATURE_FANCY_TAIL("qs:+vF"), |
126 | &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); | 126 | &str_c, &str_n IF_FEATURE_FANCY_TAIL(,&sleep_period)); |
127 | #define FOLLOW (opt & 0x1) | 127 | #define FOLLOW (opt & 0x1) |
128 | #define COUNT_BYTES (opt & 0x2) | 128 | #define COUNT_BYTES (opt & 0x2) |
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index e0133998a..ec7bde418 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -50,8 +50,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv) | |||
50 | skip_fields = skip_chars = 0; | 50 | skip_fields = skip_chars = 0; |
51 | max_chars = INT_MAX; | 51 | max_chars = INT_MAX; |
52 | 52 | ||
53 | opt_complementary = "f+:s+:w+"; | 53 | opt = getopt32(argv, "cduf:+s:+w:+", &skip_fields, &skip_chars, &max_chars); |
54 | opt = getopt32(argv, "cduf:s:w:", &skip_fields, &skip_chars, &max_chars); | ||
55 | argv += optind; | 54 | argv += optind; |
56 | 55 | ||
57 | input_filename = argv[0]; | 56 | input_filename = argv[0]; |