From ffc56bc8a4c3a18fd9e4660986d4a1055d854250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Ikl=C3=A9?= Date: Sun, 7 Jan 2024 15:34:39 +0100 Subject: [PATCH] small fix on the demo --- README.md | 16 +++++++--------- demo/main.c | 10 +++++----- docs/index.md | 3 +-- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 229fce5..5d1bac6 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,6 @@ All the documentation is available in the ## Example ```c -#include -#include -#include - /** * This is the main configuration of all options available. */ @@ -100,9 +96,9 @@ int main(int argc, char *argv[]) /** * Now we just prepare the context and iterate over all options. Simple! */ - cag_option_prepare(&context, options, CAG_ARRAY_SIZE(options), argc, argv); + cag_option_init(&context, options, CAG_ARRAY_SIZE(options), argc, argv); while (cag_option_fetch(&context)) { - identifier = cag_option_get(&context); + identifier = cag_option_get_identifier(&context); switch (identifier) { case 's': config.simple_flag = true; @@ -123,20 +119,22 @@ int main(int argc, char *argv[]) cag_option_print(options, CAG_ARRAY_SIZE(options), stdout); printf("\nNote that all formatting is done by cargs.\n"); return EXIT_SUCCESS; + case '?': + cag_option_print_error(&context, stdout); + break; } } printf("simple_flag: %i, multiple_flag: %i, long_flag: %i, key: %s\n", config.simple_flag, config.multiple_flag, config.long_flag, config.key ? config.key : "-"); - - for (param_index = context.index; param_index < argc; ++param_index) { + + for (param_index = cag_option_get_index(&context); param_index < argc; ++param_index) { printf("additional parameter: %s\n", argv[param_index]); } return EXIT_SUCCESS; } - ``` ### Example output diff --git a/demo/main.c b/demo/main.c index 9bff5ee..cbfc3c2 100755 --- a/demo/main.c +++ b/demo/main.c @@ -7,10 +7,10 @@ */ static struct cag_option options[] = { {.identifier = 's', - .access_letters = "s", - .access_name = NULL, - .value_name = NULL, - .description = "Simple flag"}, + .access_letters = "s", + .access_name = NULL, + .value_name = NULL, + .description = "Simple flag"}, {.identifier = 'm', .access_letters = "mMoO", @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) config.simple_flag, config.multiple_flag, config.long_flag, config.key ? config.key : "-"); - for (param_index = context.index; param_index < argc; ++param_index) { + for (param_index = cag_option_get_index(&context); param_index < argc; ++param_index) { printf("additional parameter: %s\n", argv[param_index]); } diff --git a/docs/index.md b/docs/index.md index a38d941..cac01d4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -98,13 +98,12 @@ int main(int argc, char *argv[]) config.simple_flag, config.multiple_flag, config.long_flag, config.key ? config.key : "-"); - for (param_index = context.index; param_index < argc; ++param_index) { + for (param_index = cag_option_get_index(&context); param_index < argc; ++param_index) { printf("additional parameter: %s\n", argv[param_index]); } return EXIT_SUCCESS; } - ``` ### Example output