From 6716e680f4aa5a0901c55be75c1a68e3512bf2e1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 30 Oct 2012 18:14:06 -0700 Subject: [PATCH] emulator: Add version and usage information --- emulator/main.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/emulator/main.c b/emulator/main.c index 82f7212d3..84d7cf5da 100644 --- a/emulator/main.c +++ b/emulator/main.c @@ -27,6 +27,8 @@ #endif #include +#include +#include #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"); -- 2.47.3