Пример #1
0
bool file_utils::full_path(dynamic_string &path)
{
#if defined(PLATFORM_WINDOWS)
    char buf[1024];
    char *p = _fullpath(buf, path.get_ptr(), sizeof(buf));
    if (!p)
        return false;
#else
    char buf[PATH_MAX];
    char *p;
    dynamic_string pn, fn;
    split_path(path.get_ptr(), pn, fn);
    if ((fn == ".") || (fn == ".."))
    {
        p = realpath(path.get_ptr(), buf);
        if (!p)
            return false;
        path.set(buf);
    }
    else
    {
        if (pn.is_empty())
            pn = "./";
        p = realpath(pn.get_ptr(), buf);
        if (!p)
            return false;
        combine_path(path, buf, fn.get_ptr());
    }
#endif

    return true;
}
Пример #2
0
    bool command_line_params::get_value_as_string(dynamic_string &value, const char *pKey, uint32_t key_index, const char *pDef, uint32_t value_index) const
    {
        param_map_const_iterator it = get_param(pKey, key_index);
        if (it == end())
            return false;
        if (value_index >= it->second.m_values.size())
        {
            vogl::console::debug("%s: Trying to retrieve value %u of command line parameter %s, but this parameter only has %u values\n", VOGL_FUNCTION_INFO_CSTR, value_index, pKey, it->second.m_values.size());
            value.set(pDef);
            return false;
        }

        value = it->second.m_values[value_index];
        return true;
    }
   void get_command_line_as_single_string(dynamic_string& cmd_line, int argc, char *argv[])
   {
      argc, argv;
#if false && CRNLIB_USE_WIN32_API // THIS DOES NOT WORK PROPERLY, ADDING TOO MANY QUOTES, SO WE IGNORE IT.
      cmd_line.set(GetCommandLineA());
#else
      cmd_line.clear();
      for (int i = 0; i < argc; i++)
      {
         dynamic_string tmp(argv[i]);
         if ((tmp.front() != '"') && (tmp.front() != '-') && (tmp.front() != '@')) 
            tmp = "\"" + tmp + "\"";
         if (cmd_line.get_len())
            cmd_line += " ";
         cmd_line += tmp;
      }
#endif
   }
Пример #4
0
   void get_command_line(dynamic_string& cmd_line, int argc, char *argv[])
   {
      argc, argv;
#if CRNLIB_USE_WIN32_API
      cmd_line.set(GetCommandLineA());
#else
      cmd_line.clear();
      for (int i = 0; i < argc; i++)
      {
         dynamic_string tmp(argv[i]);
         if ((tmp.front() != '"') && (tmp.front() != '-') && (tmp.front() != '@'))
            tmp = "\"" + tmp + "\"";
         if (cmd_line.get_len())
            cmd_line += " ";
         cmd_line += tmp;
      }
#endif
   }