summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 28b1449fe88dae7b11f98400ccdcb0f28bc85f08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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;
}