Parse commandline strings, move away from old env vars
This commit is contained in:
36
libu/cmdline_parser.h
Normal file
36
libu/cmdline_parser.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _LIBU_CMDLINE_PARSER_H
|
||||
#define _LIBU_CMDLINE_PARSER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define CMDLINE_OPT_NAME_MAX 32
|
||||
#define CMDLINE_OPT_VALUE_MAX 512
|
||||
|
||||
#define CMDLINE_OPT_VALUE_STRING 0
|
||||
#define CMDLINE_OPT_VALUE_BOOL 1
|
||||
#define CMDLINE_OPT_VALUE_INT 2
|
||||
|
||||
struct cmdline_opt {
|
||||
const char* name;
|
||||
const char* altname;
|
||||
int type;
|
||||
bool required;
|
||||
void* valueptr;
|
||||
bool end;
|
||||
bool set;
|
||||
};
|
||||
|
||||
#define CMDLINE_OPT(name1, altname1, type1, required1, valueptr1) \
|
||||
((struct cmdline_opt){.name = (name1), \
|
||||
.altname = (altname1), \
|
||||
.type = (type1), \
|
||||
.required = (required1), \
|
||||
.valueptr = (valueptr1)})
|
||||
|
||||
#define CMDLINE_END() ((struct cmdline_opt){.end = true})
|
||||
|
||||
int cmdline_parse(const char* cmdline, struct cmdline_opt* opt_array);
|
||||
|
||||
#endif // _LIBU_CMDLINE_PARSER_H
|
||||
Reference in New Issue
Block a user