X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fopt.c;h=1a94f7c0bd691042eef5f05d3e279653cd7cea3e;hb=84a25b8a8b5c99ef48dd63ca1078e22aa18ecab8;hp=0135652cc9dee1817a36bff48789bb11b61cf63f;hpb=9150f33a09541429cd592c727932dc18967a0bbf;p=libucw.git diff --git a/ucw/opt.c b/ucw/opt.c index 0135652c..1a94f7c0 100644 --- a/ucw/opt.c +++ b/ucw/opt.c @@ -17,15 +17,6 @@ #include #include -/*** - * Value flags defaults - * ~~~~~~~~~~~~~~~~~~~~ - * - * OPT_NO_VALUE for OPT_BOOL, OPT_SWITCH and OPT_INC - * OPT_MAYBE_VALUE for OPT_STRING, OPT_UNS, OPT_INT - * Some of the value flags (OPT_NO_VALUE, OPT_MAYBE_VALUE, OPT_REQUIRED_VALUE) - * must be specified for OPT_CALL and OPT_USER. - ***/ static uns opt_default_value_flags[] = { [OPT_CL_BOOL] = OPT_NO_VALUE, [OPT_CL_STATIC] = OPT_MAYBE_VALUE, @@ -37,17 +28,6 @@ static uns opt_default_value_flags[] = { [OPT_CL_HELP] = 0 }; -struct opt_context { - struct opt_precomputed * opts; - struct opt_precomputed ** shortopt; - struct opt_item ** hooks; - int opt_count; - int hook_count; - int positional_max; - int positional_count; - bool stop_parsing; -}; - void opt_failure(const char * mesg, ...) { va_list args; va_start(args, mesg); @@ -94,8 +74,10 @@ static void opt_invoke_hooks(struct opt_context *oc, uns event, struct opt_item { for (int i = 0; i < oc->hook_count; i++) { struct opt_item *hook = oc->hooks[i]; - if (hook->flags & event) - hook->u.hook(item, event, value, hook->ptr); + if (hook->flags & event) { + void *data = (hook->flags & OPT_HOOK_INTERNAL) ? oc : hook->ptr; + hook->u.hook(item, event, value, data); + } } } @@ -223,8 +205,11 @@ static void opt_parse_value(struct opt_context * oc, struct opt_precomputed * op (*((int *)item->ptr))++; break; case OPT_CL_CALL: - item->u.call(item, value, item->ptr); - break; + { + void *data = (opt->flags & OPT_INTERNAL) ? oc : item->ptr; + item->u.call(item, value, data); + break; + } case OPT_CL_USER: { char * e = NULL; @@ -380,6 +365,7 @@ static void opt_check_required(struct opt_context *oc) int opt_parse(const struct opt_section * options, char ** argv) { struct opt_context * oc = alloca(sizeof(*oc)); memset(oc, 0, sizeof (*oc)); + oc->options = options; opt_count_items(oc, options); oc->opts = alloca(sizeof(*oc->opts) * oc->opt_count);