2020-12-01 16:05:51 +03:00
|
|
|
#include "sc_option.h"
|
|
|
|
|
|
|
|
static struct sc_option_item options[] = {{.letter = 'm', .name = NULL},
|
2021-04-07 00:28:50 +03:00
|
|
|
{.letter = 'k', .name = "key"},
|
|
|
|
{.letter = 'h', .name = "help"}};
|
2020-12-01 16:05:51 +03:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-04-07 00:28:50 +03:00
|
|
|
char *value;
|
2020-12-01 16:05:51 +03:00
|
|
|
|
2021-04-07 00:28:50 +03:00
|
|
|
struct sc_option opt = {.argv = argv,
|
|
|
|
.count = sizeof(options) / sizeof(options[0]),
|
|
|
|
.options = options};
|
2020-12-01 16:05:51 +03:00
|
|
|
|
2021-04-07 00:28:50 +03:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
char c = sc_option_at(&opt, i, &value);
|
|
|
|
switch (c) {
|
|
|
|
case 'm':
|
|
|
|
// If value does not exist, it will point to '\0'
|
|
|
|
// character.
|
|
|
|
printf("Option 'm', value : %s \n", value);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
printf("Option 'k', value : %s \n", value);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
printf("Option 'h', value : %s \n", value);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
printf("Unknown option : %s \n", argv[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-01 16:05:51 +03:00
|
|
|
|
2021-04-07 00:28:50 +03:00
|
|
|
return 0;
|
2020-12-01 16:05:51 +03:00
|
|
|
}
|