diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-03-18 13:47:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 13:47:27 +0100 |
commit | 03c439110445b75dd124e55461a6d571f36c9d29 (patch) | |
tree | c9b3c0a731ed359ec9fb1fa3ccb062b1cdccc2fa | |
parent | 44d33e0e892e79867ef7d30e6c5e5042826f498c (diff) | |
parent | f657716f5207807f79ceee8fff089327be7ba540 (diff) |
Merge pull request #8816 from vespa-engine/toregge/stop-setting-optind-before-calling-getopt
Stop setting optind before calling getopt() or getopt_long().
-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 | ||||
-rw-r--r-- | searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp | 2 |
4 files changed, 39 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 (); diff --git a/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp b/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp index 6522d814529..83b55c7c698 100644 --- a/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp +++ b/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp @@ -281,6 +281,7 @@ ShowPostingListSubApp::getOptions() LONGOPT_MINDOCID }; int optIndex = 2; + _app.resetOptIndex(optIndex); while ((c = _app.GetOptLong("di:mv", optArgument, optIndex, @@ -743,6 +744,7 @@ DumpWordsSubApp::getOptions() LONGOPT_WORDNUM }; int optIndex = 2; + _app.resetOptIndex(optIndex); while ((c = _app.GetOptLong("i:", optArgument, optIndex, |