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 /searchlib/src/apps | |
parent | 1bb3dd192f4bcb91e710fe19ca54b2b8935ffb83 (diff) |
use getopt/getopt_long directly
Diffstat (limited to 'searchlib/src/apps')
3 files changed, 36 insertions, 45 deletions
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; |