-
- if(rc == POPT_ERROR_BADOPT) {
- /* We need to redo the context with information added by modules */
- g_array_append_val(lttv_options_command_popt, endOption);
- poptFreeContext(c);
- c = poptGetContext("lttv", command_argc, (const char**)command_argv,
- (struct poptOption *)lttv_options_command_popt->data,0);
- g_array_remove_index(lttv_options_command_popt,
- lttv_options_command_popt->len);
-
- /* Cut out the already parsed elements */
- if(lastrc != -1)
- while(poptGetNextOpt(c) != lastrc) { } ;
-
- /* Get the same option once again */
- g_assert(rc = poptGetNextOpt(c) != -1) ;
- if(rc == POPT_ERROR_BADOPT) {
- /* If here again we have a parsing error with all context info ok,
- * then there is a problem in the arguments themself, give up */
- g_critical("option %s: %s", poptBadOption(c,0), poptStrerror(rc));
- break ;
- }
+
+ /* The option was recognized and the rc value returned is the argument
+ position in the array. Call the associated hook if present. */
+
+ if(rc > 0) {
+ option = (LttvOption *)(list->pdata[rc - 1]);
+ if(option->hook != NULL) option->hook(option->hook_data);
+ i++;
+ }
+
+ else if(rc == POPT_ERROR_BADOPT && i != first_arg) {
+
+ /* Perhaps this option is newly added, restart parsing */
+
+ destroy_popts(&list, &popts, &c);
+ build_popts(&list, &popts, &c, argc, argv);
+
+ /* Get back to the same argument */
+
+ first_arg = i;
+ for(i = 0; i < first_arg; i++) poptGetNextOpt(c);