summaryrefslogtreecommitdiff
path: root/main.c
blob: 016ea99a99023dbe763649d093af94b6a6f0fa82 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83


#include <stdbool.h>
#include <stdio.h>
#include <getopt.h>

#include "gui.h"
#include "net.h"


// error code definition
typedef enum error {
	Ok = 0,
	UnknownError = 1,
	WrongArgs = 2,
	GuiError = 3,
} Error;

// configuration struct for all command line options
typedef struct options {
	bool unknown;
	bool help;
} Options;


// prototypes
static void get_opts(Options* opts, int argc, char* argv[]);
static void print_help(void);


int main(int argc, char* argv[]) {

	// parse command line options
	Options opts;
	get_opts(&opts, argc, argv);

	// handle correct use case
	if (opts.unknown || opts.help) {
		print_help();
	} else {
		net_init();
		gui_run();
		net_quit();
	}

}

// parses all command line arguments.
static void get_opts(Options* opts, int argc, char* argv[]) {

	// initialize Options struct
	opts->unknown = false;
	opts->help = false;

	// parse all arguments to Options struct
	int c;
	while ((c=getopt(argc, argv, "h")) != -1) {

		switch (c) {
			case 'h':
				opts->help = true;
				break;
			default:
				opts->unknown = true;
		}

	}

}

// prints out the help page.
static void print_help(void) {

	printf(
		"The Linux on mobile XMPP (LimoX) client.\n"
		"\n"
		"Usage: limox [-h]\n"
		"\n"
		"Options:\n"
		"          -h        print help page\n"
	);

}