X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkInterpreter.cxx;h=a6101a5a2881f678cc33247ad30dfa9165f0fab9;hb=3ee95453a2ba41964c9bc420cb385b024cb2a21a;hp=775ae989d66f26dc42536ddf5f30aba91bb3d055;hpb=0897431b13703ae395668c853d9932982bad55bf;p=bbtk.git diff --git a/kernel/src/bbtkInterpreter.cxx b/kernel/src/bbtkInterpreter.cxx index 775ae98..a6101a5 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/01/28 15:28:15 $ - Version: $Revision: 1.7 $ + Date: $Date: 2008/01/29 10:12:45 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -731,64 +731,128 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs // same for Windows, with c:, d: ... // + // expression like directory/subdir/scrname.bbs is FORBIDDEN (*) + // use ./directory/subdir/scrname.bbs + // + // (*) except when using packagename/boxes/* + bbtkDebugMessageInc("Interpreter",9,"Interpreter::SwitchToFile( \"" < script_paths; - std::string libname; // full path library name - std::string pkgname; // e.g. .bbs - - // Add the void path to handle absolute paths - script_paths.push_back(""); - // Add the "." path to handle paths relative to current directory - script_paths.push_back("."); - - pkgname = Utilities::ExtractScriptName(name); + std::string fullPathScriptName; // full path script name + std::string pkgname; // e.g. .bbs + if (use_configuration_file) { + // The following is *NOT* a debug time message : + // It's a user intended message. + // Please don't remove it. if (verbose) std::cout << "look for : [" << name << "] (use_configuration_file == TRUE)" << std::endl; - std::vector paths = - ConfigurationFile::GetInstance().Get_bbs_paths(); - std::vector::iterator i; - for (i=paths.begin();i!=paths.end();++i) - { - script_paths.push_back(*i); - } - + script_paths = ConfigurationFile::GetInstance().Get_bbs_paths(); } - + std::string upath; + pkgname = Utilities::ExtractScriptName(name,upath); + bool fullnameGiven = false; bool foundFile = false; + + if(pkgname == "*") // =========================================== load all boxes (e.g. std/boxes/*) + { + std::string path; + std::vector::iterator i; + std::string fullDirectoryName; + for (i=script_paths.begin();i!=script_paths.end();++i) + { + path = *i; + + // we *really* want '.' to be the current working directory + if (path == ".") { + char buf[2048]; // for getcwd + char * currentDir = getcwd(buf, 2048); + std::string cwd(currentDir); + path = currentDir; + } + + fullDirectoryName = Utilities::MakePkgnameFromPath(path, upath, false); +//std::cout <<"fullpath [" << fullDirectoryName << "]" < Filenames; + int nbFiles = Utilities::Explore(fullDirectoryName, false, Filenames); +// std::cout << "=================nbFiles " << nbFiles << std::endl; + int 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 + LoadScript(*i); + nbBssFiles++; + } + if (nbBssFiles==0) + if (verbose) + std::cout << "WARNING : No '.bbs' file found in [" << fullDirectoryName << "]" << std::endl; + + break; // a directory was found; we stop iterating + } + return; + } + std::string::size_type slash_position = name.find_last_of("/\\"); - - if (false) //slash_position != std::string::npos) - { // ------------------------------------- check user supplied location - fullnameGiven = true; - libname = Utilities::ExpandLibName(name, verbose); + // if name contains a slash (anywhere), user is assumed to have passed a relative/absolute name + // (not only a plain script name) + // we trust him, and try to explade the directory name + // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!) + + if (slash_position != std::string::npos) + { // ===========================================================check user supplied location + fullnameGiven = true; + + fullPathScriptName = Utilities::ExpandLibName(name, verbose); + // allow user to always forget ".bbs" - int l = libname.size(); - if (l>4) - { - if (libname.substr(l-4, 4) != ".bbs") + int l = fullPathScriptName.size(); + if (l!=0) { + + if (l>4) + { + if (fullPathScriptName.substr(l-4, 4) != ".bbs") { - libname = libname + ".bbs"; + fullPathScriptName = fullPathScriptName + ".bbs"; } } else { - libname = libname + ".bbs"; + fullPathScriptName = fullPathScriptName + ".bbs"; } - if (libname != "") { - if ( Utilities::FileExists(libname)) + //if (fullPathScriptName != "") { + if ( Utilities::FileExists(fullPathScriptName)) { foundFile = true; } - } + //} + } // endif l != 0 } - else // ------------------------------------- iterate on the paths + else // =============================================================== iterate on the paths { std::string path; std::vector::iterator i; @@ -804,15 +868,16 @@ verbose = true; path = currentDir; } - libname = Utilities::MakePkgnameFromPath(path, name); //pkgname); - // Check if library exists - if ( ! Utilities::FileExists(libname) ) + // fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true); //pkgname); + fullPathScriptName = Utilities::MakePkgnameFromPath(path, pkgname, 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. if (verbose) - std::cout <<" [" <open(libname.c_str()); + s->open(fullPathScriptName.c_str()); if (!s->good()) { - bbtkError("Could not open file ["<[" << libname << "] found" << std::endl; + std::cout << " -->[" << fullPathScriptName << "] found" << std::endl; mFile.push_back(s); - mFileName.push_back(libname); + mFileName.push_back(fullPathScriptName); mLine.push_back(0); - } - - - //======================================================================= - + return; + } //======================================================================= /** @@ -1186,19 +1257,18 @@ void Interpreter::Help(const std::vector& words) // empty lines are not stored in from history if (strlen(line)) { - // if history too long : delete oldest command - if (mHistory.size()>MAX_HISTORY_SIZE) - { - delete mHistory.front(); - mHistory.pop_front(); - } - mHistory.push_back(line); + // if history too long : delete oldest command + if (mHistory.size()>MAX_HISTORY_SIZE) + { + delete mHistory.front(); + mHistory.pop_front(); + } + mHistory.push_back(line); } - break; } - // Backspace - else if ( (ind>0) && + // Backspace + else if ( (ind>0) && ((c == BBTK_BACKSPACE_KBCODE) || (c == BBTK_DEL_KBCODE)) ) { @@ -1291,13 +1361,13 @@ void Interpreter::Help(const std::vector& words) PrintChar(line[ind]); ind++; } - + // Arrow left else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE) { PrintChar('\b'); ind--; - + } }