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