2020-12-05 17:58:34 -05:00
|
|
|
#include <kernaux/cmdline.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-01-21 16:42:54 -05:00
|
|
|
#define ARGV_COUNT_MAX 100
|
|
|
|
#define BUFFER_SIZE 4096
|
2020-12-05 17:58:34 -05:00
|
|
|
|
2021-12-12 10:39:17 -05:00
|
|
|
static const char *const cmdline = "foo bar\\ baz \"car cdr\"";
|
2020-12-05 17:58:34 -05:00
|
|
|
|
2022-06-16 13:35:09 -04:00
|
|
|
void example_main()
|
2020-12-05 17:58:34 -05:00
|
|
|
{
|
|
|
|
char error_msg[KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX];
|
2021-12-16 10:26:16 -05:00
|
|
|
size_t argc;
|
2020-12-05 17:58:34 -05:00
|
|
|
char *argv[ARGV_COUNT_MAX];
|
2022-01-21 16:42:54 -05:00
|
|
|
char buffer[BUFFER_SIZE];
|
2020-12-05 17:58:34 -05:00
|
|
|
|
2022-01-21 16:13:54 -05:00
|
|
|
assert(kernaux_cmdline(
|
2020-12-05 17:58:34 -05:00
|
|
|
cmdline,
|
|
|
|
error_msg,
|
|
|
|
&argc,
|
|
|
|
argv,
|
|
|
|
buffer,
|
|
|
|
ARGV_COUNT_MAX,
|
2022-01-21 16:42:54 -05:00
|
|
|
BUFFER_SIZE
|
2020-12-05 17:58:34 -05:00
|
|
|
));
|
|
|
|
|
|
|
|
assert(strcmp(error_msg, "") == 0);
|
2021-12-12 10:39:17 -05:00
|
|
|
assert(argc == 3);
|
2020-12-05 17:58:34 -05:00
|
|
|
assert(strcmp(argv[0], "foo") == 0);
|
2021-12-12 10:39:17 -05:00
|
|
|
assert(strcmp(argv[1], "bar baz") == 0);
|
|
|
|
assert(strcmp(argv[2], "car cdr") == 0);
|
2020-12-05 17:58:34 -05:00
|
|
|
}
|