diff --git a/parameterManager.cpp b/parameterManager.cpp index 45a22e6..efaeb1e 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -39,14 +39,21 @@ int manageParameter(Settings &settings, int argc, char **argv) return 1; } - int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); - if(res != 1) { - std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" : - std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl; - std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl; - std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl; - return 2; + std::vector res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); + if(res.size() != 1) { + if(res.size() == 0) + std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl; + else if(res.size() > 1) { + std::cout << " => Error: Mehrere Unteroptionen für '" << argv[1] << "' gefunden:" << std::endl; + for (auto &e : res) + std::cout << " > '" << argv[1] << "' =? " << e << std::endl; + } + std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl; + std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl; + return 2; } + res.clear(); + if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { argv[1][0] = '\0'; @@ -242,9 +249,6 @@ int loadDefaulOptions(Settings &settings) } } - - - ifs.close(); return 0; } @@ -889,8 +893,8 @@ void unterOption_clean(Settings * settings, int argc, char **argv) { if(argc > 2) if(strncmp("--help", argv[2], strlen(argv[2])) == 0) { - std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl; - std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl; + std::cout << "Aufruf: " << getProgramName() << "clean\n " << getProgramName() << "clean --help" << std::endl << std::endl + << "Beschreibung:" << std::endl << " Mit dieser Unterfunction kann man die Cookie-Dateien löschen." << std::endl << std::endl; return; } @@ -921,14 +925,15 @@ void unterOption_clean(Settings * settings, int argc, char **argv) } -int compare(std::string All_Options_with_komma_between, std::string input) +std::vector compare(std::string All_Options_with_komma_between, std::string input) { std::istringstream iStrStream( All_Options_with_komma_between + "\n"); std::string line; - int allFounds = 0; + std::vector allFounds; + while (getline(iStrStream, line).good()) if(strncmp(line.c_str(), input.c_str(), input.length()) == 0) { - allFounds++; + allFounds.push_back(line); //std::cout << "Unteroption '" << input << "' stimmt mit '" << line << "' überein." << std::endl; } return allFounds; diff --git a/parameterManager.h b/parameterManager.h index 9072c84..358168c 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -9,6 +9,7 @@ #include #include // PATH_MAX #include // readlink() +#include #ifdef _WIN32 #include @@ -61,7 +62,7 @@ struct Settings { int manageParameter(Settings &settings, int argc, char ** argv); int loadDefaulOptions(Settings & settings); -int compare(std::string All_Options_with_komma_between, std::string input); +std::vector compare(std::string All_Options_with_komma_between, std::string input); std::string getProgramName(); std::string getexepath();