The old iki_write is using the simple processing functions.
Switch to using the dedicated `f_iki_write()` function.
Switch to using the main cache design.
if (main->program.parameters.array[iki_write_parameter_wrap_e].result & f_console_result_found_e) {
main->setting.flag |= iki_write_main_flag_wrap_d;
+ main->setting.state.flag |= f_iki_state_flag_force_wrap_e;
+ }
+ else {
+ main->setting.state.flag &= ~f_iki_state_flag_force_wrap_e;
}
main->setting.quote = f_iki_syntax_quote_double_s;
"f_console_parameter_process",
"f_file_read",
"f_file_stream_open",
- "f_iki_object_is",
+ "f_iki_write",
"f_memory_arrays_resize",
"f_string_dynamic_partial_append_nulless",
"f_string_dynamic_seek_to",
"f_thread_create",
- "fll_iki_content_escape",
"fll_program_parameter_process_context_standard",
"fll_program_parameter_process_verbosity_standard",
};
iki_write_f_f_console_parameter_process_e,
iki_write_f_f_file_read_e,
iki_write_f_f_file_stream_open_e,
- iki_write_f_f_iki_object_is_e,
+ iki_write_f_f_iki_write_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,
iki_write_f_f_thread_create_e,
- iki_write_f_fll_iki_content_escape_e,
iki_write_f_fll_program_parameter_process_context_standard_e,
iki_write_f_fll_program_parameter_process_verbosity_standard_e,
}; // enum
extern "C" {
#endif
+#ifndef _di_iki_write_cache_delete_
+ void iki_write_cache_delete(iki_write_cache_t * const cache) {
+
+ if (!cache) return;
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->content.string, &cache->content.used, &cache->content.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->iki.string, &cache->iki.used, &cache->iki.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->object.string, &cache->object.used, &cache->object.size);
+ }
+#endif // _di_iki_write_cache_delete_
+
#ifndef _di_iki_write_main_delete_
void iki_write_main_delete(iki_write_main_t * const main) {
if (!main) return;
fll_program_data_delete(&main->program);
+
+ iki_write_cache_delete(&main->cache);
iki_write_setting_delete(&main->setting);
}
#endif // _di_iki_write_main_delete_
if (!setting) return;
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->escaped.string, &setting->escaped.used, &setting->escaped.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->buffer.string, &setting->buffer.used, &setting->buffer.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->object.string, &setting->object.used, &setting->object.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->content.string, &setting->content.used, &setting->content.size);
-
f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->objects.array, &setting->objects.used, &setting->objects.size, &f_string_dynamics_delete_callback);
f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->contents.array, &setting->contents.used, &setting->contents.size, &f_string_dynamics_delete_callback);
}
#endif
/**
+ * The iki write main program cache.
+ *
+ * buffer: A buffer used during processing the file.
+ * content: A buffer used to hold a Content during processing.
+ * iki: A buffer used for writing the IKI during processing.
+ * object: A buffer used to hold an Object during processing.
+ */
+#ifndef _di_iki_write_setting_t_
+ typedef struct {
+ f_string_dynamic_t buffer;
+ f_string_dynamic_t content;
+ f_string_dynamic_t iki;
+ f_string_dynamic_t object;
+ } iki_write_cache_t;
+
+ #define iki_write_cache_t_initialize \
+ { \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ }
+#endif // _di_iki_write_cache_t_
+
+/**
* The iki write main program settings.
*
* This is passed to the program-specific main entry point to designate program settings.
*
* quote: This holds the quote used during processing.
*
- * escaped: A buffer used for escaping strings during processing.
- * buffer: A buffer used during processing the file.
- * object: A buffer used to hold an Object during processing.
- * content: A buffer used to hold a Content during processing.
- *
* objects: An array of objects passed as values to the "--object" parameter.
* contents: An array of objects passed as values to the "--content" parameter and must match the length of objects.
*/
f_string_static_t quote;
- f_string_dynamic_t escaped;
- f_string_dynamic_t buffer;
- f_string_dynamic_t object;
- f_string_dynamic_t content;
-
f_string_dynamics_t objects;
f_string_dynamics_t contents;
} iki_write_setting_t;
F_okay, \
f_state_t_initialize, \
f_string_static_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
f_string_dynamics_t_initialize, \
f_string_dynamics_t_initialize, \
}
/**
* The main program data as a single structure.
*
+ * cache: The cache data.
* program: The main program data.
* setting: The settings data.
*/
#ifndef _di_iki_write_main_t_
typedef struct {
+ iki_write_cache_t cache;
fll_program_data_t program;
iki_write_setting_t setting;
} iki_write_main_t;
#define iki_write_main_t_initialize \
{ \
+ iki_write_cache_t_initialize, \
fll_program_data_t_initialize, \
iki_write_setting_t_initialize, \
}
#endif // _di_iki_write_main_t_
/**
+ * Delete the program main cache data.
+ *
+ * @param cache
+ * The program main cache data.
+ *
+ * Must not be NULL.
+ *
+ * @see f_memory_array_resize()
+ */
+#ifndef _di_iki_write_cache_delete_
+ extern void iki_write_cache_delete(iki_write_cache_t * const cache);
+#endif // _di_iki_write_cache_delete_
+
+/**
* De-allocate main program data.
*
* @param main
* This does not alter main.setting.state.status.
*
* @see fll_program_data_delete()
+ * @see iki_write_cache_delete()
* @see iki_write_setting_delete()
*/
#ifndef _di_iki_write_main_delete_
*
* This does not alter setting.state.status.
*
- * @see f_memory_array_resize()
* @see f_memory_arrays_resize()
*/
#ifndef _di_iki_write_setting_delete_
return;
}
- main->setting.escaped.used = 0;
-
if (main->setting.flag & iki_write_main_flag_pipe_d) {
bool object_ended = F_false;
-
f_number_unsigned_t previous = 0;
f_range_t range = f_range_t_initialize;
f_status_t status = F_okay;
pipe.id = F_type_descriptor_input_d;
pipe.size_read = 1;
- main->setting.buffer.used = 0;
- main->setting.object.used = 0;
- main->setting.content.used = 0;
+ main->cache.buffer.used = 0;
+ main->cache.object.used = 0;
+ main->cache.content.used = 0;
range.start = 0;
}
if (status != F_okay_eof) {
- status = f_file_read(pipe, &main->setting.buffer);
+ status = f_file_read(pipe, &main->cache.buffer);
if (F_status_is_error(status)) {
main->setting.state.status = F_status_set_error(F_pipe);
break;
}
- if (!main->setting.buffer.used) {
+ if (!main->cache.buffer.used) {
main->setting.state.status = F_status_set_error(F_parameter);
fll_program_print_error_pipe_missing_content(&main->program.error);
break;
}
- range.stop = main->setting.buffer.used - 1;
+ range.stop = main->cache.buffer.used - 1;
}
previous = range.start;
- main->setting.state.status = f_string_dynamic_seek_to(main->setting.buffer, f_string_ascii_feed_form_s.string[0], &range);
+ main->setting.state.status = f_string_dynamic_seek_to(main->cache.buffer, f_string_ascii_feed_form_s.string[0], &range);
if (main->setting.state.status == F_data_not_stop) {
main->setting.state.status = F_status_set_error(F_parameter);
range.start = previous;
if (object_ended) {
- main->setting.content.used = 0;
+ main->cache.content.used = 0;
- if (main->setting.buffer.used) {
- main->setting.state.status = f_string_dynamic_partial_append_nulless(main->setting.buffer, range, &main->setting.content);
+ 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));
}
}
- iki_write_process(main, main->setting.object, main->setting.content);
+ iki_write_process(main, main->cache.object, main->cache.content);
if (F_status_is_error(main->setting.state.status)) {
object_ended = F_false;
object_ended = F_false;
}
else {
- main->setting.object.used = 0;
+ main->cache.object.used = 0;
- main->setting.state.status = f_string_dynamic_partial_append_nulless(main->setting.buffer, range, &main->setting.object);
+ main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range, &main->cache.object);
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));
// Restore the range, positioned after the new line.
range.start = range.stop + 2;
- range.stop = main->setting.buffer.used - 1;
+ range.stop = main->cache.buffer.used - 1;
// Only clear the buffer and reset the start when the entire buffer has been processed.
if (range.start > range.stop) {
range.start = 0;
- main->setting.buffer.used = 0;
+ main->cache.buffer.used = 0;
}
- } while (status != F_okay_eof || main->setting.buffer.used || object_ended);
+ } while (status != F_okay_eof || main->cache.buffer.used || object_ended);
if (object_ended) {
main->setting.state.status = F_status_set_error(F_parameter);
*
* This alters main.setting.state.status:
* F_okay on success.
- * F_true on success when performing verification and verify passed.
- * F_false on success when performing verification and verify failed.
* F_interrupt on (exit) signal received.
*
* F_failure (with error bit) on processing failure.
* F_parameter (with error bit) if main is NULL or setting is NULL.
*
- * Errors (with error bit) from: f_iki_object_is().
- * Errors (with error bit) from: fll_iki_content_escape().
+ * Errors (with error bit) from: iki_write_process().
*
- * @see f_iki_object_is()
- * @see fll_iki_content_escape()
+ * @see iki_write_process()
*/
#ifndef _di_iki_write_main_
extern void iki_write_main(iki_write_main_t * const main);
fl_print_format("%[%QThe object '%]", print->to, print->set->error, print->prefix, print->set->error);
fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, object, print->set->notable);
- fl_print_format("%[' is not a valid IKI Object.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s);
+ fl_print_format("%[' is not a valid IKI Object (IKI Vocabulary).%]%r", print->to, print->set->error, print->set->error, f_string_eol_s);
f_file_stream_unlock(print->to);
#ifndef _di_iki_write_process_
void iki_write_process(iki_write_main_t * const main, const f_string_static_t object, const f_string_static_t content) {
+ if (!main) return;
+
if (!object.used) {
main->setting.state.status = F_status_set_error(F_failure);
return;
}
- main->setting.state.status = f_iki_object_is(object);
-
- if (main->setting.state.status == F_false) {
- main->setting.state.status = F_status_set_error(F_failure);
+ main->cache.iki.used = 0;
- iki_write_print_error_object_not_valid(&main->program.error, object);
-
- return;
- }
+ f_iki_write(object, content, main->setting.quote, &main->cache.iki, &main->setting.state);
if (F_status_is_error(main->setting.state.status)) {
- iki_write_print_error(&main->program.error, macro_iki_write_f(f_iki_object_is));
+ if (F_status_set_fine(main->setting.state.status) == F_syntax) {
+ iki_write_print_error_object_not_valid(&main->program.error, object);
+ }
+ else {
+ iki_write_print_error(&main->program.error, macro_iki_write_f(f_iki_write));
+ }
return;
}
- main->setting.escaped.used = 0;
-
- main->setting.state.status = fll_iki_content_escape(content, main->setting.quote, &main->setting.escaped);
+ f_print_dynamic(main->cache.iki, main->program.output.to);
- if (F_status_is_error(main->setting.state.status)) {
- iki_write_print_error(&main->program.error, macro_iki_write_f(fll_iki_content_escape));
-
- return;
- }
-
- if (main->setting.flag & iki_write_main_flag_wrap_d) {
- fl_print_format("%r%Q%r%r%r%Q%r", main->program.output.to, f_iki_syntax_wrap_open_s, object, f_iki_syntax_wrap_close_s, f_iki_syntax_separator_s, main->setting.quote, main->setting.escaped, main->setting.quote);
- }
- else {
- fl_print_format("%Q%r%r%Q%r", main->program.output.to, object, f_iki_syntax_separator_s, main->setting.quote, main->setting.escaped, main->setting.quote);
- }
+ main->setting.state.status = F_okay;
}
#endif // _di_iki_write_process_
#endif
/**
- * Process a given object and content, printing the IKI if valid or an error if invalid.
+ * Process a given object and content, printing it.
*
* @param main
* The program and settings data.
* This alters main.setting.state.status:
* F_okay on success.
*
- * Errors (with error bit) from: f_iki_object_is().
- * Errors (with error bit) from: fll_iki_content_escape().
+ * Errors (with error bit) from: f_iki_write().
*
* F_failure (with error bit) for any other failure.
* @param object
* @param content
* The content to escape and print.
*
- * @see f_iki_object_is()
- * @see fll_iki_content_escape()
+ * @see iki_write_print_error_object_not_valid()
+ * @see f_iki_write()
*/
#ifndef _di_iki_write_process_
- extern void iki_write_process(iki_write_main_t * const main, const f_string_static_t object, const f_string_static_t content) F_attribute_visibility_internal_d;
+ extern void iki_write_process(iki_write_main_t * const main, const f_string_static_t object, const f_string_static_t content);
#endif // _di_iki_write_process_
#ifdef __cplusplus