From a3942b3241189a003414874a96732e373e63ccae Mon Sep 17 00:00:00 2001 From: Clecio Jung Date: Sat, 18 Mar 2023 18:02:41 -0300 Subject: Initial commit --- examples/ini_file_read.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/ini_file_read.c (limited to 'examples/ini_file_read.c') diff --git a/examples/ini_file_read.c b/examples/ini_file_read.c new file mode 100644 index 0000000..7752f36 --- /dev/null +++ b/examples/ini_file_read.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------------ + * SOURCE + *------------------------------------------------------------------------------ + */ + +#include +#include + +#include "../ini_file.h" + +int error_callback(const char *const filename, const size_t line_number, const char *const line, const enum Ini_File_Errors error) { + fprintf(stderr, "%s:%lu %s:\n%s\n", filename, line_number, ini_file_error_to_string(error), line); + return 0; +} + +/*------------------------------------------------------------------------------ + * MAIN + *------------------------------------------------------------------------------ + */ + +int main(const int argc, const char **const argv) { + struct Ini_File *ini_file; + if (argc < 2) { + fprintf(stderr, "Usage: %s ini_file_name\n", argv[0]); + return EXIT_FAILURE; + } + ini_file = ini_file_parse(argv[1], error_callback); + if (ini_file == NULL) { + fprintf(stderr, "Was not possible to parse the ini_file \"%s\"\n", argv[1]); + return EXIT_FAILURE; + } + printf("\nThe properties retrieved from the the ini file \"%s\" are:\n\n", argv[1]); + ini_file_print_to(ini_file, stdout); + ini_file_free(ini_file); + return EXIT_SUCCESS; +} + +/*------------------------------------------------------------------------------ + * END + *------------------------------------------------------------------------------ + */ -- cgit v1.2.3