diff options
| author | bloodstalker <thabogre@gmail.com> | 2017-06-11 22:47:47 +0000 | 
|---|---|---|
| committer | bloodstalker <thabogre@gmail.com> | 2017-06-11 22:47:47 +0000 | 
| commit | 5bf39d243f014a839c8ffbffa9b1988d32f9fe78 (patch) | |
| tree | a9bda80d612016b1a6e2de301fc7f2461e3f7e5e | |
| parent | new command (diff) | |
| download | mutator-5bf39d243f014a839c8ffbffa9b1988d32f9fe78.tar.gz mutator-5bf39d243f014a839c8ffbffa9b1988d32f9fe78.zip | |
implemented the show source-code command
| -rw-r--r-- | bruiser/bruiser.cpp | 51 | 
1 files changed, 49 insertions, 2 deletions
| diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 40923d7..32100dd 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -186,10 +186,12 @@ class CompilationDatabaseProcessor      for(auto &iter : CCV)      { -      SourceFiles.push_back(iter.Directory + "/" + iter.Filename); +      SourceFiles.push_back(iter.Filename); +      //PRINT_WITH_COLOR_LB(RED, SourceFiles.back().c_str());      }      MakePath = CCV[0].Directory; +    //PRINT_WITH_COLOR_LB(RED, MakePath.c_str());    }    std::string GetMakePath(void) @@ -202,6 +204,19 @@ class CompilationDatabaseProcessor      return this->SourceFiles;    } +  void PopulateGPATH(void) +  { +    ShellGlobalInstance.PATH.push_back(MakePath); +  } + +  void PopulateGSOURCEFILES(void) +  { +    for (auto &iter : SourceFiles) +    { +      ShellGlobalInstance.SOURCE_FILES.push_back(iter); +    } +  } +    private:    CompilationDatabase &CDB;    std::string MakePath; @@ -1029,7 +1044,35 @@ class LuaWrapper      int BruiserLuaShowSourcecode(lua_State* __ls)      { -      return 0; +      unsigned int args = 0U; + +      if ((args = lua_gettop(__ls)) != 3U) +      { +        PRINT_WITH_COLOR_LB(RED, "function called with the wrong number of arguments. Run help()."); +        return 0; +      } + +      unsigned int linebegin = lua_tonumber(__ls, 1); +      unsigned int lineend = lua_tonumber(__ls, 2); +      std::string filename = lua_tostring(__ls, 3); +      std::fstream targetfile; + +      for(auto &iter : ShellGlobalInstance.SOURCE_FILES) +      { +        if (iter.rfind(filename) == iter.size() - filename.size()) +        { +          targetfile.open(iter); +        } +      } + +      std::string line; +      while(getline(targetfile, line)) +      { +        lua_pushstring(__ls, line.c_str()); +      } + +      targetfile.close(); +      return lineend - linebegin + 1U;      }  #define LIST_GENERATOR(__x1) \ @@ -1098,7 +1141,11 @@ int main(int argc, const char **argv)    CompilationDatabase &CDB = op.getCompilations();    std::vector<CompileCommand> CCV = CDB.getAllCompileCommands(); +  /*populating the shellglobalinstance*/    CompilationDatabaseProcessor CDBP(CDB); +  CDBP.CalcMakePath(); +  CDBP.PopulateGPATH(); +  CDBP.PopulateGSOURCEFILES();    /*initialize the LuaWrapper class so we can register and run them from lua.*/    LuaWrapper LW(Tool); | 
