Files
cworker/tests/clparser_test.c
2023-08-19 00:40:40 +02:00

52 lines
1.0 KiB
C

/*
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <cllexer.h>
#include <clparser.h>
int main(void) {
//(void)argc;
//(void)argv;
char* argv[] = { "main", "--id=-123", "--name=qwerty12234", "--debug=truew" };
int argc = 4;
cllexer_t lexer;
clparser_t parser;
cllexer_init(&lexer);
clparser_init(&parser, &lexer);
int id = 0;
char* name = "";
bool debug = false;
clparser_bind(&parser, CLVALTYPE_INT, "id", (void *)&id);
clparser_bind(&parser, CLVALTYPE_STR, "name", (void *)&name);
clparser_bind(&parser, CLVALTYPE_BOOL, "debug", (void *)&debug);
if (clparser_parse(&parser, &argv[1], argc - 1) < 0) {
printf("parse args error\n");
return 1;
}
printf("id = %d\n", id);
printf("name = %s\n", name);
printf("debug = %d\n", debug);
clparser_destroy(&parser);
cllexer_destroy(&lexer);
free(name);
return 0;
}