[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Use optind to find the first non-option argument.
From: |
Christopher Brannon |
Subject: |
[PATCH] Use optind to find the first non-option argument. |
Date: |
Thu, 10 Jun 2010 11:26:43 -0500 |
This allows us to accept commands like
spd-say -r 100 -- '-foo'
---
src/c/clients/say/say.c | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/c/clients/say/say.c b/src/c/clients/say/say.c
index 696b0e8..a815a69 100644
--- a/src/c/clients/say/say.c
+++ b/src/c/clients/say/say.c
@@ -28,6 +28,7 @@
#include <assert.h>
#include <semaphore.h>
#include <errno.h>
+#include <getopt.h>
#include "libspeechd.h"
#include "options.h"
@@ -47,6 +48,7 @@ int main(int argc, char **argv) {
SPDConnection *conn;
SPDPriority spd_priority;
int err;
+ int msg_arg_required = 0;
int ret;
int option_ret;
char *line;
@@ -70,7 +72,9 @@ int main(int argc, char **argv) {
option_ret = options_parse(argc, argv);
/* Check if the text to say or options are specified in the argument */
- if ((argc < 2) && (pipe_mode != 1)) {
+ msg_arg_required = (pipe_mode != 1) && (stop_previous != 1)
+ && (cancel_previous != 1);
+ if ((optind >= argc) && msg_arg_required) {
options_print_help(argv);
return 1;
}
@@ -218,16 +222,14 @@ int main(int argc, char **argv) {
} else {
/* Say the message with priority "text" */
- assert(argv[argc-1]);
- if (argv[argc-1][0] != '-'){
- err = spd_sayf(conn, spd_priority, (char*) argv[argc-1]);
+ /* Or do nothing in case of -C or -S with no message. */
+ if (optind < argc) {
+ err = spd_sayf(conn, spd_priority, (char*) argv[optind]);
if (err == -1) FATAL("Speech Dispatcher failed to say message");
- } else{
- wait_till_end = 0;
- }
- /* Wait till the callback is called */
- if (wait_till_end) sem_wait(&semaphore);
+ /* Wait till the callback is called */
+ if (wait_till_end) sem_wait(&semaphore);
+ }
}
/* Close the connection */
--
1.7.1