Ejemplo n.º 1
0
/* The file browser front end.  We check to see if inpath has a
 * directory in it.  If it does, we start do_browser() from there.
 * Otherwise, we start do_browser() from the current directory. */
std::string do_browse_from(const std::string& inpath)
{
	struct stat st;
	DIR *dir = NULL;

	std::string path = real_dir_from_tilde(inpath);

	/* Perhaps path is a directory.  If so, we'll pass it to
	 * do_browser().  Or perhaps path is a directory / a file.  If so,
	 * we'll try stripping off the last path element and passing it to
	 * do_browser().  Or perhaps path doesn't have a directory portion
	 * at all.  If so, we'll just pass the current directory to
	 * do_browser(). */
	if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
		path = striponedir(path);

		if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
			path = getcwd();
		}
	}

	if (path != "") {
		dir = opendir(path.c_str());
	}

	/* If we can't open the path, get out. */
	if (dir == NULL) {
		beep();
		return NULL;
	}

	return do_browser(path, dir);
}
Ejemplo n.º 2
0
Archivo: browser.c Proyecto: ris21/yoda
/* The file browser front end.  We check to see if inpath has a
 * directory in it.  If it does, we start do_browser() from there.
 * Otherwise, we start do_browser() from the current directory. */
char *do_browse_from(const char *inpath)
{
    struct stat st;
    char *path;
	/* This holds the tilde-expanded version of inpath. */
    DIR *dir = NULL;

    assert(inpath != NULL);

    path = real_dir_from_tilde(inpath);

    /* Perhaps path is a directory.  If so, we'll pass it to
     * do_browser().  Or perhaps path is a directory / a file.  If so,
     * we'll try stripping off the last path element and passing it to
     * do_browser().  Or perhaps path doesn't have a directory portion
     * at all.  If so, we'll just pass the current directory to
     * do_browser(). */
    if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
	path = mallocstrassn(path, striponedir(path));

	if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
	    free(path);

	    path = charalloc(PATH_MAX + 1);
	    path = getcwd(path, PATH_MAX + 1);

	    if (path != NULL)
		align(&path);
	}
    }

#ifndef DISABLE_OPERATINGDIR
    /* If the resulting path isn't in the operating directory, use
     * the operating directory instead. */
    if (check_operating_dir(path, FALSE))
	path = mallocstrcpy(path, operating_dir);
#endif

    if (path != NULL)
	dir = opendir(path);

    /* If we can't open the path, get out. */
    if (dir == NULL) {
	free(path);
	beep();
	return NULL;
    }

    return do_browser(path, dir);
}