diff options
| author | bloodstalker <thabogre@gmail.com> | 2017-06-24 12:25:06 +0000 | 
|---|---|---|
| committer | bloodstalker <thabogre@gmail.com> | 2017-06-24 12:25:06 +0000 | 
| commit | 229b8434a56acf77fd3b9b847465cde967f87ab5 (patch) | |
| tree | 0d406c63665ec07feb73c9bc13cbdda2a505e3c4 /bruiser | |
| parent | a new example script (diff) | |
| download | mutator-229b8434a56acf77fd3b9b847465cde967f87ab5.tar.gz mutator-229b8434a56acf77fd3b9b847465cde967f87ab5.zip | |
added a new command, fixed an old one
Diffstat (limited to 'bruiser')
| -rw-r--r-- | bruiser/bruiser.cpp | 67 | 
1 files changed, 60 insertions, 7 deletions
| diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 7030377..f9e317d 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*  #include <unistd.h>  #include <sys/time.h>  #include <sys/wait.h> +#include <thread>  /*LLVM headers*/  #include "clang/AST/AST.h"  #include "clang/AST/ASTConsumer.h" @@ -82,6 +83,7 @@ namespace      std::vector<std::string> PATH;      std::vector<std::string> SOURCE_FILES; +    std::string MAKEPATH;    };    struct ShellCache @@ -1092,22 +1094,49 @@ class LuaWrapper      int BruiserLuaRunMake(lua_State* __ls)      { -      unsigned int result = 0U;        unsigned int args = 0U;        if ((args = lua_gettop(__ls)) != 1U)        {          PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help()."); -        return 0; +        lua_pushnumber(__ls, 1); +        return 1; +      } + +      std::string makearg = lua_tostring(__ls , 1); + +      if (ShellGlobalInstance.MAKEPATH == "") +      { +        PRINT_WITH_COLOR_LB(RED, "MAKEPATH is not set. set it using setmakepath or type help."); +        lua_pushnumber(__ls, 1); +        return 1;        } -      const char *makepath; -      makepath = lua_tostring(__ls, 1); +      pid_t pid = fork(); -      result = dostring(__ls, makepath, "make"); +      if (pid < 0) +      { +        PRINT_WITH_COLOR_LB(RED, "could not fork..."); +        lua_pushnumber(__ls, EXIT_FAILURE); +      } + +      if (pid == 0) +      { +        std::cout << BLUE << "MAKEPATH: " << ShellGlobalInstance.MAKEPATH << NORMAL << "\n"; +        std::cout << BLUE << "Running: " << "make -C " << ShellGlobalInstance.MAKEPATH << " " << makearg << NORMAL << "\n"; +        int retval = execl("/usr/bin/make", "make", "-C", ShellGlobalInstance.MAKEPATH.c_str(), makearg.c_str(), NULL); +        lua_pushnumber(__ls, retval); +        exit(EXIT_SUCCESS); +      } + +      if (pid > 0) +      { +        int status; +        pid_t returned; +        returned = waitpid(pid, &status, 0); +        lua_pushnumber(__ls, returned); +      } -      lua_pushnumber(__ls, result); -      free((char*)makepath);        return 1;      } @@ -1220,6 +1249,28 @@ class LuaWrapper        return 1;      } +    int BruiserLuaStrainRecognition(lua_State* __ls) +    { +      unsigned int numthreads = std::thread::hardware_concurrency(); +      lua_pushnumber(__ls, numthreads); +      return 1; +    } + +    int BruiserLuaSetMakePath(lua_State* __ls) +    { +      int numargs = lua_gettop(__ls); + +      if (numargs != 1) +      { +        PRINT_WITH_COLOR_LB(RED, "wrong number of args. run help."); +        return 0; +      } + +      ShellGlobalInstance.MAKEPATH = lua_tostring(__ls, 1); + +      return 0; +    } +  #define LIST_GENERATOR(__x1) \      int List##__x1(lua_State* __ls)\      {\ @@ -1335,6 +1386,8 @@ int main(int argc, const char **argv)      lua_register(LE.GetLuaState(), "historysize", &LuaDispatch<&LuaWrapper::BruiserLuaChangeHistorySize>);      lua_register(LE.GetLuaState(), "showsource", &LuaDispatch<&LuaWrapper::BruiserLuaShowSourcecode>);      lua_register(LE.GetLuaState(), "extractmutagen", &LuaDispatch<&LuaWrapper::BruiserLuaMutagenExtraction>); +    lua_register(LE.GetLuaState(), "strainrecognition", &LuaDispatch<&LuaWrapper::BruiserLuaStrainRecognition>); +    lua_register(LE.GetLuaState(), "setmakepath", &LuaDispatch<&LuaWrapper::BruiserLuaSetMakePath>);      /*its just regisering the List function from LuaWrapper with X-macros.*/  #define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>); | 
