[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 10:24:45 -0500 |
This allows us to accept commands like
spd-say -r 100 -- '-foo'
---
src/c/clients/say/say.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/c/clients/say/say.c b/src/c/clients/say/say.c
index 696b0e8..fb817cc 100644
--- a/src/c/clients/say/say.c
+++ b/src/c/clients/say/say.c
@@ -47,6 +47,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 +71,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 +221,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
- [PATCH] Use optind to find the first non-option argument.,
Christopher Brannon <=