summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c63
1 files changed, 63 insertions, 0 deletions
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 <ui.h>
+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;
+}