diff options
Diffstat (limited to 'examples/all_functions.c')
-rw-r--r-- | examples/all_functions.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/examples/all_functions.c b/examples/all_functions.c index 843cf03..18cce6f 100644 --- a/examples/all_functions.c +++ b/examples/all_functions.c @@ -63,38 +63,36 @@ int main(void) { // parse value as signed integer int64_t int_val; - const char *bad_val; - if ((bad_val = pom_conf_get_int(conf, "tab-size", &int_val))) { - printf("bad tab size: %s\n", *bad_val ? bad_val : "<missing>"); + if ((error = pom_conf_get_int(conf, "tab-size", &int_val))) { + pom_error_print(error); + free(error); } else { printf("tab size: %" PRId64 "\n", int_val); } // parse value as unsigned integer, use default of 2 uint64_t uint_val; - if ((bad_val = pom_conf_get_uint_or_default(conf, "padding-pixels", &uint_val, 2))) { - printf("bad padding pixels: %s\n", bad_val); + if ((error = pom_conf_get_uint_or_default(conf, "padding-pixels", &uint_val, 2))) { + pom_error_print(error); + free(error); } else { printf("padding pixels: %" PRIu64 "\n", uint_val); } // parse value as double double float_val; - if ((bad_val = pom_conf_get_float_or_default(conf, "font-size", &float_val, 12.0))) { - printf("bad font size: %s\n", bad_val); + if ((error = pom_conf_get_float_or_default(conf, "font-size", &float_val, 12.0))) { + pom_error_print(error); + free(error); } else { printf("font size: %f\n", float_val); } // parse value as boolean bool bool_val; - if ((bad_val = pom_conf_get_bool_or_default(conf, "show-line-numbers", &bool_val, true))) { - // get location where key was defined - const char *file; - uint64_t line; - pom_conf_location(conf, "show-line-numbers", &file, &line); - printf("bad show-line-numbers: %s (defined at %s:%" PRIu64 ")\n", - bad_val, file, line); + if ((error = pom_conf_get_bool_or_default(conf, "show-line-numbers", &bool_val, true))) { + pom_error_print(error); + free(error); } else { printf("show line numbers: %d\n", bool_val); } @@ -120,8 +118,17 @@ int main(void) { const pom_conf *plugin = pom_conf_section(plugins, key); const char *path = pom_conf_get_or_default(plugin, "path", "(none)"); bool enabled; - pom_conf_get_bool_or_default(plugin, "enabled", &enabled, true); - printf("plug-in: %s (path = %s, enabled = %d)\n", key, path, enabled); + if ((error = pom_conf_get_bool_or_default(plugin, "enabled", &enabled, true))) { + pom_error_print(error); + free(error); + // (enabled will still be true in this case) + } + // get location where key was defined + const char *file; + uint64_t line; + pom_conf_location(plugins, key, &file, &line); + printf("%s:%" PRIu64 ": plug-in: %s (path = %s, enabled = %d)\n", + file, line, key, path, enabled); } // load config from string |