diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/incorrect.ini | 27 | ||||
| -rw-r--r-- | examples/ini_file_create.c | 6 | ||||
| -rw-r--r-- | examples/ini_file_read.c | 7 | ||||
| -rw-r--r-- | examples/ini_file_search.c | 7 |
4 files changed, 36 insertions, 11 deletions
diff --git a/examples/incorrect.ini b/examples/incorrect.ini index 5f8e285..06c474f 100644 --- a/examples/incorrect.ini +++ b/examples/incorrect.ini @@ -1,18 +1,20 @@ - # Test a comment +# This is the global scope, where properties are sab=ved in a global section + + # A comment # a = 5 -a = 1 - ; Test another type of comment + ; Another type of comment ; b = 3 - b = 2 ; comment c = a+b # comment + b = 2 ; comment +a = 1 [ section 1 ] test=2 beta=96 # We allow for spaces and special characters inside values, but not on keys -erro r = 56 -correct = al bel gam +erro r = 56 ; spaces inside keys are not allowed +correct = al bel gam ; spaces inside values are allowed # Section names can have special characters and spaces [ section 2 ] @@ -25,10 +27,19 @@ a = ; 15 alpha = beta +[repeated] ; Properties inside repeated sections are stored in the same section +asf = 5 +invalid = 2 +invalid = 8 ; Repeated keys are not allowed + [section 3 -[section 4] dfg +; Characters after the end of the declaration of new sections are ignored +[section 4] dfg [numbers] integer = 25 -real = 2.8e-3
\ No newline at end of file +real = 2.8e-3 + +[repeated] ; Properties inside repeated sections are stored in the same section +asd = 2 diff --git a/examples/ini_file_create.c b/examples/ini_file_create.c index e1cfd21..2aeb5a6 100644 --- a/examples/ini_file_create.c +++ b/examples/ini_file_create.c @@ -31,9 +31,9 @@ */ int main(void) { - char filename[MAX_STRING_SIZE], key[MAX_STRING_SIZE], value[MAX_STRING_SIZE]; - /* The first section is global to the file */ - char section[MAX_STRING_SIZE] = "global"; + char filename[MAX_STRING_SIZE]; + char section[MAX_STRING_SIZE]; + char key[MAX_STRING_SIZE], value[MAX_STRING_SIZE]; struct Ini_File *ini_file = ini_file_new(); /* Instruction on how to use this application */ printf("Following, type the requested fields of keys, values and section names.\n"); diff --git a/examples/ini_file_read.c b/examples/ini_file_read.c index b54bebd..2775986 100644 --- a/examples/ini_file_read.c +++ b/examples/ini_file_read.c @@ -5,6 +5,7 @@ #include <stdio.h> #include <stdlib.h> +#include <time.h> #include "../ini_file.h" @@ -20,11 +21,15 @@ int error_callback(const char *const filename, const size_t line_number, const s int main(const int argc, const char **const argv) { struct Ini_File *ini_file; + clock_t start_time, end_time; + double total_time; if (argc < 2) { fprintf(stderr, "Usage: %s ini_file_name\n", argv[0]); return EXIT_FAILURE; } + start_time = clock(); ini_file = ini_file_parse(argv[1], error_callback); + end_time = clock(); if (ini_file == NULL) { fprintf(stderr, "Was not possible to parse the ini_file \"%s\"\n", argv[1]); return EXIT_FAILURE; @@ -33,6 +38,8 @@ int main(const int argc, const char **const argv) { ini_file_print_to(ini_file, stdout); printf("\nCheck out this information of the INI file data structure:\n"); ini_file_info(ini_file); + total_time = 1000.0 * ((double)(end_time - start_time)) / CLOCKS_PER_SEC; + printf("Time needed to parse the INI file: %f ms\n\n", total_time); ini_file_free(ini_file); return EXIT_SUCCESS; } diff --git a/examples/ini_file_search.c b/examples/ini_file_search.c index 43d3ccc..b36a9dc 100644 --- a/examples/ini_file_search.c +++ b/examples/ini_file_search.c @@ -32,6 +32,13 @@ int main(const int argc, const char **const argv) { ini_file_print_to(ini_file, stdout); break; case 3: + /* First, try to find this name as a property in the global section */ + error = ini_file_find_property(ini_file, NULL, argv[2], &value); + if (error == ini_no_error) { + puts(value); + break; + } + /* If it wasn't a property, try to fnd it as a section */ error = ini_file_find_section(ini_file, argv[2], &ini_section); if (error != ini_no_error) { fprintf(stderr, "%s\n", ini_file_error_to_string(error)); |
