From b253812964e57b9592fe64bb3bc97f2aac72d3a7 Mon Sep 17 00:00:00 2001 From: jean-pierre roux Date: Fri, 14 Mar 2008 14:58:53 +0000 Subject: [PATCH] Final (?) fix of "include *" pb --- kernel/src/bbtkInterpreter.cxx | 237 ++++++++++++++++++++++----------- kernel/src/bbtkInterpreter.h | 15 ++- kernel/src/bbtkWxConsole.cxx | 122 ++++++++--------- 3 files changed, 223 insertions(+), 151 deletions(-) diff --git a/kernel/src/bbtkInterpreter.cxx b/kernel/src/bbtkInterpreter.cxx index d791462..22bd9fb 100644 --- a/kernel/src/bbtkInterpreter.cxx +++ b/kernel/src/bbtkInterpreter.cxx @@ -3,8 +3,8 @@ 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 @@ -50,6 +50,7 @@ namespace bbtk #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()" <::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::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 ) { @@ -339,7 +350,9 @@ for (ii=0;ii0) CloseCurrentFile(); @@ -670,10 +683,10 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& 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); - } + } } //======================================================================= @@ -782,39 +795,56 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // 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::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; } @@ -845,32 +875,41 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // The following is *NOT* a debug time message : // It's a user intended message. // Please don't remove it. - bbtkMessage("Interpreter",1," [" <::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 ! @@ -897,7 +936,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& int l = fullPathScriptName.size(); if (l!=0) { - + if (l>4) { if (fullPathScriptName.substr(l-4, 4) != ".bbs") @@ -910,21 +949,19 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& 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::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 == ".") { @@ -934,10 +971,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& 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) ) @@ -945,12 +979,12 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // 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, " [" <& } +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::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::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>__ %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 '"<open(fullPathScriptName.c_str()); - if (!s->good()) + if (!s->good()) { bbtkError("Could not open file ["<& } bbtkDebugMessage("Interpreter",9," Closing file '"<close(); + + std::ifstream* file = dynamic_cast(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 '"<close(); + bbtkDebugMessage("Interpreter",9," Closing file '"<close(); delete mFile[0]; mFile.erase( mFile.begin() ); - mFileName.erase( mFileName.begin() ); + mFileName.erase( mFileName.begin() ); mIncludeFileName.erase( mIncludeFileName.begin() ); mLine.erase( mLine.begin() ); */ @@ -1077,6 +1153,8 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& while (mFile.size() != 0) { + CloseCurrentFile(); + /* mFile.back()->close(); delete mFile.back(); mFile.pop_back(); @@ -1085,6 +1163,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& mFileName.pop_back(); mIncludeFileName.pop_back(); mLine.pop_back(); +*/ } bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()" < mFile; + /// Vector of open files / buffers (can be stringstream) + std::vector mFile; /// Vector of names of open files with full path (as open) std::vector mFileName; @@ -223,13 +226,11 @@ namespace bbtk /// The history of commands std::deque< char* > mHistory; + int bufferNb; }; // EO class Interpreter - - - // The "Quit" exception struct QuitException : public bbtk::Exception { diff --git a/kernel/src/bbtkWxConsole.cxx b/kernel/src/bbtkWxConsole.cxx index 45e1581..a218586 100644 --- a/kernel/src/bbtkWxConsole.cxx +++ b/kernel/src/bbtkWxConsole.cxx @@ -3,8 +3,8 @@ 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 @@ -40,7 +40,6 @@ 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. @@ -197,10 +196,10 @@ namespace bbtk //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")); @@ -242,17 +241,17 @@ namespace bbtk 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); @@ -336,7 +335,7 @@ namespace bbtk // wxDefaultPosition, // wxSize(0,0), // wxFRAME_TOOL_WINDOW) ;//wxMINIMIZE_BOX); - + Wx::SetTopWindow(top); // top->Show(); @@ -398,26 +397,27 @@ namespace bbtk 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 : "<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 ); @@ -570,20 +562,20 @@ namespace bbtk //================================================================ 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 ); + } } //================================================================ @@ -593,7 +585,7 @@ namespace bbtk void WxConsole::OnBtnReset(wxCommandEvent& event) { printf("WxConsole::OnBtnReset 01 \n"); - CommandString(_T("reset")); + CommandString(_T("reset")); printf("WxConsole::OnBtnReset 02 \n"); } //================================================================ @@ -602,7 +594,7 @@ printf("WxConsole::OnBtnReset 02 \n"); //================================================================ void WxConsole::OnBtnConfig(wxCommandEvent& event) { - CommandString(_T("config")); + CommandString(_T("config")); } //================================================================ @@ -611,21 +603,21 @@ printf("WxConsole::OnBtnReset 02 \n"); //================================================================ 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")); } //================================================================ -- 2.46.0