Skip to content

Commit

Permalink
small fix on the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
likle committed Jan 7, 2024
1 parent 5205349 commit ffc56bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ All the documentation is available in the
## Example

```c
#include <cargs.h>
#include <stdbool.h>
#include <stdlib.h>

/**
* This is the main configuration of all options available.
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions demo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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]);
}

Expand Down
3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffc56bc

Please sign in to comment.