From: Kevin Day Date: Sat, 30 Nov 2024 12:58:15 +0000 (-0600) Subject: Feature: Add eki_write program. X-Git-Tag: 0.7.0~25 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=21f68ab05c610a66e0b87f4edc511e4a65ff88e6;p=fll Feature: Add eki_write program. The eki_write program is now added and complete. This resolves the progress commits for this, such as 740d5fc88d6e05edf2a7267c422642bd14cc473c. There are no iki_write runtime tests yet, so this does not add any yet. --- diff --git a/level_3/iki_write/c/eki/common.c b/level_3/iki_write/c/eki/common.c index ea8b1ef..d17fcfe 100644 --- a/level_3/iki_write/c/eki/common.c +++ b/level_3/iki_write/c/eki/common.c @@ -41,6 +41,8 @@ extern "C" { // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0). for (index = 0; at_object < object->values.used; ) { + if (iki_write_signal_check(main)) return; + main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &objectss->array[objectss->used].array, &objectss->array[objectss->used].used, &objectss->array[objectss->used].size); if (F_status_is_error(main->setting.state.status)) { @@ -103,6 +105,8 @@ extern "C" { // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0). for (index = 0; main->setting.contents.used < content->values.used; ) { + if (iki_write_signal_check(main)) return; + index = content->values.array[main->setting.contents.used]; main->setting.contents.array[main->setting.contents.used].string = main->program.parameters.arguments.array[index].string; diff --git a/level_3/iki_write/c/eki/print.c b/level_3/iki_write/c/eki/print.c index b3201ef..a770b93 100644 --- a/level_3/iki_write/c/eki/print.c +++ b/level_3/iki_write/c/eki/print.c @@ -73,8 +73,8 @@ extern "C" { void iki_write_eki_print_message_help_note_pipe(fl_print_t * const print) { if (!print) return; - fl_print_format("%r When piping main to this program, a single form-feed character (\\f) (U+000C) must be used to separate each Object set from the Content.%r", print->to, f_string_eol_s, f_string_eol_s); - fl_print_format(" Each Object within an Object set is is separated by a single backspace character (\\b) (U+0008).%r", print->to, f_string_eol_s); + fl_print_format("%r When piping main to this program, a single Form-Feed character (\\f) (U+000C) must be used to separate each Object set from the Content.%r", print->to, f_string_eol_s, f_string_eol_s); + fl_print_format(" Each Object within an Object set is is separated by a single Backspace character (\\b) (U+0008).%r", print->to, f_string_eol_s); fl_print_format(" Each Object set must be followed by a Content.%r", print->to, f_string_eol_s); } #endif // _di_iki_write_eki_print_message_help_note_pipe_ diff --git a/level_3/iki_write/c/eki/process.c b/level_3/iki_write/c/eki/process.c index 8316c4c..6cd7d8b 100644 --- a/level_3/iki_write/c/eki/process.c +++ b/level_3/iki_write/c/eki/process.c @@ -5,13 +5,13 @@ extern "C" { #endif #ifndef _di_iki_write_eki_load_objects_content_pipe_ - void iki_write_eki_load_objects_content_pipe(void * const void_main, const f_range_t range, bool * const object_ended) { + void iki_write_eki_load_objects_content_pipe(void * const void_main, const f_range_t range, uint8_t * const pipe_state) { if (!void_main) return; iki_write_main_t * const main = (iki_write_main_t *) void_main; - if (!object_ended || !main->callback.process_objects_content) { + if (!pipe_state || !main->callback.process_objects_content) { main->setting.state.status = F_status_set_error(F_parameter); iki_write_print_error(&main->program.error, macro_iki_write_f(iki_write_callback_load_objects_content_pipe)); @@ -19,61 +19,99 @@ extern "C" { return; } - if (*object_ended) { - main->cache.content.used = 0; - + if (*pipe_state) { if (main->cache.buffer.used) { main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range, &main->cache.content); if (F_status_is_error(main->setting.state.status)) { iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless)); - *object_ended = F_false; - return; } } main->callback.process_objects_content((void *) main, main->cache.objects, main->cache.content); - - if (F_status_is_error(main->setting.state.status)) { - *object_ended = F_false; - - return; - } + if (F_status_is_error(main->setting.state.status)) return; fll_print_dynamic_raw(f_string_eol_s, main->program.output.to); - *object_ended = F_false; + *pipe_state = 0x0; main->cache.objects.used = 0; + main->cache.content.used = 0; } else { f_range_t range_object = range; + f_number_unsigned_t total = 0; + + for (; range_object.start <= range_object.stop; ++total) { + + if (iki_write_signal_check(main)) return; + + main->setting.state.status = f_string_dynamic_seek_to(main->cache.buffer, f_string_ascii_space_back_s.string[0], &range_object); - f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.objects.array, &main->cache.objects.used, &main->cache.objects.size); + if (F_status_is_error(main->setting.state.status)) { + iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_seek_to)); + + return; + } - if (F_status_is_error(main->setting.state.status)) { - iki_write_print_error(&main->program.error, macro_iki_write_f(f_memory_array_increase)); + // Seek past the found colon when the end is not reached. + if (main->setting.state.status == F_okay) { + ++range_object.start; + } + } // for - *object_ended = F_false; + // Designate that no Object is found. + if (!total) { + *pipe_state = 0x0; return; } - main->cache.objects.array[0].used = 0; + if (main->cache.objects.size < total) { + f_memory_array_increase_by(total, sizeof(f_string_dynamic_t), (void **) &main->cache.objects.array, &main->cache.objects.used, &main->cache.objects.size); - main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range, &main->cache.objects.array[0]); + if (F_status_is_error(main->setting.state.status)) { + iki_write_print_error(&main->program.error, macro_iki_write_f(f_memory_array_increase_by)); - if (F_status_is_error(main->setting.state.status)) { - iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless)); + return; + } + } - *object_ended = F_false; + range_object = range; - return; - } + f_number_unsigned_t i = 0; + f_range_t range_next = range; + + for (; i < total; ++i) { + + if (iki_write_signal_check(main)) return; + + main->cache.objects.array[main->cache.objects.used].used = 0; + + main->setting.state.status = f_string_dynamic_seek_to(main->cache.buffer, f_string_ascii_space_back_s.string[0], &range_next); + + if (F_status_is_error(main->setting.state.status)) { + iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_seek_to)); + + return; + } + + range_object.stop = range_next.start - 1; + + main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range_object, &main->cache.objects.array[main->cache.objects.used]); + + if (F_status_is_error(main->setting.state.status)) { + iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless)); + + return; + } + + ++main->cache.objects.used; + range_object.start = ++range_next.start; + } // for - *object_ended = F_true; - ++main->cache.objects.used; + *pipe_state = 0x1; } } #endif // _di_iki_write_eki_load_objects_content_pipe_ diff --git a/level_3/iki_write/c/eki/process.h b/level_3/iki_write/c/eki/process.h index e9fadc5..1fc7e2a 100644 --- a/level_3/iki_write/c/eki/process.h +++ b/level_3/iki_write/c/eki/process.h @@ -32,15 +32,20 @@ extern "C" { * Errors (with error bit) from: f_iki_write(). * * F_failure (with error bit) for any other failure. - * @param objects - * The objects to process and print. - * @param content - * The content to process and print. + * @param range + * The range within the buffer representing the objects. + * @param pipe_state + * Designate that the Object part of the pipe is complete. + * For EKI, this may represent the end of the entire set of multiple Objects. + * + * State Bits: + * - 0x0: No Object has been found. + * - 0x1: Object is found and processed. * * @see f_iki_write() */ #ifndef _di_iki_write_eki_load_objects_content_pipe_ - extern void iki_write_eki_load_objects_content_pipe(void * const main, const f_range_t range, bool * const object_ended); + extern void iki_write_eki_load_objects_content_pipe(void * const main, const f_range_t range, uint8_t * const pipe_state); #endif // _di_iki_write_eki_load_objects_content_pipe_ /** diff --git a/level_3/iki_write/c/iki/common.c b/level_3/iki_write/c/iki/common.c index bd9b0a1..22c68db 100644 --- a/level_3/iki_write/c/iki/common.c +++ b/level_3/iki_write/c/iki/common.c @@ -36,6 +36,8 @@ extern "C" { // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0). for (index = 0; main->setting.objectss.used < values->used; ) { + if (iki_write_signal_check(main)) return; + main->setting.state.status = f_memory_arrays_resize(1, sizeof(f_string_dynamic_t), (void **) &main->setting.objectss.array[main->setting.objectss.used].array, &main->setting.objectss.array[main->setting.objectss.used].used, &main->setting.objectss.array[main->setting.objectss.used].size, &f_string_dynamics_delete_callback); if (F_status_is_error(main->setting.state.status)) { @@ -78,6 +80,8 @@ extern "C" { // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0). for (index = 0; main->setting.contents.used < values->used; ) { + if (iki_write_signal_check(main)) return; + index = values->array[main->setting.contents.used]; main->setting.contents.array[main->setting.contents.used].string = main->program.parameters.arguments.array[index].string; diff --git a/level_3/iki_write/c/iki/print.c b/level_3/iki_write/c/iki/print.c index 68788c4..1c2d78c 100644 --- a/level_3/iki_write/c/iki/print.c +++ b/level_3/iki_write/c/iki/print.c @@ -51,7 +51,7 @@ extern "C" { if (!print) return; - fl_print_format("%r When piping main to this program, a single form-feed character (\\f) (U+000C) must be used to separate each Object from each Content.%r", print->to, f_string_eol_s, f_string_eol_s); + fl_print_format("%r When piping main to this program, a single Form-Feed character (\\f) (U+000C) must be used to separate each Object from each Content.%r", print->to, f_string_eol_s, f_string_eol_s); fl_print_format(" Each Object must be followed by a Content.%r", print->to, f_string_eol_s); } #endif // _di_iki_write_iki_print_message_help_note_pipe_ diff --git a/level_3/iki_write/c/iki/process.c b/level_3/iki_write/c/iki/process.c index 8ff02b4..28a480d 100644 --- a/level_3/iki_write/c/iki/process.c +++ b/level_3/iki_write/c/iki/process.c @@ -5,13 +5,13 @@ extern "C" { #endif #ifndef _di_iki_write_iki_load_objects_content_pipe_ - void iki_write_iki_load_objects_content_pipe(void * const void_main, const f_range_t range, bool * const object_ended) { + void iki_write_iki_load_objects_content_pipe(void * const void_main, const f_range_t range, uint8_t * const pipe_state) { if (!void_main) return; iki_write_main_t * const main = (iki_write_main_t *) void_main; - if (!object_ended || !main->callback.process_objects_content) { + if (!pipe_state || !main->callback.process_objects_content) { main->setting.state.status = F_status_set_error(F_parameter); iki_write_print_error(&main->program.error, macro_iki_write_f(iki_write_callback_load_objects_content_pipe)); @@ -19,7 +19,7 @@ extern "C" { return; } - if (*object_ended) { + if (*pipe_state) { main->cache.content.used = 0; if (main->cache.buffer.used) { @@ -28,33 +28,26 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless)); - *object_ended = F_false; - return; } } main->callback.process_objects_content((void *) main, main->cache.objects, main->cache.content); - - if (F_status_is_error(main->setting.state.status)) { - *object_ended = F_false; - - return; - } + if (F_status_is_error(main->setting.state.status)) return; fll_print_dynamic_raw(f_string_eol_s, main->program.output.to); - *object_ended = F_false; + *pipe_state = 0x0; main->cache.objects.used = 0; } else { + main->cache.objects.used = 0; + f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.objects.array, &main->cache.objects.used, &main->cache.objects.size); if (F_status_is_error(main->setting.state.status)) { iki_write_print_error(&main->program.error, macro_iki_write_f(f_memory_array_increase)); - *object_ended = F_false; - return; } @@ -65,12 +58,10 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless)); - *object_ended = F_false; - return; } - *object_ended = F_true; + *pipe_state = 0x1; ++main->cache.objects.used; } } diff --git a/level_3/iki_write/c/iki/process.h b/level_3/iki_write/c/iki/process.h index 30da911..adba6ec 100644 --- a/level_3/iki_write/c/iki/process.h +++ b/level_3/iki_write/c/iki/process.h @@ -32,15 +32,19 @@ extern "C" { * Errors (with error bit) from: f_iki_write(). * * F_failure (with error bit) for any other failure. - * @param objects - * The objects to process and print. - * @param content - * The content to process and print. + * @param range + * The range within the buffer representing the objects. + * @param pipe_state + * Designate that the Object part of the pipe is complete. + * + * State Bits: + * - 0x0: No Object has been found. + * - 0x1: Object is found and processed. * * @see f_iki_write() */ #ifndef _di_iki_write_iki_load_objects_content_pipe_ - extern void iki_write_iki_load_objects_content_pipe(void * const main, const f_range_t range, bool * const object_ended); + extern void iki_write_iki_load_objects_content_pipe(void * const main, const f_range_t range, uint8_t * const pipe_state); #endif // _di_iki_write_iki_load_objects_content_pipe_ /** diff --git a/level_3/iki_write/c/main/common/print.c b/level_3/iki_write/c/main/common/print.c index 9f1b546..6862137 100644 --- a/level_3/iki_write/c/main/common/print.c +++ b/level_3/iki_write/c/main/common/print.c @@ -11,6 +11,7 @@ extern "C" { "f_file_stream_open", "f_iki_write", "f_memory_array_increase", + "f_memory_array_increase_by", "f_memory_arrays_resize", "f_string_dynamic_partial_append_nulless", "f_string_dynamic_seek_to", diff --git a/level_3/iki_write/c/main/common/print.h b/level_3/iki_write/c/main/common/print.h index c4cfb9d..0579ed7 100644 --- a/level_3/iki_write/c/main/common/print.h +++ b/level_3/iki_write/c/main/common/print.h @@ -44,6 +44,7 @@ extern "C" { iki_write_f_f_file_stream_open_e, iki_write_f_f_iki_write_e, iki_write_f_f_memory_array_increase_e, + iki_write_f_f_memory_array_increase_by_e, iki_write_f_f_memory_arrays_resize_e, iki_write_f_f_string_dynamic_partial_append_nulless_e, iki_write_f_f_string_dynamic_seek_to_e, diff --git a/level_3/iki_write/c/main/common/type.h b/level_3/iki_write/c/main/common/type.h index 9c2babc..dd3497e 100644 --- a/level_3/iki_write/c/main/common/type.h +++ b/level_3/iki_write/c/main/common/type.h @@ -27,7 +27,7 @@ extern "C" { */ #ifndef _di_iki_write_callback_t_ typedef struct { - void (*load_objects_content_pipe)(void * const main, const f_range_t range, bool * const object_ended); + void (*load_objects_content_pipe)(void * const main, const f_range_t range, uint8_t * const pipe_state); void (*print_help)(fl_print_t * const print); diff --git a/level_3/iki_write/c/main/iki_write.c b/level_3/iki_write/c/main/iki_write.c index b6389bd..eb9ab45 100644 --- a/level_3/iki_write/c/main/iki_write.c +++ b/level_3/iki_write/c/main/iki_write.c @@ -28,7 +28,7 @@ extern "C" { } if (main->setting.flag & iki_write_main_flag_pipe_d) { - bool object_ended = F_false; + uint8_t pipe_state = 0x0; f_number_unsigned_t previous = 0; f_range_t range = f_range_t_initialize; f_status_t status = F_okay; @@ -44,17 +44,7 @@ extern "C" { range.start = 0; do { - if (!((++main->program.signal_check) % iki_write_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - main->setting.state.status = F_status_set_error(F_interrupt); - - object_ended = F_false; - - break; - } - - main->program.signal_check = 0; - } + if (iki_write_signal_check(main)) return; if (status != F_okay_eof) { status = f_file_read(pipe, &main->cache.buffer); @@ -64,8 +54,6 @@ extern "C" { iki_write_print_error_file(&main->program.error, macro_iki_write_f(f_file_read), f_string_ascii_minus_s, f_file_operation_read_s, fll_error_file_type_pipe_e); - object_ended = F_false; - break; } @@ -74,8 +62,6 @@ extern "C" { fll_program_print_error_pipe_missing_content(&main->program.error); - object_ended = F_false; - break; } @@ -92,18 +78,14 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_seek_to)); - object_ended = F_false; - break; } - if (object_ended && previous == range.start) { + if (pipe_state && previous == range.start) { main->setting.state.status = F_status_set_error(F_parameter); fll_program_print_error_pipe_invalid_form_feed(&main->program.error); - object_ended = F_false; - break; } @@ -111,7 +93,7 @@ extern "C" { range.start = previous; if (main->callback.load_objects_content_pipe) { - main->callback.load_objects_content_pipe((void *) main, range, &object_ended); + main->callback.load_objects_content_pipe((void *) main, range, &pipe_state); if (F_status_is_error(main->setting.state.status)) break; } @@ -125,9 +107,9 @@ extern "C" { main->cache.buffer.used = 0; } - } while (status != F_okay_eof || main->cache.buffer.used || object_ended); + } while (status != F_okay_eof || main->cache.buffer.used || pipe_state); - if (F_status_is_error_not(main->setting.state.status) && object_ended) { + if (F_status_is_error_not(main->setting.state.status) && pipe_state) { main->setting.state.status = F_status_set_error(F_parameter); fll_program_print_error_pipe_object_without_content(&main->program.error); @@ -137,15 +119,7 @@ extern "C" { if (F_status_is_error_not(main->setting.state.status) && F_status_set_fine(main->setting.state.status) != F_interrupt) { for (f_number_unsigned_t i = 0; i < main->setting.objectss.used; ++i) { - if (!((++main->program.signal_check) % iki_write_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - main->setting.state.status = F_status_set_error(F_interrupt); - - break; - } - - main->program.signal_check = 0; - } + if (iki_write_signal_check(main)) return; main->callback.process_objects_content((void *) main, main->setting.objectss.array[i], main->setting.contents.array[i]); if (F_status_is_error(main->setting.state.status)) break; diff --git a/level_3/iki_write/data/build/settings.eki_write b/level_3/iki_write/data/build/settings.eki_write index 917dda7..0efd57b 100644 --- a/level_3/iki_write/data/build/settings.eki_write +++ b/level_3/iki_write/data/build/settings.eki_write @@ -1,6 +1,6 @@ # fss-0001 # -# Builds the "iki_write" program. +# Builds the "eki_write" program. # This must be called after the "setting". #