aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser/bruiser.cpp
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2017-07-02 19:48:45 +0000
committerbloodstalker <thabogre@gmail.com>2017-07-02 19:48:45 +0000
commitb51c95776fb9d863906ce35e766bb2d1bbbb48b1 (patch)
tree2dc93151cb96ff623498d2a7cd045cdf8bfa4d3e /bruiser/bruiser.cpp
parentnew command (diff)
downloadmutator-b51c95776fb9d863906ce35e766bb2d1bbbb48b1.tar.gz
mutator-b51c95776fb9d863906ce35e766bb2d1bbbb48b1.zip
added a new command
Diffstat (limited to '')
-rw-r--r--bruiser/bruiser.cpp70
1 files changed, 56 insertions, 14 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index a19a6ca..1cb137f 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -105,12 +105,12 @@ cl::opt<bool> LuaJIT("jit", cl::desc("should bruiser use luajit or not."), cl::i
class LuaEngine
{
public:
- LuaEngine()
+ LuaEngine()
{
LS = luaL_newstate();
}
- /*@DEVI-this will just create member functions that open a single lua libarary.
+ /*@DEVI-this will just create member functions that open a single lua libarary.
* For example to load the string library just call LuaEngine::LoadstringLib().*/
#define OPEN_LUA_LIBS(__x1) \
void Load##__x1##Lib(void){\
@@ -250,12 +250,12 @@ class CompilationDatabaseProcessor
};
/**********************************************************************************************************************/
/*the implementation of the bruiser logger.*/
-bruiser::BruiserReport::BruiserReport ()
+bruiser::BruiserReport::BruiserReport ()
{
BruiserLog.open("bruiser.log");
}
-bruiser::BruiserReport::~BruiserReport()
+bruiser::BruiserReport::~BruiserReport()
{
BruiserLog.close();
}
@@ -386,7 +386,7 @@ class NameFinder
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/**********************************************************************************************************************/
-class IfBreaker : public MatchFinder::MatchCallback
+class IfBreaker : public MatchFinder::MatchCallback
{
public:
IfBreaker (Rewriter &Rewrite) : Rewrite(Rewrite) {}
@@ -464,7 +464,7 @@ public:
SourceRange SR(SL, SLE);
- std::string MainSig = Rewrite.getRewrittenText(SR);
+ std::string MainSig = Rewrite.getRewrittenText(SR);
size_t mainbegin = MainSig.find("main");
@@ -572,7 +572,7 @@ public:
BruiserASTConsumer(Rewriter &R) : HIfBreaker(R), HMainWrapper(R)
{}
- void HandleTranslationUnit(ASTContext &Context) override
+ void HandleTranslationUnit(ASTContext &Context) override
{
Matcher.addMatcher(ifStmt(hasDescendant(expr(anyOf(unaryOperator().bind("uno"), binaryOperator().bind("dous"))))), &HIfBreaker);
@@ -746,7 +746,7 @@ class BlankDiagConsumer : public clang::DiagnosticConsumer
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override {}
};
/**********************************************************************************************************************/
-class BruiserFrontendAction : public ASTFrontendAction
+class BruiserFrontendAction : public ASTFrontendAction
{
public:
BruiserFrontendAction() {}
@@ -765,7 +765,7 @@ public:
TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(*tee);
}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
{
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
@@ -1151,7 +1151,7 @@ class LuaWrapper
PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help().");
return 0;
}
-
+
unsigned int historysize = lua_tonumber(__ls, 1);
linenoiseHistorySetMaxLen(historysize);
@@ -1247,7 +1247,7 @@ class LuaWrapper
returned = waitpid(pid, &status, 0);
lua_pushnumber(__ls, returned);
}
-
+
return 1;
}
@@ -1305,6 +1305,7 @@ class LuaWrapper
if (pid == 0)
{
int retval = execl((ShellGlobalInstance.BINPATH + "/" + binname).c_str(), binname.c_str(), NULL);
+ std::cout << BLUE << "child returned " << retval << NORMAL << "\n";
lua_pushnumber(__ls, retval);
exit(EXIT_SUCCESS);
}
@@ -1348,7 +1349,7 @@ class LuaWrapper
}
ShellGlobalInstance.BINPATH = lua_tostring(__ls, 1);
-
+
return 0;
}
@@ -1393,6 +1394,46 @@ class LuaWrapper
return returncount;
}
+
+ int BruiserLuaChangeDirectory(lua_State* __ls)
+ {
+ int numargs = lua_gettop(__ls);
+
+ if (numargs != 1)
+ {
+ PRINT_WITH_COLOR_LB(RED, "wrond number of arguments. needed one. see help().");
+ lua_pushnumber(__ls, 1U);
+ return 1;
+ }
+
+ std::string destinationpath = lua_tostring(__ls, 1);
+
+ pid_t pid = fork();
+
+ if (pid < 0)
+ {
+ PRINT_WITH_COLOR_LB(RED, "could not fork...");
+ lua_pushnumber(__ls, EXIT_FAILURE);
+ return 1;
+ }
+
+ if (pid == 0)
+ {
+ int retval = execl("/usr/bin/cd", "cd", destinationpath.c_str(), NULL);
+ std::cout << BLUE << "child returned " << retval << NORMAL << "\n";
+ }
+
+ if (pid > 0)
+ {
+ int status;
+ pid_t returned;
+ returned = waitpid(pid, &status, 0);
+ lua_pushnumber(__ls, returned);
+ }
+
+ return 1;
+ }
+
#define LIST_GENERATOR(__x1) \
int List##__x1(lua_State* __ls)\
{\
@@ -1450,7 +1491,7 @@ int LuaDispatch(lua_State* __ls)
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/*Main*/
-int main(int argc, const char **argv)
+int main(int argc, const char **argv)
{
/*gets the compilation database and options for the clang instances that we would later run*/
CommonOptionsParser op(argc, argv, BruiserCategory);
@@ -1516,6 +1557,7 @@ int main(int argc, const char **argv)
lua_register(LE.GetLuaState(), "getmakepath", &LuaDispatch<&LuaWrapper::BruiserLuaGetMakePath>);
lua_register(LE.GetLuaState(), "getpaths", &LuaDispatch<&LuaWrapper::BruiserLuaGetPath>);
lua_register(LE.GetLuaState(), "getsourcefiles", &LuaDispatch<&LuaWrapper::BruiserLuaGetSourceFiles>);
+ lua_register(LE.GetLuaState(), "changedirectory", &LuaDispatch<&LuaWrapper::BruiserLuaChangeDirectory>);
/*its just regisering the List function from LuaWrapper with X-macros.*/
#define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>);
@@ -1535,7 +1577,7 @@ int main(int argc, const char **argv)
/*end of bruiser main*/
return 0;
} //end of cli block
-
+
} //end of main
/*last line intentionally left blank.*/