- int nbFiles = Utilities::Explore(upath, false, Filenames);
- nbBssFiles = 0;
- for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
- {
- int lgr = (*i).size();
- if (lgr < 5)
- continue; // ignore non .bbs file
- if ((*i).substr(lgr-4, 4) != ".bbs")
- continue;
-
-printf("EED Interpreter::SwitchToFile flag01 %s \n", (*i).c_str() );
- (*stream) << "include \"" << *i << "\"\n";
-
- nbBssFiles++;
- } // for vector
- if (nbBssFiles==0){
- bbtkMessage("Interpreter",2,
- "WARNING : No '.bbs' file found in ["
- << upath << "]" << std::endl);
- } else {
- SwitchToStream(stream);
- }
- return;
- } // if upath
-
- std::string path;
- std::vector<std::string>::iterator i;
- std::string fullDirectoryName;
- for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
- {
- 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;
- } // if path
-
- fullDirectoryName = Utilities::MakePkgnameFromPath(path, upath, false);
-
- // without last slash "\"
- std::string fullDirectoryNameClean = fullDirectoryName.substr(0,fullDirectoryName.size()-1);
-
- // Check if library exists
- if ( ! Utilities::IsDirectory( fullDirectoryNameClean ) )
- {
- // The following is *NOT* a debug time message :
- // It's a user intended message.
- // Please don't remove it.
- bbtkMessage("Interpreter",1," [" <<fullDirectoryName
- <<"] : doesn't exist" <<std::endl);
- continue; // try next path
- } // if IsDirectory
- foundFile = true;
-
- Filenames.clear();
- int nbFiles = Utilities::Explore(fullDirectoryName, false, Filenames);
+ int nbBssFiles;
+
+ std::stringstream* stream = new std::stringstream;
+ //if (upath.size()!=0) // avoid troubles for "*"
+
+ // ==== no path provided : look in root bbs path
+ if (upath.size()==0)
+ {
+ // bbtkMessage("Interpreter",1,
+ script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
+ }
+ // ==== absolute path provided
+ else if (upath[0]=='/' || upath[1] == ':' )
+ {
+ script_paths.push_back(upath);
+ }
+ // ==== relative path provided : search all bbs path appended with
+ // the relative path provided
+ else
+ {
+ std::vector<std::string>::const_iterator i;
+ for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
+ i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
+ i++)
+ {
+ std::string full_path(*i);
+ full_path += ConfigurationFile::GetInstance().Get_file_separator();
+ full_path += upath;
+ script_paths.push_back(full_path);
+ }
+ }
+ // === search paths list complete : now explore it
+ bbtkMessage("Interpreter",1,
+ "'*' provided. search paths : " << std::endl);
+ /*
+ int nbFiles = Utilities::Explore(upath, false, Filenames);
+ nbBssFiles = 0;
+ for (std::vector<std::string>::iterator i = Filenames.begin();
+ i!= Filenames.end(); ++i)
+ {
+ int lgr = (*i).size();
+ if (lgr < 5)
+ continue; // ignore non .bbs file
+ if ((*i).substr(lgr-4, 4) != ".bbs")
+ continue;
+ //printf("EED Interpreter::SwitchToFile flag01 %s \n", (*i).c_str() );
+ (*stream) << "include \"" << *i << "\"\n";
+
+ nbBssFiles++;
+ } // for vector
+ if (nbBssFiles==0)
+ {
+ bbtkMessage("Interpreter",2,
+ "WARNING : No '.bbs' file found in ["
+ << upath << "]" << std::endl);
+ }
+ else
+ {
+ SwitchToStream(stream);
+ }
+ return;
+ } // if upath
+ */
+ std::string path;
+ std::vector<std::string>::iterator i;
+ std::string fullDirectoryName;
+ for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
+ {
+ path = *i;
+
+ bbtkMessage("Interpreter",1,
+ "----> '" << path << "'" << std::endl);
+ // 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;
+ } // if path
+
+ fullDirectoryName = Utilities::MakePkgnameFromPath(path, upath, false);
+
+ // without last slash "\"
+ std::string fullDirectoryNameClean = fullDirectoryName.substr(0,fullDirectoryName.size()-1);
+
+ // Check if directory exists
+ if ( ! Utilities::IsDirectory( fullDirectoryNameClean ) )
+ {
+ // The following is *NOT* a debug time message :
+ // It's a user intended message.
+ // Please don't remove it.
+ bbtkMessage("Interpreter",1," [" <<fullDirectoryName
+ <<"] : doesn't exist" <<std::endl);
+ continue; // try next path
+ } // if IsDirectory
+ foundFile = true;
+
+ Filenames.clear();
+ int nbFiles = Utilities::Explore(fullDirectoryName, false, Filenames);
+
+ nbBssFiles = 0;
+ for (std::vector<std::string>::iterator i = Filenames.begin(); i!= Filenames.end(); ++i)
+ {
+ int lgr = (*i).size();
+ if (lgr < 5)
+ continue; // ignore non .bbs file
+ if ((*i).substr(lgr-4, 4) != ".bbs")
+ continue;
+
+ // printf("EED Interpreter::SwitchToFile flag02 %s \n", (*i).c_str() );
+ (*stream) << "include \"" << *i << "\"\n";
+
+ nbBssFiles++;
+ } // for vector
+ if (nbBssFiles==0)
+ {
+ 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 !
+ } // for vector
+ return;
+ }
+ //=============== end pkgname=="*" ===========