// // $Id: ObsFileFinder.cpp,v 1.1 2001/10/24 14:46:58 greenlee Exp $ // // File: ObsFileFinder.cpp // Purpose: Implementation for ObsFileFinder package class. // Created: 23-Oct-2001 Herb Greenlee // // $Revision: 1.1 $ // // // Include files #include #include #include "gtrbase/ObsFileFinder.hpp" using std::string; using std::ifstream; using std::cout; using std::endl; //********************************************************************** // Static data. //********************************************************************** char* ObsFileFinder::_package_dirs[] = {"cft_obs/dat", "smt_path/dat", "gtrprop/dat", "gtr_find/dat", 0}; //********************************************************************** // Local methods. //********************************************************************** namespace { bool exist_file(const string& name) { ifstream file(name.c_str()); bool result = file.good() && file.is_open(); return result; } } //********************************************************************** // Static methods //********************************************************************** string ObsFileFinder::find(const string& obsname) { // If obsname is already an absolute path, do nothing. if(obsname[0] == '/') return obsname; // Check if obsname is accessible as is (i.e. it is in current directory). if(exist_file(obsname)) return obsname; // File not found in current directory. cout << obsname << " -> "; // Search private test release packages (if defined). const char* srt_dir = getenv("SRT_PRIVATE_CONTEXT"); if(srt_dir != 0 && *srt_dir != 0) { // Loop over packages. string base(srt_dir); for(char** s = &_package_dirs[0]; *s != 0; ++s) { string file = base + '/' + string(*s) + '/' + obsname; if(exist_file(file)) { cout << file << endl; return file; } } } // Search public release packages. srt_dir = getenv("SRT_PUBLIC_CONTEXT"); if(srt_dir != 0 && *srt_dir != 0) { // Loop over packages. string base(srt_dir); for(char** s = &_package_dirs[0]; *s != 0; ++s) { string file = base + '/' + string(*s) + '/' + obsname; if(exist_file(file)) { cout << file << endl; return file; } } } // Still didn't find it? cout << "(not found)" << endl; return obsname; }