From 1840a7c2ed24c2e4fa731430d36a6c1da597b8ee Mon Sep 17 00:00:00 2001 From: sijanec Date: Tue, 16 Mar 2021 23:38:00 +0100 Subject: =?UTF-8?q?kon=C4=8Dal=20api,=20"kon=C4=8Dal"=20main,=20za=C4=8Del?= =?UTF-8?q?=20ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..28b1449 --- /dev/null +++ b/src/main.c @@ -0,0 +1,63 @@ +#include +int main (int argc, char ** argv) { + srand(time(NULL)); + int rs = 0; + int opt; + pthread_t api_thread, ui_thread; + int api_ret ui_ret; + struct dc_client * c = dc_client_init(); + struct dc_thread_control = { + .power_api = 1; + .power_ui = 1; + .clients = &c; + .clients_sizeof = 1; + .cout = stdout; + .cin = stdin; + .cerr = stderr; + }; + while ((opt = getopt(argc, argv, "e:p:h")) != -1) { + switch (opt) { + case 'h': + fprintf(stdout, DC_I18N_USAGE); + dc_client_free(c); + return 0; + break; + case 'e': + c->email = malloc(strlen(optarg)+1); + strcpy(c->email, optarg); + break; + case 'p': + c->password = malloc(strlen(optarg)+1); + strcpy(c->password, optarg); + break; + default: + fprintf(stderr, DC_I18N_UNREC_ARG "\n", opt); + dc_client_free(c); + return 1; + } + } + if (!c->email) { + if (!getenv("DC_E")) { + fprintf(stderr, DC_I18N_MISSING_EP "\n"); + dc_client_free(c); + return 2; + } + c->email = malloc(strlen(getenv("DC_E"))+1); + strcpy(c->email, getenv("DC_E")); + } + if (!c->password) { + if (!getenv("DC_P")) { + fprintf(stderr, DC_I18N_MISSING_EP "\n"); + dc_client_free(c); + return 3; + } + c->password = malloc(strlen(getenv("DC_P"))+1); + strcpy(c->password, getenv("DC_P")); + } + api_ret = pthread_create(&api_thread NULL, dc_api_thread, dc_thread_control); + ui_ret = pthread_create(&ui_thread, NULL, dc_ui_thread, dc_thread_control); + pthread_join(api_thread, NULL); + pthread_join(ui_thread, NULL); + rc: + return rs; +} -- cgit v1.2.3