diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2018-02-17 20:56:22 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2018-02-20 13:58:18 -0800 |
commit | 7cccd01fe2f56a4e1805ab7b1cb3a4ee1f852b21 (patch) | |
tree | efc1758e3a4c35f935061deb53d42d68e183c3e0 /src/rototiller.c | |
parent | e223dd74bf9ffd4dee0bcbf5f3cee07643406579 (diff) |
rototiller: rudimentary argv parsing scaffolding
Nothing wired up yet.
Diffstat (limited to 'src/rototiller.c')
-rw-r--r-- | src/rototiller.c | 43 |
1 files changed, 43 insertions, 0 deletions
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 <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -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; |