Exemplo n.º 1
0
std::string
translation_c::get_default_ui_locale() {
  std::string locale;

#if defined(HAVE_LIBINTL_H)
# if defined(SYS_WINDOWS)
  std::string env_var = get_environment_variable("LC_MESSAGES");
  if (!env_var.empty() && (-1 != look_up_translation(env_var)))
    return env_var;

  env_var = get_environment_variable("LANG");
  if (!env_var.empty() && (-1 != look_up_translation(env_var)))
    return env_var;

  char *data;
  int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, NULL, 0);
  if (0 < len) {
    data = (char *)safemalloc(len);
    memset(data, 0, len);
    if (0 != GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, data, len))
      locale = data;
    safefree(data);

    int idx = translation_c::look_up_translation(locale);
    if (-1 != idx)
      locale = ms_available_translations[idx].get_locale();
  }

# else  // SYS_WINDOWS

  char *data = setlocale(LC_MESSAGES, NULL);
  if (NULL != data) {
    std::string previous_locale = data;
    if (debugging_requested("locale"))
      mxinfo(boost::format("[get_default_ui_locale previous %1%]\n") % previous_locale);
    setlocale(LC_MESSAGES, "");
    data = setlocale(LC_MESSAGES, NULL);

    if (NULL != data)
      locale = data;

    if (debugging_requested("locale"))
      mxinfo(boost::format("[get_default_ui_locale new %1%]\n") % locale);

    setlocale(LC_MESSAGES, previous_locale.c_str());
  } else if (debugging_requested("locale"))
    mxinfo(boost::format("[get_default_ui_locale get previous failed]\n"));

# endif // SYS_WINDOWS
#endif  // HAVE_LIBINTL_H

  return locale;
}
Exemplo n.º 2
0
//@todo throw meaningful exceptions, handle exceptions
std::string parse_cgi::get_url_encoded_string_via_post()
{
  try
  {
    //no need to ask twice...
    size_t content_length = std::atoi(get_environment_variable("CONTENT_LENGTH").c_str());

    //we need to store our c_str because the std::string constructor is bad
    //we're going to abuse unique_ptr a little here...
    std::unique_ptr<char> c_str(new char[content_length+1]);

    //read content_length characters from stdin
    std::cin.read(&(*c_str), content_length);
    //make it a c_str
    (&(*c_str))[content_length] = '\0';

    //return our newly found data
    return std::string(&(*c_str));
  }
  catch(const std::exception &e)
  {
    //somebody else's problem...
    throw;
  }
}
Exemplo n.º 3
0
//@todo throw meaningful exceptions, handle exceptions
std::string parse_cgi::get_url_encoded_string()
{
  try
  {
    //how did we get the data?
    std::string request_method = get_environment_variable("REQUEST_METHOD");

    //was the data sent to us via GET?
    if(request_method == "GET")
    {
      return get_url_encoded_string_via_get();
    }
    //was the data sent to us via POST?
    else if(request_method == "POST")
    {
      return get_url_encoded_string_via_post();
    }
    //in case we decided to support HEAD
    else if(request_method == "HEAD")
    {
      return get_url_encoded_string_via_head();
    }
    //we tried :(
    else
    {
      throw std::runtime_error("REQUEST_METHOD has an invalid value of "+request_method);
    }
  }
  catch(const std::exception &e)
  {
    //somebody else's problem...
    throw;
  }
}
Exemplo n.º 4
0
	PathString get_user_application_directory(const char* application_data_path)
	{
		PathString result = get_environment_variable("LOCALAPPDATA");
		result.append(PATH_SEPARATOR_STRING);
		result.append(application_data_path);
		result.normalize(PATH_SEPARATOR);
		return result;
	}
Exemplo n.º 5
0
//@todo throw meaningful exceptions, handle exceptions
std::string parse_cgi::get_url_encoded_string_via_get()
{
  try
  {
    //our url-encoded data is in the environment variable QUERY_STRING
    return get_environment_variable("QUERY_STRING");
  }
  catch(const std::exception &e)
  {
    //somebody else's problem...
    throw;
  }
}
Exemplo n.º 6
0
		bool amptest_context_t::get_environment_variable(const std::string& name, bool default_value) const {
			std::string val_str = get_environment_variable(name);

			if(val_str.empty()) {
				return default_value;
			} else if(val_str == "1" || val_str == "true" || val_str == "TRUE") {
				return true;
			} else if(val_str == "0" || val_str == "false" || val_str == "FALSE") {
				return false;
			}

			// Unknown value, throw exception and exit
            std::stringstream ss;
			ss << "Environment variable " << name << " has invalid bool value '" << val_str << "'. Accepted values: 1,0,true,TRUE,false,FALSE.";
			std::string errmsg = ss.str();
			throw amptest_exception(errmsg.c_str());
		}
Exemplo n.º 7
0
static void load_font_from_system(font_asset* font) {
#if NE_PLATFORM_WINDOWS
	std::string path = get_environment_variable("WINDIR") + "\\Fonts\\" + font->path;
#else
# error No cross-platform compatible code available.
#endif
	if (!file_exists(path)) {
		DEBUG(0, NE_WARNING, "Font \"" << path << "\" does not exist.");
		return;
	}
	TTF_Font* TTF = TTF_OpenFont(path.c_str(), font->size);
	if (!TTF) {
		DEBUG(0, NE_WARNING, "Font \"" << path << "\" failed to load.");
		return;
	}
	TTF_SetFontKerning(TTF, 1);
	font->resource_handle = TTF;
}
Exemplo n.º 8
0
Arquivo: os.cpp Projeto: ardeujho/self
// expand ~/asfd/wert/sd or ~user/wer/wer/sdf
// out is OS::max_path_length long
// returns NULL if successful; otherwise returns an error string
char* OS::expand_unix_dir(const char* in,  char* out) {
  static char err[max_path_length + 50];
  char* dirName = (char*) "";
  
  if (*in != '~') {
    if (strlen(in) >= max_path_length) {
      sprintf(err, "'%s' exceeds %d chars in length", in, max_path_length);
      return err;
    }
    strcpy(out, in);
    return NULL;
  }
  
  // slash is location of slash after user name
  const char* slash = strchr(in, '/');  
  if (slash == NULL)  
    slash = in + strlen(in);
  
  if (in + 1  ==  slash) {
    // ~/ use HOME
    char* p = get_environment_variable("HOME");
    if (p)
      dirName = p;
  } 
  else if (!expand_user_name(in, slash, dirName)) {
    return dirName; // really an error, here
  }
  
  if (strlen(dirName) + strlen(slash)  >=  max_path_length) {
    sprintf(err, "'%s%s' exceeds %d characters in length",
            dirName, slash, max_path_length);
    return err;
  }
  sprintf(out, "%s%s", dirName, slash);
  return NULL;
}
Exemplo n.º 9
0
		bool amptest_context_t::is_buffer_aliasing_forced() const {
		
			return get_environment_variable("CPPAMP_FORCE_ALIASED_SHADER", false);			
		}
Exemplo n.º 10
0
std::string determineHost()
{
  std::string ip_env;
  // First, did the user set ROS_HOSTNAME?
  if ( get_environment_variable(ip_env, "ROS_HOSTNAME")) {
    ROSCPP_LOG_DEBUG( "determineIP: using value of ROS_HOSTNAME:%s:", ip_env.c_str());
    return ip_env;
  }

  // Second, did the user set ROS_IP?
  if ( get_environment_variable(ip_env, "ROS_IP")) {
    ROSCPP_LOG_DEBUG( "determineIP: using value of ROS_IP:%s:", ip_env.c_str());
    return ip_env;
  }

  // Third, try the hostname
  char host[1024];
  memset(host,0,sizeof(host));
  if(gethostname(host,sizeof(host)-1) != 0)
  {
    ROS_ERROR("determineIP: gethostname failed");
  }
  // We don't want localhost to be our ip
  else if(strlen(host) && strcmp("localhost", host))
  {
    return std::string(host);
  }

  // Fourth, fall back on interface search, which will yield an IP address

#ifdef HAVE_IFADDRS_H
  struct ifaddrs *ifa = NULL, *ifp = NULL;
  int rc;
  if ((rc = getifaddrs(&ifp)) < 0)
  {
    ROS_FATAL("error in getifaddrs: [%s]", strerror(rc));
    ROS_BREAK();
  }
  char preferred_ip[200] = {0};
  for (ifa = ifp; ifa; ifa = ifa->ifa_next)
  {
    char ip_[200];
    socklen_t salen;
    if (!ifa->ifa_addr)
      continue; // evidently this interface has no ip address
    if (ifa->ifa_addr->sa_family == AF_INET)
      salen = sizeof(struct sockaddr_in);
    else if (ifa->ifa_addr->sa_family == AF_INET6)
      salen = sizeof(struct sockaddr_in6);
    else
      continue;
    if (getnameinfo(ifa->ifa_addr, salen, ip_, sizeof(ip_), NULL, 0,
                    NI_NUMERICHOST) < 0)
    {
      ROSCPP_LOG_DEBUG( "getnameinfo couldn't get the ip of interface [%s]", ifa->ifa_name);
      continue;
    }
    //ROS_INFO( "ip of interface [%s] is [%s]", ifa->ifa_name, ip);
    // prefer non-private IPs over private IPs
    if (!strcmp("127.0.0.1", ip_) || strchr(ip_,':'))
      continue; // ignore loopback unless we have no other choice
    if (ifa->ifa_addr->sa_family == AF_INET6 && !preferred_ip[0])
      strcpy(preferred_ip, ip_);
    else if (isPrivateIP(ip_) && !preferred_ip[0])
      strcpy(preferred_ip, ip_);
    else if (!isPrivateIP(ip_) &&
             (isPrivateIP(preferred_ip) || !preferred_ip[0]))
      strcpy(preferred_ip, ip_);
  }
  freeifaddrs(ifp);
  if (!preferred_ip[0])
  {
    ROS_ERROR( "Couldn't find a preferred IP via the getifaddrs() call; I'm assuming that your IP "
        "address is 127.0.0.1.  This should work for local processes, "
        "but will almost certainly not work if you have remote processes."
        "Report to the ROS development team to seek a fix.");
    return std::string("127.0.0.1");
  }
  ROSCPP_LOG_DEBUG( "preferred IP is guessed to be %s", preferred_ip);
  return std::string(preferred_ip);
#else
  // @todo Fix IP determination in the case where getifaddrs() isn't
  // available.
  ROS_ERROR( "You don't have the getifaddrs() call; I'm assuming that your IP "
             "address is 127.0.0.1.  This should work for local processes, "
             "but will almost certainly not work if you have remote processes."
             "Report to the ROS development team to seek a fix.");
  return std::string("127.0.0.1");
#endif
}
Exemplo n.º 11
0
void init(const M_string& remappings)
{
  std::string log_file_name;
  M_string::const_iterator it = remappings.find("__log");
  if (it != remappings.end())
  {
    log_file_name = it->second;
  }

  {
    // Log filename can be specified on the command line through __log
    // If it's been set, don't create our own name
    if (log_file_name.empty())
    {
      // Setup the logfile appender
      // Can't do this in rosconsole because the node name is not known
      pid_t pid = getpid();
      std::string ros_log_env;
      if ( get_environment_variable(ros_log_env, "ROS_LOG_DIR"))
      {
        log_file_name = ros_log_env + std::string("/");
      }
      else
      {
        if ( get_environment_variable(ros_log_env, "ROS_HOME"))
        {
          log_file_name = ros_log_env + std::string("/log/");
        }
        else
        {
          // Not cross-platform?
          if( get_environment_variable(ros_log_env, "HOME") )
          {
            std::string dotros = ros_log_env + std::string("/.ros/");
            fs::create_directory(dotros);
            log_file_name = dotros + "log/";
            fs::create_directory(log_file_name);
          }
        }
      }

      // sanitize the node name and tack it to the filename
      for (size_t i = 1; i < this_node::getName().length(); i++)
      {
        if (!isalnum(this_node::getName()[i]))
        {
          log_file_name += '_';
        }
        else
        {
          log_file_name += this_node::getName()[i];
        }
      }

      char pid_str[100];
      snprintf(pid_str, sizeof(pid_str), "%d", pid);
      log_file_name += std::string("_") + std::string(pid_str) + std::string(".log");
    }

    log_file_name = fs::system_complete(log_file_name).string();
    g_log_directory = fs::path(log_file_name).parent_path().string();
  }
}
Exemplo n.º 12
0
	PathString get_user_temp_directory()
	{
		PathString result = get_environment_variable("TEMP");
		return result;
	}
Exemplo n.º 13
0
	PathString get_user_directory()
	{
		return get_environment_variable("HOMEPATH");
	}