diff options
author | Regina Pfeifer <regina@mailbox.org> | 2019-08-22 20:55:58 (GMT) |
---|---|---|
committer | Regina Pfeifer <regina@mailbox.org> | 2019-08-22 20:55:58 (GMT) |
commit | b14bcd9123b515c8e3919943b40cc4860996db75 (patch) | |
tree | 590df053e3013c846e43cfadeefa5b0de3f2078f /Source/cmListCommand.cxx | |
parent | 130dbe4a5d49baa4404a399860bd3a6182783ece (diff) | |
download | CMake-b14bcd9123b515c8e3919943b40cc4860996db75.zip CMake-b14bcd9123b515c8e3919943b40cc4860996db75.tar.gz CMake-b14bcd9123b515c8e3919943b40cc4860996db75.tar.bz2 |
cmListCommand: Use cmSubcommandTable
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r-- | Source/cmListCommand.cxx | 154 |
1 files changed, 43 insertions, 111 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 3c41f4a..ad75490 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -16,6 +16,7 @@ #include <vector> #include "cm_memory.hxx" +#include "cm_static_string_view.hxx" #include "cmAlgorithms.h" #include "cmExecutionStatus.h" @@ -26,121 +27,16 @@ #include "cmRange.h" #include "cmStringAlgorithms.h" #include "cmStringReplaceHelper.h" +#include "cmSubcommandTable.h" #include "cmSystemTools.h" namespace { -bool HandleLengthCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleGetCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleAppendCommand(std::vector<std::string> const& args, - cmMakefile& makefile); -bool HandlePrependCommand(std::vector<std::string> const& args, - cmMakefile& makefile); -bool HandlePopBackCommand(std::vector<std::string> const& args, - cmMakefile& makefile); -bool HandlePopFrontCommand(std::vector<std::string> const& args, - cmMakefile& makefile); -bool HandleFindCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleInsertCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleJoinCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleRemoveAtCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleRemoveItemCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleRemoveDuplicatesCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleTransformCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleSortCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleSublistCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleReverseCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); -bool HandleFilterCommand(std::vector<std::string> const& args, - cmExecutionStatus& status); + bool FilterRegex(std::vector<std::string> const& args, bool includeMatches, std::string const& listName, std::vector<std::string>& varArgsExpanded, cmExecutionStatus& status); -bool GetList(std::vector<std::string>& list, const std::string& var, - const cmMakefile& makefile); -bool GetListString(std::string& listString, const std::string& var, - const cmMakefile& makefile); -} - -bool cmListCommand(std::vector<std::string> const& args, - cmExecutionStatus& status) -{ - if (args.size() < 2) { - status.SetError("must be called with at least two arguments."); - return false; - } - - const std::string& subCommand = args[0]; - if (subCommand == "LENGTH") { - return HandleLengthCommand(args, status); - } - if (subCommand == "GET") { - return HandleGetCommand(args, status); - } - if (subCommand == "APPEND") { - return HandleAppendCommand(args, status.GetMakefile()); - } - if (subCommand == "PREPEND") { - return HandlePrependCommand(args, status.GetMakefile()); - } - if (subCommand == "POP_BACK") { - return HandlePopBackCommand(args, status.GetMakefile()); - } - if (subCommand == "POP_FRONT") { - return HandlePopFrontCommand(args, status.GetMakefile()); - } - if (subCommand == "FIND") { - return HandleFindCommand(args, status); - } - if (subCommand == "INSERT") { - return HandleInsertCommand(args, status); - } - if (subCommand == "JOIN") { - return HandleJoinCommand(args, status); - } - if (subCommand == "REMOVE_AT") { - return HandleRemoveAtCommand(args, status); - } - if (subCommand == "REMOVE_ITEM") { - return HandleRemoveItemCommand(args, status); - } - if (subCommand == "REMOVE_DUPLICATES") { - return HandleRemoveDuplicatesCommand(args, status); - } - if (subCommand == "TRANSFORM") { - return HandleTransformCommand(args, status); - } - if (subCommand == "SORT") { - return HandleSortCommand(args, status); - } - if (subCommand == "SUBLIST") { - return HandleSublistCommand(args, status); - } - if (subCommand == "REVERSE") { - return HandleReverseCommand(args, status); - } - if (subCommand == "FILTER") { - return HandleFilterCommand(args, status); - } - - std::string e = "does not recognize sub-command " + subCommand; - status.SetError(e); - return false; -} - -namespace { bool GetListString(std::string& listString, const std::string& var, const cmMakefile& makefile) { @@ -276,7 +172,7 @@ bool HandleGetCommand(std::vector<std::string> const& args, } bool HandleAppendCommand(std::vector<std::string> const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); @@ -285,6 +181,7 @@ bool HandleAppendCommand(std::vector<std::string> const& args, return true; } + cmMakefile& makefile = status.GetMakefile(); std::string const& listName = args[1]; // expand the variable std::string listString; @@ -301,7 +198,7 @@ bool HandleAppendCommand(std::vector<std::string> const& args, } bool HandlePrependCommand(std::vector<std::string> const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); @@ -310,6 +207,7 @@ bool HandlePrependCommand(std::vector<std::string> const& args, return true; } + cmMakefile& makefile = status.GetMakefile(); std::string const& listName = args[1]; // expand the variable std::string listString; @@ -327,10 +225,11 @@ bool HandlePrependCommand(std::vector<std::string> const& args, } bool HandlePopBackCommand(std::vector<std::string> const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); + cmMakefile& makefile = status.GetMakefile(); auto ai = args.cbegin(); ++ai; // Skip subcommand name std::string const& listName = *ai++; @@ -374,10 +273,11 @@ bool HandlePopBackCommand(std::vector<std::string> const& args, } bool HandlePopFrontCommand(std::vector<std::string> const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); + cmMakefile& makefile = status.GetMakefile(); auto ai = args.cbegin(); ++ai; // Skip subcommand name std::string const& listName = *ai++; @@ -1566,4 +1466,36 @@ bool FilterRegex(std::vector<std::string> const& args, bool includeMatches, status.GetMakefile().AddDefinition(listName, value); return true; } + +} // namespace + +bool cmListCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + if (args.size() < 2) { + status.SetError("must be called with at least two arguments."); + return false; + } + + static cmSubcommandTable const subcommand{ + { "LENGTH"_s, HandleLengthCommand }, + { "GET"_s, HandleGetCommand }, + { "APPEND"_s, HandleAppendCommand }, + { "PREPEND"_s, HandlePrependCommand }, + { "POP_BACK"_s, HandlePopBackCommand }, + { "POP_FRONT"_s, HandlePopFrontCommand }, + { "FIND"_s, HandleFindCommand }, + { "INSERT"_s, HandleInsertCommand }, + { "JOIN"_s, HandleJoinCommand }, + { "REMOVE_AT"_s, HandleRemoveAtCommand }, + { "REMOVE_ITEM"_s, HandleRemoveItemCommand }, + { "REMOVE_DUPLICATES"_s, HandleRemoveDuplicatesCommand }, + { "TRANSFORM"_s, HandleTransformCommand }, + { "SORT"_s, HandleSortCommand }, + { "SUBLIST"_s, HandleSublistCommand }, + { "REVERSE"_s, HandleReverseCommand }, + { "FILTER"_s, HandleFilterCommand }, + }; + + return subcommand(args[0], args, status); } |