diff options
author | Håvard Pettersen <havardpe@oath.com> | 2022-03-31 11:44:10 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2022-04-01 10:24:32 +0000 |
commit | d71f76a73fe54558f613e75a3a8cfd70fc46a7e8 (patch) | |
tree | 7d170e5b792dbf5fed06ff7c7b2db398b6cb64c7 | |
parent | 1bb3dd192f4bcb91e710fe19ca54b2b8935ffb83 (diff) |
use getopt/getopt_long directly
28 files changed, 263 insertions, 380 deletions
diff --git a/config/src/apps/vespa-configproxy-cmd/main.cpp b/config/src/apps/vespa-configproxy-cmd/main.cpp index ec5d2167a72..2af645b9351 100644 --- a/config/src/apps/vespa-configproxy-cmd/main.cpp +++ b/config/src/apps/vespa-configproxy-cmd/main.cpp @@ -4,6 +4,7 @@ #include "methods.h" #include <vespa/fastos/app.h> #include <iostream> +#include <unistd.h> class Application : public FastOS_Application { @@ -20,18 +21,16 @@ bool Application::parseOpts() { int c = '?'; - const char *optArg = NULL; - int optInd = 0; - while ((c = GetOpt("m:s:p:h", optArg, optInd)) != -1) { + while ((c = getopt(_argc, _argv, "m:s:p:h")) != -1) { switch (c) { case 'm': - _flags.method = optArg; + _flags.method = optarg; break; case 's': - _flags.targethost = optArg; + _flags.targethost = optarg; break; case 'p': - _flags.portnumber = atoi(optArg); + _flags.portnumber = atoi(optarg); break; case 'h': default: @@ -39,18 +38,18 @@ Application::parseOpts() } } const Method method = methods::find(_flags.method); - if (optInd + method.args <= _argc) { + if (optind + method.args <= _argc) { for (int i = 0; i < method.args; ++i) { - vespalib::string arg = _argv[optInd++]; + vespalib::string arg = _argv[optind++]; _flags.args.push_back(arg); } } else { std::cerr << "ERROR: method "<< _flags.method << " requires " << method.args - << " arguments, only got " << (_argc - optInd) << std::endl; + << " arguments, only got " << (_argc - optind) << std::endl; return false; } - if (optInd != _argc) { - std::cerr << "ERROR: "<<(_argc - optInd)<<" extra arguments\n"; + if (optind != _argc) { + std::cerr << "ERROR: "<<(_argc - optind)<<" extra arguments\n"; return false; } _flags.method = method.rpcMethod; diff --git a/config/src/apps/vespa-get-config/getconfig.cpp b/config/src/apps/vespa-get-config/getconfig.cpp index 5c681d09526..e62521d8db1 100644 --- a/config/src/apps/vespa-get-config/getconfig.cpp +++ b/config/src/apps/vespa-get-config/getconfig.cpp @@ -12,6 +12,7 @@ #include <vespa/config/common/configresponse.h> #include <vespa/config/common/trace.h> #include <vespa/fastos/app.h> +#include <unistd.h> #include <sstream> #include <fstream> @@ -117,24 +118,22 @@ GetConfig::Main() int serverPort = 19090; - const char *optArg = nullptr; - int optInd = 0; - while ((c = GetOpt("a:n:v:g:i:jlm:c:t:V:w:r:s:p:dh", optArg, optInd)) != -1) { + while ((c = getopt(_argc, _argv, "a:n:v:g:i:jlm:c:t:V:w:r:s:p:dh")) != -1) { int retval = 1; switch (c) { case 'a': - schemaString = optArg; + schemaString = optarg; break; case 'n': - defName = optArg; + defName = optarg; break; case 'v': break; case 'g': - generation = atoll(optArg); + generation = atoll(optarg); break; case 'i': - configId = optArg; + configId = optarg; break; case 'j': printAsJson = true; @@ -143,25 +142,25 @@ GetConfig::Main() printAsJson = false; break; case 'm': - defMD5 = optArg; + defMD5 = optarg; break; case 't': - serverTimeout = vespalib::from_s(atof(optArg)); + serverTimeout = vespalib::from_s(atof(optarg)); break; case 'w': - clientTimeout = vespalib::from_s(atof(optArg)); + clientTimeout = vespalib::from_s(atof(optarg)); break; case 'r': - traceLevel = atoi(optArg); + traceLevel = atoi(optarg); break; case 'V': - vespaVersionString = optArg; + vespaVersionString = optarg; break; case 's': - serverHost = optArg; + serverHost = optarg; break; case 'p': - serverPort = atoi(optArg); + serverPort = atoi(optarg); break; case 'd': debugging = true; diff --git a/config/src/apps/vespa-ping-configproxy/pingproxy.cpp b/config/src/apps/vespa-ping-configproxy/pingproxy.cpp index 3d3e3081108..92d07b743f5 100644 --- a/config/src/apps/vespa-ping-configproxy/pingproxy.cpp +++ b/config/src/apps/vespa-ping-configproxy/pingproxy.cpp @@ -4,6 +4,7 @@ #include <vespa/fnet/frt/target.h> #include <vespa/fnet/frt/rpcrequest.h> #include <vespa/fastos/app.h> +#include <unistd.h> #include <sstream> @@ -76,18 +77,16 @@ PingProxy::Main() int clientTimeout = 5; int serverPort = 19090; - const char *optArg = nullptr; - int optInd = 0; - while ((c = GetOpt("w:s:p:dh", optArg, optInd)) != -1) { + while ((c = getopt(_argc, _argv, "w:s:p:dh")) != -1) { switch (c) { case 'w': - clientTimeout = atoi(optArg); + clientTimeout = atoi(optarg); break; case 's': - serverHost = optArg; + serverHost = optarg; break; case 'p': - serverPort = atoi(optArg); + serverPort = atoi(optarg); break; case 'd': debugging = true; diff --git a/configutil/src/apps/configstatus/main.cpp b/configutil/src/apps/configstatus/main.cpp index 3656013cf2e..6233a9d9bb5 100644 --- a/configutil/src/apps/configstatus/main.cpp +++ b/configutil/src/apps/configstatus/main.cpp @@ -6,6 +6,7 @@ #include <vespa/config/subscription/sourcespec.h> #include <vespa/fastos/app.h> #include <iostream> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-config-status"); @@ -34,24 +35,22 @@ Application::~Application() { } int Application::parseOpts() { int c = '?'; - const char *optArg = NULL; - int optInd = 0; - while ((c = GetOpt("c:s:vC:f:", optArg, optInd)) != -1) { + while ((c = getopt(_argc, _argv, "c:s:vC:f:")) != -1) { switch (c) { case 'v': _flags.verbose = true; break; case 'C': - _cfgId = optArg; + _cfgId = optarg; break; case 'c': - _specString = optArg; + _specString = optarg; break; case 'h': usage(); std::_Exit(0); case 'f': - _flags.host_filter = parse_host_set(optArg); + _flags.host_filter = parse_host_set(optarg); break; default: usage(); @@ -61,7 +60,7 @@ int Application::parseOpts() { if (_specString.empty()) { _specString = getSources(); } - return optInd; + return optind; } HostFilter Application::parse_host_set(vespalib::stringref raw_arg) const { diff --git a/configutil/src/apps/modelinspect/main.cpp b/configutil/src/apps/modelinspect/main.cpp index 7053adf17fa..84893ffdf07 100644 --- a/configutil/src/apps/modelinspect/main.cpp +++ b/configutil/src/apps/modelinspect/main.cpp @@ -6,6 +6,7 @@ #include <vespa/config/subscription/sourcespec.h> #include <vespa/fastos/app.h> #include <iostream> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-model-inspect"); @@ -33,9 +34,7 @@ int Application::parseOpts() { int c = '?'; - const char *optArg = NULL; - int optInd = 0; - while ((c = GetOpt("hvut:c:C:", optArg, optInd)) != -1) { + while ((c = getopt(_argc, _argv, "hvut:c:C:")) != -1) { switch (c) { case 'v': _flags.verbose = true; @@ -44,14 +43,14 @@ Application::parseOpts() _flags.makeuri = true; break; case 't': - _flags.tagFilter.push_back(optArg); + _flags.tagFilter.push_back(optarg); _flags.tagfilt = true; break; case 'C': - _cfgId = optArg; + _cfgId = optarg; break; case 'c': - _specString = optArg; + _specString = optarg; break; case 'h': return _argc; @@ -63,7 +62,7 @@ Application::parseOpts() if (_specString.empty()) { _specString = getSources(); } - return optInd; + return optind; } vespalib::string diff --git a/fastos/src/vespa/fastos/unix_app.cpp b/fastos/src/vespa/fastos/unix_app.cpp index 6b1ff743506..733b8806fb5 100644 --- a/fastos/src/vespa/fastos/unix_app.cpp +++ b/fastos/src/vespa/fastos/unix_app.cpp @@ -22,31 +22,6 @@ extern "C" extern char **environ; }; -int -FastOS_UNIX_Application::GetOpt (const char *optionsString, const char* &optionArgument, int &optionIndex) -{ - int rc = getopt(_argc, _argv, optionsString); - optionArgument = optarg; - optionIndex = optind; - return rc; -} - -int -FastOS_UNIX_Application::GetOptLong(const char *optionsString, const char* &optionArgument, int &optionIndex, - const struct option *longopts,int *longindex) -{ - int rc = getopt_long(_argc, _argv, optionsString, longopts, longindex); - optionArgument = optarg; - optionIndex = optind; - return rc; -} - -void -FastOS_UNIX_Application::resetOptIndex(int optionIndex) -{ - optind = optionIndex; -} - bool FastOS_UNIX_Application::PreThreadInit () { bool rc = true; diff --git a/fastos/src/vespa/fastos/unix_app.h b/fastos/src/vespa/fastos/unix_app.h index beb494b4fea..0f11356614e 100644 --- a/fastos/src/vespa/fastos/unix_app.h +++ b/fastos/src/vespa/fastos/unix_app.h @@ -24,43 +24,6 @@ public: FastOS_UNIX_Application(const FastOS_UNIX_Application&) = delete; FastOS_UNIX_Application& operator=(const FastOS_UNIX_Application&) = delete; 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. - */ - static void resetOptIndex(int OptionIndex); - bool Init () override; void Cleanup () override; }; diff --git a/fbench/src/fbench/fbench.cpp b/fbench/src/fbench/fbench.cpp index 0cd9498258e..c69d4f5af18 100644 --- a/fbench/src/fbench/fbench.cpp +++ b/fbench/src/fbench/fbench.cpp @@ -18,6 +18,7 @@ #include <csignal> #include <cinttypes> #include <cstdlib> +#include <unistd.h> namespace { @@ -367,66 +368,63 @@ FBench::Main(int argc, char *argv[]) int printInterval = 0; // parse options and override defaults. - int idx; int opt; - const char *arg; bool optError; - idx = 1; optError = false; - while((opt = GetOpt(argc, argv, "H:A:T:C:K:Da:n:c:l:i:s:q:o:r:m:p:kdxyzP", arg, idx)) != -1) { + while((opt = getopt(argc, argv, "H:A:T:C:K:Da:n:c:l:i:s:q:o:r:m:p:kdxyzP")) != -1) { switch(opt) { case 'A': - authority = arg; + authority = optarg; break; case 'H': - extraHeaders += std::string(arg) + "\r\n"; - if (strncmp(arg, "Host:", 5) == 0) { + extraHeaders += std::string(optarg) + "\r\n"; + if (strncmp(optarg, "Host:", 5) == 0) { fprintf(stderr, "Do not override 'Host:' header, use -A option instead\n"); return -1; } break; case 'T': - ca_certs_file_name = std::string(arg); + ca_certs_file_name = std::string(optarg); break; case 'C': - cert_chain_file_name = std::string(arg); + cert_chain_file_name = std::string(optarg); break; case 'K': - private_key_file_name = std::string(arg); + private_key_file_name = std::string(optarg); break; case 'D': allow_default_tls = true; break; case 'a': - queryStringToAppend = std::string(arg); + queryStringToAppend = std::string(optarg); break; case 'n': - numClients = atoi(arg); + numClients = atoi(optarg); break; case 'c': - cycleTime = atoi(arg); + cycleTime = atoi(optarg); break; case 'l': - byteLimit = atoi(arg); + byteLimit = atoi(optarg); break; case 'i': - ignoreCount = atoi(arg); + ignoreCount = atoi(optarg); break; case 's': - seconds = atoi(arg); + seconds = atoi(optarg); break; case 'q': - queryFilePattern = arg; + queryFilePattern = optarg; break; case 'o': - outputFilePattern = arg; + outputFilePattern = optarg; break; case 'r': - restartLimit = atoi(arg); + restartLimit = atoi(optarg); break; case 'm': - maxLineSize = atoi(arg); + maxLineSize = atoi(optarg); if (maxLineSize < minLineSize) { maxLineSize = minLineSize; } @@ -435,7 +433,7 @@ FBench::Main(int argc, char *argv[]) usePostMode = true; break; case 'p': - printInterval = atoi(arg); + printInterval = atoi(optarg); if (printInterval < 0) optError = true; break; @@ -461,12 +459,12 @@ FBench::Main(int argc, char *argv[]) } } - if ( argc < (idx + 2) || optError) { + if ( argc < (optind + 2) || optError) { Usage(); return -1; } // Hostname/port must be in pair - int args = (argc - idx); + int args = (argc - optind); if (args % 2 != 0) { fprintf(stderr, "Not equal number of hostnames and ports\n"); return -1; @@ -481,10 +479,10 @@ FBench::Main(int argc, char *argv[]) for (int i=0; i<hosts; ++i) { - _hostnames.push_back(std::string(argv[idx+2*i])); - int port = atoi(argv[idx+2*i+1]); + _hostnames.push_back(std::string(argv[optind+2*i])); + int port = atoi(argv[optind+2*i+1]); if (port == 0) { - fprintf(stderr, "Not a valid port:\t%s\n", argv[idx+2*i+1]); + fprintf(stderr, "Not a valid port:\t%s\n", argv[optind+2*i+1]); return -1; } _ports.push_back(port); diff --git a/fbench/src/filterfile/filterfile.cpp b/fbench/src/filterfile/filterfile.cpp index 446a4ae2429..7c2edce3640 100644 --- a/fbench/src/filterfile/filterfile.cpp +++ b/fbench/src/filterfile/filterfile.cpp @@ -3,6 +3,7 @@ #include <iostream> #include <string.h> #include <cassert> +#include <unistd.h> /** * Extract query urls from web logs. The filterfile application reads @@ -20,14 +21,11 @@ main(int argc, char** argv) int bufsize = 10240; // parse options and override defaults. - int optIdx; int opt; - const char *arg; bool optError; - optIdx = 1; optError = false; - while((opt = GetOpt(argc, argv, "ahm:", arg, optIdx)) != -1) { + while((opt = getopt(argc, argv, "ahm:")) != -1) { switch(opt) { case 'a': allowAllParams = true; @@ -36,7 +34,7 @@ main(int argc, char** argv) showUsage = true; break; case 'm': - bufsize = atoi(arg); + bufsize = atoi(optarg); if (bufsize < 10240) { bufsize = 10240; } diff --git a/fbench/src/splitfile/splitfile.cpp b/fbench/src/splitfile/splitfile.cpp index abf42f0e9ba..d3c4fc35b54 100644 --- a/fbench/src/splitfile/splitfile.cpp +++ b/fbench/src/splitfile/splitfile.cpp @@ -3,6 +3,7 @@ #include <fstream> #include <vector> #include <memory> +#include <unistd.h> /** * Split a text file randomly in a number of parts. Process an input @@ -19,20 +20,17 @@ main(int argc, char** argv) int linebufsize = 10240; // parse options and override defaults. - int idx; int opt; - const char *arg; bool optError; - idx = 1; optError = false; - while((opt = GetOpt(argc, argv, "p:m:", arg, idx)) != -1) { + while((opt = getopt(argc, argv, "p:m:")) != -1) { switch(opt) { case 'p': - pattern = arg; + pattern = optarg; break; case 'm': - linebufsize = atoi(arg); + linebufsize = atoi(optarg); if (linebufsize < 10240) { linebufsize = 10240; } @@ -43,7 +41,7 @@ main(int argc, char** argv) } } - if (argc < (idx + 1) || argc > (idx + 2) || optError) { + if (argc < (optind + 1) || argc > (optind + 2) || optError) { printf("usage: vespa-fbench-split-file [-p pattern] [-m maxLineSize] <numparts> [<file>]\n\n"); printf(" -p pattern : output name pattern ['query%%03d.txt']\n"); printf(" -m <num> : max line size for input/output lines.\n"); @@ -57,7 +55,7 @@ main(int argc, char** argv) return -1; } - int outcnt = atoi(argv[idx]); + int outcnt = atoi(argv[optind]); if (outcnt < 1) { printf("too few output files!\n"); return -1; @@ -70,8 +68,8 @@ main(int argc, char** argv) std::unique_ptr<FileReader> input = std::make_unique<FileReader>(); std::vector<std::unique_ptr<std::ostream>> output; - if (argc > (idx + 1)) { - if (!input->Open(argv[idx + 1])) { + if (argc > (optind + 1)) { + if (!input->Open(argv[optind + 1])) { printf("could not open input file!\n"); return -1; } diff --git a/fbench/src/util/filereader.cpp b/fbench/src/util/filereader.cpp index 71c1b5ae703..1b2ce61dfc3 100644 --- a/fbench/src/util/filereader.cpp +++ b/fbench/src/util/filereader.cpp @@ -4,18 +4,6 @@ #include <unistd.h> #include <vespa/vespalib/util/size_literals.h> -int GetOpt (int argc, char *argv[], const char *optionsString, - const char* &optionArgument, - int &optionIndex) -{ - optind = optionIndex; - - int rc = getopt(argc, argv, optionsString); - optionArgument = optarg; - optionIndex = optind; - return rc; -} - FileReader::FileReader() : _backing(), _file(&std::cin), diff --git a/fbench/src/util/filereader.h b/fbench/src/util/filereader.h index 96fae6d2858..0cf8bdae2ea 100644 --- a/fbench/src/util/filereader.h +++ b/fbench/src/util/filereader.h @@ -5,10 +5,6 @@ #include <memory> #include <vector> -int GetOpt (int argc, char *argv[], const char *optionsString, - const char* &optionArgument, - int &optionIndex); - /** * This is a wrapper class for std::ifstream that may be used when * reading line based text files. An internal buffer is used to diff --git a/juniper/src/test/testenv.cpp b/juniper/src/test/testenv.cpp index bd40ae511e3..2dec01ffe3e 100644 --- a/juniper/src/test/testenv.cpp +++ b/juniper/src/test/testenv.cpp @@ -5,7 +5,7 @@ #include "testenv.h" #include <vespa/juniper/propreader.h> - +#include <unistd.h> namespace juniper { @@ -20,16 +20,14 @@ TestEnv::TestEnv(FastOS_Application* app, const char* propfile) : _props(), _config(), _juniper(), _wordFolder() { int c; - const char* oarg = NULL; - int oind = 1; - while ((c = app->GetOpt("d:hcm:", oarg, oind)) != EOF) + while ((c = getopt(app->_argc, app->_argv, "d:hcm:")) != EOF) { switch (c) { case 'd': #ifdef FASTOS_DEBUG - debug_level = strtol(oarg, NULL, 0); + debug_level = strtol(optarg, NULL, 0); #else fprintf(stderr, "This version of Juniper compiled without debug\n"); #endif @@ -49,7 +47,7 @@ TestEnv::TestEnv(FastOS_Application* app, const char* propfile) : int expected_args = 0; - if (app->_argc - oind < expected_args) + if (app->_argc - optind < expected_args) { Usage(app->_argv[0]); return; diff --git a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp index 5fb359e5e9c..9b5956d3910 100644 --- a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp +++ b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp @@ -28,6 +28,7 @@ #include <getopt.h> #include <iostream> #include <thread> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-feed-bm"); @@ -241,7 +242,6 @@ bool App::get_options() { int c; - const char *opt_argument = nullptr; int long_opt_index = 0; static struct option long_opts[] = { { "bucket-db-stripe-bits", 1, nullptr, 0 }, @@ -296,23 +296,22 @@ App::get_options() LONGOPT_USE_MESSAGE_BUS, LONGOPT_USE_STORAGE_CHAIN }; - int opt_index = 1; - resetOptIndex(opt_index); - while ((c = GetOptLong("", opt_argument, opt_index, long_opts, &long_opt_index)) != -1) { + optind = 1; + while ((c = getopt_long(_argc, _argv, "", long_opts, &long_opt_index)) != -1) { switch (c) { case 0: switch(long_opt_index) { case LONGOPT_BUCKET_DB_STRIPE_BITS: - _bm_params.set_bucket_db_stripe_bits(atoi(opt_argument)); + _bm_params.set_bucket_db_stripe_bits(atoi(optarg)); break; case LONGOPT_CLIENT_THREADS: - _bm_params.set_client_threads(atoi(opt_argument)); + _bm_params.set_client_threads(atoi(optarg)); break; case LONGOPT_DISTRIBUTOR_STRIPES: - _bm_params.set_distributor_stripes(atoi(opt_argument)); + _bm_params.set_distributor_stripes(atoi(optarg)); break; case LONGOPT_DOCUMENTS: - _bm_params.set_documents(atoi(opt_argument)); + _bm_params.set_documents(atoi(optarg)); break; case LONGOPT_ENABLE_DISTRIBUTOR: _bm_params.set_enable_distributor(true); @@ -321,40 +320,40 @@ App::get_options() _bm_params.set_enable_service_layer(true); break; case LONGOPT_GET_PASSES: - _bm_params.set_get_passes(atoi(opt_argument)); + _bm_params.set_get_passes(atoi(optarg)); break; case LONGOPT_GROUPS: - _bm_params.set_groups(atoi(opt_argument)); + _bm_params.set_groups(atoi(optarg)); break; case LONGOPT_INDEXING_SEQUENCER: - _bm_params.set_indexing_sequencer(opt_argument); + _bm_params.set_indexing_sequencer(optarg); break; case LONGOPT_MAX_PENDING: - _bm_params.set_max_pending(atoi(opt_argument)); + _bm_params.set_max_pending(atoi(optarg)); break; case LONGOPT_NODES_PER_GROUP: - _bm_params.set_nodes_per_group(atoi(opt_argument)); + _bm_params.set_nodes_per_group(atoi(optarg)); break; case LONGOPT_PUT_PASSES: - _bm_params.set_put_passes(atoi(opt_argument)); + _bm_params.set_put_passes(atoi(optarg)); break; case LONGOPT_UPDATE_PASSES: - _bm_params.set_update_passes(atoi(opt_argument)); + _bm_params.set_update_passes(atoi(optarg)); break; case LONGOPT_REMOVE_PASSES: - _bm_params.set_remove_passes(atoi(opt_argument)); + _bm_params.set_remove_passes(atoi(optarg)); break; case LONGOPT_RESPONSE_THREADS: - _bm_params.set_response_threads(atoi(opt_argument)); + _bm_params.set_response_threads(atoi(optarg)); break; case LONGOPT_RPC_EVENTS_BEFORE_WAKEUP: - _bm_params.set_rpc_events_before_wakeup(atoi(opt_argument)); + _bm_params.set_rpc_events_before_wakeup(atoi(optarg)); break; case LONGOPT_RPC_NETWORK_THREADS: - _bm_params.set_rpc_network_threads(atoi(opt_argument)); + _bm_params.set_rpc_network_threads(atoi(optarg)); break; case LONGOPT_RPC_TARGETS_PER_NODE: - _bm_params.set_rpc_targets_per_node(atoi(opt_argument)); + _bm_params.set_rpc_targets_per_node(atoi(optarg)); break; case LONGOPT_SKIP_COMMUNICATIONMANAGER_THREAD: _bm_params.set_skip_communicationmanager_thread(true); diff --git a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp index 5c20c302b73..669581a85ed 100644 --- a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp +++ b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp @@ -14,6 +14,7 @@ #include <getopt.h> #include <vector> #include <limits> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-gen-testdocs"); @@ -696,7 +697,6 @@ bool GenTestDocsApp::getOptions() { int c; - const char *optArgument = NULL; int longopt_index = 0; static struct option longopts[] = { { "basedir", 1, NULL, 0 }, @@ -729,28 +729,25 @@ GenTestDocsApp::getOptions() LONGOPT_HEADERS, LONGOPT_JSON }; - int optIndex = 2; - _app.resetOptIndex(optIndex); - while ((c = _app.GetOptLong("v", - optArgument, - optIndex, - longopts, - &longopt_index)) != -1) { + optind = 2; + while ((c = getopt_long(_app._argc, _app._argv, "v", + longopts, + &longopt_index)) != -1) { FieldGenerator::SP g; switch (c) { case 0: switch (longopt_index) { case LONGOPT_BASEDIR: - _baseDir = optArgument; + _baseDir = optarg; break; case LONGOPT_CONSTTEXTFIELD: - _fields.emplace_back(std::make_shared<ConstTextFieldGenerator>(splitArg(optArgument))); + _fields.emplace_back(std::make_shared<ConstTextFieldGenerator>(splitArg(optarg))); break; case LONGOPT_PREFIXTEXTFIELD: - _fields.emplace_back(std::make_shared<PrefixTextFieldGenerator>(splitArg(optArgument))); + _fields.emplace_back(std::make_shared<PrefixTextFieldGenerator>(splitArg(optarg))); break; case LONGOPT_RANDTEXTFIELD: - g.reset(new RandTextFieldGenerator(optArgument, + g.reset(new RandTextFieldGenerator(optarg, _rnd, _numWords, 20, @@ -758,33 +755,33 @@ GenTestDocsApp::getOptions() _fields.push_back(g); break; case LONGOPT_MODTEXTFIELD: - g.reset(new ModTextFieldGenerator(optArgument, + g.reset(new ModTextFieldGenerator(optarg, _rnd, _mods)); _fields.push_back(g); break; case LONGOPT_IDTEXTFIELD: - g.reset(new IdTextFieldGenerator(optArgument)); + g.reset(new IdTextFieldGenerator(optarg)); _fields.push_back(g); break; case LONGOPT_RANDINTFIELD: - g.reset(new RandIntFieldGenerator(optArgument, + g.reset(new RandIntFieldGenerator(optarg, _rnd, 0, 100000)); _fields.push_back(g); break; case LONGOPT_DOCIDLIMIT: - _docIdLimit = atoi(optArgument); + _docIdLimit = atoi(optarg); break; case LONGOPT_MINDOCID: - _minDocId = atoi(optArgument); + _minDocId = atoi(optarg); break; case LONGOPT_NUMWORDS: - _numWords = atoi(optArgument); + _numWords = atoi(optarg); break; case LONGOPT_DOCTYPE: - _docType = optArgument; + _docType = optarg; break; case LONGOPT_HEADERS: _headers = true; @@ -793,10 +790,10 @@ GenTestDocsApp::getOptions() _json = true; break; default: - if (optArgument != NULL) { + if (optarg != NULL) { LOG(error, "longopt %s with arg %s", - longopts[longopt_index].name, optArgument); + longopts[longopt_index].name, optarg); } else { LOG(error, "longopt %s", @@ -811,11 +808,11 @@ GenTestDocsApp::getOptions() return false; } } - _optIndex = optIndex; + _optIndex = optind; if (_optIndex >= _app._argc) { return false; } - _outFile = _app._argv[optIndex]; + _outFile = _app._argv[optind]; return true; } diff --git a/searchcore/src/apps/vespa-redistribute-bm/vespa_redistribute_bm.cpp b/searchcore/src/apps/vespa-redistribute-bm/vespa_redistribute_bm.cpp index 33f84f14ae9..f331c3f2511 100644 --- a/searchcore/src/apps/vespa-redistribute-bm/vespa_redistribute_bm.cpp +++ b/searchcore/src/apps/vespa-redistribute-bm/vespa_redistribute_bm.cpp @@ -31,6 +31,7 @@ #include <getopt.h> #include <iostream> #include <thread> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-redistribute-bm"); @@ -499,7 +500,6 @@ bool App::get_options() { int c; - const char *opt_argument = nullptr; int long_opt_index = 0; static struct option long_opts[] = { { "bucket-db-stripe-bits", 1, nullptr, 0 }, @@ -560,89 +560,88 @@ App::get_options() LONGOPT_USE_ASYNC_MESSAGE_HANDLING, LONGOPT_USE_FEED_SETTLE }; - int opt_index = 1; - resetOptIndex(opt_index); - while ((c = GetOptLong("", opt_argument, opt_index, long_opts, &long_opt_index)) != -1) { + optind = 1; + while ((c = getopt_long(_argc, _argv, "", long_opts, &long_opt_index)) != -1) { switch (c) { case 0: switch(long_opt_index) { case LONGOPT_BUCKET_DB_STRIPE_BITS: - _bm_params.set_bucket_db_stripe_bits(atoi(opt_argument)); + _bm_params.set_bucket_db_stripe_bits(atoi(optarg)); break; case LONGOPT_CLIENT_THREADS: - _bm_params.set_client_threads(atoi(opt_argument)); + _bm_params.set_client_threads(atoi(optarg)); break; case LONGOPT_DISTRIBUTOR_MERGE_BUSY_WAIT: - _bm_params.set_distributor_merge_busy_wait(atoi(opt_argument)); + _bm_params.set_distributor_merge_busy_wait(atoi(optarg)); break; case LONGOPT_DISTRIBUTOR_STRIPES: - _bm_params.set_distributor_stripes(atoi(opt_argument)); + _bm_params.set_distributor_stripes(atoi(optarg)); break; case LONGOPT_DOC_STORE_CHUNK_COMPRESSION_LEVEL: - _bm_params.set_doc_store_chunk_compression_level(atoi(opt_argument)); + _bm_params.set_doc_store_chunk_compression_level(atoi(optarg)); break; case LONGOPT_DOC_STORE_CHUNK_MAXBYTES: - _bm_params.set_doc_store_chunk_maxbytes(atoi(opt_argument)); + _bm_params.set_doc_store_chunk_maxbytes(atoi(optarg)); break; case LONGOPT_DOCUMENTS: - _bm_params.set_documents(atoi(opt_argument)); + _bm_params.set_documents(atoi(optarg)); break; case LONGOPT_FLIP_NODES: - _bm_params.set_flip_nodes(atoi(opt_argument)); + _bm_params.set_flip_nodes(atoi(optarg)); break; case LONGOPT_GROUPS: - _bm_params.set_groups(atoi(opt_argument)); + _bm_params.set_groups(atoi(optarg)); break; case LONGOPT_IGNORE_MERGE_QUEUE_LIMIT: _bm_params.set_disable_queue_limits_for_chained_merges(true); break; case LONGOPT_INDEXING_SEQUENCER: - _bm_params.set_indexing_sequencer(opt_argument); + _bm_params.set_indexing_sequencer(optarg); break; case LONGOPT_MAX_MERGES_PER_NODE: - _bm_params.set_max_merges_per_node(atoi(opt_argument)); + _bm_params.set_max_merges_per_node(atoi(optarg)); break; case LONGOPT_MAX_MERGE_QUEUE_SIZE: - _bm_params.set_max_merge_queue_size(atoi(opt_argument)); + _bm_params.set_max_merge_queue_size(atoi(optarg)); break; case LONGOPT_MAX_PENDING: - _bm_params.set_max_pending(atoi(opt_argument)); + _bm_params.set_max_pending(atoi(optarg)); break; case LONGOPT_MAX_PENDING_IDEALSTATE_OPERATIONS: - _bm_params.set_max_pending_idealstate_operations(atoi(opt_argument)); + _bm_params.set_max_pending_idealstate_operations(atoi(optarg)); break; case LONGOPT_MBUS_DISTRIBUTOR_NODE_MAX_PENDING_COUNT: - _bm_params.set_mbus_distributor_node_max_pending_count(atoi(opt_argument)); + _bm_params.set_mbus_distributor_node_max_pending_count(atoi(optarg)); break; case LONGOPT_MODE: - _bm_params.set_mode(get_mode(opt_argument)); + _bm_params.set_mode(get_mode(optarg)); if (_bm_params.get_mode() == Mode::BAD) { - std::cerr << "Unknown mode name " << opt_argument << std::endl; + std::cerr << "Unknown mode name " << optarg << std::endl; } break; case LONGOPT_NODES_PER_GROUP: - _bm_params.set_nodes_per_group(atoi(opt_argument)); + _bm_params.set_nodes_per_group(atoi(optarg)); break; case LONGOPT_REDUNDANCY: - _bm_params.set_redundancy(atoi(opt_argument)); + _bm_params.set_redundancy(atoi(optarg)); break; case LONGOPT_REFEED: - _bm_params.set_refeed_mode(get_refeed_mode(opt_argument)); + _bm_params.set_refeed_mode(get_refeed_mode(optarg)); if (_bm_params.get_refeed_mode() == ReFeedMode::BAD) { - std::cerr << "Unknown refeed-mode name " << opt_argument << std::endl; + std::cerr << "Unknown refeed-mode name " << optarg << std::endl; } break; case LONGOPT_RESPONSE_THREADS: - _bm_params.set_response_threads(atoi(opt_argument)); + _bm_params.set_response_threads(atoi(optarg)); break; case LONGOPT_RPC_EVENTS_BEFORE_WAKEUP: - _bm_params.set_rpc_events_before_wakeup(atoi(opt_argument)); + _bm_params.set_rpc_events_before_wakeup(atoi(optarg)); break; case LONGOPT_RPC_NETWORK_THREADS: - _bm_params.set_rpc_network_threads(atoi(opt_argument)); + _bm_params.set_rpc_network_threads(atoi(optarg)); break; case LONGOPT_RPC_TARGETS_PER_NODE: - _bm_params.set_rpc_targets_per_node(atoi(opt_argument)); + _bm_params.set_rpc_targets_per_node(atoi(optarg)); break; case LONGOPT_SKIP_COMMUNICATIONMANAGER_THREAD: _bm_params.set_skip_communicationmanager_thread(true); diff --git a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp index 2d722a53adf..5cf7528ff1c 100644 --- a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp +++ b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp @@ -9,6 +9,7 @@ #include <vespa/fastlib/io/bufferedfile.h> #include <vespa/fastos/app.h> +#include <unistd.h> namespace search { @@ -112,11 +113,9 @@ LoadAttribute::Main() bool doFastSearch = false; bool doHuge = false; - int idx = 1; int opt; - const char * arg; bool optError = false; - while ((opt = GetOpt("pasf:h", arg, idx)) != -1) { + while ((opt = getopt(_argc, _argv, "pasf:h")) != -1) { switch (opt) { case 'p': doPrintContent = true; @@ -128,11 +127,11 @@ LoadAttribute::Main() doHuge = true; break; case 'f': - if (strcmp(arg, "search") == 0) { + if (strcmp(optarg, "search") == 0) { doFastSearch = true; } else { std::cerr << "Expected 'search' or 'aggregate', got '" << - arg << "'" << std::endl; + optarg << "'" << std::endl; optError = true; } break; @@ -145,12 +144,12 @@ LoadAttribute::Main() } } - if (_argc != (idx + 1) || optError) { + if (_argc != (optind + 1) || optError) { usage(); return -1; } - vespalib::string fileName(_argv[idx]); + vespalib::string fileName(_argv[optind]); vespalib::FileHeader fh; { vespalib::string datFileName(fileName + ".dat"); diff --git a/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp b/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp index bdc841ab235..349064eb2a8 100644 --- a/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp +++ b/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp @@ -6,6 +6,7 @@ #include <iostream> #include <vespa/vespalib/data/fileheader.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-fileheader-inspect"); @@ -58,15 +59,13 @@ int Application::parseOpts() { int c = '?'; - const char *optArg = NULL; - int optInd = 0; - while ((c = GetOpt("d:f:qh", optArg, optInd)) != -1) { + while ((c = getopt(_argc, _argv, "d:f:qh")) != -1) { switch (c) { case 'd': - _delimiter = optArg[0]; + _delimiter = optarg[0]; break; case 'f': - _fileName = optArg; + _fileName = optarg; break; case 'q': _quiet = true; @@ -79,8 +78,8 @@ Application::parseOpts() return EXIT_FAILURE; } } - if (_argc == optInd + 1) { - _fileName = _argv[optInd]; + if (_argc == optind + 1) { + _fileName = _argv[optind]; } if (_fileName.empty()) { std::cerr << "No filename given." << std::endl; 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 25e5a7bd8a3..79d205d7ad6 100644 --- a/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp +++ b/searchlib/src/apps/vespa-index-inspect/vespa-index-inspect.cpp @@ -16,6 +16,7 @@ #include <iostream> #include <getopt.h> #include <cstdlib> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-index-inspect"); @@ -262,7 +263,6 @@ bool ShowPostingListSubApp::getOptions() { int c; - const char *optArgument = NULL; int longopt_index = 0; static struct option longopts[] = { { "indexdir", 1, NULL, 0 }, @@ -279,36 +279,33 @@ ShowPostingListSubApp::getOptions() LONGOPT_DOCIDLIMIT, LONGOPT_MINDOCID }; - int optIndex = 2; - _app.resetOptIndex(optIndex); - while ((c = _app.GetOptLong("di:mv", - optArgument, - optIndex, - longopts, - &longopt_index)) != -1) { + optind = 2; + while ((c = getopt_long(_app._argc, _app._argv, "di:mv", + longopts, + &longopt_index)) != -1) { switch (c) { case 0: switch (longopt_index) { case LONGOPT_INDEXDIR: - _indexDir = optArgument; + _indexDir = optarg; break; case LONGOPT_FIELD: - _fieldOptions.addField(optArgument); + _fieldOptions.addField(optarg); break; case LONGOPT_TRANSPOSE: _transpose = true; break; case LONGOPT_DOCIDLIMIT: - _docIdLimit = atoi(optArgument); + _docIdLimit = atoi(optarg); break; case LONGOPT_MINDOCID: - _minDocId = atoi(optArgument); + _minDocId = atoi(optarg); break; default: - if (optArgument != NULL) { + if (optarg != NULL) { LOG(error, "longopt %s with arg %s", - longopts[longopt_index].name, optArgument); + longopts[longopt_index].name, optarg); } else { LOG(error, "longopt %s", @@ -320,7 +317,7 @@ ShowPostingListSubApp::getOptions() _directio = true; break; case 'i': - _indexDir = optArgument; + _indexDir = optarg; break; case 'm': _readmmap = true; @@ -339,13 +336,13 @@ ShowPostingListSubApp::getOptions() if (_fieldOptions._fields.size() > 1) return false; } - _optIndex = optIndex; + _optIndex = optind; if (_transpose) { } else { if (_optIndex >= _app._argc) { return false; } - _word = _app._argv[optIndex]; + _word = _app._argv[optind]; } return true; } @@ -719,7 +716,6 @@ bool DumpWordsSubApp::getOptions() { int c; - const char *optArgument = NULL; int longopt_index = 0; static struct option longopts[] = { { "indexdir", 1, NULL, 0 }, @@ -736,24 +732,21 @@ DumpWordsSubApp::getOptions() LONGOPT_VERBOSE, LONGOPT_WORDNUM }; - int optIndex = 2; - _app.resetOptIndex(optIndex); - while ((c = _app.GetOptLong("i:", - optArgument, - optIndex, - longopts, - &longopt_index)) != -1) { + optind = 2; + while ((c = getopt_long(_app._argc, _app._argv, "i:", + longopts, + &longopt_index)) != -1) { switch (c) { case 0: switch (longopt_index) { case LONGOPT_INDEXDIR: - _indexDir = optArgument; + _indexDir = optarg; break; case LONGOPT_FIELD: - _fieldOptions.addField(optArgument); + _fieldOptions.addField(optarg); break; case LONGOPT_MINNUMDOCS: - _minNumDocs = atol(optArgument); + _minNumDocs = atol(optarg); break; case LONGOPT_VERBOSE: _verbose = true; @@ -762,10 +755,10 @@ DumpWordsSubApp::getOptions() _showWordNum = true; break; default: - if (optArgument != NULL) { + if (optarg != NULL) { LOG(error, "longopt %s with arg %s", - longopts[longopt_index].name, optArgument); + longopts[longopt_index].name, optarg); } else { LOG(error, "longopt %s", @@ -774,7 +767,7 @@ DumpWordsSubApp::getOptions() } break; case 'i': - _indexDir = optArgument; + _indexDir = optarg; break; default: return false; diff --git a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp index 7d168407328..4a690a28cc8 100644 --- a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp +++ b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp @@ -11,6 +11,7 @@ #include "attributesearcher.h" #include "attributeupdater.h" #include <sys/resource.h> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("attributebenchmark"); @@ -485,62 +486,60 @@ AttributeBenchmark::Main() dc._prefixLength = 2; dc._prefixSearch = false; - int idx = 1; int opt; - const char * arg; bool optError = false; - while ((opt = GetOpt("n:u:v:s:q:p:r:c:l:h:i:a:e:S:E:D:L:bRPtw", arg, idx)) != -1) { + while ((opt = getopt(_argc, _argv, "n:u:v:s:q:p:r:c:l:h:i:a:e:S:E:D:L:bRPtw")) != -1) { switch (opt) { case 'n': - dc._numDocs = atoi(arg); + dc._numDocs = atoi(optarg); break; case 'u': - dc._numUpdates = atoi(arg); + dc._numUpdates = atoi(optarg); break; case 'v': - dc._numValues = atoi(arg); + dc._numValues = atoi(optarg); break; case 's': - dc._numSearchers = atoi(arg); + dc._numSearchers = atoi(optarg); break; case 'q': - dc._numQueries = atoi(arg); + dc._numQueries = atoi(optarg); break; case 'p': - dc._populateRuns = atoi(arg); + dc._populateRuns = atoi(optarg); break; case 'r': - dc._updateRuns = atoi(arg); + dc._updateRuns = atoi(optarg); break; case 'c': - dc._commitFreq = atoi(arg); + dc._commitFreq = atoi(optarg); break; case 'l': - dc._minValueCount = atoi(arg); + dc._minValueCount = atoi(optarg); break; case 'h': - dc._maxValueCount = atoi(arg); + dc._maxValueCount = atoi(optarg); break; case 'i': - dc._minStringLen = atoi(arg); + dc._minStringLen = atoi(optarg); break; case 'a': - dc._maxStringLen = atoi(arg); + dc._maxStringLen = atoi(optarg); break; case 'e': - dc._seed = atoi(arg); + dc._seed = atoi(optarg); break; case 'S': - dc._rangeStart = strtoll(arg, NULL, 10); + dc._rangeStart = strtoll(optarg, NULL, 10); break; case 'E': - dc._rangeEnd = strtoll(arg, NULL, 10); + dc._rangeEnd = strtoll(optarg, NULL, 10); break; case 'D': - dc._rangeDelta = strtoll(arg, NULL, 10); + dc._rangeDelta = strtoll(optarg, NULL, 10); break; case 'L': - dc._prefixLength = atoi(arg); + dc._prefixLength = atoi(optarg); break; case 'b': dc._searchersOnly = false; @@ -563,12 +562,12 @@ AttributeBenchmark::Main() } } - if (_argc != (idx + 1) || optError) { + if (_argc != (optind + 1) || optError) { usage(); return -1; } - dc._attribute = vespalib::string(_argv[idx]); + dc._attribute = vespalib::string(_argv[optind]); _threadPool = new FastOS_ThreadPool(256000); diff --git a/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp b/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp index 52888d0c659..e140814a5ad 100644 --- a/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp +++ b/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp @@ -6,6 +6,7 @@ #include <string> #include <vector> #include <cassert> +#include <unistd.h> LOG_SETUP("bitvectorbenchmark"); @@ -165,19 +166,17 @@ void BitVectorBenchmark::testOrSpeed2() int BitVectorBenchmark::Main() { - int idx = 1; std::string operation; size_t numBits(8*1000000); int opt; - const char * arg; bool optError = false; - while ((opt = GetOpt("n:t:", arg, idx)) != -1) { + while ((opt = getopt(_argc, _argv, "n:t:")) != -1) { switch (opt) { case 'n': - numBits = strtoll(arg, NULL, 10); + numBits = strtoll(optarg, NULL, 10); break; case 't': - operation = arg; + operation = optarg; break; default: optError = true; @@ -185,7 +184,7 @@ int BitVectorBenchmark::Main() } } - if ((_argc != idx ) || optError) { + if ((_argc != optind ) || optError) { usage(); return -1; } diff --git a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp index 35b42223cfc..aa5f9a13e7d 100644 --- a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp +++ b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp @@ -21,6 +21,7 @@ #include <openssl/evp.h> #include <vespa/fastos/file.h> #include <vespa/fastos/app.h> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("fieldwriter_test"); @@ -665,30 +666,27 @@ testFieldWriterVariantsWithHighLids(FakeWordSet &wordSet, uint32_t docIdLimit, int FieldWriterTest::Main() { - int argi; int c; - const char *optArg; if (_argc > 0) { DummyFileHeaderContext::setCreator(_argv[0]); } - argi = 1; - while ((c = GetOpt("c:d:vw:", optArg, argi)) != -1) { + while ((c = getopt(_argc, _argv, "c:d:vw:")) != -1) { switch(c) { case 'c': - _commonDocFreq = atoi(optArg); + _commonDocFreq = atoi(optarg); if (_commonDocFreq == 0) _commonDocFreq = 1; break; case 'd': - _numDocs = atoi(optArg); + _numDocs = atoi(optarg); break; case 'v': _verbose = true; break; case 'w': - _numWordsPerClass = atoi(optArg); + _numWordsPerClass = atoi(optarg); break; default: Usage(); diff --git a/searchlib/src/tests/features/featurebenchmark.cpp b/searchlib/src/tests/features/featurebenchmark.cpp index f4fc830335d..5a70f1752fc 100644 --- a/searchlib/src/tests/features/featurebenchmark.cpp +++ b/searchlib/src/tests/features/featurebenchmark.cpp @@ -17,6 +17,7 @@ #include <iomanip> #include <iostream> #include <string> +#include <unistd.h> using namespace search::features; using namespace search::fef; @@ -596,19 +597,17 @@ Benchmark::Main() setup_fef_test_plugin(_factory); setup_search_features(_factory); - int idx = 1; int opt; - const char * arg; bool optError = false; vespalib::string file; vespalib::string feature; - while ((opt = GetOpt("c:f:", arg, idx)) != -1) { + while ((opt = getopt(_argc, _argv, "c:f:")) != -1) { switch (opt) { case 'c': - file.assign(arg); + file.assign(optarg); break; case 'f': - feature.assign(arg); + feature.assign(optarg); break; default: optError = true; @@ -616,7 +615,7 @@ Benchmark::Main() } } - if (_argc != idx || optError) { + if (_argc != optind || optError) { //usage(); return -1; } diff --git a/searchlib/src/tests/postinglistbm/postinglistbm.cpp b/searchlib/src/tests/postinglistbm/postinglistbm.cpp index 198ff57435a..d0552958611 100644 --- a/searchlib/src/tests/postinglistbm/postinglistbm.cpp +++ b/searchlib/src/tests/postinglistbm/postinglistbm.cpp @@ -12,6 +12,7 @@ #include <vespa/searchlib/test/fakedata/fpfactory.h> #include <vespa/vespalib/util/rand48.h> #include <vespa/vespalib/util/size_literals.h> +#include <unistd.h> #include <vespa/log/log.h> @@ -109,52 +110,49 @@ PostingListBM::~PostingListBM() = default; int PostingListBM::Main() { - int argi; int c; - const char *optArg; - argi = 1; bool hasElements = false; bool hasElementWeights = false; - while ((c = GetOpt("C:c:m:r:d:l:s:t:o:uw:T:q", optArg, argi)) != -1) { + while ((c = getopt(_argc, _argv, "C:c:m:r:d:l:s:t:o:uw:T:q")) != -1) { switch(c) { case 'C': - _skipCommonPairsRate = atoi(optArg); + _skipCommonPairsRate = atoi(optarg); break; case 'T': - if (strcmp(optArg, "single") == 0) { + if (strcmp(optarg, "single") == 0) { hasElements = false; hasElementWeights = false; - } else if (strcmp(optArg, "array") == 0) { + } else if (strcmp(optarg, "array") == 0) { hasElements = true; hasElementWeights = false; - } else if (strcmp(optArg, "weightedSet") == 0) { + } else if (strcmp(optarg, "weightedSet") == 0) { hasElements = true; hasElementWeights = true; } else { - printf("Bad collection type: '%s'\n", optArg); + printf("Bad collection type: '%s'\n", optarg); printf("Supported types: single, array, weightedSet\n"); return 1; } break; case 'c': - _commonDocFreq = atoi(optArg); + _commonDocFreq = atoi(optarg); break; case 'm': - _mediumDocFreq = atoi(optArg); + _mediumDocFreq = atoi(optarg); break; case 'r': - _rareDocFreq = atoi(optArg); + _rareDocFreq = atoi(optarg); break; case 'd': - _numDocs = atoi(optArg); + _numDocs = atoi(optarg); break; case 'l': - _loops = atoi(optArg); + _loops = atoi(optarg); break; case 's': - _stride = atoi(optArg); + _stride = atoi(optarg); break; case 't': do { @@ -163,17 +161,17 @@ PostingListBM::Main() DataType::STRING, CollectionType::SINGLE); schema.addIndexField(indexField); - std::unique_ptr<FPFactory> ff(getFPFactory(optArg, schema)); + std::unique_ptr<FPFactory> ff(getFPFactory(optarg, schema)); if (ff.get() == nullptr) { - badPostingType(optArg); + badPostingType(optarg); return 1; } } while (0); - _postingTypes.push_back(optArg); + _postingTypes.push_back(optarg); break; case 'o': { - vespalib::string operatorType(optArg); + vespalib::string operatorType(optarg); if (operatorType == "direct") { _operatorType = StressRunner::OperatorType::Direct; } else if (operatorType == "and") { @@ -191,7 +189,7 @@ PostingListBM::Main() _unpack = true; break; case 'w': - _numWordsPerClass = atoi(optArg); + _numWordsPerClass = atoi(optarg); break; default: usage(); diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp index de0e1b60ca0..cfd2138f2e8 100644 --- a/searchlib/src/tests/transactionlogstress/translogstress.cpp +++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp @@ -12,6 +12,7 @@ #include <iostream> #include <sstream> #include <thread> +#include <unistd.h> #include <vespa/log/log.h> #include <vespa/vespalib/util/time.h> @@ -642,44 +643,42 @@ TransLogStress::Main() vespalib::duration sleepTime = 4s; - int idx = 1; int opt; - const char * arg; bool optError = false; - while ((opt = GetOpt("d:p:t:f:s:v:c:e:g:i:a:b:h", arg, idx)) != -1) { + while ((opt = getopt(_argc, _argv, "d:p:t:f:s:v:c:e:g:i:a:b:h")) != -1) { switch (opt) { case 'd': - _cfg.domainPartSize = atol(arg); + _cfg.domainPartSize = atol(optarg); break; case 'p': - _cfg.packetSize = atol(arg); + _cfg.packetSize = atol(optarg); break; case 't': - _cfg.stressTime = std::chrono::milliseconds(1000 * atol(arg)); + _cfg.stressTime = std::chrono::milliseconds(1000 * atol(optarg)); break; case 'f': - _cfg.feedRate = atoi(arg); + _cfg.feedRate = atoi(optarg); break; case 'v': - _cfg.numVisitors = atoi(arg); + _cfg.numVisitors = atoi(optarg); break; case 'c': - _cfg.visitorInterval = std::chrono::milliseconds(atol(arg)); + _cfg.visitorInterval = std::chrono::milliseconds(atol(optarg)); break; case 'e': - _cfg.pruneInterval = vespalib::from_s(atol(arg)); + _cfg.pruneInterval = vespalib::from_s(atol(optarg)); break; case 'g': - _cfg.numPreGeneratedBuffers = atoi(arg); + _cfg.numPreGeneratedBuffers = atoi(optarg); break; case 'i': - _cfg.minStrLen = atoi(arg); + _cfg.minStrLen = atoi(optarg); break; case 'a': - _cfg.maxStrLen = atoi(arg); + _cfg.maxStrLen = atoi(optarg); break; case 'b': - _cfg.baseSeed = atol(arg); + _cfg.baseSeed = atol(optarg); break; case 'h': usage(); @@ -693,7 +692,7 @@ TransLogStress::Main() printConfig(); std::this_thread::sleep_for(sleepTime); - if (_argc != idx || optError) { + if (_argc != optind || optError) { usage(); return -1; } diff --git a/slobrok/src/apps/slobrok/slobrok.cpp b/slobrok/src/apps/slobrok/slobrok.cpp index a662c59d979..791b98996fe 100644 --- a/slobrok/src/apps/slobrok/slobrok.cpp +++ b/slobrok/src/apps/slobrok/slobrok.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/exceptions.h> #include <vespa/fastos/app.h> #include <csignal> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("vespa-slobrok"); @@ -51,16 +52,14 @@ App::Main() uint32_t portnum = 2773; vespalib::string cfgId; - int argi = 1; - const char* optArg; int c; - while ((c = GetOpt("c:s:p:N", optArg, argi)) != -1) { + while ((c = getopt(_argc, _argv, "c:s:p:N")) != -1) { switch (c) { case 'c': - cfgId = std::string(optArg); + cfgId = std::string(optarg); break; case 'p': - portnum = atoi(optArg); + portnum = atoi(optarg); break; case 'N': // ignored diff --git a/slobrok/src/tests/startsome/tstdst.cpp b/slobrok/src/tests/startsome/tstdst.cpp index cd38e6cbf97..8e58fc23b27 100644 --- a/slobrok/src/tests/startsome/tstdst.cpp +++ b/slobrok/src/tests/startsome/tstdst.cpp @@ -7,6 +7,7 @@ #include <vespa/fnet/transport.h> #include <vespa/fnet/frt/target.h> #include <sstream> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("testrpcserver"); @@ -187,19 +188,17 @@ public: int myport = 2774; const char *rpcsrvname = "testrpcsrv/17"; - int argi = 1; - const char* optArg; int c; - while ((c = GetOpt("n:p:s:", optArg, argi)) != -1) { + while ((c = getopt(_argc, _argv, "n:p:s:")) != -1) { switch (c) { case 'p': - myport = atoi(optArg); + myport = atoi(optarg); break; case 's': - sbport = atoi(optArg); + sbport = atoi(optarg); break; case 'n': - rpcsrvname = optArg; + rpcsrvname = optarg; break; default: LOG(error, "unknown option letter '%c'", c); diff --git a/vespalib/src/tests/btree/iteratespeed.cpp b/vespalib/src/tests/btree/iteratespeed.cpp index 115024209b2..92a756a6eaa 100644 --- a/vespalib/src/tests/btree/iteratespeed.cpp +++ b/vespalib/src/tests/btree/iteratespeed.cpp @@ -18,6 +18,7 @@ #include <vespa/vespalib/util/time.h> #include <vespa/fastos/app.h> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("iteratespeed"); @@ -135,25 +136,22 @@ IterateSpeed::usage() int IterateSpeed::Main() { - int argi; int c; - const char *optArg; - argi = 1; int loops = 1; bool backwards = false; bool forwards = false; bool lambda = false; int leafSlots = 0; - while ((c = GetOpt("F:bc:fl", optArg, argi)) != -1) { + while ((c = getopt(_argc, _argv, "F:bc:fl")) != -1) { switch (c) { case 'F': - leafSlots = atoi(optArg); + leafSlots = atoi(optarg); break; case 'b': backwards = true; break; case 'c': - loops = atoi(optArg); + loops = atoi(optarg); break; case 'f': forwards = true; |