2015-05-15 22:39:43 +00:00
|
|
|
#include <stdio.h>
|
2015-05-19 07:01:18 +00:00
|
|
|
#include <string.h>
|
2015-05-26 04:42:20 +00:00
|
|
|
#include <stdlib.h>
|
2015-05-27 09:09:05 +00:00
|
|
|
#include <sys/param.h>
|
2015-05-20 05:22:32 +00:00
|
|
|
#include <regex>
|
|
|
|
#include <stdexcept>
|
2015-05-26 04:42:20 +00:00
|
|
|
#include <list>
|
2015-05-17 04:55:29 +00:00
|
|
|
#include <HECLDatabase.hpp>
|
|
|
|
|
2015-05-19 21:01:32 +00:00
|
|
|
#include "CToolBase.hpp"
|
2015-05-19 07:01:18 +00:00
|
|
|
#include "CToolInit.hpp"
|
2015-06-09 23:21:45 +00:00
|
|
|
#include "CToolSpec.hpp"
|
2015-05-19 07:01:18 +00:00
|
|
|
#include "CToolAdd.hpp"
|
2015-05-20 05:22:32 +00:00
|
|
|
#include "CToolRemove.hpp"
|
2015-05-19 07:01:18 +00:00
|
|
|
#include "CToolGroup.hpp"
|
|
|
|
#include "CToolCook.hpp"
|
|
|
|
#include "CToolClean.hpp"
|
|
|
|
#include "CToolPackage.hpp"
|
|
|
|
#include "CToolHelp.hpp"
|
2015-05-15 22:39:43 +00:00
|
|
|
|
2015-05-26 04:42:20 +00:00
|
|
|
bool XTERM_COLOR = false;
|
|
|
|
|
2015-05-20 05:22:32 +00:00
|
|
|
/* Main usage message */
|
|
|
|
static void printHelp(const char* pname)
|
2015-05-15 22:39:43 +00:00
|
|
|
{
|
2015-05-26 04:42:20 +00:00
|
|
|
if (XTERM_COLOR)
|
|
|
|
printf(BOLD "HECL" NORMAL);
|
|
|
|
else
|
|
|
|
printf("HECL");
|
2015-05-20 05:22:32 +00:00
|
|
|
#if HECL_GIT
|
2015-05-26 04:42:20 +00:00
|
|
|
printf(" Commit " #HECL_GIT " (" #HECL_BRANCH ")\n"
|
2015-05-20 05:22:32 +00:00
|
|
|
"Usage: %s init|add|remove|group|cook|clean|package|help\n", pname);
|
|
|
|
#elif HECL_VER
|
2015-05-26 04:42:20 +00:00
|
|
|
printf(" Version " #HECL_VER "\n"
|
2015-05-20 05:22:32 +00:00
|
|
|
"Usage: %s init|add|remove|group|cook|clean|package|help\n", pname);
|
|
|
|
#else
|
2015-05-26 04:42:20 +00:00
|
|
|
printf("\n"
|
2015-05-20 05:22:32 +00:00
|
|
|
"Usage: %s init|add|remove|group|cook|clean|package|help\n", pname);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Regex patterns */
|
2015-05-26 04:42:20 +00:00
|
|
|
static const std::regex regOPEN("-o([^\"]*|\\S*))", std::regex::ECMAScript|std::regex::optimize);
|
2015-05-20 05:22:32 +00:00
|
|
|
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);
|
2015-05-19 07:01:18 +00:00
|
|
|
|
2015-05-24 04:51:16 +00:00
|
|
|
#include "../blender/CBlenderConnection.hpp"
|
|
|
|
|
2015-05-19 07:01:18 +00:00
|
|
|
int main(int argc, const char** argv)
|
|
|
|
{
|
2015-05-26 04:42:20 +00:00
|
|
|
/* Xterm check */
|
|
|
|
const char* term = getenv("TERM");
|
|
|
|
if (!strncmp(term, "xterm", 5))
|
|
|
|
XTERM_COLOR = true;
|
|
|
|
|
|
|
|
//CBlenderConnection bconn(false);
|
|
|
|
//return 0;
|
2015-05-24 04:51:16 +00:00
|
|
|
|
2015-05-20 05:22:32 +00:00
|
|
|
/* Basic usage check */
|
2015-05-19 07:01:18 +00:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
printHelp(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (argc == 0)
|
|
|
|
{
|
|
|
|
printHelp("hecl");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-20 05:22:32 +00:00
|
|
|
/* Assemble common tool pass info */
|
|
|
|
SToolPassInfo info;
|
|
|
|
info.pname = argv[0];
|
2015-05-27 09:09:05 +00:00
|
|
|
char cwdbuf[MAXPATHLEN];
|
|
|
|
if (getcwd(cwdbuf, MAXPATHLEN))
|
|
|
|
info.cwd = cwdbuf;
|
2015-05-19 07:01:18 +00:00
|
|
|
|
2015-05-20 05:22:32 +00:00
|
|
|
/* Concatenate args */
|
2015-05-26 04:42:20 +00:00
|
|
|
std::list<std::string> args;
|
2015-05-20 05:22:32 +00:00
|
|
|
for (int i=2 ; i<argc ; ++i)
|
2015-05-26 04:42:20 +00:00
|
|
|
args.push_back(std::string(argv[i]));
|
2015-05-20 05:22:32 +00:00
|
|
|
|
|
|
|
if (!args.empty())
|
|
|
|
{
|
|
|
|
/* Extract output argument */
|
2015-05-26 04:42:20 +00:00
|
|
|
for (std::list<std::string>::const_iterator it = args.begin() ; it != args.end() ;)
|
2015-05-20 05:22:32 +00:00
|
|
|
{
|
2015-05-26 04:42:20 +00:00
|
|
|
const std::string& arg = *it;
|
|
|
|
std::smatch oMatch;
|
|
|
|
if (std::regex_search(arg, oMatch, regOPEN))
|
|
|
|
{
|
|
|
|
const std::string& token = oMatch[1].str();
|
|
|
|
if (token.size())
|
|
|
|
{
|
|
|
|
if (info.output.empty())
|
|
|
|
info.output = oMatch[1].str();
|
|
|
|
it = args.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
it = args.erase(it);
|
|
|
|
if (it == args.end())
|
|
|
|
break;
|
|
|
|
if (info.output.empty())
|
|
|
|
info.output = *it;
|
|
|
|
it = args.erase(it);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
2015-05-20 05:22:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Count verbosity */
|
2015-05-26 04:42:20 +00:00
|
|
|
for (std::list<std::string>::const_iterator it = args.begin() ; it != args.end() ;)
|
2015-05-20 05:22:32 +00:00
|
|
|
{
|
2015-05-26 04:42:20 +00:00
|
|
|
const std::string& arg = *it;
|
|
|
|
std::smatch vMatch;
|
|
|
|
if (std::regex_search(arg, vMatch, regVERBOSE))
|
|
|
|
{
|
|
|
|
++info.verbosityLevel;
|
|
|
|
info.verbosityLevel += vMatch[1].str().size();
|
|
|
|
it = args.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
2015-05-20 05:22:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check force argument */
|
2015-05-26 04:42:20 +00:00
|
|
|
for (std::list<std::string>::const_iterator it = args.begin() ; it != args.end() ;)
|
2015-05-20 05:22:32 +00:00
|
|
|
{
|
2015-05-26 04:42:20 +00:00
|
|
|
const std::string& arg = *it;
|
|
|
|
if (std::regex_search(arg, regFORCE))
|
|
|
|
{
|
|
|
|
info.force = true;
|
|
|
|
it = args.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
2015-05-20 05:22:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Gather remaining args */
|
2015-05-26 04:42:20 +00:00
|
|
|
for (const std::string& arg : args)
|
|
|
|
info.args.push_back(arg);
|
2015-05-20 05:22:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct selected tool */
|
|
|
|
std::string toolName(argv[1]);
|
|
|
|
std::transform(toolName.begin(), toolName.end(), toolName.begin(), tolower);
|
|
|
|
CToolBase* tool = NULL;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (toolName == "init")
|
|
|
|
tool = new CToolInit(info);
|
2015-06-09 22:19:59 +00:00
|
|
|
else if (toolName == "platform")
|
|
|
|
tool = new CToolPlatform(info);
|
2015-05-20 05:22:32 +00:00
|
|
|
else if (toolName == "add")
|
|
|
|
tool = new CToolAdd(info);
|
|
|
|
else if (toolName == "remove" || toolName == "rm")
|
|
|
|
tool = new CToolRemove(info);
|
|
|
|
else if (toolName == "group")
|
|
|
|
tool = new CToolGroup(info);
|
|
|
|
else if (toolName == "cook")
|
|
|
|
tool = new CToolCook(info);
|
|
|
|
else if (toolName == "clean")
|
|
|
|
tool = new CToolClean(info);
|
2015-05-26 04:42:20 +00:00
|
|
|
else if (toolName == "package" || toolName == "pack")
|
2015-05-20 05:22:32 +00:00
|
|
|
tool = new CToolPackage(info);
|
|
|
|
else if (toolName == "help")
|
|
|
|
tool = new CToolHelp(info);
|
|
|
|
else
|
|
|
|
throw std::invalid_argument("unrecognized tool '" + toolName + "'");
|
|
|
|
}
|
|
|
|
catch (std::exception& ex)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to construct HECL tool '%s':\n%s\n", toolName.c_str(), ex.what());
|
|
|
|
delete tool;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.verbosityLevel)
|
|
|
|
printf("Constructed tool '%s' %d\n", tool->toolName().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;
|
|
|
|
}
|
2015-05-19 07:01:18 +00:00
|
|
|
|
2015-05-20 05:22:32 +00:00
|
|
|
delete tool;
|
|
|
|
return retval;
|
2015-05-15 22:39:43 +00:00
|
|
|
}
|