#include "cxxexecutor.h" #include #include "strutilxx.h" #include "dvlist.h" #include "nomgadapter.h" #include "pistdimgapp.h" /* --Methode-- */ CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */) : mUserCodeFn(""), mUserFctFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("") , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(1) { mIncList.resize(0); mCallArgs.resize(0); // Gestion des fichiers par default dans TmpDir //.... CMV a gerer mais pas forcement OK ... voir avec Rz //NamedObjMgr omg; //string tmpdir = omg.GetTmpDir(); //if(tmpdir.size()>1) mDefTmp = tmpdir; // On enregistre les nouvelles commandes string hgrp = "CxxExecutorCmd"; string usage,kw; kw = "c++exec"; usage = "c++exec: Execute the following c++ user code\n"; usage+= "Usage: c++exec c++ user code\n"; usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n"; usage+= " total generated code can be found in \"TmpDir/"+mDefRoot+".cc\""; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++execfrf"; usage = "c++execfrf: Execute c++ user_code [user_function_code]\n"; usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n"; usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\""; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++args"; usage = "c++args: Define user function arguments for c++exec and c++execfrf\n"; usage+= "Usage: c++args arg1 arg2 arg3 ...\n"; usage+= " c++args -? : give current arguments\n"; usage+= " c++args : reset current arguments"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++create"; usage = "c++create: create a file to be used by spiapp\n"; usage+= "Usage: c++create file.cc func c++ user code...\n"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++createfrf"; usage = "c++createfrf: create a file \"file.cc\"to be used by spiapp\n"; usage+= " with a user file code \"fileuser.cc\"\n"; usage+= " and an optional user function code \"fileuserfct.cc\"\n"; usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++compile"; usage = "c++compile: compile a file (file.cc -> file.so)\n"; usage+= "Usage: c++compile file\n"; usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n"; usage+= " : to be used before c++link"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++link"; usage = "c++link: link function \"func\" in file.so to spiapp\n"; usage+= "Usage: c++link file.so func"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++include"; usage = "c++include: give personnal includes to be used\n"; usage+= "Usage: c++include myinc1.h myinc2.h ...\n"; usage+= " c++include -? : give current include files\n"; usage+= " c++include : reset current include files\n"; usage+= "Warning: to be used before c++create... c++exec..."; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++compileopt"; usage = "c++compileopt: give additionnal compile options\n"; usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n"; usage+= " c++compileopt -? : give current compile options\n"; usage+= " c++compileopt : reset current compile options\n"; usage+= "Warning: to be used before c++compile"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++linkopt"; usage = "c++linkopt: give additionnal link options\n"; usage+= "Usage: c++linkopt -g -O5 ...\n"; usage+= " c++linkopt -? : give current link options\n"; usage+= " c++linkopt : reset current link options\n"; usage+= "Warning: to be used before c++compile"; mpiac->RegisterCommand(kw, usage, this, hgrp); kw = "c++mylibs"; usage = "c++mylibs: give additionnal libraries\n"; usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n"; usage+= " c++mylibs -? : give current additionnal libraries\n"; usage+= " c++mylibs : reset current additionnal libraries\n"; usage+= "Warning: to be used before c++compile"; mpiac->RegisterCommand(kw, usage, this, hgrp); } /* --Methode-- */ CxxExecutor::~CxxExecutor() { } /* --Methode-- */ int CxxExecutor::Execute(string& kw, vector& tokens, string& toks) { int rc=0; if(kw == "c++exec") { if(tokens.size()<1) { cout<<"Usage: c++exec c++ user code"<1) rc = FillUserFctFrF(tokens[1]); rc = CrFile(); if(rc) return(1); rc = Compile(); if(rc) return(1); rc = Link(); if(rc) return(1); rc = Call(); if(rc) return(1); } else if(kw == "c++args") { if(tokens.size()==1) if(tokens[0]=="-?") {cout<<"c++args "<3) FillUserFctFrF(tokens[3]); rc = CrFile(tokens[0],tokens[1]); if(rc) return(1); } else if(kw == "c++compile") { if(tokens.size()>=1) rc = Compile(tokens[0]); else rc = Compile(); if(rc) return(1); } else if(kw == "c++link") { if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]); else if(tokens.size()>=1) rc = Link(tokens[0]); else rc = Link(); if(rc) return(1); } else if(kw == "c++include") { if(tokens.size()==1) if(tokens[0]=="-?") {cout<<"c++include "<0) os<<"#include \""<& args );"<& args )"<0) os<<"#include \""<0) cout<<" User code was in file "<0) cout<<" User function code was in file "<"<"<"<"<"<"<"<"<"<"<"<"<"<"< objlist; string patt = "*"; omg.GetObjList(patt,objlist); int nobjs = objlist.size(); os<<"//-------------- Object List --------------"<GetDataObjType(); stmp = "___" + nobj; os<<"___nomobj = \""<(omg.GetObj(___nomobj));"<=code.size()) {code=""; break;} code = code.substr(q); if(i==first) break; q = code.find_first_of(" \t"); if(q>=code.size()) {code=""; break;} code = code.substr(q); } if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code after "<0) cout<<"User code filled from file "<0) cout<<"User Function code filled from file "<CmdInterpreter(); string key("linkff2"); vector arg; arg.push_back(libname); arg.push_back(func); string toks = libname + " " + func; int rc = mpiac->ExecuteCommand(key,arg,toks); if(mPrtLevel) cout<<"Link from "<CmdInterpreter(); string key("call"); vector arg; arg.push_back(func); string toks = func; if(mCallArgs.size()>0) for(uint_4 i=0;iExecuteCommand(key,arg,toks); return 0; } /* --Methode-- */ void CxxExecutor::FillArgs(vector& args) { mCallArgs.resize(0); if(args.size()<1) return; for(uint_4 i=0;i& inc) { mIncList.resize(0); if(inc.size()<1) return; for(uint_4 i=0;i& copt) { mCompOpt = ""; if(copt.size()<1) return; for(uint_4 i=0;i& lopt) { mLinkOpt = ""; if(lopt.size()<1) return; for(uint_4 i=0;i& llibs) { mMyLibs = ""; if(llibs.size()<1) return; for(uint_4 i=0;i