From 7cccd01fe2f56a4e1805ab7b1cb3a4ee1f852b21 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 17 Feb 2018 20:56:22 -0800 Subject: rototiller: rudimentary argv parsing scaffolding Nothing wired up yet. --- src/rototiller.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/rototiller.c b/src/rototiller.c index fb54694..9362d19 100644 --- a/src/rototiller.c +++ b/src/rototiller.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -83,6 +84,48 @@ static void module_render_page(rototiller_module_t *module, void *context, threa } +typedef struct argv_t { + const char *module; + const char *video; + + unsigned defaults:1; + unsigned help:1; +} argv_t; + +/* + * ./rototiller --video=drm,dev=/dev/dri/card3,connector=VGA-1,mode=640x480@60 + * ./rototiller --video=sdl,size=640x480 + * ./rototiller --module=roto,foo=bar,module=settings + * ./rototiller --defaults + */ +int parse_argv(int argc, const char *argv[], argv_t *res_args) +{ + int i; + + assert(argc > 0); + assert(argv); + assert(res_args); + + /* this is intentionally being kept very simple, no new dependencies like getopt. */ + + for (i = 1; i < argc; i++) { + if (!strncmp("--video=", argv[i], 8)) { + res_args->video = &argv[i][8]; + } else if (!strncmp("--module=", argv[i], 9)) { + res_args->module = &argv[i][9]; + } else if (!strcmp("--defaults", argv[i])) { + res_args->defaults = 1; + } else if (!strcmp("--help", argv[i])) { + res_args->help = 1; + } else { + return -EINVAL; + } + } + + return 0; +} + + int main(int argc, const char *argv[]) { int drm_fd; -- cgit v1.2.3