#endif // _di_f_console_max_size_
#ifndef _di_f_console_default_allocation_step_
- #define f_console_default_allocation_step f_memory_default_allocation_step
+ // provide a UTF-8 friendly allocation step.
+ #define f_console_default_allocation_step 4
#endif // _di_f_console_default_allocation_step_
#ifndef _di_f_console_types_
/**
* none: parameter not found.
* found: parameter found.
- * additional: parameter found, extra data exists (such as '-f filename', filename would be the extra data).
+ * additional: parameter found, extra data exists (such as '-f filename', 'filename' would be the extra data).
*/
enum {
f_console_result_none,
* perform checks against short & long options to see if the string is one of them (normal).
*/
#define f_console_is_enable(result, string, short_option, long_option, max_length) \
- ((result == f_console_short_enable && strncmp(string, short_option, 1) == 0) || \
- (result == f_console_long_enable && strncmp(string, long_option, max_length) == 0))
+ ((result == f_console_short_enable && strncmp(string, short_option, max_length) == 0) || \
+ (result == f_console_long_enable && strncmp(string, long_option, max_length) == 0))
#endif // _di_f_console_is_enable_
#ifndef _di_f_console_is_disable_
* perform checks against short & long options to see if the string is one of them (inverse).
*/
#define f_console_is_disable(result, string, short_option, long_option, max_length) \
- ((result == f_console_short_disable && strncmp(string, short_option, 1) == 0) || \
- (result == f_console_long_disable && strncmp(string, long_option, max_length) == 0))
+ ((result == f_console_short_disable && strncmp(string, short_option, max_length) == 0) || \
+ (result == f_console_long_disable && strncmp(string, long_option, max_length) == 0))
#endif // _di_f_console_is_disable_
#ifndef _di_f_console_is_extra_enable_
f_string_lengths extra_initiator = f_string_lengths_initialize;
-
// loop through and read all parameters
while (location < argc) {
f_console_identify(argv[location], &result);
// Now handle the normal commands
if (argv[location][0] == f_console_symbol_enable) {
- while (sub_location < string_length) {
+ if (sub_location < string_length) {
for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) {
- if (parameters[parameter_counter].type == f_console_type_normal) {
- if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
- if (f_console_is_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
- parameters[parameter_counter].result = f_console_result_found;
-
- if (parameters[parameter_counter].has_additional) {
- if (extra_initiator.used >= extra_initiator.size) {
- f_status allocation_status = f_none;
-
- f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
- if (f_error_is_error(allocation_status)) {
- f_delete_string_lengths(status, extra_initiator);
- return f_error_set_error(allocation_status);
- }
- }
+ if (parameters[parameter_counter].type != f_console_type_normal) {
+ continue;
+ }
+
+ if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
+ if (f_console_is_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
+ parameters[parameter_counter].result = f_console_result_found;
- extra_initiator.array[extra_initiator.used] = parameter_counter;
- extra_initiator.used++;
+ if (parameters[parameter_counter].has_additional) {
+ if (extra_initiator.used >= extra_initiator.size) {
+ f_status allocation_status = f_none;
+
+ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+ if (f_error_is_error(allocation_status)) {
+ f_delete_string_lengths(status, extra_initiator);
+ return f_error_set_error(allocation_status);
+ }
}
+
+ extra_initiator.array[extra_initiator.used] = parameter_counter;
+ extra_initiator.used++;
}
}
+ }
- if (parameters[parameter_counter].symbol_extra != 0) {
- if (f_console_is_extra_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
- parameters[parameter_counter].result = f_console_result_found;
+ if (parameters[parameter_counter].symbol_extra != 0) {
+ if (f_console_is_extra_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
+ parameters[parameter_counter].result = f_console_result_found;
- if (parameters[parameter_counter].has_additional) {
- if (extra_initiator.used >= extra_initiator.size) {
- f_status allocation_status = f_none;
+ if (parameters[parameter_counter].has_additional) {
+ if (extra_initiator.used >= extra_initiator.size) {
+ f_status allocation_status = f_none;
- f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
- if (f_error_is_error(allocation_status)) {
- f_delete_string_lengths(status, extra_initiator);
- return f_error_set_error(allocation_status);
- }
+ if (f_error_is_error(allocation_status)) {
+ f_delete_string_lengths(status, extra_initiator);
+ return f_error_set_error(allocation_status);
}
-
- extra_initiator.array[extra_initiator.used] = parameter_counter;
- extra_initiator.used++;
}
+
+ extra_initiator.array[extra_initiator.used] = parameter_counter;
+ extra_initiator.used++;
}
}
}
} // for
-
- sub_location += increments;
- } // while
-
- // now handle the inverse commands
+ }
}
+ // now handle the inverse commands
else if (argv[location][0] == f_console_symbol_disable) {
- while (sub_location < string_length) {
+ if (sub_location < string_length) {
for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) {
- if (parameters[parameter_counter].type == f_console_type_inverse) {
- if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
- if (f_console_is_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
- parameters[parameter_counter].result = f_console_result_found;
+ if (parameters[parameter_counter].type != f_console_type_inverse) {
+ continue;
+ }
- if (parameters[parameter_counter].has_additional) {
- if (extra_initiator.used >= extra_initiator.size) {
- f_status allocation_status = f_none;
+ if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
+ if (f_console_is_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
+ parameters[parameter_counter].result = f_console_result_found;
- f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+ if (parameters[parameter_counter].has_additional) {
+ if (extra_initiator.used >= extra_initiator.size) {
+ f_status allocation_status = f_none;
- if (f_error_is_error(allocation_status)) {
- f_delete_string_lengths(status, extra_initiator);
- return f_error_set_error(allocation_status);
- }
- }
+ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
- extra_initiator.array[extra_initiator.used] = parameter_counter;
- extra_initiator.used++;
+ if (f_error_is_error(allocation_status)) {
+ f_delete_string_lengths(status, extra_initiator);
+ return f_error_set_error(allocation_status);
+ }
}
+
+ extra_initiator.array[extra_initiator.used] = parameter_counter;
+ extra_initiator.used++;
}
}
+ }
- if (parameters[parameter_counter].symbol_extra != 0) {
- if (f_console_is_extra_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
- parameters[parameter_counter].result = f_console_result_found;
+ if (parameters[parameter_counter].symbol_extra != 0) {
+ if (f_console_is_extra_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
+ parameters[parameter_counter].result = f_console_result_found;
- if (parameters[parameter_counter].has_additional) {
- if (extra_initiator.used >= extra_initiator.size) {
- f_status allocation_status = f_none;
+ if (parameters[parameter_counter].has_additional) {
+ if (extra_initiator.used >= extra_initiator.size) {
+ f_status allocation_status = f_none;
- f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
- if (f_error_is_error(allocation_status)) {
- f_delete_string_lengths(status, extra_initiator);
- return f_error_set_error(allocation_status);
- }
+ if (f_error_is_error(allocation_status)) {
+ f_delete_string_lengths(status, extra_initiator);
+ return f_error_set_error(allocation_status);
}
-
- extra_initiator.array[extra_initiator.used] = parameter_counter;
- extra_initiator.used++;
}
+
+ extra_initiator.array[extra_initiator.used] = parameter_counter;
+ extra_initiator.used++;
}
}
}
} // for
-
- sub_location += increments;
- } // while
+ }
}
else {
// use found to determine if the remaining parameter should be populated
found = f_false;
for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) {
- if (parameters[parameter_counter].type == f_console_type_other) {
- if (parameters[parameter_counter].length > 0 && parameters[parameter_counter].symbol_other != 0) {
- if (strncmp(argv[location], parameters[parameter_counter].symbol_other, parameters[parameter_counter].length + 1) == 0) {
- f_status allocation_status = f_none;
+ if (parameters[parameter_counter].type != f_console_type_other) {
+ continue;
+ }
- if (parameters[parameter_counter].additional.used >= parameters[parameter_counter].additional.size) {
- f_resize_string_lengths(allocation_status, parameters[parameter_counter].additional, parameters[parameter_counter].additional.size + f_console_default_allocation_step);
- }
+ if (parameters[parameter_counter].length > 0 && parameters[parameter_counter].symbol_other != 0) {
+ if (strncmp(argv[location], parameters[parameter_counter].symbol_other, parameters[parameter_counter].length + 1) == 0) {
+ f_status allocation_status = f_none;
- if (f_error_is_error(allocation_status)) {
- f_delete_string_lengths(status, extra_initiator);
- return f_error_set_error(allocation_status);
- }
+ if (parameters[parameter_counter].additional.used >= parameters[parameter_counter].additional.size) {
+ f_resize_string_lengths(allocation_status, parameters[parameter_counter].additional, parameters[parameter_counter].additional.size + f_console_default_allocation_step);
+ }
- parameters[parameter_counter].result = f_console_result_found;
+ if (f_error_is_error(allocation_status)) {
+ f_delete_string_lengths(status, extra_initiator);
+ return f_error_set_error(allocation_status);
+ }
- // when "other" is supplied, the extra will be recycled to represent the location of the "other" such that ordering can be determined by the caller
- parameters[parameter_counter].additional.array[parameters[parameter_counter].additional.used] = location;
- parameters[parameter_counter].additional.used++;
+ parameters[parameter_counter].result = f_console_result_found;
- found = f_true;
- break;
- }
+ // when "other" is supplied, the extra will be recycled to represent the location of the "other" such that ordering can be determined by the caller
+ parameters[parameter_counter].additional.array[parameters[parameter_counter].additional.used] = location;
+ parameters[parameter_counter].additional.used++;
+
+ found = f_true;
+ break;
}
}
} // for