Line data Source code
1 : 2 : #include <alma/ASDM/Misc.h> 3 : 4 : #include <sys/stat.h> 5 : #include <unistd.h> 6 : #include <casacore/casa/System/AppState.h> 7 : #include <casacore/casa/OS/Path.h> 8 : 9 : using namespace std; 10 : 11 : namespace asdm { 12 : // CASA needs a unique implementation here, the ALMA implementation is not included in the CASA code tree 13 : 14 18 : string ASDMUtils::pathToxslTransform( const string& xsltFilename) { 15 : struct stat path_stat; 16 36 : string xslt_path = "alma/asdm/" + xsltFilename; 17 36 : const std::list<std::string> &state_path = casacore::AppStateSource::fetch( ).dataPath( ); 18 18 : if ( state_path.size( ) > 0 ) { 19 36 : for ( std::list<std::string>::const_iterator it=state_path.begin(); it != state_path.end(); ++it ) { 20 72 : string xslpath = casacore::Path( *it + "/" + xslt_path ).absoluteName( ); 21 36 : if ( stat(xslpath.c_str( ), &path_stat ) == 0 && S_ISREG(path_stat.st_mode) ) { 22 18 : return xslpath; 23 : } 24 : } 25 : } else { 26 : // try using CASAPATH 27 : char * casaPath_p; 28 0 : if ((casaPath_p = getenv("CASAPATH")) != 0) { 29 0 : string casaPath(casaPath_p); 30 0 : vector<string> casaPathElements; 31 0 : strsplit(casaPath, ' ', casaPathElements); 32 0 : if (casaPath.size() > 0) { 33 0 : string dataPath = casaPathElements[0]; 34 0 : if (dataPath.back()!='/') dataPath += "/"; 35 0 : string xslpath = casacore::Path( dataPath + "data/" + xslt_path ).absoluteName( ); 36 0 : if ( stat(xslpath.c_str( ), &path_stat ) == 0 && S_ISREG(path_stat.st_mode) ) { 37 0 : return xslpath; 38 : } 39 : } 40 : } 41 : } 42 : 43 0 : if (getenv("ASDM_DEBUG")) 44 0 : cout << "pathToxslTransform returns an empty xsltPath " << endl; 45 : 46 0 : return "" ; // An empty string will be interpreted as no file found. 47 : } 48 : } 49 :