This is provided to help shorten the number of parameters passed to functions.
/**
* Provide a helper structure for references and processing parameters.
*
+ * The f_console_parameters is designed for passing this to a function as a single argument.
+ * The "parameters" property is intended to be populated with an aray of f_console_parameter_id whose size is defined by the "used" property.
+ * This follows the idea of f_string_dynamic and has a "used" instead of length, but because this is not intended to be dynamically allocated there is no "size" property.
+ */
+#ifndef _di_f_console_parameters_
+ typedef struct {
+ f_console_parameter *parameter;
+ f_array_length used;
+ } f_console_parameters;
+
+ #define f_console_parameters_initialize { 0, 0 }
+#endif // _di_f_console_parameters_
+
+/**
+ * Provide a helper structure for references and processing standard C main() arguments.
+ *
* The f_console_parameter_id is designed to be used for the enums to represent a any given parameter by the ID.
*
* The f_console_parameter_ids is designed for passing this to a function as a single argument.
- * The "ids" property is intended to be populated with an aray of f_console_parameter_id whose size is defined by the "used" property.
+ * The "id" property is intended to be populated with an aray of f_console_parameter_id whose size is defined by the "used" property.
* This follows the idea of f_string_dynamic and has a "used" instead of length, but because this is not intended to be dynamically allocated there is no "size" property.
*/
#ifndef _di_f_console_parameter_id_
typedef uint16_t f_console_parameter_id;
typedef struct {
- f_console_parameter_id *ids;
+ f_console_parameter_id *id;
f_array_length used;
} f_console_parameter_ids;
#endif
#ifndef _di_fl_console_parameter_process_
- f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, f_string_lengths *remaining) {
+ f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameters parameters, f_string_lengths *remaining) {
#ifndef _di_level_1_parameter_checking_
if (remaining == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_1_parameter_checking_
if (needs_additional.used > 0) {
parameter_counter = needs_additional.array[0];
- if (parameters[parameter_counter].additional.used >= parameters[parameter_counter].additional.size) {
+ if (parameters.parameter[parameter_counter].additional.used >= parameters.parameter[parameter_counter].additional.size) {
f_status allocation_status = f_none;
- f_macro_string_lengths_resize(allocation_status, parameters[parameter_counter].additional, parameters[parameter_counter].additional.size + f_console_default_allocation_step);
+ f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].additional, parameters.parameter[parameter_counter].additional.size + f_console_default_allocation_step);
if (f_status_is_error(allocation_status)) {
f_macro_string_lengths_delete(status, needs_additional);
}
}
- parameters[parameter_counter].result = f_console_result_additional;
- parameters[parameter_counter].additional.array[parameters[parameter_counter].additional.used] = location;
- parameters[parameter_counter].additional.used++;
+ parameters.parameter[parameter_counter].result = f_console_result_additional;
+ parameters.parameter[parameter_counter].additional.array[parameters.parameter[parameter_counter].additional.used] = location;
+ parameters.parameter[parameter_counter].additional.used++;
needs_additional.used--;
else 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).
while (sub_location < string_length) {
- for (parameter_counter = 0; parameter_counter < parameters_total; parameter_counter++) {
- if (parameters[parameter_counter].type != console_type) {
+ for (parameter_counter = 0; parameter_counter < parameters.used; parameter_counter++) {
+ if (parameters.parameter[parameter_counter].type != console_type) {
continue;
}
if (result == console_short) {
- if (parameters[parameter_counter].symbol_short == 0) {
+ if (parameters.parameter[parameter_counter].symbol_short == 0) {
continue;
}
- if (strncmp(&arguments.argv[location][sub_location], parameters[parameter_counter].symbol_short, increment_by + 1) != 0) {
+ if (strncmp(&arguments.argv[location][sub_location], parameters.parameter[parameter_counter].symbol_short, increment_by + 1) != 0) {
continue;
}
}
else if (result == console_long) {
- if (parameters[parameter_counter].symbol_long == 0) {
+ if (parameters.parameter[parameter_counter].symbol_long == 0) {
continue;
}
- if (strncmp(&arguments.argv[location][sub_location], parameters[parameter_counter].symbol_long, increment_by + 1) != 0) {
+ if (strncmp(&arguments.argv[location][sub_location], parameters.parameter[parameter_counter].symbol_long, increment_by + 1) != 0) {
continue;
}
}
continue;
}
- parameters[parameter_counter].result = f_console_result_found;
- parameters[parameter_counter].location = location;
- parameters[parameter_counter].location_sub = 0;
- parameters[parameter_counter].total++;
+ parameters.parameter[parameter_counter].result = f_console_result_found;
+ parameters.parameter[parameter_counter].location = location;
+ parameters.parameter[parameter_counter].location_sub = 0;
+ parameters.parameter[parameter_counter].total++;
if (result == console_short) {
- parameters[parameter_counter].location_sub = sub_location;
+ parameters.parameter[parameter_counter].location_sub = sub_location;
}
- if (parameters[parameter_counter].has_additional) {
- if (needs_additional.used + parameters[parameter_counter].has_additional > needs_additional.size) {
+ if (parameters.parameter[parameter_counter].has_additional) {
+ if (needs_additional.used + parameters.parameter[parameter_counter].has_additional > needs_additional.size) {
f_status allocation_status = f_none;
- f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters[parameter_counter].has_additional);
+ f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters.parameter[parameter_counter].has_additional);
if (f_status_is_error(allocation_status)) {
f_macro_string_lengths_delete(status, needs_additional);
}
}
- for (f_array_length additional = 0; additional < parameters[parameter_counter].has_additional; additional++) {
+ for (f_array_length additional = 0; additional < parameters.parameter[parameter_counter].has_additional; additional++) {
needs_additional.array[needs_additional.used] = parameter_counter;
needs_additional.used++;
} // for
else {
found = f_false;
- for (parameter_counter = 0; parameter_counter < parameters_total; parameter_counter++) {
- if (parameters[parameter_counter].type != f_console_type_other) {
+ for (parameter_counter = 0; parameter_counter < parameters.used; parameter_counter++) {
+ if (parameters.parameter[parameter_counter].type != f_console_type_other) {
continue;
}
- if (parameters[parameter_counter].symbol_other == 0) {
+ if (parameters.parameter[parameter_counter].symbol_other == 0) {
continue;
}
- if (strncmp(arguments.argv[location], parameters[parameter_counter].symbol_other, string_length + 1) != 0) {
+ if (strncmp(arguments.argv[location], parameters.parameter[parameter_counter].symbol_other, string_length + 1) != 0) {
continue;
}
- parameters[parameter_counter].result = f_console_result_found;
- parameters[parameter_counter].location = location;
- parameters[parameter_counter].location_sub = 0;
- parameters[parameter_counter].total++;
+ parameters.parameter[parameter_counter].result = f_console_result_found;
+ parameters.parameter[parameter_counter].location = location;
+ parameters.parameter[parameter_counter].location_sub = 0;
+ parameters.parameter[parameter_counter].total++;
- if (parameters[parameter_counter].has_additional) {
- if (needs_additional.used + parameters[parameter_counter].has_additional > needs_additional.size) {
+ if (parameters.parameter[parameter_counter].has_additional) {
+ if (needs_additional.used + parameters.parameter[parameter_counter].has_additional > needs_additional.size) {
f_status allocation_status = f_none;
- f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters[parameter_counter].has_additional);
+ f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters.parameter[parameter_counter].has_additional);
if (f_status_is_error(allocation_status)) {
f_macro_string_lengths_delete(status, needs_additional);
}
}
- for (f_array_length additional = 0; additional < parameters[parameter_counter].has_additional; additional++) {
+ for (f_array_length additional = 0; additional < parameters.parameter[parameter_counter].has_additional; additional++) {
needs_additional.array[needs_additional.used] = parameter_counter;
needs_additional.used++;
} // for
} // for
if (!found) {
- // populate list of remaining parameters not associated with anything.
+ // populate list of remaining parameters.parameter not associated with anything.
if (remaining->used >= remaining->size) {
f_status allocation_status = f_none;
#endif // _di_fl_console_parameter_process_
#ifndef _di_fl_console_parameter_prioritize_
- f_return_status fl_console_parameter_prioritize(const f_console_parameter parameters[], const f_array_length parameters_total, const f_console_parameter_ids choices, f_console_parameter_id *decision) {
+ f_return_status fl_console_parameter_prioritize(const f_console_parameters parameters, const f_console_parameter_ids choices, f_console_parameter_id *decision) {
#ifndef _di_level_1_parameter_checking_
if (decision == 0) return f_status_set_error(f_invalid_parameter);
- if (parameters_total == 0) return f_status_set_error(f_invalid_parameter);
- if (choices.ids == 0) return f_status_set_error(f_invalid_parameter);
+ if (parameters.used == 0) return f_status_set_error(f_invalid_parameter);
+ if (choices.id == 0) return f_status_set_error(f_invalid_parameter);
if (choices.used == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_1_parameter_checking_
f_console_parameter_id priority = 0;
for (f_array_length i = 0; i < choices.used; i++) {
- if (choices.ids[i] > parameters_total) return f_status_set_error(f_invalid_parameter);
+ if (choices.id[i] > parameters.used) return f_status_set_error(f_invalid_parameter);
- if (parameters[choices.ids[i]].result == f_console_result_found) {
- if (parameters[choices.ids[i]].location > location) {
- location = parameters[choices.ids[i]].location;
- location_sub = parameters[choices.ids[i]].location_sub;
- priority = choices.ids[i];
+ if (parameters.parameter[choices.id[i]].result == f_console_result_found) {
+ if (parameters.parameter[choices.id[i]].location > location) {
+ location = parameters.parameter[choices.id[i]].location;
+ location_sub = parameters.parameter[choices.id[i]].location_sub;
+ priority = choices.id[i];
}
- else if (parameters[choices.ids[i]].location == location && parameters[choices.ids[i]].location_sub > location_sub) {
- location_sub = parameters[choices.ids[i]].location_sub;
- priority = choices.ids[i];
+ else if (parameters.parameter[choices.id[i]].location == location && parameters.parameter[choices.id[i]].location_sub > location_sub) {
+ location_sub = parameters.parameter[choices.id[i]].location_sub;
+ priority = choices.id[i];
}
}
} // for
* The parameters passed to the process.
* @param parameters
* The console parameters to look for.
- * @param parameters_total
- * The used size of the parameters array.
+ * This will be updated by this function with the results.
* @param remaining
* A list of remaining parameters not associated with anything.
*
* f_reallocation_error (with error bit) on memory reallocation error.
*/
#ifndef _di_fl_console_parameter_process_
- extern f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, f_string_lengths *remaining);
+ extern f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameters parameters, f_string_lengths *remaining);
#endif // _di_fl_console_parameter_process_
/**
*
* @param parameters
* The parameters to process.
- * @param parameters_total
- * The used size of the parameters array.
* @param choices
* An array of numeric ids, each representing a parameter within the parameters variable.
* The order does not matter.
* f_invalid_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_fl_console_parameter_prioritize__
- extern f_return_status fl_console_parameter_prioritize(const f_console_parameter parameters[], const f_array_length parameters_total, const f_console_parameter_ids choices, f_console_parameter_id *decision);
+ extern f_return_status fl_console_parameter_prioritize(const f_console_parameters parameters, const f_console_parameter_ids choices, f_console_parameter_id *decision);
#endif // _di_fl_console_parameter_prioritize__
#ifdef __cplusplus
#endif // _di_fll_program_print_version_
#ifndef _di_fll_program_process_parameters_
- f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context) {
+ f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameters parameters, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context) {
f_status status = f_none;
f_status allocation_status = f_none;
- status = fl_console_parameter_process(arguments, parameters, parameters_total, remaining);
+ status = fl_console_parameter_process(arguments, parameters, remaining);
f_console_parameter_ids choices = f_console_parameter_ids_initialize;
f_console_parameter_id decision = parameter_dark;
f_console_parameter_id ids[3] = { parameter_no_color, parameter_light, parameter_dark};
- choices.ids = ids;
+ choices.id = ids;
choices.used = 3;
- fl_console_parameter_prioritize(parameters, parameters_total, choices, &decision);
+ fl_console_parameter_prioritize(parameters, choices, &decision);
// load colors unless told not to.
if (decision != parameter_no_color) {
* The parameters passed to the process.
* @param parameters
* The console parameters to look for.
- * @param parameters_total
- * The used size of the parameters array.
* @param parameter_no_color
* The parameter in the parameters array representing the no-color option.
* @param parameter_light
* f_reallocation_error (with error bit) on memory reallocation error.
*/
#ifndef _di_fll_program_process_parameters_
- extern f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context);
+ extern f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameters parameters, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context);
#endif // _di_fll_program_process_parameters_
#ifdef __cplusplus
#ifndef _di_bit_dump_main_
f_return_status bit_dump_main(const f_console_arguments arguments, bit_dump_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, bit_dump_total_parameters, bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, bit_dump_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
bit_dump_delete_data(data);
#ifndef _di_firewall_main_
f_return_status firewall_main(const f_console_arguments arguments, firewall_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, firewall_total_parameters, firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, firewall_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
firewall_delete_data(data);
f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility ("internal")));
f_return_status fss_basic_list_read_main(const f_console_arguments arguments, fss_basic_list_read_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_list_read_total_parameters, fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_basic_list_read_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_basic_list_read_delete_data(data);
#ifndef _di_fss_basic_list_write_main_
f_return_status fss_basic_list_write_main(const f_console_arguments arguments, fss_basic_list_write_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_list_write_total_parameters, fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_basic_list_write_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_basic_list_write_delete_data(data);
f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) f_gcc_attribute_visibility_internal;
f_return_status fss_basic_read_main(const f_console_arguments arguments, fss_basic_read_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_read_total_parameters, fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_basic_read_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_basic_read_delete_data(data);
#ifndef _di_fss_basic_write_main_
f_return_status fss_basic_write_main(const f_console_arguments arguments, fss_basic_write_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_write_total_parameters, fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_basic_write_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_basic_write_delete_data(data);
f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) f_gcc_attribute_visibility_internal;
f_return_status fss_extended_read_main(const f_console_arguments arguments, fss_extended_read_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_extended_read_total_parameters, fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_extended_read_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_extended_read_delete_data(data);
#ifndef _di_fss_extended_write_main_
f_return_status fss_extended_write_main(const f_console_arguments arguments, fss_extended_write_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_extended_write_total_parameters, fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_extended_write_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_extended_write_delete_data(data);
#ifndef _di_fss_status_code_main_
f_return_status fss_status_code_main(const f_console_arguments arguments, fss_status_code_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, fss_status_code_total_parameters, fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, fss_status_code_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
fss_status_code_delete_data(data);
f_u_short do_socket_file = f_true;
f_u_short do_socket_port = f_false;
- status = fll_program_process_parameters(arguments, data->parameters, init_total_parameters, init_parameter_no_color, init_parameter_light, init_parameter_dark, &data->remaining, &data->context);
+ {
+ f_console_parameters parameters = { data->parameters, init_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, init_parameter_no_color, init_parameter_light, init_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
init_delete_data(data);
#ifndef _di_status_code_main_
f_return_status status_code_main(const f_console_arguments arguments, status_code_data *data) {
- f_status status = fll_program_process_parameters(arguments, data->parameters, status_code_total_parameters, status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark, &data->remaining, &data->context);
+ f_status status = f_none;
+
+ {
+ f_console_parameters parameters = { data->parameters, status_code_total_parameters };
+ status = fll_program_process_parameters(arguments, parameters, status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark, &data->remaining, &data->context);
+ }
if (f_status_is_error(status)) {
status_code_delete_data(data);