#include #include #include #include #include #include "CToolBase.hpp" #include "CToolInit.hpp" #include "CToolAdd.hpp" #include "CToolRemove.hpp" #include "CToolGroup.hpp" #include "CToolCook.hpp" #include "CToolClean.hpp" #include "CToolPackage.hpp" #include "CToolHelp.hpp" /* Main usage message */ static void printHelp(const char* pname) { #if HECL_GIT printf("HECL Commit " #HECL_GIT " (" #HECL_BRANCH ")\n" "Usage: %s init|add|remove|group|cook|clean|package|help\n", pname); #elif HECL_VER printf("HECL Version " #HECL_VER "\n" "Usage: %s init|add|remove|group|cook|clean|package|help\n", pname); #else printf("HECL\n" "Usage: %s init|add|remove|group|cook|clean|package|help\n", pname); #endif } /* Regex patterns */ static const std::regex regOPEN("-o\\s*(\\S+)", std::regex::ECMAScript|std::regex::optimize); static const std::regex regVERBOSE("-v(v*)", std::regex::ECMAScript|std::regex::optimize); static const std::regex regFORCE("-f", std::regex::ECMAScript|std::regex::optimize); static const std::regex regNOWS("\\S+", std::regex::ECMAScript|std::regex::optimize); /* Iterates string segments around matched arguments and * filters args string accordingly */ static void whiddleArgs(std::string& args, const std::regex& regex) { std::string remArgs; for (std::sregex_token_iterator it(args.begin(), args.end(), regex, -1); it != std::sregex_token_iterator() ; ++it) { const std::string& str = *it; remArgs += str; } args = remArgs; } int main(int argc, const char** argv) { /* Basic usage check */ if (argc == 1) { printHelp(argv[0]); return 0; } else if (argc == 0) { printHelp("hecl"); return 0; } /* Assemble common tool pass info */ SToolPassInfo info; info.pname = argv[0]; /* Concatenate args */ std::string args; for (int i=2 ; itoolName().c_str(), info.verbosityLevel); /* Run tool */ int retval; try { retval = tool->run(); } catch (std::exception& ex) { fprintf(stderr, "Error running HECL tool '%s':\n%s\n", toolName.c_str(), ex.what()); delete tool; return -1; } delete tool; return retval; }