From: Kevin Day Date: Thu, 2 Sep 2021 03:33:28 +0000 (-0500) Subject: Bugfix: Console parameter processing should handle unknown parameters with -/+ as... X-Git-Tag: 0.5.5~11 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=61a5583f6c9b78ca99f1f520d5ccfe68c2ac3e41;p=fll Bugfix: Console parameter processing should handle unknown parameters with -/+ as regular parameters. If the parameters are not found, then they should be added to the "remaining" set. This allows unknown parameters to be used as regular parameters. This is easily seen when using status_code or fss_status_code and attempting to pass a negative number, such as -200. While -200 should be an out of range error for these programs, it is instead silently ignored. Given that there is no reserved parameter with -200, then the -200 can be used normally. There should also be a way to explicitly designate that all remaining parameters are processed as "remaining". Add a comment by this. There may also need to be a way to escape these parameters as an alternative. Such changes are left to another time. --- diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index 1ee4318..d7669e0 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -137,6 +137,8 @@ extern "C" { console_short = f_console_none; } + found = F_false; + if (console_short != f_console_none) { // The sub_location is used on a per increment basis (such as 'tar -xcf', the '-' would have an increment of 1, therefore x, c, and f would all be three separate parameters). @@ -144,9 +146,7 @@ extern "C" { for (i = 0; i < parameters.used; ++i) { - if (parameters.parameter[i].type != console_type) { - continue; - } + if (parameters.parameter[i].type != console_type) continue; if (result == console_short) { if (!parameters.parameter[i].symbol_short) continue; @@ -216,6 +216,8 @@ extern "C" { return status; } + found = F_true; + parameters.parameter[i].locations.array[parameters.parameter[i].locations.used++] = location; parameters.parameter[i].result = f_console_result_found; @@ -253,8 +255,6 @@ extern "C" { } // while } else { - found = F_false; - for (i = 0; i < parameters.used; ++i) { if (parameters.parameter[i].type != f_console_type_other) continue; @@ -305,20 +305,21 @@ extern "C" { found = F_true; break; } // for + } - if (!found) { + if (!found) { - // populate list of remaining parameters.parameter not associated with anything. - if (remaining->used == remaining->size) { - macro_f_memory_structure_increment(status, (*remaining), 1, f_memory_default_allocation_small, macro_f_array_lengths_t_resize, F_array_too_large); - if (F_status_is_error(status)) { - macro_f_array_lengths_t_delete_simple(needs_value); - return status; - } - } + // populate list of remaining parameters.parameter not associated with anything. + if (remaining->used == remaining->size) { + macro_f_memory_structure_increment(status, (*remaining), 1, f_memory_default_allocation_small, macro_f_array_lengths_t_resize, F_array_too_large); - remaining->array[remaining->used++] = location; + if (F_status_is_error(status)) { + macro_f_array_lengths_t_delete_simple(needs_value); + return status; + } } + + remaining->array[remaining->used++] = location; } ++location; diff --git a/level_0/f_console/c/console.h b/level_0/f_console/c/console.h index 6316161..f4569a9 100644 --- a/level_0/f_console/c/console.h +++ b/level_0/f_console/c/console.h @@ -6,6 +6,9 @@ * Licenses: lgplv2.1 * * Some console input/output commands. + * + * @todo It may be a good idea to provide a standard parameter process process disable sequence. + * This does not yet exist, so "--help" would always be a parameter, but would if there was something like "-/ --help" where this help does not designate the help option? */ #ifndef _F_console_h #define _F_console_h