diff --git a/bin/main b/bin/main index 2ec0340..392c605 100755 Binary files a/bin/main and b/bin/main differ diff --git a/obj/main.o b/obj/main.o index 16cfb27..d850670 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/options.o b/obj/options.o index bcbf6b3..68ad361 100644 Binary files a/obj/options.o and b/obj/options.o differ diff --git a/obj/util.o b/obj/util.o index 5d82e7d..b2c0c1b 100644 Binary files a/obj/util.o and b/obj/util.o differ diff --git a/src/main.cpp b/src/main.cpp index ed68379..63d9f94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,6 +88,15 @@ int main(int argc, char *argv[]) std::cout << "there are " << valid_words.size() << " valid words.\n"; + // test for a regex filter + /* + if (Options["regex"]) { + // there is a regex option + std::cout << "main(): regex option value: " << Options["regex"] << ".\n"; + } + */ + + // display the inputted command line, for reference std::cout << "You entered: "; for ( int i = 0 ; i<= argc ; i++ ) { std::cout << argv[i] << " "; diff --git a/src/options.cpp b/src/options.cpp index 41ec432..6e154a5 100755 --- a/src/options.cpp +++ b/src/options.cpp @@ -143,8 +143,7 @@ void Option_Switch( int count, char** arg, int* j, std::unordered_map= count ) { + // thia means now value was submitted with the -x option. That's an error/ + std::cout << "Option_Switch(): \"-x\" option requires a regex, exiting.\n"; + show_usage(""); + exit(1); + } + + // test if the next arg is an option + if ( isOption( arg[*j+1] ) ) { + // this is also an error, because if the next argv element is an option, it again + // means no regex was submitted with -x. That's an error. + std::cout << "Option_Switch(): \"-x\" option requires a regex, exiting.\n"; + show_usage(""); + exit(1); + } + + std::cout << "Option_Switch: " << arg[*j] << " returned value " << arg[*j+1] << ".\n"; + + ( *n ).emplace( "regex", arg[*j+1] ); + // increment j becaue the j+1 arg has already been used. Don't want + // to use it in the for loop twice + *j += 1; + } else if ( strcmp(arg[*j],"-b") == 0 ) { // std::cout << "Option_Switch(): option b loop index value is " << *j << "\n"; ( *n ).insert({"blanks","blank1"}); diff --git a/src/util.cpp b/src/util.cpp index c8f6a11..3d0f58a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -51,7 +51,6 @@ std::set WWF::get_dictionary() { } - struct comp { template @@ -103,19 +102,13 @@ std::set> WWF::Words_Sorted( // std::cout << "About to test regex.\n"; options.count("regex") == 1 ? isRegex = true : isRegex = false; - - if ( options.count("regex") == 1 ) { - isRegex = 1; - // this casts the std::string input to a std::regex - regex_input = std::regex( options.at("regex") ); - } - -// std::cout << "Tested regex.\n"; + // std::cout << "Util::Words_Sorted(): isRegex = " << isRegex << "\n"; for (auto& it : S) { // this prints the valid, sorted words to the screen std::cout << it.first << ' ' << it.second << "\n"; if ( isRegex ) { + regex_input = std::regex( options.at("regex") ); if ( std::regex_search(it.first, regex_input ) ) { // long-ass process to cast an int to a string std::stringstream stream; @@ -127,17 +120,22 @@ std::set> WWF::Words_Sorted( } } } - if ( regex_matches.size() ) { - std::cout << regex_matches.size() - << " words match your regex \"" - << options.at("regex") - << "\"\n"; - - for ( auto elem : regex_matches ) { - std::cout << elem << "\n"; + + if ( isRegex ) { + + if ( regex_matches.size() ) { + std::cout << regex_matches.size() + << " words match your regex \"" + << options.at("regex") + << "\"\n"; + for ( auto elem : regex_matches ) { + std::cout << elem << "\n"; + } + } + else { + std::cout << "Words_Sorted(): no words match \"" << options.at("regex") << "\"\n"; } } - return return_value; } // end Words_Sorted()