source: Sophya/trunk/SophyaPI/PIext/cxxexecutor.cc@ 1262

Last change on this file since 1262 was 1262, checked in by ercodmgr, 25 years ago

Reorganisation classe PIACmd (interpreteur de piapp) - Utilisation des services de NameObjMgr pour les variables de l'interpreteur - Reza 27/10/2000

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