1 | #include "cxxexecutor.h"
|
---|
2 |
|
---|
3 | #include <typeinfo>
|
---|
4 |
|
---|
5 | #include "dvlist.h"
|
---|
6 |
|
---|
7 | #include "nomgadapter.h"
|
---|
8 | #include "pistdimgapp.h"
|
---|
9 |
|
---|
10 |
|
---|
11 | void FillVStringFrString(string s,vector<string>& vs,char sep = ' ');
|
---|
12 |
|
---|
13 |
|
---|
14 | /* --Methode-- */
|
---|
15 | CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
|
---|
16 | : mCompOpt(""), mLinkOpt(""), mMyLibs("")
|
---|
17 | {
|
---|
18 | mUserCode.resize(0);
|
---|
19 | mIncList.resize(0);
|
---|
20 | mCallArgs.resize(0);
|
---|
21 |
|
---|
22 | NamedObjMgr omg;
|
---|
23 |
|
---|
24 | // On enregistre les nouvelles commandes
|
---|
25 | string hgrp = "CxxExecutorCmd";
|
---|
26 | string usage,kw;
|
---|
27 |
|
---|
28 | kw = "c++exec";
|
---|
29 | usage = "c++exec: Execute the following c++ user code\n";
|
---|
30 | usage+= "Usage: c++exec c++ user code";
|
---|
31 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
32 |
|
---|
33 | kw = "c++execfrf";
|
---|
34 | usage = "c++execfrf: Execute c++ user code contained in a file\n";
|
---|
35 | usage+= "Usage: c++execfrf fileuser.cc";
|
---|
36 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
37 |
|
---|
38 | kw = "c++args";
|
---|
39 | usage = "c++args: Define user function arguments\n";
|
---|
40 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
|
---|
41 | usage+= " c++args -? : give current arguments\n";
|
---|
42 | usage+= " c++args : reset current arguments";
|
---|
43 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
44 |
|
---|
45 | kw = "c++create";
|
---|
46 | usage = "c++create: create a file to be used by spiapp\n";
|
---|
47 | usage+= "Usage: c++create file.cc func c++ user code...\n";
|
---|
48 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
49 |
|
---|
50 | kw = "c++createfrf";
|
---|
51 | usage = "c++createfrf: create a file \"file.cc\"to be used by spiapp\n";
|
---|
52 | usage+= " with a user file \"fileuser.cc\"\n";
|
---|
53 | usage+= "Usage: c++createfrf file.cc func fileuser.cc\n";
|
---|
54 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
55 |
|
---|
56 | kw = "c++compile";
|
---|
57 | usage = "c++compile: compile a file (file.cc -> file.so)\n";
|
---|
58 | usage+= "Usage: c++compile file\n";
|
---|
59 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n";
|
---|
60 | usage+= " : to be used before c++link";
|
---|
61 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
62 |
|
---|
63 | kw = "c++link";
|
---|
64 | usage = "c++link: link function \"func\" in file.so to spiapp\n";
|
---|
65 | usage+= "Usage: c++link file.so func";
|
---|
66 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
67 |
|
---|
68 | kw = "c++include";
|
---|
69 | usage = "c++include: give personnal includes to be used\n";
|
---|
70 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
|
---|
71 | usage+= " c++include -? : give current include files\n";
|
---|
72 | usage+= " c++include : reset current include files\n";
|
---|
73 | usage+= "Warning: to be used before c++create... c++exec...";
|
---|
74 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
75 |
|
---|
76 | kw = "c++compileopt";
|
---|
77 | usage = "c++compileopt: give additionnal compile options\n";
|
---|
78 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
|
---|
79 | usage+= " c++compileopt -? : give current compile options\n";
|
---|
80 | usage+= " c++compileopt : reset current compile options\n";
|
---|
81 | usage+= "Warning: to be used before c++compile";
|
---|
82 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
83 |
|
---|
84 | kw = "c++linkopt";
|
---|
85 | usage = "c++linkopt: give additionnal link options\n";
|
---|
86 | usage+= "Usage: c++linkopt -g -O5 ...\n";
|
---|
87 | usage+= " c++linkopt -? : give current link options\n";
|
---|
88 | usage+= " c++linkopt : reset current link options\n";
|
---|
89 | usage+= "Warning: to be used before c++compile";
|
---|
90 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
91 |
|
---|
92 | kw = "c++mylibs";
|
---|
93 | usage = "c++mylibs: give additionnal libraries\n";
|
---|
94 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
|
---|
95 | usage+= " c++mylibs -? : give current additionnal libraries\n";
|
---|
96 | usage+= " c++mylibs : reset current additionnal libraries\n";
|
---|
97 | usage+= "Warning: to be used before c++compile";
|
---|
98 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | kw = "c++setvar";
|
---|
103 | usage = "c++setvar: Setting test variable \n";
|
---|
104 | usage+= "c++setvar varname varcontent ";
|
---|
105 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
106 |
|
---|
107 | kw = "c++getvar";
|
---|
108 | usage = "c++getvar: Getting test variable content\n";
|
---|
109 | usage+= "c++getvar varname ";
|
---|
110 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
111 |
|
---|
112 | kw = "c++varlist";
|
---|
113 | usage = "c++getvar: Printing test variable list\n";
|
---|
114 | usage+= "c++varlist ";
|
---|
115 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 | /* --Methode-- */
|
---|
120 | CxxExecutor::~CxxExecutor()
|
---|
121 | {
|
---|
122 | }
|
---|
123 |
|
---|
124 | /* --Methode-- */
|
---|
125 | int CxxExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
126 | {
|
---|
127 | int rc=0;
|
---|
128 | if(kw == "c++exec" || kw == "c++execfrf") {
|
---|
129 | if(tokens.size()<1) {
|
---|
130 | cout<<"Usage: c++exec c++ user code"<<endl;
|
---|
131 | cout<<"Usage: c++execfrf fileuser.cc"<<endl;
|
---|
132 | return(1);
|
---|
133 | }
|
---|
134 | if(kw == "c++exec") rc = FillUserCode(tokens,0);
|
---|
135 | if(kw == "c++execfrf") rc = FillUserCode(tokens[0]);
|
---|
136 | if(rc) return(1);
|
---|
137 | rc = CrFile(); if(rc) return(1);
|
---|
138 | rc = Compile(); if(rc) return(1);
|
---|
139 | rc = Link(); if(rc) return(1);
|
---|
140 | rc = Call(); if(rc) return(1);
|
---|
141 |
|
---|
142 | } else if(kw == "c++args") {
|
---|
143 | if(tokens.size()==1) if(tokens[0]=="-?") cout<<"c++args "<<GetArgs()<<endl;
|
---|
144 | FillArgs(tokens);
|
---|
145 |
|
---|
146 | } else if(kw == "c++create") {
|
---|
147 | if(tokens.size()<3) {
|
---|
148 | cout<<"Usage: c++create file.cc func c++ user code ..."<<endl;
|
---|
149 | return(1);
|
---|
150 | }
|
---|
151 | rc = FillUserCode(tokens,2); if(rc) return(1);
|
---|
152 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
153 |
|
---|
154 | } else if(kw == "c++createfrf") {
|
---|
155 | if(tokens.size()<3) {
|
---|
156 | cout<<"Usage: c++createfrf file.cc func fileuser.cc"<<endl;
|
---|
157 | return(1);
|
---|
158 | }
|
---|
159 | rc = FillUserCode(tokens[2]); if(rc) return(1);
|
---|
160 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
161 |
|
---|
162 | } else if(kw == "c++compile") {
|
---|
163 | if(tokens.size()>=1) rc = Compile(tokens[0]);
|
---|
164 | else rc = Compile();
|
---|
165 | if(rc) return(1);
|
---|
166 |
|
---|
167 | } else if(kw == "c++link") {
|
---|
168 | if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]);
|
---|
169 | else if(tokens.size()>=1) rc = Link(tokens[0]);
|
---|
170 | else rc = Link();
|
---|
171 | if(rc) return(1);
|
---|
172 |
|
---|
173 | } else if(kw == "c++include") {
|
---|
174 | if(tokens.size()==1) if(tokens[0]=="-?") cout<<"c++include "<<GetInclude()<<endl;
|
---|
175 | FillInclude(tokens);
|
---|
176 |
|
---|
177 | } else if(kw == "c++compileopt") {
|
---|
178 | if(tokens.size()==1) if(tokens[0]=="-?") cout<<"c++compileopt "<<GetCompileOpt()<<endl;
|
---|
179 | FillCompileOpt(tokens);
|
---|
180 |
|
---|
181 | } else if(kw == "c++linkopt") {
|
---|
182 | if(tokens.size()==1) if(tokens[0]=="-?") cout<<"c++linkopt "<<GetLinkOpt()<<endl;
|
---|
183 | FillLinkOpt(tokens);
|
---|
184 |
|
---|
185 | } else if(kw == "c++mylibs") {
|
---|
186 | if(tokens.size()==1) if(tokens[0]=="-?") cout<<"c++mylibs "<<GetLinkLibs()<<endl;
|
---|
187 | FillLinkLibs(tokens);
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 | } else if(kw == "c++setvar") {
|
---|
192 | if(tokens.size()<2) {
|
---|
193 | cout<<" Usage: c++setvar varname varcontent "<<endl;
|
---|
194 | return(1);
|
---|
195 | }
|
---|
196 | string varcont = tokens[1];
|
---|
197 | if(tokens.size()>2)
|
---|
198 | for(uint_4 i=2;i<tokens.size();i++) varcont += " " + tokens[i] ;
|
---|
199 | NamedObjMgr omg;
|
---|
200 | omg.SetVar(tokens[0], varcont);
|
---|
201 | } else if(kw == "c++getvar") {
|
---|
202 | if(tokens.size()<1) {
|
---|
203 | cout<<" Usage: c++getvar varname "<<endl;
|
---|
204 | return(1);
|
---|
205 | }
|
---|
206 | NamedObjMgr omg;
|
---|
207 | cout<<"c++getvar("<<tokens[0]<<")="<<omg.GetVar(tokens[0])<<endl;
|
---|
208 | } else if(kw == "c++varlist") {
|
---|
209 | NamedObjMgr omg;
|
---|
210 | cout<<omg.GetVarList();
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | return(0);
|
---|
215 | }
|
---|
216 |
|
---|
217 | /* --Methode-- */
|
---|
218 | int CxxExecutor::CrFile(string cfilename,string func)
|
---|
219 | {
|
---|
220 | ofstream os(cfilename.c_str(),ios::out);
|
---|
221 | if(!os) {
|
---|
222 | cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
|
---|
223 | return 1;
|
---|
224 | }
|
---|
225 |
|
---|
226 | PutInclude(os);
|
---|
227 | os<<endl;
|
---|
228 |
|
---|
229 | PutIncludeUser(os);
|
---|
230 | os<<endl;
|
---|
231 |
|
---|
232 | os<<"extern \"C\" {"<<endl;
|
---|
233 | os<<" int "<<func<<"( vector<string>& args );"<<endl;
|
---|
234 | os<<"}"<<endl<<endl;
|
---|
235 | os<<"int "<<func<<"( vector<string>& args )"<<endl;
|
---|
236 | os<<"{"<<endl;
|
---|
237 | os<<"// Some definitions to help using spiapp;"<<endl;
|
---|
238 | os<<"NamedObjMgr omg;"<<endl;
|
---|
239 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl;
|
---|
240 | os<<"//omg.AddObj(OBJECT* object,string nom_object);"<<endl;
|
---|
241 | os<<endl;
|
---|
242 |
|
---|
243 | PutObject(os);
|
---|
244 | os<<endl;
|
---|
245 |
|
---|
246 | PutVar(os);
|
---|
247 | os<<endl;
|
---|
248 |
|
---|
249 | PutUserCode(os);
|
---|
250 | os<<endl;
|
---|
251 |
|
---|
252 | os<<endl;
|
---|
253 | os<<"return 0;"<<endl;
|
---|
254 | os<<"}"<<endl;
|
---|
255 |
|
---|
256 | cout<<"File "<<cfilename<<" for function "<<func<<" created"<<endl;
|
---|
257 | return 0;
|
---|
258 | }
|
---|
259 |
|
---|
260 | /* --Methode-- */
|
---|
261 | void CxxExecutor::PutInclude(ofstream& os)
|
---|
262 | {
|
---|
263 | os<<"#include \"machdefs.h\""<<endl
|
---|
264 | <<endl
|
---|
265 |
|
---|
266 | <<"//---- System et stdc++ include files"<<endl
|
---|
267 | <<"#include <stdio.h>"<<endl
|
---|
268 | <<"#include <stdlib.h>"<<endl
|
---|
269 | <<"#include <math.h>"<<endl
|
---|
270 | <<"#include <ctype.h>"<<endl
|
---|
271 | <<"#include <string.h>"<<endl
|
---|
272 | <<"#include <iostream.h>"<<endl
|
---|
273 | <<"#include <fstream.h>"<<endl
|
---|
274 | <<"#include <complex>"<<endl
|
---|
275 | <<endl
|
---|
276 |
|
---|
277 | <<"#include <typeinfo>"<<endl
|
---|
278 | <<"#include <string>"<<endl
|
---|
279 | <<"#include <vector>"<<endl
|
---|
280 | <<"#include <map>"<<endl
|
---|
281 | <<"#include <functional>"<<endl
|
---|
282 | <<"#include <list>"<<endl
|
---|
283 | <<endl
|
---|
284 |
|
---|
285 | <<"//---- Sophya include files"<<endl
|
---|
286 | <<"#include \"systools.h\""<<endl
|
---|
287 | <<"#include \"ntools.h\""<<endl
|
---|
288 | <<"#include \"array.h\""<<endl
|
---|
289 | <<"#include \"histats.h\""<<endl
|
---|
290 | <<endl
|
---|
291 |
|
---|
292 | <<"//---- Spiapp include files"<<endl
|
---|
293 | <<"#include \"nobjmgr.h\""<<endl
|
---|
294 | <<"#include \"servnobjm.h\""<<endl
|
---|
295 | <<endl
|
---|
296 |
|
---|
297 | <<"#define KeepObj(obj) ___nomobj = #obj; omg.AddObj(obj,___nomobj);"<<endl
|
---|
298 | <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
|
---|
299 | <<endl;
|
---|
300 |
|
---|
301 | return;
|
---|
302 | }
|
---|
303 |
|
---|
304 | /* --Methode-- */
|
---|
305 | void CxxExecutor::PutIncludeUser(ofstream& os)
|
---|
306 | {
|
---|
307 | if(mIncList.size()<1) return;
|
---|
308 | for(uint_4 i=0;i<mIncList.size();i++)
|
---|
309 | os<<"#include \""<<mIncList[i]<<"\""<<endl;
|
---|
310 | }
|
---|
311 |
|
---|
312 | /* --Methode-- */
|
---|
313 | void CxxExecutor::PutObject(ofstream& os)
|
---|
314 | {
|
---|
315 | NamedObjMgr omg;
|
---|
316 | NObjMgrAdapter* objmgrad;
|
---|
317 | vector<string> objlist;
|
---|
318 | string patt = "*";
|
---|
319 | omg.GetObjList(patt,objlist);
|
---|
320 | int nobjs = objlist.size();
|
---|
321 |
|
---|
322 | os<<"//-------------- Object List --------------"<<endl;
|
---|
323 | os<<"//Number of objects = "<<nobjs<<endl;
|
---|
324 | os<<"string ___nomobj;"<<endl<<endl;
|
---|
325 | if(nobjs<=0) return;
|
---|
326 |
|
---|
327 | string dir,nobj,stmp,obtype;
|
---|
328 | for(int i=0;i<nobjs;i++) {
|
---|
329 | objmgrad = omg.GetObjAdapter(objlist[i]);
|
---|
330 | omg.ParseObjectName(objlist[i],dir,nobj);
|
---|
331 | obtype = objmgrad->GetDataObjType();
|
---|
332 | stmp = "___" + nobj;
|
---|
333 |
|
---|
334 | os<<"___nomobj = \""<<nobj<<"\";"<<endl;
|
---|
335 | os<<obtype<<"* "<<stmp
|
---|
336 | <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
|
---|
337 | os<<"if("<<stmp<<"==NULL) throw NullPtrError"
|
---|
338 | <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
|
---|
339 | <<"... please update file\");"<<endl;
|
---|
340 | os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
|
---|
341 | }
|
---|
342 |
|
---|
343 | return;
|
---|
344 | }
|
---|
345 |
|
---|
346 | /* --Methode-- */
|
---|
347 | void CxxExecutor::PutVar(ofstream& os)
|
---|
348 | {
|
---|
349 | os<<"//-------------- Variable List --------------"<<endl;
|
---|
350 | NamedObjMgr omg;
|
---|
351 | DVList& varlist = omg.GetVarList();
|
---|
352 | // varlist.Show(); varlist.Print();
|
---|
353 | DVList::ValList::const_iterator it;
|
---|
354 | for(it=varlist.Begin(); it!=varlist.End(); it++) {
|
---|
355 | string key = (*it).first;
|
---|
356 | os<<"___nomobj = \""<<key<<"\";"<<endl;
|
---|
357 | os<<"MuTyV & "<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
|
---|
358 | }
|
---|
359 |
|
---|
360 | }
|
---|
361 |
|
---|
362 | /* --Methode-- */
|
---|
363 | void CxxExecutor::PutUserCode(ofstream& os)
|
---|
364 | {
|
---|
365 | os<<"//--------------------------------------------//"<<endl;
|
---|
366 | os<<"//------------- Code utilisateur -------------//"<<endl;
|
---|
367 | os<<"//--------------------------------------------//"<<endl;
|
---|
368 | os<<endl;
|
---|
369 | if(mUserCode.size()<1) return;
|
---|
370 | for(uint_4 i=0;i<mUserCode.size();i++) os<<mUserCode[i]<<endl;
|
---|
371 | }
|
---|
372 |
|
---|
373 | /* --Methode-- */
|
---|
374 | int CxxExecutor::FillUserCode(vector<string>& usercode,uint_4 first)
|
---|
375 | // - first is the first position in the vector<> where the code starts
|
---|
376 | {
|
---|
377 | mUserCode.resize(0);
|
---|
378 | uint_4 nus = usercode.size();
|
---|
379 | if(nus<=first) {
|
---|
380 | cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
381 | return 1;
|
---|
382 | }
|
---|
383 | string dum = "";
|
---|
384 | // On ajoute un blanc pour les chaines de caracteres contenant des blancs
|
---|
385 | for(uint_4 i=first;i<nus;i++) dum += " " + usercode[i];
|
---|
386 | // Tout dans une seule ligne pour eviter les pbs (cf au bas du fichier)
|
---|
387 | mUserCode.push_back(dum);
|
---|
388 | cout<<"User code filled from standard input"<<endl;
|
---|
389 | return 0;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /* --Methode-- */
|
---|
393 | int CxxExecutor::FillUserCode(string filename)
|
---|
394 | {
|
---|
395 | mUserCode.resize(0);
|
---|
396 |
|
---|
397 | ifstream is(filename.c_str());
|
---|
398 | if(!is) {
|
---|
399 | cout<<"CxxExecutor::FillUserCode: unable to open "<<filename<<endl;
|
---|
400 | return 1;
|
---|
401 | }
|
---|
402 |
|
---|
403 | int nline = 4096; // Au plus 4096 characters par ligne!
|
---|
404 | char *str = new char[nline+2];
|
---|
405 | while(is)
|
---|
406 | {is.getline(str,nline); mUserCode.push_back((string) str);}
|
---|
407 | delete [] str;
|
---|
408 | if(mUserCode.size()<=0) {
|
---|
409 | return 2;
|
---|
410 | cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
411 | }
|
---|
412 |
|
---|
413 | cout<<"User code filled from file "<<filename<<endl;
|
---|
414 | return 0;
|
---|
415 | }
|
---|
416 |
|
---|
417 | /* --Methode-- */
|
---|
418 | int CxxExecutor::Compile(string rootfilename)
|
---|
419 | {
|
---|
420 | string fc = rootfilename + ".cc";
|
---|
421 | string fl = rootfilename + ".so";
|
---|
422 | cout<<"Compile: "<<rootfilename<<endl;
|
---|
423 | int rc = 0;
|
---|
424 | rc = CrMakefile();
|
---|
425 | if(rc) return(1);
|
---|
426 | string make = "make -f cxx_spiapp_Makefile";
|
---|
427 | make += " CXXFLAGS=\"" + mCompOpt + "\"";
|
---|
428 | make += " LDFLAGS=\"" + mLinkOpt + "\"";
|
---|
429 | make += " MYLIBS=\"" + mMyLibs + "\"";
|
---|
430 | make += " " + rootfilename;
|
---|
431 | rc = system(make.c_str());
|
---|
432 | if(rc)
|
---|
433 | {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
|
---|
434 | return 1000+rc;}
|
---|
435 | return 0;
|
---|
436 | }
|
---|
437 |
|
---|
438 | /* --Methode-- */
|
---|
439 | int CxxExecutor::CrMakefile(void)
|
---|
440 | {
|
---|
441 | ofstream os("cxx_spiapp_Makefile",ios::out);
|
---|
442 | if(!os)
|
---|
443 | {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
|
---|
444 | return 1;}
|
---|
445 | //---------------------------------------------------------------------
|
---|
446 | os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
|
---|
447 | os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
|
---|
448 | os<<"MYLIBS ="<<endl;
|
---|
449 | os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
|
---|
450 | os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
|
---|
451 | os<<"LIBS := $(LIBS) -lfor"<<endl;
|
---|
452 | os<<"endif"<<endl;
|
---|
453 | os<<"ifeq ($(MACHEROS),Linux)"<<endl;
|
---|
454 | os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
|
---|
455 | os<<"endif"<<endl;
|
---|
456 | os<<"%.so:$(OBJ)%.o"<<endl;
|
---|
457 | os<<"%:%.cc"<<endl;
|
---|
458 | os<<"%:%.o"<<endl;
|
---|
459 | os<<"%.o:%.cc"<<endl;
|
---|
460 | os<<"%.o:%.c"<<endl;
|
---|
461 | os<<"%:%.c"<<endl;
|
---|
462 | os<<endl;
|
---|
463 | os<<".PRECIOUS: %.so"<<endl;
|
---|
464 | os<<endl;
|
---|
465 | os<<"%:%.so"<<endl;
|
---|
466 | os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
|
---|
467 | os<<"%.so:$(OBJ)%.o"<<endl;
|
---|
468 | os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
|
---|
469 | os<<"$(OBJ)%.o:%.cc"<<endl;
|
---|
470 | os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
|
---|
471 | os<<"$(OBJ)%.o:%.c"<<endl;
|
---|
472 | os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
|
---|
473 | //---------------------------------------------------------------------
|
---|
474 | return 0;
|
---|
475 | }
|
---|
476 |
|
---|
477 | /* --Methode-- */
|
---|
478 | int CxxExecutor::Link(string libname,string func)
|
---|
479 | {
|
---|
480 | NamedObjMgr omg;
|
---|
481 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
482 | string key("link");
|
---|
483 | vector<string> arg; arg.push_back(libname); arg.push_back(func);
|
---|
484 | int rc = mpiac->ExecuteCommand(key,arg);
|
---|
485 | cout<<"Link from "<<libname<<" for function "<<func
|
---|
486 | <<" (rc="<<rc<<")"<<endl;
|
---|
487 | return 0;
|
---|
488 | }
|
---|
489 |
|
---|
490 | /* --Methode-- */
|
---|
491 | int CxxExecutor::Call(string func)
|
---|
492 | {
|
---|
493 | NamedObjMgr omg;
|
---|
494 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
495 | string key("call");
|
---|
496 | vector<string> arg; arg.push_back(func);
|
---|
497 | if(mCallArgs.size()>0)
|
---|
498 | for(int i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
|
---|
499 | mpiac->ExecuteCommand(key,arg);
|
---|
500 | return 0;
|
---|
501 | }
|
---|
502 |
|
---|
503 | /* --Methode-- */
|
---|
504 | void CxxExecutor::FillArgs(vector<string>& args)
|
---|
505 | {
|
---|
506 | mCallArgs.resize(0);
|
---|
507 | if(args.size()<1) return;
|
---|
508 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
|
---|
509 | }
|
---|
510 |
|
---|
511 | void CxxExecutor::FillArgs(string& args)
|
---|
512 | {
|
---|
513 | mCallArgs.resize(0);
|
---|
514 | FillVStringFrString(args,mCallArgs,' ');
|
---|
515 | }
|
---|
516 |
|
---|
517 | string CxxExecutor::GetArgs(void)
|
---|
518 | {
|
---|
519 | string dum = "";
|
---|
520 | if(mCallArgs.size()<1) return dum;
|
---|
521 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
|
---|
522 | return dum;
|
---|
523 | }
|
---|
524 |
|
---|
525 | /* --Methode-- */
|
---|
526 | void CxxExecutor::FillInclude(vector<string>& inc)
|
---|
527 | {
|
---|
528 | mIncList.resize(0);
|
---|
529 | if(inc.size()<1) return;
|
---|
530 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
|
---|
531 | }
|
---|
532 |
|
---|
533 | void CxxExecutor::FillInclude(string& inc)
|
---|
534 | {
|
---|
535 | mIncList.resize(0);
|
---|
536 | FillVStringFrString(inc,mIncList,' ');
|
---|
537 | }
|
---|
538 |
|
---|
539 | string CxxExecutor::GetInclude(void)
|
---|
540 | {
|
---|
541 | string dum = "";
|
---|
542 | if(mIncList.size()<1) return dum;
|
---|
543 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
|
---|
544 | return dum;
|
---|
545 | }
|
---|
546 |
|
---|
547 | /* --Methode-- */
|
---|
548 | void CxxExecutor::FillCompileOpt(vector<string>& copt)
|
---|
549 | {
|
---|
550 | mCompOpt = "";
|
---|
551 | if(copt.size()<1) return;
|
---|
552 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
|
---|
553 | }
|
---|
554 |
|
---|
555 | void CxxExecutor::FillCompileOpt(string& copt)
|
---|
556 | {
|
---|
557 | mCompOpt = copt;
|
---|
558 | }
|
---|
559 |
|
---|
560 | string CxxExecutor::GetCompileOpt(void)
|
---|
561 | {
|
---|
562 | return mCompOpt;
|
---|
563 | }
|
---|
564 |
|
---|
565 | /* --Methode-- */
|
---|
566 | void CxxExecutor::FillLinkOpt(vector<string>& lopt)
|
---|
567 | {
|
---|
568 | mLinkOpt = "";
|
---|
569 | if(lopt.size()<1) return;
|
---|
570 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
|
---|
571 | }
|
---|
572 |
|
---|
573 | void CxxExecutor::FillLinkOpt(string& lopt)
|
---|
574 | {
|
---|
575 | mLinkOpt = lopt;
|
---|
576 | }
|
---|
577 |
|
---|
578 | string CxxExecutor::GetLinkOpt(void)
|
---|
579 | {
|
---|
580 | return mLinkOpt;
|
---|
581 | }
|
---|
582 |
|
---|
583 | /* --Methode-- */
|
---|
584 | void CxxExecutor::FillLinkLibs(vector<string>& llibs)
|
---|
585 | {
|
---|
586 | mMyLibs = "";
|
---|
587 | if(llibs.size()<1) return;
|
---|
588 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
|
---|
589 | }
|
---|
590 |
|
---|
591 | void CxxExecutor::FillLinkLibs(string& llibs)
|
---|
592 | {
|
---|
593 | mMyLibs = llibs;
|
---|
594 | }
|
---|
595 |
|
---|
596 | string CxxExecutor::GetLinkLibs(void)
|
---|
597 | {
|
---|
598 | return mMyLibs;
|
---|
599 | }
|
---|
600 |
|
---|
601 |
|
---|
602 |
|
---|
603 |
|
---|
604 | /* --Methode-- DO NOT DELETE.... cmv property !!!
|
---|
605 | int CxxExecutor::FillUserCode(vector<string>& usercode,uint_4 first)
|
---|
606 | // - first is the first position in the vector<> where the code starts
|
---|
607 | {
|
---|
608 | mUserCode.resize(0);
|
---|
609 | uint_4 nus = usercode.size();
|
---|
610 | if(nus<=first) {
|
---|
611 | cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
612 | return 1;
|
---|
613 | }
|
---|
614 | // **** 1er probleme ****
|
---|
615 | // - Pour la lisibilite et eviter les bugs avec les chaines de caracteres
|
---|
616 | // contenant des blancs, on ne casse les lignes qu'apres un ";" a condition
|
---|
617 | // qu'il ne soit pas dans une chaine de caracteres c'est a dire
|
---|
618 | // entoure de "....;....".
|
---|
619 | // - Attention aux " dans les chaines de caracteres: "...\"..."
|
---|
620 | // - Bugs non-gere pour les tortures: ".....\\" suivi par une autre
|
---|
621 | // chaine de caracteres qui contient un ';'
|
---|
622 | // ex: cout<<"aaa\\"; cout<<"blabla;blabla";
|
---|
623 | // **** 2ieme probleme ****
|
---|
624 | // - Le decodeur de ligne va couper les commentaires qui contiennent des blancs:
|
---|
625 | // "salut ca va" --> tokens[0]="salut tokens[1]=ca tokens[2]=va" --> "salutcava"
|
---|
626 | // - On contourne partiellement le pb en ajoutant un blanc en debut des tokens[]
|
---|
627 | // identifies comme etant dans une chaine de caracteres (mais impossible de gerer
|
---|
628 | // si il y a plusieurs blancs!): "salut ca va" -> "salut ca va"
|
---|
629 | // **** Conclusion ****
|
---|
630 | // Pour ecrire du code sophistique, le faire dans un fichier
|
---|
631 | string dum = "";
|
---|
632 | bool lastchar = false;
|
---|
633 | bool comment = false;
|
---|
634 | for(uint_4 i=first;i<nus;i++) {
|
---|
635 | const char* str = usercode[i].c_str();
|
---|
636 | size_t lstr= strlen(str);
|
---|
637 | for(uint_4 j=0;j<lstr;j++) {
|
---|
638 | // debut de mot dans un commentaire -> ajouter un blanc
|
---|
639 | if(j==0 && comment) dum += " ";
|
---|
640 | // on arrive sur un " : debut ou fin commentaire? inactif (\")?
|
---|
641 | if(str[j]=='"') {
|
---|
642 | if(j==0) comment = (comment) ? false: true;
|
---|
643 | else {if(str[j-1]!='\\') comment = (comment) ? false: true;}
|
---|
644 | }
|
---|
645 | dum += str[j];
|
---|
646 | if( i==nus-1 && j==lstr-1 ) lastchar = true;
|
---|
647 | // On charge la string "dum" si : 1-/ on a un ";"
|
---|
648 | // 2-/ c'est le dernier charactere
|
---|
649 | if((str[j]==';' && !comment) || lastchar)
|
---|
650 | {mUserCode.push_back(dum); dum = "";}
|
---|
651 | }
|
---|
652 | }
|
---|
653 | cout<<"User code filled from standard input"<<endl;
|
---|
654 | return 0;
|
---|
655 | }
|
---|
656 | */
|
---|
657 |
|
---|
658 |
|
---|
659 | void FillVStringFrString(string s,vector<string>& vs,char sep)
|
---|
660 | // Use string "s" to fill vector of strings "vs"
|
---|
661 | // considering char "sep" as a separator.
|
---|
662 | // Vector is filled from its end (no reset done).
|
---|
663 | // Tp write a "sep" char, use \'sep'
|
---|
664 | // Warning: separator "sep" could not be set to '\'
|
---|
665 | // Ex: sep=' ': s="aaa bbb cc d " -> vs=(aaa,bbb,cc,d)
|
---|
666 | // Ex: sep=';': s="aaa ;bbb; cc;d " -> vs=(aaa ,bbb, cc,d )
|
---|
667 | // Ex: sep=';': s=";aaa\;bbb;;;ccc;ddd" -> vs=(aaa;bbb,ccc,ddd)
|
---|
668 | // Ex: sep=';': s=";aaa\;bbb;;;ccc;ddd\" -> vs=(aaa;bbb,ccc,ddd\)
|
---|
669 | {
|
---|
670 | uint_4 ls = s.size();
|
---|
671 | if(ls<=0 || sep=='\\') return;
|
---|
672 | s += sep; // add a separator at the end
|
---|
673 | const char* str = s.c_str();
|
---|
674 | ls = strlen(str); // str[ls-1]==sep cf ci-dessus
|
---|
675 | string dum = "";
|
---|
676 | for(uint_4 i=0; i<ls; i++) {
|
---|
677 | if(i==0 && str[i]==sep) {
|
---|
678 | continue;
|
---|
679 | } else if(str[i]=='\\') {
|
---|
680 | if(str[i+1]!=sep || i==ls-2) dum += str[i];
|
---|
681 | } else if(str[i]!=sep) {
|
---|
682 | dum += str[i];
|
---|
683 | } else { // C'est un "sep" mais est-ce vraiment un separateur?
|
---|
684 | if(str[i-1]=='\\' && i!=ls-1) dum += str[i];
|
---|
685 | else { // C'est un separateur, ne delimite t-il pas d'autres separateurs?
|
---|
686 | if(dum.size()<=0) continue;
|
---|
687 | vs.push_back(dum);
|
---|
688 | dum = "";
|
---|
689 | }
|
---|
690 | }
|
---|
691 | }
|
---|
692 | }
|
---|