Program: bbtk
Module: $RCSfile: bbtkInterpreter.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/11 12:27:21 $
- Version: $Revision: 1.43 $
+ Date: $Date: 2008/03/14 14:58:53 $
+ Version: $Revision: 1.44 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#endif
mCommandLine(false)
{
+bufferNb =0;
bbtk::MessageManager::RegisterMessageType("Echo","Level>0 : Prints the 'echo' commands of the user.\n\tLevel>1 : Prints the command being interpreted",1);
bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0);
bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <<std::endl);
void Interpreter::InterpretFile( const std::string& filename )
{
bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
-
+ // std::cout << "==========================================Entree InterpretFile ["<<filename<<"] try SwitchToFile "<<std::endl;
bool exm = mCommandLine;
mCommandLine = false;
try
{
SwitchToFile(filename);
- /*
- printf("EED Interpreter::InterpretFile 0001\n" );
-int ii,ssize = mFileName.size();
-for (ii=0;ii<ssize;ii++)
-{
- printf("EED RRR Interpreter::InterpretFile %s\n", mFileName[ii].c_str() );
-}
- */
+
+/*
+ for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
+ {
+ std::cout << "A=== [" << (*it) << "]" << std::endl;
+ }
+*/
bool insideComment = false; // for multiline comment
while (mFile.size()>0)
{
- //printf("EED --- %s --- Interpreter::InterpretFile \n", mFileName[0].c_str() );
- while ((mFile.size()>0) &&
- (!mFile.back()->eof()))
+/*
+ for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
{
- mLine.back()++;
+ std::cout << "B=== [" << (*it) << "]" << std::endl;
+ }
+*/
+//printf("EED --- %s --- Interpreter::InterpretFile \n", mFileName[0].c_str() );
+ //printf("EED --- %s --- Interpreter::InterpretFile \n", mFileName[0].c_str() );
+
+ //while ((mFile.size()>0) && !mFile.back()->eof() )
+ //{
+// std::cout << "mFile.size() "<< mFile.size() << " mFileName.back() [" << mFileName.back() << "]" << std::endl;
+
+ while (!mFile.back()->eof()) {
+ mLine.back()++;
char buf[500];
mFile.back()->getline(buf,500);
std::string str(buf);
+// std::cout << " in InterpretFile mFile.back()->getline [" << str << "]" << std::endl;
int size=str.length();
if ( str[ size-1 ]==13 )
{
}
InterpretLine(str, insideComment);
- //printf("EED Interpreter::InterpretFile %s\n", str.c_str() );
+
+//printf("EED Interpreter::InterpretFile %s\n", str.c_str() );
+
}
//if (mFile.size()>0)
CloseCurrentFile();
pos = s.find(ss,0);
char* cr = "\n";
while ( pos != std::string::npos )
- {
+ {
s.replace(pos,2,cr,1);
pos = s.find(ss, pos-1);
- }
+ }
}
//=======================================================================
// It's a user intended message.
// Please don't remove it.
bbtkMessage("Interpreter",1,
- "look for : [" << name
- << "]" << std::endl);
+ "look for : [" << name
+ << "]" << std::endl);
script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
std::string upath;
pkgname = Utilities::ExtractScriptName(name,upath);
+ bbtkMessage("Interpreter",1,
+ "extract : pkgname [" << pkgname
+ << "] upath [" << upath << "]" << std::endl);
bool fullnameGiven = false;
bool foundFile = false;
if(pkgname == "*") // =========================================== load all boxes (e.g. std/boxes/*)
{
+// std::cout << "JPR================== * found, load all boxes " << std::endl;
int nbBssFiles;
+ std::stringstream* stream = new std::stringstream;
+ //if (upath.size()!=0) // avoid troubles for "*"
+
if (upath[0]=='/' || upath[1] == ':' ) // ==== absolute name, load all .bbs files
{
+// std::cout << "JPR================== absolute name, load all .bbs files " << std::endl;
int nbFiles = Utilities::Explore(upath, false, Filenames);
nbBssFiles = 0;
for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
{
- if ((*i).substr((*i).size()-4, 4) != ".bbs")
- continue; // ignore non .bbs files
- std::string command("include ");
- command += *i;
- // LoadScript(*i,name);
- bool tmp;
- InterpretLine(command,tmp);
+// std::cout << "JPR================== iterate [" << *i << "]" << std::endl;
+ int lgr = (*i).size();
+ if (lgr < 5)
+ continue; // ignore non .bbs file
+ if ((*i).substr(lgr-4, 4) != ".bbs")
+ continue;
+ /*
+ if (lgr > 10) // 10 -> '-appli.bbs'
+ {
+ if ((*i).substr(lgr-10, 10) == "-appli.bbs")
+ continue; // ignore '-appli.bbs' files
+ }
+ */
+ (*stream) << "include " << *i << "\n";
nbBssFiles++;
}
if (nbBssFiles==0)
bbtkMessage("Interpreter",2,
"WARNING : No '.bbs' file found in ["
<< upath << "]" << std::endl);
+ else
+ SwitchToStream(stream);
return;
}
// The following is *NOT* a debug time message :
// It's a user intended message.
// Please don't remove it.
- bbtkMessage("Interpreter",1," [" <<fullDirectoryName
+ bbtkMessage("Interpreter",1," [" <<fullDirectoryName
<<"] : doesn't exist" <<std::endl);
continue; // try next path
}
foundFile = true;
- Filenames.clear();
+ Filenames.clear();
int nbFiles = Utilities::Explore(fullDirectoryName, false, Filenames);
nbBssFiles = 0;
for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
{
//EEDprintf("EED Interpreter::SwitchToFile %s\n",(*i).c_str() );
- if ((*i).substr((*i).size()-4, 4) != ".bbs")
- continue; // ignore non .bbs files
- std::string command("include ");
- command += *i;
- bool tmp;
- InterpretLine(command,tmp);
- // LoadScript(*i,name);
+// std::cout << "JPR================== iterate [" << *i << "]" << std::endl;
+ int lgr = (*i).size();
+ if (lgr < 5)
+ continue; // ignore non .bbs file
+ if ((*i).substr(lgr-4, 4) != ".bbs")
+ continue;
+ /*
+ if (lgr > 10) // 10 -> '-appli.bbs'
+ {
+ if ((*i).substr(lgr-10, 10) == "-appli.bbs")
+ continue; // ignore '-appli.bbs' files
+ }
+ */
+ (*stream) << "include " << *i << "\n";
nbBssFiles++;
}
if (nbBssFiles==0)
- bbtkMessage("Interpreter",1,
+ bbtkMessage("Interpreter",1,
"WARNING : No '.bbs' file found in ["
<< fullDirectoryName << "]" << std::endl);
+ else
+ SwitchToStream(stream);
//break; // a directory was found; we stop iterating
// LG : No! We want all files included !
int l = fullPathScriptName.size();
if (l!=0) {
-
+
if (l>4)
{
if (fullPathScriptName.substr(l-4, 4) != ".bbs")
fullPathScriptName = fullPathScriptName + ".bbs";
}
- if ( Utilities::FileExists(fullPathScriptName))
- {
- foundFile = true;
- }
- } // endif l != 0
- }
- else
-
- // =============================================================== iterate on the paths
+ if ( Utilities::FileExists(fullPathScriptName))
{
+ foundFile = true;
+ }
+ } // endif l != 0
+ }
+ else
+ // =============================================================== iterate on the paths
+ {
std::string path;
std::vector<std::string>::iterator i;
for (i=script_paths.begin();i!=script_paths.end();++i)
{
-
path = *i;
// we *really* want '.' to be the current working directory
if (path == ".") {
path = currentDir;
}
- // fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true); //pkgname);
-
- fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
-
+ fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
// Check if library exists
if ( ! Utilities::FileExists(fullPathScriptName) )
// The following is *NOT* a debug time message :
// It's a user intended message.
// Please don't remove it.
- bbtkMessage("Interpreter",2,
+ bbtkMessage("Interpreter",2,
" [" <<fullPathScriptName <<"] : doesn't exist"
<<std::endl);
continue; // try next path
}
- bbtkMessage("Interpreter",2,
+ bbtkMessage("Interpreter",2,
" [" <<fullPathScriptName
<<"] : found" <<std::endl);
foundFile = true;
}
+void Interpreter::SwitchToStream( std::stringstream* stream )
+{
+//std::cout << "== 1 Entry in Interpreter::SwitchToStream " << std::endl;
+ mFile.push_back(stream);
+ //std::cout << " mFile.size() " << mFile.size() << std::endl;
+ std::ostringstream buffer_name;
+ bufferNb++;
+ buffer_name << "buffer_" ; // << bufferNb;
+
+// std::cout << " mFile.size() " << mFile.size() << std::endl;
+// std::cout << " mFileName.size() " << mFileName.size() << std::endl;
+// std::cout << " mLine.size() " << mLine.size() << std::endl;
+ // std::vector<std::string>::iterator j = mFileName.begin();
+ // std::cout << " mFileName.begin() succeeded" << std::endl;
+ // std::cout << " mFileName[0] " << mFileName[0] << std::endl;
+ //std::cout << " mFileName.begin() " << mFileName.begin() << std::endl;
+/*
+ for( std::vector<std::string>::iterator i = mFileName.begin(); i!= mFileName.end(); ++i)
+ {
+
+ std::cout << "Interpreter::SwitchToStream : mFileName [" << *i << "]" << std::endl;
+ }
+*/
+ // std::cout << " mLine.back() " << mLine.back() << std::endl;
+ // std::cout << " mFileName.back() " << mFileName.back() << std::endl;
+
+ if (mFileName.size()>0 )// && (mFile.size()>0) ) // NO!!!
+ {
+ // std::cout << " mFileName.back() " << mFileName.back() << std::endl;
+ // std::cout << " mLine.back() " << mLine.back() << std::endl;
+ buffer_name << mFileName.back() << "_" << mLine.back();
+ }
+//std::cout << "3 in Interpreter::SwitchToStream buffer_name :[" << buffer_name.str() << "]" << std::endl;
+ mFileName.push_back(buffer_name.str());
+ mIncludeFileName.push_back(buffer_name.str());
+ mLine.push_back(0);
+}
+
//=======================================================================
void Interpreter::LoadScript( std::string fullPathScriptName,
std::string includeScriptName)
{
-//EED printf("EED Interpreter::LoadScript >>01\n");
- Utilities::replace( fullPathScriptName , INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
+//std::cout << "--------------------------EED Interpreter::LoadScript >>01\n" << std::endl;
+ Utilities::replace( fullPathScriptName , INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
- bool okScriptExist=false;
- int iStrScript,sizeVecStricpt=mFileName.size();
- for ( iStrScript=0;iStrScript<sizeVecStricpt;iStrScript++)
- {
+ bool okScriptExist=false;
+ int iStrScript,sizeVecStricpt=mFileName.size();
+ for ( iStrScript=0;iStrScript<sizeVecStricpt;iStrScript++)
+ {
//EED printf(" EED %d Interpreter::LoadScript %s __>>__ %s\n", iStrScript,mFileName[iStrScript].c_str(),fullPathScriptName.c_str() );
- if (mFileName[iStrScript] == fullPathScriptName )
- {
- // printf(" EED %d Interpreter::LoadScript iguales\n",iStrScript );
- okScriptExist=true;
- } // if
- } // for
-
- if (find(mFileName.begin(),mFileName.end(),fullPathScriptName)!=mFileName.end())
-// if (okScriptExist==true)
- {
+
+ if (mFileName[iStrScript] == fullPathScriptName )
+ {
+ printf(" EED %d Interpreter::LoadScript iguales\n",iStrScript );
+ okScriptExist=true;
+ } // if
+ } // for
+
+ if (find(mFileName.begin(),mFileName.end(),fullPathScriptName)!=mFileName.end())
+// if (okScriptExist==true)
+ {
//EED printf("EED Interpreter::LoadScript Exit method\n");
- bbtkMessage("Interpreter",1,"file '"<<fullPathScriptName
+ bbtkMessage("Interpreter",1,"file '"<<fullPathScriptName
<<"' already open : I do not open it once more to prevent recursive inclusion"<<std::endl);
- return;
- }
+ return;
+ }
std::ifstream* s;
s = new std::ifstream;
s->open(fullPathScriptName.c_str());
- if (!s->good())
+ if (!s->good())
{
bbtkError("Could not open file ["<<fullPathScriptName<<"]");
return;
}
bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
- mFile.back()->close();
+
+ std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
+ if (file!=0) file->close();
+
delete mFile.back();
mFile.pop_back();
mFileName.pop_back();
mIncludeFileName.pop_back();
- mLine.pop_back();
+ mLine.pop_back();
/*EED3
- bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName[0]<<"'"<<std::endl);
- mFile[0]->close();
+ bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName[0]<<"'"<<std::endl);
+ mFile[0]->close();
delete mFile[0];
mFile.erase( mFile.begin() );
- mFileName.erase( mFileName.begin() );
+ mFileName.erase( mFileName.begin() );
mIncludeFileName.erase( mIncludeFileName.begin() );
mLine.erase( mLine.begin() );
*/
while (mFile.size() != 0)
{
+ CloseCurrentFile();
+ /*
mFile.back()->close();
delete mFile.back();
mFile.pop_back();
mFileName.pop_back();
mIncludeFileName.pop_back();
mLine.pop_back();
+*/
}
bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
<<std::endl);
Program: bbtk
Module: $RCSfile: bbtkWxConsole.cxx,v $
Language: C++
- Date: $Date: 2008/03/11 12:27:21 $
- Version: $Revision: 1.12 $
+ Date: $Date: 2008/03/14 14:58:53 $
+ Version: $Revision: 1.13 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
namespace bbtk
{
-
// On Windows when compiling a dll, wx prevents the compilation
// of the class wxStreamToTextRedirector (why ? it is a nightmare...)
// The blocking symbol is wxHAS_TEXT_WINDOW_STREAM.
//EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
// mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
mwxNotebook = new wxAuiNotebook(this,
- -1,
- wxPoint(0, 0),
- wxSize(500,500),
- wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
+ -1,
+ wxPoint(0, 0),
+ wxSize(500,500),
+ wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
mwxPageCommand = new wxPanel(mwxNotebook,-1);
mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
mwxTextHistory =
new wxTextCtrl(mwxPageCommand,
- ID_Text_History,
- _T(""),wxDefaultPosition,
- wxDefaultSize, //HistorySize,
- wxTE_READONLY |
- wxTE_MULTILINE );
+ ID_Text_History,
+ _T(""),wxDefaultPosition,
+ wxDefaultSize, //HistorySize,
+ wxTE_READONLY |
+ wxTE_MULTILINE );
wxFont* FixedFont = new wxFont(10,
- wxFONTFAMILY_MODERN,
- wxFONTSTYLE_NORMAL,
- wxFONTWEIGHT_NORMAL,
- false);
+ wxFONTFAMILY_MODERN,
+ wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL,
+ false);
mwxTextHistoryAttr = new wxTextAttr;
mwxTextHistoryAttr->SetFont(*FixedFont);
// wxDefaultPosition,
// wxSize(0,0),
// wxFRAME_TOOL_WINDOW) ;//wxMINIMIZE_BOX);
-
+
Wx::SetTopWindow(top);
// top->Show();
try
{
bool insideComment = false;
- //printf("WxConsole::CommandString 04 \n");
- mInterpreter->InterpretLine( wx2std(line), insideComment );
- //printf("WxConsole::CommandString 05 \n");
+
+printf("WxConsole::CommandString 04 \n");
+ mInterpreter->InterpretLine( wx2std(line), insideComment );
+printf("WxConsole::CommandString 05 \n");
}
catch (bbtk::QuitException)
{
- Close(true);
+ Close(true);
}
catch (bbtk::Exception e)
{
- e.Print();
+ e.Print();
}
catch (std::exception& e)
{
- std::cout << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
+ std::cout << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
}
catch (...)
{
- std::cout << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
- << std::endl;
+ std::cout << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
+ << std::endl;
}
//printf("WxConsole::CommandString 06 \n");
}
{
wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2007"),
- _T("About ..."), wxOK | wxICON_INFORMATION,
- this);
+ _T("About ..."), wxOK | wxICON_INFORMATION,
+ this);
}
//================================================================
{
wxMessageBox(_T(" Creating blackbox"),
- _T("Creating blackbox ..."), wxOK | wxICON_INFORMATION,
- this);
+ _T("Creating blackbox ..."), wxOK | wxICON_INFORMATION,
+ this);
}
//================================================================
}
else
{
- // std::cout << "ERROR html"<<std::endl;
+ // std::cout << "ERROR html"<<std::endl;
}
}
//================================================================
wxPanel* WxConsole::CreateBtnsCtrlPanel(wxWindow *parent)
{
- wxPanel *btnsCtrlPanel = new wxPanel(parent,-1);
- wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL);
-
- wxButton *btnInclude = new wxButton( btnsCtrlPanel,-1,_T("Include") );
- wxButton *btnReset = new wxButton( btnsCtrlPanel,-1,_T("Reset") );
- wxButton *btnConfig = new wxButton( btnsCtrlPanel,-1,_T("Config") );
- wxButton *btnGraphS = new wxButton( btnsCtrlPanel,-1,_T("Graph S.") );
- wxButton *btnGraphD = new wxButton( btnsCtrlPanel,-1,_T("Graph D.") );
- wxButton *btnHelp = new wxButton( btnsCtrlPanel,-1,_T("Help") );
+ wxPanel *btnsCtrlPanel = new wxPanel(parent,-1);
+ wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL);
- btnsSizer->Add( btnInclude );
- btnsSizer->Add( btnReset );
- btnsSizer->Add( btnConfig );
- btnsSizer->Add( btnGraphS );
- btnsSizer->Add( btnGraphD );
- btnsSizer->Add( btnHelp );
- btnsCtrlPanel->SetSizer(btnsSizer);
+ wxButton *btnInclude = new wxButton( btnsCtrlPanel,-1,_T("Include") );
+ wxButton *btnReset = new wxButton( btnsCtrlPanel,-1,_T("Reset") );
+ wxButton *btnConfig = new wxButton( btnsCtrlPanel,-1,_T("Config") );
+ wxButton *btnGraphS = new wxButton( btnsCtrlPanel,-1,_T("Graph S.") );
+ wxButton *btnGraphD = new wxButton( btnsCtrlPanel,-1,_T("Graph D.") );
+ wxButton *btnHelp = new wxButton( btnsCtrlPanel,-1,_T("Help") );
Connect(btnInclude->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxConsole::OnBtnInclude );
Connect(btnReset->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxConsole::OnBtnReset );
//================================================================
void WxConsole::OnBtnInclude(wxCommandEvent& event)
{
- std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
- std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
- wxString defaultDir(stdDir.c_str(), wxConvUTF8);
-
- wxFileDialog dialog(this, _T("Choose a file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
- if (dialog.ShowModal() == wxID_OK)
- {
-// std::string command(_T("include "));
-// std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
- wxString command(_T("include "));
- wxString pathfilename = dialog.GetPath();
- command += pathfilename;
- CommandString( command );
- }
+ std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
+ std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
+ wxString defaultDir(stdDir.c_str(), wxConvUTF8);
+
+ wxFileDialog dialog(this, _T("Choose a file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
+ if (dialog.ShowModal() == wxID_OK)
+ {
+ // std::string command(_T("include "));
+ // std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
+ wxString command(_T("include "));
+ wxString pathfilename = dialog.GetPath();
+ command += pathfilename;
+ CommandString( command );
+ }
}
//================================================================
void WxConsole::OnBtnReset(wxCommandEvent& event)
{
printf("WxConsole::OnBtnReset 01 \n");
- CommandString(_T("reset"));
+ CommandString(_T("reset"));
printf("WxConsole::OnBtnReset 02 \n");
}
//================================================================
//================================================================
void WxConsole::OnBtnConfig(wxCommandEvent& event)
{
- CommandString(_T("config"));
+ CommandString(_T("config"));
}
//================================================================
//================================================================
void WxConsole::OnBtnGraphS(wxCommandEvent& event)
{
- CommandString(_T("graph"));
+ CommandString(_T("graph"));
}
//================================================================
//================================================================
void WxConsole::OnBtnGraphD(wxCommandEvent& event)
{
- CommandString(_T("graph . 1"));
+ CommandString(_T("graph . 1"));
}
//================================================================
//================================================================
void WxConsole::OnBtnHelp(wxCommandEvent& event)
{
- CommandString(_T("help"));
+ CommandString(_T("help"));
}
//================================================================