diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-03-18 11:47:50 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2019-03-18 12:16:24 +0100 |
commit | f657716f5207807f79ceee8fff089327be7ba540 (patch) | |
tree | ec68bbb65063818317f7b3047d3c0f7f12681ee6 /fastos/src | |
parent | e52b3ab39a5ae05fc1b1d538b6efa852f321a2f2 (diff) |
Stop setting optind before calling getopt() or getopt_long().
Diffstat (limited to 'fastos/src')
-rw-r--r-- | fastos/src/vespa/fastos/app.h | 31 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_app.cpp | 10 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_app.h | 31 |
3 files changed, 37 insertions, 35 deletions
diff --git a/fastos/src/vespa/fastos/app.h b/fastos/src/vespa/fastos/app.h index 9560d1ced6a..01938f93d35 100644 --- a/fastos/src/vespa/fastos/app.h +++ b/fastos/src/vespa/fastos/app.h @@ -197,37 +197,6 @@ public: virtual void Cleanup (); /** - * Parse program arguments. @ref GetOpt() incrementally parses the - * command line argument list and returns the next known option - * character. An option character is known if it has been - * specified in the string of accepted option characters, - * [optionsString]. - * - * The option string [optionsString] may contain the following - * elements: individual characters, and characters followed by a - * colon to indicate an option argument is to follow. For example, - * an option string "x" recognizes an option ``-x'', and an option - * string "x:" recognizes an option and argument ``-x argument''. - * It does not matter to @ref GetOpt() if a following argument has - * leading white space. - * - * @ref GetOpt() returns -1 when the argument list is exhausted, or - * `?' if a non-recognized option is encountered. The - * interpretation of options in the argument list may be canceled - * by the option `--' (double dash) which causes getopt() to signal - * the end of argument processing and return -1. When all options - * have been processed (i.e., up to the first non-option argument), - * getopt() returns -1. - * - * @ref GetOpt() should only be run by a single thread at the same - * time. In order to evaluate the argument list multiple times, the - * previous GetOpt loop must be finished (-1 returned). - */ - char GetOpt (const char *optionsString, - const char* &optionArgument, - int &optionIndex); - - /** * This method is invoked each time an IPC message is received. * The default implementation discards the message. Subclass this * method to process the data. You should assume that any diff --git a/fastos/src/vespa/fastos/unix_app.cpp b/fastos/src/vespa/fastos/unix_app.cpp index c60035aa5ab..d20b5b424b7 100644 --- a/fastos/src/vespa/fastos/unix_app.cpp +++ b/fastos/src/vespa/fastos/unix_app.cpp @@ -41,8 +41,6 @@ FastOS_UNIX_Application::GetOpt (const char *optionsString, const char* &optionArgument, int &optionIndex) { - optind = optionIndex; - int rc = getopt(_argc, _argv, optionsString); optionArgument = optarg; optionIndex = optind; @@ -56,8 +54,6 @@ FastOS_UNIX_Application::GetOptLong(const char *optionsString, const struct option *longopts, int *longindex) { - optind = optionIndex; - int rc = getopt_long(_argc, _argv, optionsString, longopts, longindex); @@ -67,6 +63,12 @@ FastOS_UNIX_Application::GetOptLong(const char *optionsString, return rc; } +void +FastOS_UNIX_Application::resetOptIndex(int optionIndex) +{ + optind = optionIndex; +} + bool FastOS_UNIX_Application:: SendIPCMessage (FastOS_UNIX_Process *xproc, const void *buffer, int length) diff --git a/fastos/src/vespa/fastos/unix_app.h b/fastos/src/vespa/fastos/unix_app.h index 49a5950c433..ef48a7785d2 100644 --- a/fastos/src/vespa/fastos/unix_app.h +++ b/fastos/src/vespa/fastos/unix_app.h @@ -34,10 +34,41 @@ public: FastOS_UNIX_Application (); virtual ~FastOS_UNIX_Application(); + /** + * Parse program arguments. @ref GetOpt() incrementally parses the + * command line argument list and returns the next known option + * character. An option character is known if it has been + * specified in the string of accepted option characters, + * [optionsString]. + * + * The option string [optionsString] may contain the following + * elements: individual characters, and characters followed by a + * colon to indicate an option argument is to follow. For example, + * an option string "x" recognizes an option ``-x'', and an option + * string "x:" recognizes an option and argument ``-x argument''. + * It does not matter to @ref GetOpt() if a following argument has + * leading white space. + * + * @ref GetOpt() returns -1 when the argument list is exhausted, or + * `?' if a non-recognized option is encountered. The + * interpretation of options in the argument list may be canceled + * by the option `--' (double dash) which causes getopt() to signal + * the end of argument processing and return -1. When all options + * have been processed (i.e., up to the first non-option argument), + * getopt() returns -1. + * + * @ref GetOpt() should only be run by a single thread at the same + * time. In order to evaluate the argument list multiple times, the + * previous GetOpt loop must be finished (-1 returned). + */ int GetOpt (const char *optionsString, const char* &optionArgument, int &optionIndex); int GetOptLong(const char *optionsString, const char* &optionArgument, int &optionIndex, const struct option *longopts, int *longindex); + /** + * Called before calling GetOpt() or GetOptLong() by sub-applications. + */ + void resetOptIndex(int OptionIndex); static unsigned int GetCurrentProcessId (); |