From ba43745c2b8a764088a3bf39485849c0ec64a1ac Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Tue, 8 May 2018 23:56:30 +0300 Subject: server: add an initial GTK UI front-end. --- src/server/main.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/server/main.c') diff --git a/src/server/main.c b/src/server/main.c index e75929c..11f4a59 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -40,11 +40,11 @@ struct settings { unsigned short int port; }; -static int init(int argc, char ***argv, const struct settings * const settings); +static int init(int *argc, char ***argv, const struct settings * const settings); static struct settings parseargs(int argc, char **argv); -static enum uitype identify_ui(const char * const s); +static enum uitype identify_ui(const char * const s, const char * const name); static struct timespec calc_period(const char * const s); -static size_t printhelp(const char * const name); +static size_t printhelp(const char * const name) __attribute__((noreturn)); int main(int argc, char **argv) { @@ -53,7 +53,7 @@ int main(int argc, char **argv) int nd; settings = parseargs(argc, argv); - nd = init(argc, &argv, &settings); + nd = init(&argc, &argv, &settings); if (nd == ERROR) { ret = nd; @@ -66,7 +66,7 @@ fail: return ret; } -static int init(int argc, char ***argv, const struct settings * const settings) +static int init(int *argc, char ***argv, const struct settings * const settings) { int ret = A_OK; int nd; @@ -104,7 +104,7 @@ static struct settings parseargs(int argc, char **argv) if (!(strncmp(argv[i], "--period=", 8))) { ret.period = strlen(argv[i]) > 9 ? calc_period(argv[i] + 9) : (struct timespec) {0, printhelp(*argv)}; } else if (!(strncmp(argv[i], "--ui=", 5))) { - ret.ui = strlen(argv[i]) > 5 ? identify_ui(argv[i] + 5) : printhelp(*argv); + ret.ui = strlen(argv[i]) > 5 ? identify_ui(argv[i] + 5, *argv) : printhelp(*argv); } else if (!(strncmp(argv[i], "--port=", 7))) { ret.port = strlen(argv[i]) > 7 ? strtoul(argv[i] + 7, NULL, 10) : printhelp(*argv); } else { @@ -115,10 +115,28 @@ static struct settings parseargs(int argc, char **argv) return ret; } -static enum uitype identify_ui(const char * const s) +static enum uitype identify_ui(const char * const s, const char * const name) { - /* TODO: stub! */ - return ui_curses; + static const struct uituple { + char *name; + enum uitype type; + } uilist[] = {{"none", ui_none}, {"file", ui_file}, {"curses", ui_curses}, {"gtk", ui_gtk}}; + size_t i; + int found = 0; + enum uitype ret = ui_none; + + for (i = 0; i < arrsize(uilist); ++i) { + if (!strcmp(s, uilist[i].name)) { + found = 1; + ret = uilist[i].type; + } + } + + if (!found) { + printhelp(name); + } + + return ret; } static struct timespec calc_period(const char * const s) -- cgit v1.2.3