summaryrefslogtreecommitdiff
path: root/main.c
blob: 4fc3d1ae00a7fb236540920d882dc2827a2f0451 (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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <getopt.h>

void help(const char *argv0) {
	printf("Usage: %s [options]\n"
			"\nAvailable options:\n"
			"  -h,--help                  this help\n"
			"  -v,--version               show version\n"
			"  -p,--port=client:port      device port\n",
			argv0);
}

int main(int argc, char *argv[]) {
	const char short_options[] = "hvlp";
	const struct option long_options[] = {
		{"help", 0, NULL, 'h'},
		{"version", 0, NULL, 'v'},
		{"list", 0, NULL, 'l'},
		{"port", 1, NULL, 'p'},
		{0},
	};

	int c;
	while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
		switch (c) {
			case 'h':
				help(argv[0]);
				return 0;
			case 'v':
				fprintf(stdout, "Version\n");
				return 0;
			case 'l':
				fprintf(stdout, "List\n");
				return 0;
			case 'p':
				fprintf(stdout, "Port\n");
				return 0;
			default:
				fprintf(stdout, "No option provided\n");
				return 0;
		}
	}

	return 0;
}