summaryrefslogtreecommitdiffstats
path: root/src/server/main.c
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2018-05-08 23:56:30 +0300
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2018-05-08 23:56:30 +0300
commitba43745c2b8a764088a3bf39485849c0ec64a1ac (patch)
treea07edfdc0221c4a7e0e7824c215c9702e5e8f7cd /src/server/main.c
parent92c7163d6c0ddf0ffb958db5528ee35bb0460293 (diff)
downloadcoffeetemp-ba43745c2b8a764088a3bf39485849c0ec64a1ac.tar.gz
coffeetemp-ba43745c2b8a764088a3bf39485849c0ec64a1ac.tar.bz2
coffeetemp-ba43745c2b8a764088a3bf39485849c0ec64a1ac.zip
server: add an initial GTK UI front-end.
Diffstat (limited to 'src/server/main.c')
-rw-r--r--src/server/main.c36
1 files changed, 27 insertions, 9 deletions
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)