Diff between 9b40e38e726a54199d201cf7ab1e25c99ad6ca83 and 6716e680f4aa5a0901c55be75c1a68e3512bf2e1

Changed Files

File Additions Deletions Status
emulator/main.c +38 -0 modified

Full Patch

diff --git a/emulator/main.c b/emulator/main.c
index 82f7212..84d7cf5 100644
--- a/emulator/main.c
+++ b/emulator/main.c
@@ -27,6 +27,8 @@
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
 
 #include "mainloop.h"
 #include "server.h"
@@ -42,6 +44,21 @@ static void signal_callback(int signum, void *user_data)
 	}
 }
 
+static void usage(void)
+{
+	printf("btvirt - Bluetooth emulator\n"
+		"Usage:\n");
+	printf("\tbtvirt [options]\n");
+	printf("options:\n"
+		"\t-h, --help            Show help options\n");
+}
+
+static const struct option main_options[] = {
+	{ "version", no_argument, NULL, 'v' },
+	{ "help",    no_argument, NULL, 'h' },
+	{ }
+};
+
 int main(int argc, char *argv[])
 {
 	struct vhci *vhci;
@@ -51,12 +68,33 @@ int main(int argc, char *argv[])
 
 	mainloop_init();
 
+	for (;;) {
+		int opt;
+
+		opt = getopt_long(argc, argv, "vh", main_options, NULL);
+		if (opt < 0)
+			break;
+
+		switch (opt) {
+		case 'v':
+			printf("%s\n", VERSION);
+			return EXIT_SUCCESS;
+		case 'h':
+			usage();
+			return EXIT_SUCCESS;
+		default:
+			return EXIT_FAILURE;
+		}
+	}
+
 	sigemptyset(&mask);
 	sigaddset(&mask, SIGINT);
 	sigaddset(&mask, SIGTERM);
 
 	mainloop_set_signal(&mask, signal_callback, NULL, NULL);
 
+	printf("Bluetooth emulator ver %s\n", VERSION);
+
 	vhci = vhci_open(VHCI_TYPE_BREDR);
 	if (!vhci)
 		fprintf(stderr, "Failed to open Virtual HCI device\n");