aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-01-22 07:10:13 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-01-22 07:10:13 +0000
commit85c5152cb874fdac2e59072b6d958af18965182a (patch)
treee0c8f0e8e44cdcfbfb7d66073e5acc82f0b68e31
parenta1e4a0ef671f9c1597446e0aafe87f1319c5c527 (diff)
downloadbusybox-w32-85c5152cb874fdac2e59072b6d958af18965182a.tar.gz
busybox-w32-85c5152cb874fdac2e59072b6d958af18965182a.tar.bz2
busybox-w32-85c5152cb874fdac2e59072b6d958af18965182a.zip
Vodz, last_patch_123, patch have new version getopt_ulflags.
- size reduced 34 bytes - don`t use dynamic memory allocation - small indent correction.
-rw-r--r--libbb/getopt_ulflags.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c
index 42e83c413..81d22c3fe 100644
--- a/libbb/getopt_ulflags.c
+++ b/libbb/getopt_ulflags.c
@@ -46,7 +46,7 @@ Warning! You can check returned flag, pointer to "d:" argument seted
46to own optarg always. 46to own optarg always.
47Example two: cut applet must only one type of list may be specified, 47Example two: cut applet must only one type of list may be specified,
48and -b, -c and -f incongruously option, overwited option is error also. 48and -b, -c and -f incongruously option, overwited option is error also.
49You must set bb_opt_complementaly = "b~bcf:c~bcf:f~bcf". 49You must set bb_opt_complementaly = "b~cf:c~bf:f~bc".
50If called have more one specified, return value have error flag - 50If called have more one specified, return value have error flag -
51high bite set (0x80000000UL). 51high bite set (0x80000000UL).
52Example three: grep applet can have one or more "-e pattern" arguments. 52Example three: grep applet can have one or more "-e pattern" arguments.
@@ -81,10 +81,10 @@ const struct option *bb_applet_long_options = bb_default_long_options;
81unsigned long 81unsigned long
82bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) 82bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
83{ 83{
84 unsigned long flags = 0; 84 unsigned long flags = 0;
85 int c = 0; 85 t_complementaly complementaly[sizeof(flags) * 8 + 1];
86 const unsigned char *s; 86 int c;
87 t_complementaly *complementaly; 87 const unsigned char *s;
88 t_complementaly *on_off; 88 t_complementaly *on_off;
89 va_list p; 89 va_list p;
90 90
@@ -95,34 +95,27 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
95 if(*s == '+' || *s == '-') 95 if(*s == '+' || *s == '-')
96 s++; 96 s++;
97 97
98 for (; *s; s++) {
99 c++;
100 while (s[1] == ':') {
101 /* check GNU extension "o::" - optional arg */
102 s++;
103 }
104 }
105 complementaly = xcalloc (c + 1, sizeof (t_complementaly));
106 c = 0; 98 c = 0;
107 /* skip GNU extension */ 99 on_off = complementaly;
108 s = applet_opts;
109 if(*s == '+' || *s == '-')
110 s++;
111
112 for (; *s; s++) { 100 for (; *s; s++) {
113 complementaly->opt = *s; 101 if(c >= (sizeof(flags)*8))
114 complementaly->switch_on |= (1 << c); 102 break;
115 c++; 103 on_off->opt = *s;
104 on_off->switch_on |= (1 << c);
105 on_off->list_flg = 0;
106 on_off->switch_off = 0;
107 on_off->incongruously = 0;
108 on_off->optarg = NULL;
116 if (s[1] == ':') { 109 if (s[1] == ':') {
117 complementaly->optarg = va_arg (p, void **); 110 on_off->optarg = va_arg (p, void **);
118 do 111 do
119 s++; 112 s++;
120 while (s[1] == ':'); 113 while (s[1] == ':');
121 }
122 complementaly++;
123 } 114 }
124 complementaly->opt = 0; 115 on_off++;
125 complementaly -= c; 116 c++;
117 }
118 on_off->opt = 0;
126 c = 0; 119 c = 0;
127 for (s = bb_opt_complementaly; s && *s; s++) { 120 for (s = bb_opt_complementaly; s && *s; s++) {
128 t_complementaly *pair; 121 t_complementaly *pair;
@@ -174,6 +167,5 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
174 *(char **)(on_off->optarg) = optarg; 167 *(char **)(on_off->optarg) = optarg;
175 } 168 }
176 } 169 }
177 free(complementaly); 170 return flags;
178 return flags;
179} 171}