aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-08-18 15:32:12 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-08-18 15:32:12 +0000
commitfe7cd642b0b732f5d41403c2f6983ad676b69dd9 (patch)
treee5962885cb72c976f44b178a350a92ba5f1aa02d /libbb
parentd6cd9d7fe9eab19a9e36fdda729c78c40205b1e5 (diff)
downloadbusybox-w32-fe7cd642b0b732f5d41403c2f6983ad676b69dd9.tar.gz
busybox-w32-fe7cd642b0b732f5d41403c2f6983ad676b69dd9.tar.bz2
busybox-w32-fe7cd642b0b732f5d41403c2f6983ad676b69dd9.zip
don't pass argc in getopt32, it's superfluous
(add/remove: 0/0 grow/shrink: 12/131 up/down: 91/-727) Total: -636 bytes text data bss dec hex filename 773469 1058 11092 785619 bfcd3 busybox_old 772644 1058 11092 784794 bf99a busybox_unstripped
Diffstat (limited to 'libbb')
-rw-r--r--libbb/getopt32.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 3e1299fc3..3033bf11e 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -13,12 +13,12 @@
13/* Documentation 13/* Documentation
14 14
15uint32_t 15uint32_t
16getopt32(int argc, char **argv, const char *applet_opts, ...) 16getopt32(char **argv, const char *applet_opts, ...)
17 17
18 The command line options must be declared in const char 18 The command line options must be declared in const char
19 *applet_opts as a string of chars, for example: 19 *applet_opts as a string of chars, for example:
20 20
21 flags = getopt32(argc, argv, "rnug"); 21 flags = getopt32(argv, "rnug");
22 22
23 If one of the given options is found, a flag value is added to 23 If one of the given options is found, a flag value is added to
24 the return value (an unsigned long). 24 the return value (an unsigned long).
@@ -26,7 +26,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
26 The flag value is determined by the position of the char in 26 The flag value is determined by the position of the char in
27 applet_opts string. For example, in the above case: 27 applet_opts string. For example, in the above case:
28 28
29 flags = getopt32(argc, argv, "rnug"); 29 flags = getopt32(argv, "rnug");
30 30
31 "r" will add 1 (bit 0) 31 "r" will add 1 (bit 0)
32 "n" will add 2 (bit 1) 32 "n" will add 2 (bit 1)
@@ -52,7 +52,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
52 char *pointer_to_arg_for_c; 52 char *pointer_to_arg_for_c;
53 char *pointer_to_arg_for_d; 53 char *pointer_to_arg_for_d;
54 54
55 flags = getopt32(argc, argv, "a:b:c:d:", 55 flags = getopt32(argv, "a:b:c:d:",
56 &pointer_to_arg_for_a, &pointer_to_arg_for_b, 56 &pointer_to_arg_for_a, &pointer_to_arg_for_b,
57 &pointer_to_arg_for_c, &pointer_to_arg_for_d); 57 &pointer_to_arg_for_c, &pointer_to_arg_for_d);
58 58
@@ -105,7 +105,7 @@ const char *opt_complementary
105 if they are not specifed on the command line. For example: 105 if they are not specifed on the command line. For example:
106 106
107 opt_complementary = "abc"; 107 opt_complementary = "abc";
108 flags = getopt32(argc, argv, "abcd") 108 flags = getopt32(argv, "abcd")
109 109
110 If getopt() finds "-a" on the command line, then 110 If getopt() finds "-a" on the command line, then
111 getopt32's return value will be as if "-a -b -c" were 111 getopt32's return value will be as if "-a -b -c" were
@@ -119,7 +119,7 @@ const char *opt_complementary
119 119
120 int w_counter = 0; 120 int w_counter = 0;
121 opt_complementary = "ww"; 121 opt_complementary = "ww";
122 getopt32(argc, argv, "w", &w_counter); 122 getopt32(argv, "w", &w_counter);
123 if (w_counter) 123 if (w_counter)
124 width = (w_counter == 1) ? 132 : INT_MAX; 124 width = (w_counter == 1) ? 132 : INT_MAX;
125 else 125 else
@@ -135,7 +135,7 @@ const char *opt_complementary
135 llist_t *my_b = NULL; 135 llist_t *my_b = NULL;
136 int verbose_level = 0; 136 int verbose_level = 0;
137 opt_complementary = "vv:b::b-c:c-b"; 137 opt_complementary = "vv:b::b-c:c-b";
138 f = getopt32(argc, argv, "vb:c", &my_b, &verbose_level); 138 f = getopt32(argv, "vb:c", &my_b, &verbose_level);
139 if (f & 2) // -c after -b unsets -b flag 139 if (f & 2) // -c after -b unsets -b flag
140 while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; } 140 while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; }
141 if (my_b) // but llist is stored if -b is specified 141 if (my_b) // but llist is stored if -b is specified
@@ -150,7 +150,7 @@ Special characters:
150 use ':' or end of line. For example: 150 use ':' or end of line. For example:
151 151
152 opt_complementary = "-:w-x:x-w"; 152 opt_complementary = "-:w-x:x-w";
153 getopt32(argc, argv, "wx"); 153 getopt32(argv, "wx");
154 154
155 Allows any arguments to be given without a dash (./program w x) 155 Allows any arguments to be given without a dash (./program w x)
156 as well as with a dash (./program -x). 156 as well as with a dash (./program -x).
@@ -197,7 +197,7 @@ Special characters:
197 char *smax_print_depth; 197 char *smax_print_depth;
198 198
199 opt_complementary = "s-d:d-s:x-x"; 199 opt_complementary = "s-d:d-s:x-x";
200 opt = getopt32(argc, argv, "sd:x", &smax_print_depth); 200 opt = getopt32(argv, "sd:x", &smax_print_depth);
201 201
202 if (opt & 2) 202 if (opt & 2)
203 max_print_depth = atoi(smax_print_depth); 203 max_print_depth = atoi(smax_print_depth);
@@ -235,7 +235,7 @@ Special characters:
235 235
236 opt_complementary = "e::"; 236 opt_complementary = "e::";
237 237
238 getopt32(argc, argv, "e:", &patterns); 238 getopt32(argv, "e:", &patterns);
239 $ grep -e user -e root /etc/passwd 239 $ grep -e user -e root /etc/passwd
240 root:x:0:0:root:/root:/bin/bash 240 root:x:0:0:root:/root:/bin/bash
241 user:x:500:500::/home/user:/bin/bash 241 user:x:500:500::/home/user:/bin/bash
@@ -248,7 +248,7 @@ Special characters:
248 248
249 // Don't allow -n -r -rn -ug -rug -nug -rnug 249 // Don't allow -n -r -rn -ug -rug -nug -rnug
250 opt_complementary = "r?ug:n?ug:?u--g:g--u"; 250 opt_complementary = "r?ug:n?ug:?u--g:g--u";
251 flags = getopt32(argc, argv, "rnug"); 251 flags = getopt32(argv, "rnug");
252 252
253 This example allowed only: 253 This example allowed only:
254 $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng 254 $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng
@@ -260,7 +260,7 @@ Special characters:
260 260
261 // Don't allow -KS -SK, but -S or -K is required 261 // Don't allow -KS -SK, but -S or -K is required
262 opt_complementary = "K:S:?K--S:S--K"; 262 opt_complementary = "K:S:?K--S:S--K";
263 flags = getopt32(argc, argv, "KS...); 263 flags = getopt32(argv, "KS...);
264 264
265 265
266 Don't forget to use ':'. For example, "?322-22-23X-x-a" 266 Don't forget to use ':'. For example, "?322-22-23X-x-a"
@@ -296,8 +296,9 @@ const char *applet_long_options;
296uint32_t option_mask32; 296uint32_t option_mask32;
297 297
298uint32_t 298uint32_t
299getopt32(int argc, char **argv, const char *applet_opts, ...) 299getopt32(char **argv, const char *applet_opts, ...)
300{ 300{
301 int argc;
301 unsigned flags = 0; 302 unsigned flags = 0;
302 unsigned requires = 0; 303 unsigned requires = 0;
303 t_complementary complementary[33]; 304 t_complementary complementary[33];
@@ -320,6 +321,10 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
320#define FREE_FIRST_ARGV_IS_OPT 8 321#define FREE_FIRST_ARGV_IS_OPT 8
321 int spec_flgs = 0; 322 int spec_flgs = 0;
322 323
324 argc = 0;
325 while (argv[argc])
326 argc++;
327
323 va_start(p, applet_opts); 328 va_start(p, applet_opts);
324 329
325 c = 0; 330 c = 0;