コード例 #1
0
void TPKGS::dump(std::ostream &stream) const {
	stream << "mainPackageDir: " << _mainPackageDir << "\n";
	stream << "installPathMap:\n";
	for(auto a = _installPathMap.begin(); a != _installPathMap.end(); a++) {
		stream << a->first << " -> " << a->second << "\n";
		if(!a->first.is_absolute()) {
			stream << "^^ source should be absolute!\n";
		}
		if(a->second.is_absolute()) {
			stream << "^^ destination should be relative!\n";
		}
	}
	stream << "keepDirs:\n";
	for(auto a = _keepDirs.begin(); a != _keepDirs.end(); a++) {
		stream << *a << "\n";
	}
	stream << "ignoreInSource:\n";
	for(auto a = _ignoreInSource.begin(); a != _ignoreInSource.end(); a++) {
		stream << *a << "\n";
		if(a->is_absolute()) {
			stream << "^^ should be relative!\n";
		}
	}
	stream << "ignoreInSystem:\n";
	for(auto a = _ignoreInSystem.begin(); a != _ignoreInSystem.end(); a++) {
		stream << *a << "\n";
		if(!a->is_absolute()) {
			stream << "^^ should be absolute!\n";
		}
	}
}
コード例 #2
0
	bool is_root(const char* path)
	{
		CE_ENSURE(NULL != path);
#if CROWN_PLATFORM_POSIX
		return is_absolute(path) && strlen32(path) == 1;
#elif CROWN_PLATFORM_WINDOWS
		return is_absolute(path) && strlen32(path) == 3;
#endif
	}
コード例 #3
0
ファイル: Config.cpp プロジェクト: xdv/divvyd
boost::filesystem::path Config::getDebugLogFile () const
{
    auto log_file = DEBUG_LOGFILE;

    if (!log_file.empty () && !log_file.is_absolute ())
    {
        // Unless an absolute path for the log file is specified, the
        // path is relative to the config file directory.
        log_file = boost::filesystem::absolute (
            log_file, getConfig ().CONFIG_DIR);
    }

    if (!log_file.empty ())
    {
        auto log_dir = log_file.parent_path ();

        if (!boost::filesystem::is_directory (log_dir))
        {
            boost::system::error_code ec;
            boost::filesystem::create_directories (log_dir, ec);

            // If we fail, we warn but continue so that the calling code can
            // decide how to handle this situation.
            if (ec)
            {
                std::cerr <<
                    "Unable to create log file path " << log_dir <<
                    ": " << ec.message() << '\n';
            }
        }
    }

    return log_file;
}
コード例 #4
0
ファイル: getpath.c プロジェクト: AbnerChang/edk2-staging
/** Add a path component, by appending stuff to buffer.
    buffer must have at least MAXPATHLEN + 1 bytes allocated, and contain a
    NUL-terminated string with no more than MAXPATHLEN characters (not counting
    the trailing NUL).  It's a fatal error if it contains a string longer than
    that (callers must be careful!).  If these requirements are met, it's
    guaranteed that buffer will still be a NUL-terminated string with no more
    than MAXPATHLEN characters at exit.  If stuff is too long, only as much of
    stuff as fits will be appended.

    @param[in,out]    buffer    The path to be extended.
    @param[in]        stuff     The stuff to join onto the path.
*/
static void
joinpath(char *buffer, char *stuff)
{
  size_t n, k;

  k = 0;
  if (is_absolute(stuff) == 1) {
    n = 0;
  }
  else {
    n = strlen(buffer);
    if(n == 0) {
      strncpy(buffer, volume_name, MAXPATHLEN);
      n = strlen(buffer);
    }
    /* We must not use an else clause here because we want to test n again.
        volume_name may have been empty.
    */
    if (n > 0 && n < MAXPATHLEN) {
      if(!is_sep(buffer[n-1])) {
        buffer[n++] = SEP;
      }
      if(is_sep(stuff[0]))   ++stuff;
    }
  }
  if (n > MAXPATHLEN)
    Py_FatalError("buffer overflow in getpath.c's joinpath()");
  k = strlen(stuff);
  if (n + k > MAXPATHLEN)
    k = MAXPATHLEN - n;
  strncpy(buffer+n, stuff, k);
  buffer[n+k] = '\0';
}
コード例 #5
0
ファイル: path.cpp プロジェクト: zbigg/tinfra
std::string search_executable(tstring const& filename, tstring const& path)
{
    const bool filename_has_extension    = has_extension(filename);
    const bool filename_is_absolute_path = is_absolute(filename);
    
    const std::vector<std::string> extensions = get_executable_extensions();  
    
    if( ! filename_is_absolute_path ) {
        const std::vector<std::string> dirs = split(path, PATH_SEPARATOR);
        
        for(std::vector<std::string>::const_iterator ipath = dirs.begin(); ipath != dirs.end(); ++ipath ) {
            const std::string path1 = tinfra::path::join(*ipath, filename);
            if( filename_has_extension ) {
                if( is_executable(path1 ,extensions) )
                    return path1;
                continue;
            }
            std::string maybe_with_ext = find_variant(path1, extensions);
            if( ! maybe_with_ext.empty() )
                return maybe_with_ext;
        }
    } else if( ! filename_has_extension ) {
        return find_variant(filename.str(), extensions);
    } else {
        if( is_executable(filename, extensions) ) {
            return filename.str();
        }
    }
    return "";
}
コード例 #6
0
 inline
 std::string
 absolute(
   char const* path)
 {
   char const* path_without_drive = split_drive(path);
   if (is_absolute(path_without_drive, /*drive_split_already*/ true)) {
     return std::string(path);
   }
   std::string result;
   static const size_t buf_size = 10000; // ad-hoc
   char buf[buf_size];
   char* getcwd_result = FEM_UTILS_PATH_GETCWD(buf, buf_size);
   if (getcwd_result == 0) {
     int en = errno;
     std::string msg = "fem::utils::path::absolute(): ";
     if (en != 0) {
       msg += std::strerror(en);
     }
     else {
       msg += "unknown error";
     }
     throw std::runtime_error(msg);
   }
   else {
     if (path != path_without_drive) {
       result += std::string(path, path_without_drive);
     }
     result += getcwd_result;
     result += separator();
     result += path_without_drive;
   }
   return result;
 }
コード例 #7
0
/** \brief return a sub path2 of this file_path2_t with nb_sub name
 */
file_path2_t	file_path2_t::subpath(size_t nb_sub)	const throw()
{
#if 1	// 
	// sanity check - the nb_sub+1 MUST be < size()
	DBG_ASSERT( nb_sub < size() );
	// NOTE: some kludge about the is_absolute	
	if( is_absolute() )	nb_sub++;
	// copy this object into result - all object fields
	file_path2_t	result	= *this;
	// special copy for the name_db field
	result.name_db	= std::vector<std::string>();
	for(size_t i = 0; i < nb_sub; i++)	result.name_db.push_back(name_db[i]);
	// normalize the result
	result.normalize();
	// return the result
	return result;
#else
	// sanity check - the nb_sub MUST be < size()
	DBG_ASSERT( nb_sub < size() );
	// build the string
	std::ostringstream 	oss;
	for( size_t i = 0; i <= nb_sub; i++ ){
		if( i != 0 )	oss << FS_DIR_SEPARATOR;
		oss << (*this)[i];
	}
	// return and convert and normalize the file_path2_t
	return oss.str();
#endif
}
コード例 #8
0
ファイル: getpath.c プロジェクト: AbnerChang/edk2-staging
/** Modify path so that the result is an absolute path.
    absolutize() requires that path be allocated at least MAXPATHLEN+1 bytes.

    @param[in,out]    path    The path to be made absolute.
*/
static void
absolutize(char *path)
{
    char buffer[MAXPATHLEN + 1];

    if (is_absolute(path) == 1)
        return;
    copy_absolute(buffer, path);
    strcpy(path, buffer);
}
コード例 #9
0
/** \brief Return the dirname
 */
file_path2_t	file_path2_t::dirname()	const throw()
{
	// sanity check - the file_path2_t MUST NOT be null
	DBG_ASSERT( !is_null() );
	// if this file_path2_t contain only a directory, return it as is
	if( name_db.size() <= 1 )	return *this;
	// return the dirname
	if( is_absolute() )	return this->subpath(name_db.size()-2);
	return this->subpath(name_db.size()-1);
}
コード例 #10
0
ファイル: Audio_File.C プロジェクト: elthariel/non-daw
/** return a static pointer to /name/ corrected for relative path. */
const char *Audio_File::realname ( const char *name )
{
    static char rname[512];

    if ( is_absolute( name ) )
        strncpy( rname, name, sizeof( rname ) );
    else
        snprintf( rname, sizeof( rname ), "sources/%s", name );

    return rname;
}
コード例 #11
0
ファイル: settings.cpp プロジェクト: autoscatto/mkvtoolnix
QString
Settings::exeWithPath(QString const &exe) {
#if defined(SYS_WINDOWS)
  auto path = bfs::path{ to_utf8(exe) };
  if (path.is_absolute())
    return exe;

  return to_qs((mtx::sys::get_installation_path() / path).string());
#else  // defined(SYS_WINDOWS)
  return exe;
#endif // defined(SYS_WINDOWS)
}
コード例 #12
0
ファイル: getpath.c プロジェクト: AbnerChang/edk2-staging
/** Extract the volume name from a path.

    @param[out]   Dest    Pointer to location in which to store the extracted volume name.
    @param[in]    path    Pointer to the path to extract the volume name from.
**/
static void
set_volume(char *Dest, char *path)
{
  size_t    VolLen;

  if(is_absolute(path)) {
    VolLen = strcspn(path, "/\\:");
    if((VolLen != 0) && (path[VolLen] == ':')) {
      (void) strncpyX(Dest, path, VolLen + 1);
    }
  }
}
コード例 #13
0
/* send a button event */
static void wcmSendButtonClick(WacomDevicePtr priv, int button, int state)
{
	int mode = is_absolute(priv->pInfo);

	/* send button event in state */
	xf86PostButtonEventP(priv->pInfo->dev, mode,button,
		state,0,0,0);

	/* We have changed the button state (from down to up) for the device
	 * so we need to update the record */
	if (button == 1)
		priv->oldState.buttons = 0;
}
コード例 #14
0
ファイル: uri.cpp プロジェクト: Corvusoft/restbed
 string Uri::get_path( void ) const
 {
     static const regex pattern( "^([a-zA-Z][a-zA-Z0-9+\\-.]*://([^/?#]+)?)?([a-zA-Z0-9\\-._~%!$&'()*+,;=:@/]*)" );
     
     smatch match;
     
     if ( regex_search( m_pimpl->m_uri, match, pattern ) )
     {
         return ( is_absolute( ) ) ? match[ 3 ] : string( match[ 2 ] ) + string( match[ 3 ] );
     }
     
     return String::empty;
 }
コード例 #15
0
ファイル: files.c プロジェクト: ggjjlldd/swftools
char* normalize_path(const char*path)
{
    char*n = 0, *d = 0;
    if(!is_absolute(path)) {
        char buf[512];
        char*c = getcwd(buf,512);
        int l = strlen(buf);
        d = n = malloc(l+strlen(path)+10);
        strcpy(n, buf);d += l;
        if(!l || n[l-1]!=path_seperator) {
            *d=path_seperator;d++;
        }
    } else {
        d = n = strdup(path);
    }
    const char*s=path;
    char init = 1;

    while(*s) {
        if(init && s[0] == '.' && (s[1]==path_seperator || s[1]=='\0')) {
            if(!s[1]) break;
            s+=2;
            init=1;
            continue;
        }
        if(init && s[0] == '.' && s[1] == '.' && (s[2] == path_seperator || s[2]=='\0')) {
            // step one down
            char*last = 0;
            if(d<=n) 
                return 0;
            *--d = 0;
            if(!(last=strrchr(n, path_seperator))) {
                return 0;
            }
            d = last+1;
            if(!s[2]) break;
            s+=3;
            init=1;
            continue;
        }

        *d = *s;
        if(*s==path_seperator) init=1;
        else init=0;
        d++;s++;
    }
    if(d!=n && d[-1]==path_seperator) 
        d--;
    *d = 0;
    return n;
}
コード例 #16
0
  saga::url filesystem_adaptor::make_absolute (const saga::url & base, 
                                               const saga::url & u)
  {
    if ( is_absolute (u) )
    {
      return u;
    }

    // relative 
    saga::url ret (base); // copy scheme, host, etc
    ret.set_path  (base.get_path () + "/" + u.get_path ());

    return ret;
  }
コード例 #17
0
ファイル: ELFLinkingContext.cpp プロジェクト: lamproae/lld
ErrorOr<StringRef> ELFLinkingContext::searchFile(StringRef fileName,
        bool isSysRooted) const {
    SmallString<128> path;
    if (is_absolute(fileName) && isSysRooted) {
        path.assign(_sysrootPath);
        path.append(fileName);
        if (exists(path.str()))
            return path.str().copy(_allocator);
    } else if (exists(fileName)) {
        return fileName;
    }

    if (is_absolute(fileName))
        return make_error_code(llvm::errc::no_such_file_or_directory);

    for (StringRef dir : _inputSearchPaths) {
        buildSearchPath(path, dir, _sysrootPath);
        llvm::sys::path::append(path, fileName);
        if (exists(path.str()))
            return path.str().copy(_allocator);
    }
    return make_error_code(llvm::errc::no_such_file_or_directory);
}
コード例 #18
0
/** \brief Return the fullpath2 of this file_path2_t
 * 
 * - WARNING: this function assume that the file_path2_t is relative to the 
 *            *CURRENT* directory !
 *   - so if the file_path2_t is created for with a relative path2 with a given 
 *     current directory, then the current directory is changed, and then
 *     fullpath2() is called, it will return the full path2 in the SECOND
 *     current directory
 */
file_path2_t	file_path2_t::fullpath2()		const throw()
{
	// if this file_path2_t is already 'absolute', return it as is
	if( is_absolute() )	return *this;
	// sanity check - here the 
	DBG_ASSERT( is_relative() );
#if	0
	// prepend the current directory to this relative path2
	return file_utils_t::get_current_dir() / *this;
#else
//	EXP_ASSERT(0);
	KLOG_ERR("file_utils_t::get_current_dir() return file_path_t. so wont work for file_path2_t");
	return file_path2_t();
#endif
}
コード例 #19
0
ファイル: utl_idlist.cpp プロジェクト: DOCGroup/ACE_TAO
char *
UTL_IdList::get_string_copy ()
{
  /*
   * Absolute Names have "::" as the first item in the idlist, so delimiters
   * have to start be inserted depending on if the name is absolute or not
   */
  size_t delimiter_start = is_absolute () ? 1 : 0;

  // Get buffer of the correct size
  size_t n = 0;
  size_t size = 1;
  for (UTL_IdListActiveIterator i (this);
       !i.is_done ();
       i.next ())
    {
      if (n > delimiter_start)
        {
          size += 2; // For delimiter
        }
      const char *item = i.item ()->get_string ();
      size += ACE_OS::strlen (item);
      n++;
    }
  char *buffer = new char[size];
  buffer[0] = '\0';

  // Fill buffer
  n = 0;
  for (UTL_IdListActiveIterator i (this);
       !i.is_done ();
       i.next ())
    {
      if (n > delimiter_start)
        {
          ACE_OS::strncat (buffer, "::", 2);
        }
      const char *item = i.item ()->get_string ();
      ACE_OS::strcat (buffer, item);
      n++;
    }

  buffer[size - 1] = '\0';

  return buffer;
}
コード例 #20
0
ファイル: path.cpp プロジェクト: zbigg/tinfra
// TODO: move it to posix_common.sh
std::string search_executable(tstring const& filename, tstring const& path)
{
    if( is_absolute(filename) )
        if( is_executable(filename) )
            return filename.str();
    
    std::vector<std::string> dirs = split(path, PATH_SEPARATOR);
    
    for(std::vector<std::string>::const_iterator ipath = dirs.begin(); ipath != dirs.end(); ++ipath )
    {
        std::string result_name = tinfra::path::join(*ipath, filename);
        if( is_executable(result_name) ) {
            return result_name;
        }
    }
    return "";
}
コード例 #21
0
ファイル: lib.c プロジェクト: pfmoore/shimmy
wchar_t *make_absolute(wchar_t *path, wchar_t *base) {
    wchar_t *ret;
    size_t sz;

    if (is_absolute(path)) {
        return _wcsdup(path);
    }
    sz = wcslen(path) + wcslen(base) + 2;
    ret = (wchar_t *)calloc(sz, sizeof(wchar_t));
    if (ret == NULL) {
        error(RC_NOT_ENOUGH_MEM, L"Not enough memory in make_absolute()");
    }
    /* TODO: base might have a terminating \ which we should skip */
    wcscpy(ret, base);
    wcscat(ret, L"\\");
    wcscat(ret, path);
    return ret;
}
コード例 #22
0
PathObjectList get_objects(const hdf5::node::Group &base,const Path &path)
{
  PathObjectList list;

  if(path.has_attribute())
  {
    //if we are looking for attributes we first have to identify the parent
    //objects.
    NodeList parent_list;

    if(path.size()==0)
    {
      parent_list.push_back(base);
    }
    else
    {
      Path parent_path(path);
      parent_path.attribute(std::string());
      parent_list = get_objects(base,parent_path);
    }

    //once we have identified the parents we can select those who have
    //an attribute of appropriate name
    for(auto node: parent_list)
    {
      if(node.attributes.exists(path.attribute()))
        list.push_back(node.attributes[path.attribute()]);
    }
  }
  else
  {
    auto iter_begin = hdf5::node::RecursiveLinkIterator::begin(base);
    auto iter_end = hdf5::node::RecursiveLinkIterator::end(base);

    if(is_absolute(path))
      std::copy_if(iter_begin,iter_end,std::back_inserter(list),AbsolutePathMatcher(path));
    else
    {
      std::copy_if(iter_begin,iter_end,std::back_inserter(list),RelativePathMatcher(path,get_path(base)));
    }
  }

  return list;
}
コード例 #23
0
ファイル: getpath.c プロジェクト: AbnerChang/edk2-staging
/** Copy p into path, ensuring that the result is an absolute path.

    copy_absolute requires that path be allocated at least
    MAXPATHLEN + 1 bytes and that p be no more than MAXPATHLEN bytes.

    @param[out]     path    Destination to receive the absolute path.
    @param[in]      p       Path to be tested and possibly converted.
**/
static void
copy_absolute(char *path, char *p)
{
  if (is_absolute(p) == 1)
        strcpy(path, p);
  else {
    if (!getcwd(path, MAXPATHLEN)) {
      /* unable to get the current directory */
      if(volume_name[0] != 0) {
        strcpy(path, volume_name);
        joinpath(path, p);
      }
      else
        strcpy(path, p);
      return;
    }
    if (p[0] == '.' && is_sep(p[1]))
        p += 2;
    joinpath(path, p);
  }
}
コード例 #24
0
void CL_CSSUsedValues::calc_noncontent_height(const CL_CSSBoxProperties &properties)
{
	margin.top = get_margin_width(properties.margin_width_top);
	margin.bottom = get_margin_width(properties.margin_width_bottom);
	border.top = properties.border_width_top.length.value;
	border.bottom = properties.border_width_bottom.length.value;
	padding.top = get_padding_width(properties.padding_width_top);
	padding.bottom = get_padding_width(properties.padding_width_bottom);

	if (is_absolute(properties))
	{
		if (replaced)
		{
			// 'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block
		}
		else
		{
			// 'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block
		}
	}
}
コード例 #25
0
ファイル: path_db.cpp プロジェクト: Alex-doc/godot
NodePath NodePath::rel_path_to(const NodePath &p_np) const {

	ERR_FAIL_COND_V(!is_absolute(), NodePath());
	ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath());

	Vector<StringName> src_dirs = get_names();
	Vector<StringName> dst_dirs = p_np.get_names();

	//find common parent
	int common_parent = 0;

	while (true) {
		if (src_dirs.size() == common_parent)
			break;
		if (dst_dirs.size() == common_parent)
			break;
		if (src_dirs[common_parent] != dst_dirs[common_parent])
			break;
		common_parent++;
	}

	common_parent--;

	Vector<StringName> relpath;

	for (int i = src_dirs.size() - 1; i > common_parent; i--) {

		relpath.push_back("..");
	}

	for (int i = common_parent + 1; i < dst_dirs.size(); i++) {

		relpath.push_back(dst_dirs[i]);
	}

	if (relpath.size() == 0)
		relpath.push_back(".");

	return NodePath(relpath, p_np.get_subnames(), false, p_np.get_property());
}
コード例 #26
0
ファイル: util.c プロジェクト: GabrielDiniz/FluxNetControl
void my_mkdir(const char *name)
{
   char w0[MAXLEN];
   int i;
   int chars;

   if(!is_absolute(name)) {
      debuga(_("Invalid path (%s). Please, use absolute paths only.\n"),name);
      debuga(_("process aborted.\n"));
      exit(EXIT_FAILURE);
   }

   chars=0;
   for (i=0 ; name[i] ; i++) {
      if (i>=sizeof(w0)) {
         debuga(_("directory name too long: %s\n"),name);
         exit(EXIT_FAILURE);
      }
      if (chars>0 && name[i] == '/') {
         w0[i] = '\0';
         if(access(w0, R_OK) != 0) {
            if(mkdir(w0,0755)) {
               debuga(_("mkdir %s %s\n"),w0,strerror(errno));
               debuga(_("process aborted.\n"));
               exit(EXIT_FAILURE);
            }
         }
      }
      if (name[i] != '/') chars++;
      w0[i] = name[i];
   }

   if(access(name, R_OK) != 0) {
      if(mkdir(name,0755)) {
         debuga(_("mkdir %s %s\n"),name,strerror(errno));
         debuga(_("process aborted.\n"));
         exit(EXIT_FAILURE);
      }
   }
}
コード例 #27
0
ファイル: files.c プロジェクト: ggjjlldd/swftools
char*find_file(const char*filename, char error)
{
    include_dir_t*i = current_include_dirs;
    FILE*fi = 0;
    if(is_absolute(filename)) {
        FILE*fi = fopen(filename, "rb");
        if(fi) {
            fclose(fi);
            return strdup(filename);
        }
    } else {
        if(!i && error) {
            as3_warning("Include directory stack is empty, while looking for file %s", filename);
        }
        while(i) {
            char*p = concat_paths(i->path, filename);
            fi = fopen(p, "rb");
            if(fi) {
                fclose(fi);
                return p;
            } else {
                free(p);
            }
            i = i->next;
        }
    }
    if(!error) {
        return 0;
    }

    as3_error("Couldn't find file %s", filename);
    i = current_include_dirs;
    while(i) {
        fprintf(stderr, "include dir: %s\n", i->path);
        i = i->next;
    }
    return 0;
}
コード例 #28
0
ファイル: helper_fnc.c プロジェクト: ggrrin/ftp_server
//params is string representing path, either absolute or relative in respect to cur_path and root_path
//remove relatives from params and returns path concatenated of root cur_path params, buffer is allocated.
//to cur_path store new current path relative to root, buffer is allocated
char *
get_full_path(char *root, char  **cur_path, char *params)
{
	char *c_path;
	if(is_absolute(params))
	{
		c_path = malloc(strlen(params) + 1);
		strcpy(c_path, params);
	}
	else
	{
		c_path = malloc(strlen(*cur_path) + 1 + strlen(params) + 1);
		strcpy(c_path, *cur_path);
		strcat(c_path, "/");
		strcat(c_path, params);
	}
	
	char *normalized_path = remove_relatives(remove_slashes(c_path));
	free(c_path);

	if(normalized_path)
	{
		*cur_path = normalized_path;
	}
	else
	{
		char *empty = malloc(1);
		*empty = '\0';
		*cur_path = empty; 
	}

	char *res = malloc(strlen(root) + strlen(*cur_path) + 1);
	strcpy(res, root);
	strcat(res, *cur_path);
	return res;
}
コード例 #29
0
ファイル: getpath.c プロジェクト: AbnerChang/edk2-staging
/** Determine paths.

    Two directories must be found, the platform independent directory
    (prefix), containing the common .py and .pyc files, and the platform
    dependent directory (exec_prefix), containing the shared library
    modules.  Note that prefix and exec_prefix are the same directory
    for UEFI installations.

    Separate searches are carried out for prefix and exec_prefix.
    Each search tries a number of different locations until a ``landmark''
    file or directory is found.  If no prefix or exec_prefix is found, a
    warning message is issued and the preprocessor defined PREFIX and
    EXEC_PREFIX are used (even though they may not work); python carries on
    as best as is possible, but some imports may fail.

    Before any searches are done, the location of the executable is
    determined.  If argv[0] has one or more slashes in it, it is used
    unchanged.  Otherwise, it must have been invoked from the shell's path,
    so we search %PATH% for the named executable and use that.  If the
    executable was not found on %PATH% (or there was no %PATH% environment
    variable), the original argv[0] string is used.

    Finally, argv0_path is set to the directory containing the executable
    (i.e. the last component is stripped).

    With argv0_path in hand, we perform a number of steps.  The same steps
    are performed for prefix and for exec_prefix, but with a different
    landmark.

    The prefix landmark will always be lib/python.VERSION/os.py and the
    exec_prefix will always be lib/python.VERSION/dynaload, where VERSION
    is Python's version number as defined at the beginning of this file.

    First. See if the %PYTHONHOME% environment variable points to the
    installed location of the Python libraries.  If %PYTHONHOME% is set, then
    it points to prefix and exec_prefix.  %PYTHONHOME% can be a single
    directory, which is used for both, or the prefix and exec_prefix
    directories separated by the DELIM character.

    Next. Search the directories pointed to by the preprocessor variables
    PREFIX and EXEC_PREFIX.  These paths are prefixed with the volume name
    extracted from argv0_path.  The volume names correspond to the UEFI
    shell "map" names.

    That's it!

    Well, almost.  Once we have determined prefix and exec_prefix, the
    preprocessor variable PYTHONPATH is used to construct a path.  Each
    relative path on PYTHONPATH is prefixed with prefix.  Then the directory
    containing the shared library modules is appended.  The environment
    variable $PYTHONPATH is inserted in front of it all.  Finally, the
    prefix and exec_prefix globals are tweaked so they reflect the values
    expected by other code, by stripping the "lib/python$VERSION/..." stuff
    off.  This seems to make more sense given that currently the only
    known use of sys.prefix and sys.exec_prefix is for the ILU installation
    process to find the installed Python tree.

    The final, fully resolved, paths should look something like:
      fs0:/Efi/Tools/python.efi
      fs0:/Efi/StdLib/lib/python27
      fs0:/Efi/StdLib/lib/python27/dynaload

**/
static void
calculate_path(void)
{
    extern char *Py_GetProgramName(void);

    static char delimiter[2] = {DELIM, '\0'};
    static char separator[2] = {SEP, '\0'};
    char *pythonpath = PYTHONPATH;
    char *rtpypath = Py_GETENV("PYTHONPATH");
    //char *home = Py_GetPythonHome();
    char *path = getenv("path");
    char *prog = Py_GetProgramName();
    char argv0_path[MAXPATHLEN+1];
    char zip_path[MAXPATHLEN+1];
    char *buf;
    size_t bufsz;
    size_t prefixsz;
    char *defpath;


/* ###########################################################################
      Determine path to the Python.efi binary.
      Produces progpath, argv0_path, and volume_name.
########################################################################### */

    /* If there is no slash in the argv0 path, then we have to
     * assume python is on the user's $PATH, since there's no
     * other way to find a directory to start the search from.  If
     * $PATH isn't exported, you lose.
     */
    if (strchr(prog, SEP))
            strncpy(progpath, prog, MAXPATHLEN);
    else if (path) {
      while (1) {
        char *delim = strchr(path, DELIM);

        if (delim) {
                size_t len = delim - path;
                if (len > MAXPATHLEN)
                        len = MAXPATHLEN;
                strncpy(progpath, path, len);
                *(progpath + len) = '\0';
        }
        else
                strncpy(progpath, path, MAXPATHLEN);

        joinpath(progpath, prog);
        if (isxfile(progpath))
                break;

        if (!delim) {
                progpath[0] = '\0';
                break;
        }
        path = delim + 1;
      }
    }
    else
            progpath[0] = '\0';
    if ( (!is_absolute(progpath)) && (progpath[0] != '\0') )
            absolutize(progpath);
    strncpy(argv0_path, progpath, MAXPATHLEN);
    argv0_path[MAXPATHLEN] = '\0';
    set_volume(volume_name, argv0_path);

    reduce(argv0_path);
    /* At this point, argv0_path is guaranteed to be less than
       MAXPATHLEN bytes long.
    */

/* ###########################################################################
      Build the FULL prefix string, including volume name.
      This is the full path to the platform independent libraries.
########################################################################### */

    strncpy(prefix, volume_name, MAXPATHLEN);
    joinpath(prefix, PREFIX);
    joinpath(prefix, lib_python);

/* ###########################################################################
      Build the FULL path to the zipped-up Python library.
########################################################################### */

    strncpy(zip_path, prefix, MAXPATHLEN);
    zip_path[MAXPATHLEN] = '\0';
    reduce(zip_path);
    joinpath(zip_path, "python00.zip");
    bufsz = strlen(zip_path);   /* Replace "00" with version */
    zip_path[bufsz - 6] = VERSION[0];
    zip_path[bufsz - 5] = VERSION[1];

/* ###########################################################################
      Build the FULL path to dynamically loadable libraries.
########################################################################### */

    strncpy(exec_prefix, volume_name, MAXPATHLEN);    // "fs0:"
    joinpath(exec_prefix, EXEC_PREFIX);               // "fs0:/Efi/StdLib"
    joinpath(exec_prefix, lib_python);                // "fs0:/Efi/StdLib/lib/python.27"
    joinpath(exec_prefix, "lib-dynload");             // "fs0:/Efi/StdLib/lib/python.27/lib-dynload"

/* ###########################################################################
      Build the module search path.
########################################################################### */

    /* Reduce prefix and exec_prefix to their essence,
     * e.g. /usr/local/lib/python1.5 is reduced to /usr/local.
     * If we're loading relative to the build directory,
     * return the compiled-in defaults instead.
     */
    reduce(prefix);
    reduce(prefix);
    /* The prefix is the root directory, but reduce() chopped
     * off the "/". */
    if (!prefix[0]) {
      strcpy(prefix, volume_name);
    }
    bufsz = strlen(prefix);
    if(prefix[bufsz-1] == ':') {    // if prefix consists solely of a volume_name
      prefix[bufsz] = SEP;          //    then append SEP indicating the root directory
      prefix[bufsz+1] = 0;          //    and ensure the new string is terminated
    }

    /* Calculate size of return buffer.
     */
    defpath = pythonpath;
    bufsz = 0;

    if (rtpypath)
        bufsz += strlen(rtpypath) + 1;

    prefixsz = strlen(prefix) + 1;

    while (1) {
        char *delim = strchr(defpath, DELIM);

        if (is_absolute(defpath) == 0)
            /* Paths are relative to prefix */
            bufsz += prefixsz;

        if (delim)
            bufsz += delim - defpath + 1;
        else {
            bufsz += strlen(defpath) + 1;
            break;
        }
        defpath = delim + 1;
    }

    bufsz += strlen(zip_path) + 1;
    bufsz += strlen(exec_prefix) + 1;

    /* This is the only malloc call in this file */
    buf = (char *)PyMem_Malloc(bufsz);

    if (buf == NULL) {
        /* We can't exit, so print a warning and limp along */
        fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n");
        fprintf(stderr, "Using default static PYTHONPATH.\n");
        module_search_path = PYTHONPATH;
    }
    else {
        /* Run-time value of $PYTHONPATH goes first */
        if (rtpypath) {
            strcpy(buf, rtpypath);
            strcat(buf, delimiter);
        }
        else
            buf[0] = '\0';

        /* Next is the default zip path */
        strcat(buf, zip_path);
        strcat(buf, delimiter);

        /* Next goes merge of compile-time $PYTHONPATH with
         * dynamically located prefix.
         */
        defpath = pythonpath;
        while (1) {
            char *delim = strchr(defpath, DELIM);

            if (is_absolute(defpath) != 1) {
                strcat(buf, prefix);
                strcat(buf, separator);
            }

            if (delim) {
                size_t len = delim - defpath + 1;
                size_t end = strlen(buf) + len;
                strncat(buf, defpath, len);
                *(buf + end) = '\0';
            }
            else {
                strcat(buf, defpath);
                break;
            }
            defpath = delim + 1;
        }
        strcat(buf, delimiter);

        /* Finally, on goes the directory for dynamic-load modules */
        strcat(buf, exec_prefix);

        /* And publish the results */
        module_search_path = buf;
    }
        /*  At this point, exec_prefix is set to VOL:/Efi/StdLib/lib/python.27/dynalib.
            We want to get back to the root value, so we have to remove the final three
            segments to get VOL:/Efi/StdLib.  Because we don't know what VOL is, and
            EXEC_PREFIX is also indeterminate, we just remove the three final segments.
        */
        reduce(exec_prefix);
        reduce(exec_prefix);
        reduce(exec_prefix);
        if (!exec_prefix[0]) {
          strcpy(exec_prefix, volume_name);
        }
        bufsz = strlen(exec_prefix);
        if(exec_prefix[bufsz-1] == ':') {
          exec_prefix[bufsz] = SEP;
          exec_prefix[bufsz+1] = 0;
        }
    if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: module_search_path = \"%s\"\n", __func__, __LINE__, module_search_path);
    if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: prefix             = \"%s\"\n", __func__, __LINE__, prefix);
    if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: exec_prefix        = \"%s\"\n", __func__, __LINE__, exec_prefix);
    if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: progpath           = \"%s\"\n", __func__, __LINE__, progpath);
}
コード例 #30
0
ファイル: path.cpp プロジェクト: Bhudipta/minix
/// Converts a relative path in the current directory to an absolute path.
///
/// \pre The path is relative.
///
/// \return The absolute representation of the relative path.
fs::path
fs::path::to_absolute(void) const
{
    PRE(!is_absolute());
    return fs::current_path() / *this;
}