1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/examples/cmdline.c

36 lines
767 B
C
Raw Normal View History

#include <kernaux/cmdline.h>
#include <assert.h>
#include <string.h>
2021-12-16 10:26:16 -05:00
static const size_t ARGV_COUNT_MAX = 100;
static const size_t ARG_SIZE_MAX = 4096;
2021-12-12 10:39:17 -05:00
static const char *const cmdline = "foo bar\\ baz \"car cdr\"";
int main()
{
char error_msg[KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX];
2021-12-16 10:26:16 -05:00
size_t argc;
char *argv[ARGV_COUNT_MAX];
char buffer[ARGV_COUNT_MAX * ARG_SIZE_MAX];
assert(kernaux_cmdline_parse(
cmdline,
error_msg,
&argc,
argv,
buffer,
ARGV_COUNT_MAX,
ARG_SIZE_MAX
));
assert(strcmp(error_msg, "") == 0);
2021-12-12 10:39:17 -05:00
assert(argc == 3);
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);
return 0;
}