diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2012-10-30 18:14:06 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-10-30 18:14:06 -0700 |
commit | 6716e680f4aa5a0901c55be75c1a68e3512bf2e1 (patch) | |
tree | de8ce794b10c662c914ad3d2b064388f5b700b1b /emulator/main.c | |
parent | 9b40e38e726a54199d201cf7ab1e25c99ad6ca83 (diff) | |
download | bluez-6716e680f4aa5a0901c55be75c1a68e3512bf2e1.tar.gz |
emulator: Add version and usage information
Diffstat (limited to 'emulator/main.c')
-rw-r--r-- | emulator/main.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 <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"); |