Create iki_write_data_t for private data and passing the fll_program_data_t pointer.
Move parameter initialization and deallocation for FLL program data into main.c.
const f_string_static_t iki_write_long_single_s = macro_f_string_static_t_initialize(IKI_WRITE_long_single_s, 0, IKI_WRITE_long_single_s_length);
#endif // _di_iki_write_parameters_
-#ifndef _di_iki_write_main_delete_
- f_status_t iki_write_main_delete(iki_write_main_t * const main) {
-
- f_console_parameters_delete(&main->parameters);
-
- f_string_dynamic_resize(0, &main->buffer);
-
- macro_f_color_context_t_delete_simple(main->context);
-
- return F_none;
- }
-#endif // _di_iki_write_main_delete_
-
#ifdef __cplusplus
} // extern "C"
#endif
#define iki_write_total_parameters_d 14
#endif // _di_iki_write_parameters_
-/**
- * The main program data.
- *
- * parameters: The state of pre-defined parameters passed to the program.
- * process_pipe: Designate whether or not to process the input pipe.
- * output: The output file for general printing.
- * error: The output file for error printing.
- * warning: The output file for warning printing.
- * signal: The process signal management structure.
- * context: The color context.
- */
-#ifndef _di_iki_write_main_t_
- typedef struct {
- f_console_parameters_t parameters;
-
- uint16_t signal_check;
- bool process_pipe;
-
- fl_print_t output;
- fl_print_t error;
- fl_print_t warning;
-
- f_signal_t signal;
-
- f_string_static_t quote;
- f_string_dynamic_t buffer;
-
- f_color_context_t context;
- } iki_write_main_t;
-
- #define iki_write_main_t_initialize \
- { \
- f_console_parameters_t_initialize, \
- 0, \
- F_false, \
- fl_print_t_initialize, \
- macro_fl_print_t_initialize_error(), \
- macro_fl_print_t_initialize_warning(), \
- f_signal_t_initialize, \
- f_string_static_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_color_context_t_initialize, \
- }
-#endif // _di_iki_write_main_t_
-
-/**
- * Deallocate main.
- *
- * Be sure to call this after executing iki_write_main().
- *
- * @param main
- * The main program data.
- *
- * @return
- * F_none on success.
- *
- * Status codes (with error bit) are returned on any problem.
- *
- * @see iki_write_main()
- */
-#ifndef _di_iki_write_main_delete_
- extern f_status_t iki_write_main_delete(iki_write_main_t * const main);
-#endif // _di_iki_write_main_delete_
-
#ifdef __cplusplus
} // extern "C"
#endif
#endif // _di_iki_write_print_help_
#ifndef _di_iki_write_main_
- f_status_t iki_write_main(iki_write_main_t * const main, const f_console_arguments_t *arguments) {
+ f_status_t iki_write_main(fll_program_data_t * const main, const f_console_arguments_t *arguments) {
f_status_t status = F_none;
- f_console_parameter_t parameters[] = iki_write_console_parameter_t_initialize;
- main->parameters.array = parameters;
- main->parameters.used = iki_write_total_parameters_d;
-
{
f_console_parameter_id_t ids[3] = { iki_write_parameter_no_color_e, iki_write_parameter_light_e, iki_write_parameter_dark_e };
const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 3);
f_print_dynamic_raw(f_string_eol_s, main->error.to.stream);
}
- iki_write_main_delete(main);
-
return F_status_set_error(status);
}
}
status = f_console_parameter_prioritize_right(main->parameters, choices, &choice);
- if (F_status_is_error(status)) {
- iki_write_main_delete(main);
-
- return status;
- }
+ if (F_status_is_error(status)) return status;
if (choice == iki_write_parameter_verbosity_quiet_e) {
main->output.verbosity = f_console_verbosity_quiet_e;
}
}
- f_string_static_t * const argv = main->parameters.arguments.array;
+ iki_write_data_t data = iki_write_data_t_initialize;
+ data.main = main;
+ data.argv = main->parameters.arguments.array;
status = F_none;
if (main->parameters.array[iki_write_parameter_help_e].result == f_console_result_found_e) {
iki_write_print_help(main->output.to, main->context);
- iki_write_main_delete(main);
+ iki_write_data_delete(&data);
return F_none;
}
if (main->parameters.array[iki_write_parameter_version_e].result == f_console_result_found_e) {
fll_program_print_version(main->output.to, iki_write_program_version_s);
- iki_write_main_delete(main);
+ iki_write_data_delete(&data);
return F_none;
}
file.id = -1;
file.stream = 0;
- status = f_file_stream_open(argv[index], f_string_empty_s, &file);
+ status = f_file_stream_open(data.argv[index], f_string_empty_s, &file);
if (F_status_is_error(status)) {
- fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stream_open", F_true, argv[index], f_file_operation_open_s, fll_error_file_type_file_e);
+ fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stream_open", F_true, data.argv[index], f_file_operation_open_s, fll_error_file_type_file_e);
}
}
}
}
}
- main->quote = f_iki_syntax_quote_double_s;
+ data.quote = f_iki_syntax_quote_double_s;
if (F_status_is_error_not(status)) {
if (main->parameters.array[iki_write_parameter_double_e].result == f_console_result_found_e) {
if (main->parameters.array[iki_write_parameter_single_e].result == f_console_result_found_e) {
if (main->parameters.array[iki_write_parameter_double_e].location < main->parameters.array[iki_write_parameter_single_e].location) {
- main->quote = f_iki_syntax_quote_single_s;
+ data.quote = f_iki_syntax_quote_single_s;
}
}
}
else if (main->parameters.array[iki_write_parameter_single_e].result == f_console_result_found_e) {
- main->quote = f_iki_syntax_quote_single_s;
+ data.quote = f_iki_syntax_quote_single_s;
}
}
for (f_status_t status_pipe = F_none; ; ) {
if (!((++main->signal_check) % iki_write_signal_check_d)) {
- if (iki_write_signal_received(main)) {
+ if (iki_write_signal_received(&data)) {
status = F_status_set_error(F_interrupt);
break;
}
}
- status = iki_write_process(main, file, object, content, &escaped);
+ status = iki_write_process(&data, file, object, content, &escaped);
if (F_status_is_error(status)) break;
fll_print_dynamic_raw(f_string_eol_s, file.stream);
for (f_array_length_t i = 0; i < main->parameters.array[iki_write_parameter_object_e].values.used; ++i) {
if (!((++main->signal_check) % iki_write_signal_check_d)) {
- if (iki_write_signal_received(main)) {
+ if (iki_write_signal_received(&data)) {
status = F_status_set_error(F_interrupt);
+
break;
}
main->signal_check = 0;
}
- status = iki_write_process(main, file, argv[main->parameters.array[iki_write_parameter_object_e].values.array[i]], argv[main->parameters.array[iki_write_parameter_content_e].values.array[i]], &escaped);
+ status = iki_write_process(&data, file, data.argv[main->parameters.array[iki_write_parameter_object_e].values.array[i]], data.argv[main->parameters.array[iki_write_parameter_content_e].values.array[i]], &escaped);
if (F_status_is_error(status)) break;
fll_print_dynamic_raw(f_string_eol_s, file.stream);
}
}
- iki_write_main_delete(main);
+ iki_write_data_delete(&data);
return status;
}
* This is the IKI Write program.
*
* This program utilizes the Featureless Linux Library.
- * This program processes files or other input in fss format and stores the results in the iki_write_main_t.
+ * This program processes files or other input in fss format.
*
* This processes in accordance to the IKI specification.
*/
* @see iki_write_main_delete()
*/
#ifndef _di_iki_write_main_
- extern f_status_t iki_write_main(iki_write_main_t * const main, const f_console_arguments_t *arguments);
+ extern f_status_t iki_write_main(fll_program_data_t * const main, const f_console_arguments_t *arguments);
#endif // _di_iki_write_main_
#ifdef __cplusplus
int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp);
- iki_write_main_t data = iki_write_main_t_initialize;
+ fll_program_data_t data = fll_program_data_t_initialize;
+
+ f_console_parameter_t parameters[] = iki_write_console_parameter_t_initialize;
+ data.parameters.array = parameters;
+ data.parameters.used = iki_write_total_parameters_d;
if (f_pipe_input_exists()) {
data.process_pipe = F_true;
fll_program_standard_setdown(&data.signal);
+ fll_program_data_delete(&data);
+
if (F_status_is_error(status)) return 1;
return 0;
extern "C" {
#endif
+#ifndef _di_iki_write_data_delete_
+ void iki_write_data_delete(iki_write_data_t *data) {
+
+ // Nothing to deallocate.
+ }
+#endif // _di_iki_write_data_delete_
+
#ifndef _di_iki_write_print_signal_received_
- void iki_write_print_signal_received(iki_write_main_t * const main, const f_status_t signal) {
+ void iki_write_print_signal_received(iki_write_data_t * const data, const f_status_t signal) {
- if (main->warning.verbosity != f_console_verbosity_verbose_e) return;
+ if (data->main->warning.verbosity != f_console_verbosity_verbose_e) return;
// Must flush and reset color because the interrupt may have interrupted the middle of a print function.
- fflush(main->warning.to.stream);
+ fflush(data->main->warning.to.stream);
- flockfile(main->warning.to.stream);
+ flockfile(data->main->warning.to.stream);
- fl_print_format("%]%r%r%[Received signal code %]", main->warning.to.stream, main->context.set.reset, f_string_eol_s, f_string_eol_s, main->context.set.warning, main->context.set.warning);
- fl_print_format("%[%i%]", main->warning.to.stream, main->context.set.notable, signal, main->context.set.notable);
- fl_print_format("%[.%]%r", main->warning.to.stream, main->context.set.warning, main->context.set.warning, f_string_eol_s);
+ fl_print_format("%]%r%r%[Received signal code %]", data->main->warning.to.stream, data->main->context.set.reset, f_string_eol_s, f_string_eol_s, data->main->context.set.warning, data->main->context.set.warning);
+ fl_print_format("%[%i%]", data->main->warning.to.stream, data->main->context.set.notable, signal, data->main->context.set.notable);
+ fl_print_format("%[.%]%r", data->main->warning.to.stream, data->main->context.set.warning, data->main->context.set.warning, f_string_eol_s);
- funlockfile(main->warning.to.stream);
+ funlockfile(data->main->warning.to.stream);
}
#endif // _di_iki_write_print_signal_received_
#ifndef _di_iki_write_signal_received_
- f_status_t iki_write_signal_received(iki_write_main_t * const main) {
+ f_status_t iki_write_signal_received(iki_write_data_t * const data) {
- if (main->signal.id == -1) {
+ if (data->main->signal.id == -1) {
return F_false;
}
memset(&information, 0, sizeof(struct signalfd_siginfo));
- if (f_signal_read(main->signal, 0, &information) == F_signal) {
+ if (f_signal_read(data->main->signal, 0, &information) == F_signal) {
switch (information.ssi_signo) {
case F_signal_abort:
case F_signal_broken_pipe:
case F_signal_interrupt:
case F_signal_quit:
case F_signal_termination:
- iki_write_print_signal_received(main, information.ssi_signo);
+ iki_write_print_signal_received(data, information.ssi_signo);
return information.ssi_signo;
}
#endif
/**
+ * The program data.
+ *
+ * argv: The argument structure in the progam data parameters for simplifying syntax.
+ * main: The main program data.
+ * quote: The quote to use when writing.
+ */
+#ifndef _di_iki_write_data_t_
+ typedef struct {
+ fll_program_data_t *main;
+ f_string_static_t *argv;
+
+ f_string_static_t quote;
+ } iki_write_data_t;
+
+ #define iki_write_data_t_initialize \
+ { \
+ 0, \
+ 0, \
+ f_string_static_t_initialize, \
+ }
+#endif // _di_iki_write_data_t_
+
+/**
* Provide common/generic definitions.
*
* iki_write_common_allocation_*:
#endif // _di_iki_write_common_
/**
+ * Deallocate program data.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * F_none on success.
+ */
+#ifndef _di_iki_write_data_delete_
+ extern void iki_write_data_delete(iki_write_data_t *data) F_attribute_visibility_internal_d;
+#endif // _di_iki_write_data_delete_
+
+/**
* Print a message about a process signal being recieved, such as an interrupt signal.
*
- * @param main
- * The main program data.
+ * @param data
+ * The program data.
* @param signal
* The signal received.
*/
#ifndef _di_iki_write_print_signal_received_
- extern void iki_write_print_signal_received(iki_write_main_t * const main, const f_status_t signal) F_attribute_visibility_internal_d;
+ extern void iki_write_print_signal_received(iki_write_data_t * const data, const f_status_t signal) F_attribute_visibility_internal_d;
#endif // _di_iki_write_print_signal_received_
/**
*
* Only signals that are blocked via main.signal will be received.
*
- * @param main
- * The main program data.
+ * @param data
+ * The program data.
*
* @return
* A positive number representing a valid signal on signal received.
* @see f_signal_read()
*/
#ifndef _di_iki_write_signal_received_
- extern f_status_t iki_write_signal_received(iki_write_main_t * const main) F_attribute_visibility_internal_d;
+ extern f_status_t iki_write_signal_received(iki_write_data_t * const data) F_attribute_visibility_internal_d;
#endif // _di_iki_write_signal_received_
#ifdef __cplusplus
#endif
#ifndef _di_iki_write_process_
- f_status_t iki_write_process(iki_write_main_t * const main, const f_file_t output, const f_string_static_t object, const f_string_static_t content, f_string_dynamic_t *escaped) {
+ f_status_t iki_write_process(iki_write_data_t * const data, const f_file_t output, const f_string_static_t object, const f_string_static_t content, f_string_dynamic_t *escaped) {
if (!object.used) {
- if (main->error.verbosity != f_console_verbosity_quiet_e) {
- flockfile(main->error.to.stream);
+ if (data->main->error.verbosity != f_console_verbosity_quiet_e) {
+ flockfile(data->main->error.to.stream);
- fl_print_format("%r%[%QThe object is missing, it must not have a length of %]", main->error.to.stream, f_string_eol_s, main->error.context, main->error.prefix, main->error.context);
- fl_print_format("%[0%]", main->error.to.stream, main->error.notable, main->error.notable);
- fl_print_format("%[.%]%r", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s);
+ fl_print_format("%r%[%QThe object is missing, it must not have a length of %]", data->main->error.to.stream, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context);
+ fl_print_format("%[0%]", data->main->error.to.stream, data->main->error.notable, data->main->error.notable);
+ fl_print_format("%[.%]%r", data->main->error.to.stream, data->main->error.context, data->main->error.context, f_string_eol_s);
- funlockfile(main->error.to.stream);
+ funlockfile(data->main->error.to.stream);
}
return F_status_set_error(F_failure);
f_status_t status = f_iki_object_is(object);
if (status == F_false) {
- if (main->error.verbosity != f_console_verbosity_quiet_e) {
- flockfile(main->error.to.stream);
+ if (data->main->error.verbosity != f_console_verbosity_quiet_e) {
+ flockfile(data->main->error.to.stream);
- fl_print_format("%r%[%QThe object '%]", main->error.to.stream, f_string_eol_s, main->error.context, main->error.prefix, main->error.context);
- fl_print_format("%[%Q%]", main->error.to.stream, main->error.notable, object, main->error.notable);
- fl_print_format("%[' is not a valid IKI object.%]%r", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s);
+ fl_print_format("%r%[%QThe object '%]", data->main->error.to.stream, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context);
+ fl_print_format("%[%Q%]", data->main->error.to.stream, data->main->error.notable, object, data->main->error.notable);
+ fl_print_format("%[' is not a valid IKI object.%]%r", data->main->error.to.stream, data->main->error.context, data->main->error.context, f_string_eol_s);
- funlockfile(main->error.to.stream);
+ funlockfile(data->main->error.to.stream);
}
return F_status_set_error(F_failure);
}
else if (F_status_is_error(status)) {
- fll_error_print(main->error, F_status_set_fine(status), "f_iki_object_is", F_true);
+ fll_error_print(data->main->error, F_status_set_fine(status), "f_iki_object_is", F_true);
return F_status_set_error(F_failure);
}
escaped->used = 0;
- status = fll_iki_content_escape(content, main->quote, escaped);
+ status = fll_iki_content_escape(content, data->quote, escaped);
if (F_status_is_error(status)) {
- fll_error_print(main->error, F_status_set_fine(status), "fll_iki_content_escape", F_true);
+ fll_error_print(data->main->error, F_status_set_fine(status), "fll_iki_content_escape", F_true);
return F_status_set_error(F_failure);
}
- fl_print_format("%Q%r%r%Q%r", output.stream, object, f_iki_syntax_separator_s, main->quote, *escaped, main->quote);
+ fl_print_format("%Q%r%r%Q%r", output.stream, object, f_iki_syntax_separator_s, data->quote, *escaped, data->quote);
return F_none;
}
/**
* Process a given object and content, printing the IKI if valid or an error if invalid.
*
- * @param main
- * The main program data.
+ * @param data
+ * The program data.
* @param output
* The file to output to.
* @param object
* F_failure (with error bit) for any othe failure.
*/
#ifndef _di_iki_write_process_
- extern f_status_t iki_write_process(iki_write_main_t * const main, const f_file_t output, const f_string_static_t object, const f_string_static_t content, f_string_dynamic_t *escaped) F_attribute_visibility_internal_d;
+ extern f_status_t iki_write_process(iki_write_data_t * const data, const f_file_t output, const f_string_static_t object, const f_string_static_t content, f_string_dynamic_t *escaped) F_attribute_visibility_internal_d;
#endif // _di_iki_write_process_
#ifdef __cplusplus