linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerzy Kasenberg <jerzy.kasenberg@tieto.com>
To: <linux-bluetooth@vger.kernel.org>
Cc: Jerzy Kasenberg <jerzy.kasenberg@tieto.com>
Subject: [PATCH 4/8] android/client: Add command line arguments
Date: Fri, 8 Nov 2013 13:48:26 +0100	[thread overview]
Message-ID: <1383914910-2304-5-git-send-email-jerzy.kasenberg@tieto.com> (raw)
In-Reply-To: <1383914910-2304-1-git-send-email-jerzy.kasenberg@tieto.com>

This patch adds command line argument parsing.
Options added:
 -h, --help
 -n, --no-init - disable initialization of interfaces
     --version
---
 android/client/haltest.c |   68 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 2 deletions(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index 107dfec..7154d27 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <poll.h>
 #include <unistd.h>
+#include <getopt.h>
 
 #include "if-main.h"
 #include "terminal.h"
@@ -222,7 +223,7 @@ const char *interface_name(void *v, int i)
 /* Function to enumerate command and interface names */
 const char *command_name(void *v, int i)
 {
-	int cmd_cnt = (int) (sizeof(commands)/sizeof(commands[0]) - 1);
+	int cmd_cnt = NELEM(commands);
 
 	if (i >= cmd_cnt)
 		return interface_name(v, i - cmd_cnt);
@@ -318,6 +319,65 @@ static void stdin_handler(struct pollfd *pollfd)
 	}
 }
 
+static void usage(void)
+{
+	printf("haltest Android Bluetooth HAL testing tool\n"
+		"Usage:\n");
+	printf("\thaltest [options]\n");
+	printf("options:\n"
+		"\t-n, --no-init          Don't call init for interfaces\n"
+		"\t    --version          Print version\n"
+		"\t-h, --help             Show help options\n");
+}
+
+enum {
+	PRINT_VERSION = 1000
+};
+
+int version = 1;
+int revision = 0;
+
+static void print_version(void)
+{
+	printf("haltest version %d.%d\n", version, revision);
+}
+
+static const struct option main_options[] = {
+	{ "no-init", no_argument, NULL, 'n' },
+	{ "help",    no_argument, NULL, 'h' },
+	{ "version", no_argument, NULL, PRINT_VERSION },
+	{ NULL }
+};
+
+static bool no_init = false;
+
+static void parse_command_line(int argc, char *argv[])
+{
+	for (;;) {
+		int opt;
+
+		opt = getopt_long(argc, argv, "nh", main_options, NULL);
+		if (opt < 0)
+			break;
+
+		switch (opt) {
+		case 'n':
+			no_init = true;
+			break;
+		case 'h':
+			usage();
+			exit(0);
+		case PRINT_VERSION:
+			print_version();
+			exit(0);
+		default:
+			putchar('\n');
+			exit(-1);
+			break;
+		}
+	}
+}
+
 static void init(void)
 {
 	static const char * const inames[] = {
@@ -356,8 +416,12 @@ int main(int argc, char **argv)
 {
 	struct stat rcstat;
 
+	parse_command_line(argc, argv);
+
 	terminal_setup();
-	init();
+
+	if (!no_init)
+		init();
 
 	history_restore(".haltest_history");
 
-- 
1.7.9.5


  parent reply	other threads:[~2013-11-08 12:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08 12:48 [PATCH 0/8] Improve user experience Jerzy Kasenberg
2013-11-08 12:48 ` [PATCH 1/8] android/client: Export get_interface_method Jerzy Kasenberg
2013-11-08 12:48 ` [PATCH 2/8] android/client: Add NELEM macro for count elements Jerzy Kasenberg
2013-11-08 12:48 ` [PATCH 3/8] android/client: Initialize all interfaces at start Jerzy Kasenberg
2013-11-08 12:48 ` Jerzy Kasenberg [this message]
2013-11-08 12:48 ` [PATCH 5/8] android/client: Split terminal_process_char Jerzy Kasenberg
2013-11-08 12:48 ` [PATCH 6/8] android/client: Add prompting for answer Jerzy Kasenberg
2013-11-08 12:48 ` [PATCH 7/8] android/client: Add pin handling for bind Jerzy Kasenberg
2013-11-08 12:48 ` [PATCH 8/8] android/client: Add ssp key confirmation helper Jerzy Kasenberg
2013-11-08 13:16 ` [PATCH 0/8] Improve user experience Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383914910-2304-5-git-send-email-jerzy.kasenberg@tieto.com \
    --to=jerzy.kasenberg@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).