When a process signal is being received, F_signal is being set with the error bit.
This should not have the error bit set.
Move the conditional logic inside the appropriate printing functions.
Add utf8_print_character_invalid() for printing an error character.
Invalid UTF-8 fragments should not result in an exit on error.
Instead, these should be handled by either appropriate printing or by setting the is valid property on exit.
}
#endif // _di_utf8_print_character_
+#ifndef _di_utf8_print_character_invalid_
+ void utf8_print_character_invalid(utf8_data_t * const data, const f_string_static_t character) {
+
+ if (!character.used) return;
+ if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_found) return;
+ if (data->main->parameters[utf8_parameter_verify].result == f_console_result_found) return;
+
+ utf8_print_character(data, character, data->valid_not);
+ }
+#endif // _di_utf8_print_character_invalid_
+
#ifndef _di_utf8_print_codepoint_
void utf8_print_codepoint(utf8_data_t * const data, const uint32_t codepoint) {
void utf8_print_error_decode(utf8_data_t * const data, const f_status_t status, const f_string_static_t character) {
if (data->main->error.verbosity == f_console_verbosity_quiet) return;
+ if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_found) return;
+ if (data->main->parameters[utf8_parameter_verify].result == f_console_result_found) return;
fl_print_format("%c%[%SFailed to decode character code '%]", data->main->error.to.stream, f_string_eol_s[0], data->main->context.set.error, data->main->error.prefix, data->main->context.set.error);
if (F_status_set_fine(status) == F_utf) {
fl_print_format("%[', not a valid UTF-8 character sequence.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
}
+ else if (F_status_set_fine(status) == F_utf_fragment) {
+ fl_print_format("%[', invalid UTF-8 fragment.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+ }
else {
fl_print_format("%[', error status code%] ", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
fl_print_format("%[%ui%]", data->main->error.to.stream, data->main->context.set.notable, F_status_set_fine(status), data->main->context.set.notable);
#endif // _di_utf8_print_character_
/**
+ * Print an invalid character either as a Unicode codeblock or as a binary.
+ *
+ * This handles whether or not the invalid character should be printed or not based on program parameters.
+ *
+ * @param data
+ * The program data.
+ * @param character
+ * The character block to print.
+ */
+#ifndef _di_utf8_print_character_invalid_
+ extern void utf8_print_character_invalid(utf8_data_t * const data, const f_string_static_t character) F_attribute_visibility_internal_d;
+#endif // _di_utf8_print_character_invalid_
+
+/**
* Print the codepoint number as a codepoint string (such as U+8C78).
*
* @param data
}
if (F_status_is_error(status)) {
- if (F_status_set_fine(status) == F_failure || F_status_set_fine(status) == F_utf || F_status_set_fine(status) == F_valid_not) {
+ status = F_status_set_fine(status);
+
+ if (status == F_failure || status == F_utf || status == F_utf_fragment || status == F_valid_not) {
valid_not = F_true;
- if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
- utf8_print_character(data, character, data->valid_not);
- }
+ utf8_print_character_invalid(data, data->text);
}
else {
- if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
- utf8_print_error_decode(data, status, character);
- }
+ status = F_status_set_error(status);
+
+ utf8_print_error_decode(data, status, character);
return status;
}
if (utf8_signal_received(data)) {
utf8_print_signal_received(data, status);
- status = F_status_set_error(F_signal);
+ status = F_signal;
break;
}
}
data->buffer.used = 0;
- if (F_status_is_error(status)) {
+ if (F_status_is_error(status) || status == F_signal) {
return status;
}
status = f_utf_unicode_string_to(data->text.string, data->text.used, &codepoint);
if (F_status_is_error(status)) {
- if (F_status_set_fine(status) == F_failure || F_status_set_fine(status) == F_utf || F_status_set_fine(status) == F_valid_not) {
+ status = F_status_set_fine(status);
+
+ if (status == F_failure || status == F_utf || status == F_utf_fragment || status == F_valid_not) {
valid_not = F_true;
- if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
- fl_print_format("%s%[%r%]%s", data->file.stream, data->prepend, data->valid_not, data->text, data->valid_not, data->append);
- }
+ utf8_print_character_invalid(data, data->text);
}
else {
- if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
- utf8_print_error_decode(data, status, character);
- }
+ status = F_status_set_error(status);
+
+ utf8_print_error_decode(data, status, character);
return status;
}
else {
status = F_none;
- if (data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
- fl_print_format("%s%[%r%]%s", data->file.stream, data->prepend, data->valid_not, data->text, data->valid_not, data->append);
- }
+ utf8_print_character_invalid(data, data->text);
}
*mode = utf8_codepoint_mode_ready;
}
else if (macro_f_utf_byte_width_is(*character.string)) {
status = f_utf_is_whitespace(character.string, 4);
- if (F_status_is_error(status)) return status;
+
+ if (F_status_is_error(status)) {
+ if (F_status_set_fine(status) == F_utf_fragment) {
+ status = F_valid_not;
+ }
+ else {
+ return status;
+ }
+ }
if (status == F_true) {
status = F_space;
}
else {
if (character.string[0] < 0x30 || character.string[0] > 0x39 && character.string[0] < 0x41 || character.string[0] > 0x46 && character.string[0] < 0x61 || character.string[0] > 0x66) {
-
status = f_utf_is_whitespace(character.string, 4);
- if (F_status_is_error(status)) return status;
+
+ if (F_status_is_error(status)) {
+ if (F_status_set_fine(status) == F_utf_fragment) {
+ status = F_valid_not;
+ }
+ else {
+ return status;
+ }
+ }
if (status == F_true) {
status = F_space;
if (utf8_signal_received(data)) {
utf8_print_signal_received(data, status);
- status = F_status_set_error(F_signal);
+ status = F_signal;
break;
}
}
data->buffer.used = 0;
- if (F_status_is_error(status)) {
+ if (F_status_is_error(status) || status == F_signal) {
return status;
}
status = utf8_process_file_codepoint(&data, file);
}
- if (F_status_is_error(status)) {
+ if (F_status_is_error(status) && F_status_set_fine(status) != F_utf_fragment) {
fll_error_file_print(main->error, F_status_set_fine(status), data.mode & utf8_mode_from_binary_d ? "utf8_process_file_binary" : "utf8_process_file_codepoint", F_true, 0, utf8_string_process_s, fll_error_file_type_pipe);
}
}
}
}
- if (F_status_is_error(status)) {
+ if (F_status_is_error(status) && F_status_set_fine(status) != F_utf_fragment) {
fll_error_file_print(main->error, F_status_set_fine(status), data.mode & utf8_mode_from_binary_d ? "utf8_process_file_binary" : "utf8_process_file_codepoint", F_true, arguments->argv[index], utf8_string_process_s, fll_error_file_type_file);
break;
}
if (main->output.verbosity != f_console_verbosity_quiet && main->parameters[utf8_parameter_verify].result == f_console_result_none) {
- if (F_status_set_fine(status) == F_interrupt) {
+ if (status == F_signal) {
fflush(data.file.stream);
if (data.file.stream != main->output.to.stream) {
utf8_data_delete(&data);
utf8_main_delete(main);
- if (F_status_is_error(status)) {
+ if (F_status_is_error(status) || status == F_signal) {
return status;
}