Vodz, last_patch_123, patch have new version getopt_ulflags.

- size reduced 34 bytes
- don`t use dynamic memory allocation
- small indent correction.
This commit is contained in:
Glenn L McGrath 2004-01-22 07:10:13 +00:00
parent a1e4a0ef67
commit 85c5152cb8

View File

@ -46,7 +46,7 @@ Warning! You can check returned flag, pointer to "d:" argument seted
to own optarg always. to own optarg always.
Example two: cut applet must only one type of list may be specified, Example two: cut applet must only one type of list may be specified,
and -b, -c and -f incongruously option, overwited option is error also. and -b, -c and -f incongruously option, overwited option is error also.
You must set bb_opt_complementaly = "b~bcf:c~bcf:f~bcf". You must set bb_opt_complementaly = "b~cf:c~bf:f~bc".
If called have more one specified, return value have error flag - If called have more one specified, return value have error flag -
high bite set (0x80000000UL). high bite set (0x80000000UL).
Example three: grep applet can have one or more "-e pattern" arguments. Example 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;
unsigned long unsigned long
bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
{ {
unsigned long flags = 0; unsigned long flags = 0;
int c = 0; t_complementaly complementaly[sizeof(flags) * 8 + 1];
const unsigned char *s; int c;
t_complementaly *complementaly; const unsigned char *s;
t_complementaly *on_off; t_complementaly *on_off;
va_list p; va_list p;
@ -95,34 +95,27 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
if(*s == '+' || *s == '-') if(*s == '+' || *s == '-')
s++; s++;
for (; *s; s++) {
c++;
while (s[1] == ':') {
/* check GNU extension "o::" - optional arg */
s++;
}
}
complementaly = xcalloc (c + 1, sizeof (t_complementaly));
c = 0; c = 0;
/* skip GNU extension */ on_off = complementaly;
s = applet_opts;
if(*s == '+' || *s == '-')
s++;
for (; *s; s++) { for (; *s; s++) {
complementaly->opt = *s; if(c >= (sizeof(flags)*8))
complementaly->switch_on |= (1 << c); break;
c++; on_off->opt = *s;
on_off->switch_on |= (1 << c);
on_off->list_flg = 0;
on_off->switch_off = 0;
on_off->incongruously = 0;
on_off->optarg = NULL;
if (s[1] == ':') { if (s[1] == ':') {
complementaly->optarg = va_arg (p, void **); on_off->optarg = va_arg (p, void **);
do do
s++; s++;
while (s[1] == ':'); while (s[1] == ':');
}
complementaly++;
} }
complementaly->opt = 0; on_off++;
complementaly -= c; c++;
}
on_off->opt = 0;
c = 0; c = 0;
for (s = bb_opt_complementaly; s && *s; s++) { for (s = bb_opt_complementaly; s && *s; s++) {
t_complementaly *pair; t_complementaly *pair;
@ -174,6 +167,5 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
*(char **)(on_off->optarg) = optarg; *(char **)(on_off->optarg) = optarg;
} }
} }
free(complementaly); return flags;
return flags;
} }