diff options
author | sijanec <anton@sijanec.eu> | 2021-03-17 23:21:37 +0100 |
---|---|---|
committer | sijanec <anton@sijanec.eu> | 2021-03-17 23:21:37 +0100 |
commit | 2a5e31c42603f38e9933e0f0cc1857da618f98c5 (patch) | |
tree | d27a1278eb8a5fa9255ea33c16b7427779f3bf1d /src/main.c | |
parent | končal api, "končal" main, začel ui (diff) | |
download | discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.tar discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.tar.gz discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.tar.bz2 discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.tar.lz discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.tar.xz discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.tar.zst discord.c-2a5e31c42603f38e9933e0f0cc1857da618f98c5.zip |
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 53 |
1 files changed, 33 insertions, 20 deletions
@@ -1,26 +1,31 @@ -#include <ui.h> +#define _XOPEN_SOURCE 600 +#include <stdio.h> +FILE * netreq; +#include <ui.c> int main (int argc, char ** argv) { + curl_global_init(CURL_GLOBAL_ALL); srand(time(NULL)); + netreq = fopen("netreq.log", "w"); int rs = 0; int opt; pthread_t api_thread, ui_thread; - int api_ret ui_ret; + 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; + struct dc_thread_control t = { + .power_api = 0, + .power_ui = 1, /* so we don't start without user interface lol */ + .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; + fprintf(stdout, DC_I18N_USAGE, argv[0]); + rs = 4; + goto rc; break; case 'e': c->email = malloc(strlen(optarg)+1); @@ -33,14 +38,15 @@ int main (int argc, char ** argv) { default: fprintf(stderr, DC_I18N_UNREC_ARG "\n", opt); dc_client_free(c); - return 1; + rs = 1; + goto rc; } } if (!c->email) { if (!getenv("DC_E")) { fprintf(stderr, DC_I18N_MISSING_EP "\n"); - dc_client_free(c); - return 2; + rs = 2; + goto rc; } c->email = malloc(strlen(getenv("DC_E"))+1); strcpy(c->email, getenv("DC_E")); @@ -48,16 +54,23 @@ int main (int argc, char ** argv) { if (!c->password) { if (!getenv("DC_P")) { fprintf(stderr, DC_I18N_MISSING_EP "\n"); - dc_client_free(c); - return 3; + rs = 3; + goto rc; } 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); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" + api_ret = pthread_create(&api_thread, NULL, dc_api_thread, &t); + ui_ret = pthread_create(&ui_thread, NULL, dc_ui_thread, &t); +#pragma GCC diagnostic pop pthread_join(api_thread, NULL); pthread_join(ui_thread, NULL); rc: + fclose(netreq); + dc_client_free(c); + if (api_ret || ui_ret); /* to hide warnings */ + curl_global_cleanup(); return rs; } |