From a98b46299c906e7abcd7e43897565102e6e9ba14 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 30 Mar 2012 11:24:20 -0500 Subject: [PATCH] Update: add fll fss object and content write support This adds the functions that allow for writing fss objects and contents. --- level_2/fll_fss/c/fss_basic.c | 44 ++++++++++++++++++++++++++++++++++++++ level_2/fll_fss/c/fss_basic.h | 5 +++++ level_2/fll_fss/c/fss_basic_list.c | 44 ++++++++++++++++++++++++++++++++++++++ level_2/fll_fss/c/fss_basic_list.h | 5 +++++ level_2/fll_fss/c/fss_extended.c | 41 +++++++++++++++++++++++++++++++++++ level_2/fll_fss/c/fss_extended.h | 5 +++++ 6 files changed, 144 insertions(+) diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index 4cc2d52..38adae2 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -118,6 +118,50 @@ extern "C"{ } #endif // _di_fll_fss_basic_read_ +#ifndef _di_fll_fss_basic_write_ + f_return_status fll_fss_basic_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { + #ifndef _di_level_2_parameter_checking_ + if (buffer == f_null) return f_invalid_parameter; + if (contents.used > contents.size) return f_invalid_parameter; + #endif // _di_level_2_parameter_checking_ + + f_status status = 0; + f_array_length current = 0; + f_string_location location = f_string_location_initialize; + + location.start = 0; + location.stop = object.used - 1; + + status = fl_fss_basic_object_write(object, &location, buffer); + + if (f_macro_test_for_no_data_errors(status)) { + return status; + } + + if (f_macro_test_for_none_errors(status)) { + if (contents.used > 0) { + location.start = 0; + location.stop = contents.array[0].used - 1; + status = fl_fss_basic_content_write(contents.array[0], &location, buffer); + + if (f_macro_test_for_no_data_errors(status)) { + return status; + } + } else { + if (buffer->used >= buffer->size) { + f_resize_dynamic_string(status, (*buffer), buffer->size + f_fss_default_allocation_step); + if (f_macro_test_for_allocation_errors(status)) return status; + } + + buffer->string[buffer->used] = f_eol; + buffer->used++; + } + } + + return f_none; + } +#endif // _di_fll_fss_basic_write_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_basic.h b/level_2/fll_fss/c/fss_basic.h index d879655..6924728 100644 --- a/level_2/fll_fss/c/fss_basic.h +++ b/level_2/fll_fss/c/fss_basic.h @@ -32,6 +32,11 @@ extern "C"{ extern f_return_status fll_fss_basic_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_basic_read_ +#ifndef _di_fll_fss_basic_write_ + // write an fss-0000 object and then content + extern f_return_status fll_fss_basic_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer); +#endif // _di_fll_fss_basic_write_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 93c76c4..50688c1 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -118,6 +118,50 @@ extern "C"{ } #endif // _di_fll_fss_basic_list_read_ +#ifndef _di_fll_fss_basic_list_write_ + f_return_status fll_fss_basic_list_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { + #ifndef _di_level_2_parameter_checking_ + if (buffer == f_null) return f_invalid_parameter; + if (contents.used > contents.size) return f_invalid_parameter; + #endif // _di_level_2_parameter_checking_ + + f_status status = 0; + f_array_length current = 0; + f_string_location location = f_string_location_initialize; + + location.start = 0; + location.stop = object.used - 1; + + status = fl_fss_basic_list_object_write(object, &location, buffer); + + if (f_macro_test_for_no_data_errors(status)) { + return status; + } + + if (f_macro_test_for_none_errors(status)) { + if (contents.used > 0) { + location.start = 0; + location.stop = contents.array[0].used - 1; + status = fl_fss_basic_list_content_write(contents.array[0], &location, buffer); + + if (f_macro_test_for_no_data_errors(status)) { + return status; + } + } else { + if (buffer->used >= buffer->size) { + f_resize_dynamic_string(status, (*buffer), buffer->size + f_fss_default_allocation_step); + if (f_macro_test_for_allocation_errors(status)) return status; + } + + buffer->string[buffer->used] = f_eol; + buffer->used++; + } + } + + return f_none; + } +#endif // _di_fll_fss_basic_list_write_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_basic_list.h b/level_2/fll_fss/c/fss_basic_list.h index cfe1fe6..f99ec3d 100644 --- a/level_2/fll_fss/c/fss_basic_list.h +++ b/level_2/fll_fss/c/fss_basic_list.h @@ -32,6 +32,11 @@ extern "C"{ extern f_return_status fll_fss_basic_list_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_basic_list_read_ +#ifndef _di_fll_fss_basic_list_write_ + // write an fss-0000 object and then content + extern f_return_status fll_fss_basic_list_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer); +#endif // _di_fll_fss_basic_list_write_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 7fb209e..8792e0d 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -118,6 +118,47 @@ extern "C"{ } #endif // _di_fll_fss_extended_read_ +#ifndef _di_fll_fss_extended_write_ + f_return_status fll_fss_extended_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { + #ifndef _di_level_2_parameter_checking_ + if (buffer == f_null) return f_invalid_parameter; + if (contents.used > contents.size) return f_invalid_parameter; + #endif // _di_level_2_parameter_checking_ + + f_status status = 0; + f_array_length current = 0; + f_string_location location = f_string_location_initialize; + + location.start = 0; + location.stop = object.used - 1; + + status = fl_fss_extended_object_write(object, &location, buffer); + + if (f_macro_test_for_no_data_errors(status)) { + return status; + } + + if (f_macro_test_for_none_errors(status)) { + while (current < contents.used) { + location.start = 0; + location.stop = contents.array[current].used - 1; + status = fl_fss_extended_content_write(contents.array[current], &location, buffer); + + if (f_macro_test_for_no_data_errors(status)) { + return status; + } + + current++; + } // while + + // extended always ends each call with a space, and so the last position should be replaced with an eol. + buffer->string[buffer->used - 1] = f_eol; + } + + return f_none; + } +#endif // _di_fll_fss_extended_write_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_extended.h b/level_2/fll_fss/c/fss_extended.h index 5ad469a..c97ae7a 100644 --- a/level_2/fll_fss/c/fss_extended.h +++ b/level_2/fll_fss/c/fss_extended.h @@ -32,6 +32,11 @@ extern "C"{ extern f_return_status fll_fss_extended_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_extended_read_ +#ifndef _di_fll_fss_extended_write_ + // write an fss-0000 object and then content + extern f_return_status fll_fss_extended_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer); +#endif // _di_fll_fss_extended_write_ + #ifdef __cplusplus } // extern "C" #endif -- 1.8.3.1