2010-08-09 18:24:08 +00:00
|
|
|
//
|
2011-01-14 00:22:07 +00:00
|
|
|
// Copyright 2010-2011 Ettus Research LLC
|
2010-08-09 18:24:08 +00:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <uhd/config.hpp>
|
2011-01-06 23:38:56 +00:00
|
|
|
#include <boost/tokenizer.hpp>
|
2010-08-09 18:24:08 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
#include <boost/bind.hpp>
|
2011-04-19 00:17:32 +00:00
|
|
|
#include <cstdlib>
|
2010-08-09 18:24:08 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Determine the paths separator
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
#ifdef UHD_PLATFORM_WIN32
|
|
|
|
|
static const std::string env_path_sep = ";";
|
|
|
|
|
#else
|
|
|
|
|
static const std::string env_path_sep = ":";
|
|
|
|
|
#endif /*UHD_PLATFORM_WIN32*/
|
|
|
|
|
|
2011-01-06 23:38:56 +00:00
|
|
|
#define path_tokenizer(inp) \
|
|
|
|
|
boost::tokenizer<boost::char_separator<char> > \
|
|
|
|
|
(inp, boost::char_separator<char>(env_path_sep.c_str()))
|
|
|
|
|
|
2010-08-09 18:24:08 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Get a list of paths for an environment variable
|
|
|
|
|
**********************************************************************/
|
2011-04-19 00:17:32 +00:00
|
|
|
static std::string get_env_var(const std::string &var_name, const std::string &def_val = ""){
|
|
|
|
|
const char *var_value_ptr = std::getenv(var_name.c_str());
|
|
|
|
|
return (var_value_ptr == NULL)? def_val : var_value_ptr;
|
2010-08-09 18:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::vector<fs::path> get_env_paths(const std::string &var_name){
|
|
|
|
|
|
2011-04-19 00:17:32 +00:00
|
|
|
std::string var_value = get_env_var(var_name);
|
2010-08-09 18:24:08 +00:00
|
|
|
|
|
|
|
|
//convert to filesystem path, filter blank paths
|
|
|
|
|
std::vector<fs::path> paths;
|
2011-01-26 19:27:25 +00:00
|
|
|
if (var_value.empty()) return paths; //FIXME boost tokenizer throws w/ blank strings on some platforms
|
2011-01-06 23:38:56 +00:00
|
|
|
BOOST_FOREACH(const std::string &path_string, path_tokenizer(var_value)){
|
2010-08-12 03:49:37 +00:00
|
|
|
if (path_string.empty()) continue;
|
2010-08-09 18:24:08 +00:00
|
|
|
paths.push_back(fs::system_complete(path_string));
|
|
|
|
|
}
|
|
|
|
|
return paths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Get a list of special purpose paths
|
|
|
|
|
**********************************************************************/
|
2011-04-19 00:17:32 +00:00
|
|
|
static fs::path get_uhd_pkg_data_path(void){
|
|
|
|
|
return fs::path(get_env_var("UHD_PKG_DATA_PATH", UHD_PKG_DATA_PATH));
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 18:24:08 +00:00
|
|
|
std::vector<fs::path> get_image_paths(void){
|
|
|
|
|
std::vector<fs::path> paths = get_env_paths("UHD_IMAGE_PATH");
|
2011-04-19 00:17:32 +00:00
|
|
|
paths.push_back(get_uhd_pkg_data_path() / "images");
|
2010-08-09 18:24:08 +00:00
|
|
|
return paths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<fs::path> get_module_paths(void){
|
|
|
|
|
std::vector<fs::path> paths = get_env_paths("UHD_MODULE_PATH");
|
2011-04-19 00:17:32 +00:00
|
|
|
paths.push_back(get_uhd_pkg_data_path() / "modules");
|
2010-08-09 18:24:08 +00:00
|
|
|
return paths;
|
|
|
|
|
}
|