summaryrefslogtreecommitdiff
path: root/cethcan/main.c
blob: 938721e5bce687ebff2e85de1d4515e541a75f6a (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
#include "cethcan.h"

struct event_base *ev_base;
json_t *config;

int main(int argc, char **argv)
{
	int optch = 0;
	const char *cfgfile = "cethcan.json";
	json_error_t je;

	do {
		optch = getopt(argc, argv, "c:");
		switch (optch) {
		case 'c':
			cfgfile = optarg;
			break;
		case -1:
			break;
		}
	} while (optch != -1);

	if (optind < argc) {
		fprintf(stderr, "leftover arguments\n");
		return 1;
	}

	config = json_load_file(cfgfile, JSON_REJECT_DUPLICATES, &je);
	if (!config) {
		fprintf(stderr, "failed to load config:\n%s:%d:%d %s\n",
			je.source, je.line, je.column, je.text);
		return 1;
	}
	if (!json_is_object(config)) {
		fprintf(stderr, "config must be object/dictionary\n");
		return 1;
	}

	ev_base = event_base_new();

	can_init();

	event_base_loop(ev_base, 0);
	return 0;
}