opt_complementary = "vv:b::b-c:c-b";
f = getopt32(argv, "vb:c", &my_b, &verbose_level);
if (f & 2) // -c after -b unsets -b flag
- while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; }
+ while (my_b) dosomething_with(llist_pop(&my_b));
if (my_b) // but llist is stored if -b is specified
free_llist(my_b);
if (verbose_level) printf("verbose level is %d\n", verbose_level);
uint32_t option_mask32;
-uint32_t
+uint32_t FAST_FUNC
getopt32(char **argv, const char *applet_opts, ...)
{
int argc;
va_end(p);
if (spec_flgs & FIRST_ARGV_IS_OPT) {
- if (argv[1] && argv[1][0] != '-' && argv[1][1] != '\0') {
+ if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
#if DONT_USE_PRINTF
char *pp = alloca(strlen(argv[1]) + 2);
- *pp++ = '-';
- argv[1] = strcpy(pp, argv[1]);
+ *pp = '-';
+ strcpy(pp + 1, argv[1]);
+ argv[1] = pp;
#else
argv[1] = xasprintf("-%s", argv[1]);
- if (ENABLE_FEATURE_CLEAN_UP)
- spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
+ spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
#endif
}
}
llist_add_to_end((llist_t **)(on_off->optarg), optarg);
} else if (on_off->param_type == PARAM_INT) {
if (optarg)
+//TODO: xatoi_u indirectly pulls in printf machinery
*(unsigned*)(on_off->optarg) = xatoi_u(optarg);
} else if (on_off->optarg) {
if (optarg)
}
}
-#if ENABLE_FEATURE_CLEAN_UP
if (spec_flgs & FREE_FIRST_ARGV_IS_OPT)
free(argv[1]);
-#endif
+
/* check depending requires for given options */
for (on_off = complementary; on_off->opt_char; on_off++) {
if (on_off->requires && (flags & on_off->switch_on) &&