summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-08 08:36:27 +0100
committerStef Walter <stefw@gnome.org>2013-03-08 21:38:54 +0100
commitb96095115a17818d3e6107e10bad0fef757611d7 (patch)
tree8eddefacb5cde7ca00ce610bbbdabb8ff1fc0eaf /tools
parent2ce1b21109c90b7dab240806686829e498875d74 (diff)
tools: Parse global options appropriately, even if after command
Diffstat (limited to 'tools')
-rw-r--r--tools/tool.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/tools/tool.c b/tools/tool.c
index b736dd2..269fc06 100644
--- a/tools/tool.c
+++ b/tools/tool.c
@@ -241,22 +241,24 @@ main (int argc, char *argv[])
for (in = 1, out = 1; in < argc; in++, out++) {
- /* Already seen the command, keep the arguments */
- if (command) {
- skip = false;
-
/* The non-option is the command, take it out of the arguments */
- } else if (argv[in][0] != '-') {
- skip = true;
- command = argv[in];
+ if (argv[in][0] != '-') {
+ if (!command) {
+ skip = true;
+ command = argv[in];
+ }
/* The global long options */
} else if (argv[in][1] == '-') {
skip = false;
if (strcmp (argv[in], "--") == 0) {
- p11_message ("no command specified");
- return 2;
+ if (!command) {
+ p11_message ("no command specified");
+ return 2;
+ } else {
+ break;
+ }
} else if (strcmp (argv[in], "--verbose") == 0) {
verbose_arg ();
@@ -268,8 +270,8 @@ main (int argc, char *argv[])
command_usage ();
return 0;
- } else {
- p11_message ("unknown option: %s", argv[in]);
+ } else if (!command) {
+ p11_message ("unknown global option: %s", argv[in]);
return 2;
}
@@ -297,8 +299,11 @@ main (int argc, char *argv[])
break;
default:
- p11_message ("unknown option: -%c", (int)argv[in][i]);
- return 2;
+ if (!command) {
+ p11_message ("unknown global option: -%c", (int)argv[in][i]);
+ return 2;
+ }
+ break;
}
}
}