コード例 #1
0
ファイル: filename_modifiers.c プロジェクト: cfillion/vifm
/* Implementation of :h filename modifier. */
static int
apply_h_mod(const char *path, char *buf, size_t buf_len)
{
	char *p = strrchr(path, '/');
	if(p == NULL)
	{
		snprintf(buf, buf_len, ".");
	}
	else
	{
		snprintf(buf, buf_len, "%s", path);
		if(!is_root_dir(path))
		{
			buf[p - path + 1] = '\0';
			if(!is_root_dir(buf))
				buf[p - path] = '\0';
		}
	}
	return 0;
}
コード例 #2
0
ファイル: autocmds.c プロジェクト: cfillion/vifm
/* Registers action handler for a particular combination of event and path
 * pattern.  Event name is case insensitive.  Returns zero on successful
 * registration or non-zero on error. */
static int
add_aucmd(const char event[], const char pattern[], int negated,
		const char action[], vle_aucmd_handler handler)
{
	char canonic_path[PATH_MAX];
	aucmd_info_t *autocmd;
	char *regexp;

	autocmd = DA_EXTEND(autocmds);
	if(autocmd == NULL)
	{
		return 1;
	}

	if(strchr(pattern, '/') != NULL)
	{
		canonicalize_path(pattern, canonic_path, sizeof(canonic_path));
		if(!is_root_dir(canonic_path))
		{
			chosp(canonic_path);
		}
		pattern = canonic_path;
	}

	regexp = glob_to_regex(pattern, 1);
	if(regexp == NULL)
	{
		return 1;
	}

	if(regcomp(&autocmd->regex, regexp, REG_EXTENDED | REG_ICASE) != 0)
	{
		free(regexp);
		return 1;
	}
	free(regexp);

	autocmd->event = strdup(event);
	autocmd->pattern = strdup(pattern);
	autocmd->negated = negated;
	autocmd->action = strdup(action);
	autocmd->handler = handler;
	if(autocmd->event == NULL || autocmd->pattern == NULL ||
			autocmd->action == NULL)
	{
		free_autocmd_data(autocmd);
		return 1;
	}

	DA_COMMIT(autocmds);
	/* TODO: sort by event name (case insensitive) and then by pattern? */
	return 0;
}
コード例 #3
0
ファイル: commands_completion.c プロジェクト: sshilovsky/vifm
static void
filename_completion_in_dir(const char *path, const char *str,
		CompletionType type)
{
	char buf[PATH_MAX];
	if(is_root_dir(str))
	{
		snprintf(buf, sizeof(buf), "%s", str);
	}
	else
	{
		snprintf(buf, sizeof(buf), "%s/%s", path, str);
	}
	filename_completion(buf, type);
}
コード例 #4
0
ファイル: path.c プロジェクト: sshilovsky/vifm
void
remove_last_path_component(char *path)
{
	char *slash;

	while(ends_with_slash(path))
	{
		chosp(path);
	}

	if((slash = strrchr(path, '/')) != NULL)
	{
		int pos = is_root_dir(path) ? 1 : 0;
		slash[pos] = '\0';
	}
}
コード例 #5
0
ファイル: path.c プロジェクト: jubalh/vifm
void
remove_last_path_component(char path[])
{
	char *slash;

	while(ends_with_slash(path))
	{
		chosp(path);
	}

	slash = strrchr(path, '/');
	if(slash != NULL)
	{
		const int offset = is_root_dir(path) ? 1 : 0;
		slash[offset] = '\0';
	}
}
コード例 #6
0
ファイル: autocmds.c プロジェクト: cfillion/vifm
void
vle_aucmd_execute(const char event[], const char path[], void *arg)
{
	size_t i;
	char canonic_path[PATH_MAX];

	canonicalize_path(path, canonic_path, sizeof(canonic_path));
	if(!is_root_dir(canonic_path))
	{
		chosp(canonic_path);
	}

	for(i = 0U; i < DA_SIZE(autocmds); ++i)
	{
		if(strcasecmp(event, autocmds[i].event) == 0 &&
				is_pattern_match(&autocmds[i], canonic_path))
		{
			autocmds[i].handler(autocmds[i].action, arg);
		}
	}
}
コード例 #7
0
ファイル: path.c プロジェクト: jubalh/vifm
char *
replace_home_part(const char directory[])
{
	static char buf[PATH_MAX];
	size_t len;

	len = strlen(cfg.home_dir) - 1;
	if(strnoscmp(directory, cfg.home_dir, len) == 0 &&
			(directory[len] == '\0' || directory[len] == '/'))
	{
		strncat(strcpy(buf, "~"), directory + len, sizeof(buf) - strlen(buf) - 1);
	}
	else
	{
		copy_str(buf, sizeof(buf), directory);
	}

	if(!is_root_dir(buf))
		chosp(buf);

	return buf;
}
コード例 #8
0
ファイル: utils.c プロジェクト: acklinr/vifm
void
make_abs_path(char buf[], size_t buf_len, const char base[], const char sub[],
		const char cwd[])
{
	char local_buf[buf_len];

	if(is_path_absolute(base))
	{
		snprintf(local_buf, buf_len, "%s%s%s", base, (sub[0] == '\0' ? "" : "/"),
				sub);
	}
	else
	{
		snprintf(local_buf, buf_len, "%s/%s%s%s", cwd, base,
				(sub[0] == '\0' ? "" : "/"), sub);
	}

	canonicalize_path(local_buf, buf, buf_len);
	if(!ends_with_slash(sub) && !is_root_dir(buf))
	{
		chosp(buf);
	}
}
コード例 #9
0
ファイル: vifm.c プロジェクト: ackeack/workenv
static void
parse_args(int argc, char *argv[], const char *dir, char *lwin_path,
		char *rwin_path, int *lwin_handle, int *rwin_handle)
{
	int x;
	int select = 0;

	(void)my_chdir(dir);

	/* Get Command Line Arguments */
	for(x = 1; x < argc; x++)
	{
		if(!strcmp(argv[x], "--select"))
		{
			select = 1;
		}
		else if(!strcmp(argv[x], "--remote"))
		{
			if(!ipc_server())
			{
				ipc_send(argv + x + 1);
				quit_on_invalid_arg();
			}
		}
		else if(!strcmp(argv[x], "-f"))
		{
			cfg.vim_filter = 1;
		}
		else if(!strcmp(argv[x], "--no-configs"))
		{
		}
		else if(!strcmp(argv[x], "--version") || !strcmp(argv[x], "-v"))
		{
			show_version_msg();
			quit_on_invalid_arg();
		}
		else if(!strcmp(argv[x], "--help") || !strcmp(argv[x], "-h"))
		{
			show_help_msg();
			quit_on_invalid_arg();
		}
		else if(!strcmp(argv[x], "--logging"))
		{
			/* do nothing, it's handeled in main() */
		}
		else if(!strcmp(argv[x], "-c"))
		{
			if(x == argc - 1)
			{
				puts("Argument missing after \"-c\"");
				quit_on_invalid_arg();
			}
			/* do nothing, it's handeled in exec_startup_commands() */
			x++;
		}
		else if(argv[x][0] == '+')
		{
			/* do nothing, it's handeled in exec_startup_commands() */
		}
		else if(path_exists(argv[x]) || is_path_absolute(argv[x]) ||
				is_root_dir(argv[x]))
		{
			if(lwin_path[0] != '\0')
			{
				parse_path(dir, argv[x], rwin_path);
				*rwin_handle = !select;
			}
			else
			{
				parse_path(dir, argv[x], lwin_path);
				*lwin_handle = !select;
			}
			select = 0;
		}
		else if(curr_stats.load_stage == 0)
		{
			show_help_msg();
			quit_on_invalid_arg();
		}
		else
		{
			show_error_msgf("--remote error", "Invalid argument: %s", argv[x]);
		}
	}
}
コード例 #10
0
ファイル: filtering.c プロジェクト: vifm/vifm
/* Copies/moves elements of the unfiltered list into dir_entry list.  add
 * parameter controls whether entries matching filter are copied into dir_entry
 * list.  clear parameter controls whether entries not matching filter are
 * cleared in unfiltered list.  Returns zero unless addition is performed in
 * which case can return non-zero when all files got filtered out. */
static int
update_filtering_lists(view_t *view, int add, int clear)
{
	/* filters_drop_temporaries() is a similar function. */

	size_t i;
	size_t list_size = 0U;
	dir_entry_t *parent_entry = NULL;
	int parent_added = 0;

	for(i = 0; i < view->local_filter.unfiltered_count; ++i)
	{
		/* FIXME: some very long file names won't be matched against some
		 * regexps. */
		char name_with_slash[NAME_MAX + 1 + 1];

		dir_entry_t *const entry = &view->local_filter.unfiltered[i];
		const char *name = entry->name;

		if(is_parent_dir(name))
		{
			if(entry->child_pos == 0)
			{
				parent_entry = entry;
				if(add && cfg_parent_dir_is_visible(is_root_dir(view->curr_dir)))
				{
					(void)add_dir_entry(&view->dir_entry, &list_size, entry);

					parent_added = 1;
				}
				continue;
			}
			else if(!filter_is_empty(&view->local_filter.filter))
			{
				if(clear)
				{
					fentry_free(view, entry);
				}
				continue;
			}
		}

		if(fentry_is_dir(entry))
		{
			append_slash(name, name_with_slash, sizeof(name_with_slash));
			name = name_with_slash;
		}

		/* tag links to position of nodes passed through filter in list of visible
		 * files.  Nodes that didn't pass have -1. */
		entry->tag = -1;
		if(filter_matches(&view->local_filter.filter, name) != 0)
		{
			if(add)
			{
				dir_entry_t *e = add_dir_entry(&view->dir_entry, &list_size, entry);
				if(e != NULL)
				{
					entry->tag = list_size - 1U;
					/* We basically grow the tree node by node while performing
					 * reparenting. */
					reparent_tree_node(entry, e);
				}
			}
		}
		else
		{
			if(clear)
			{
				fentry_free(view, entry);
			}
		}
	}

	if(clear)
	{
		/* XXX: the check of name pointer is horrible, but is needed to prevent
		 *      freeing of entry in use. */
		if(!parent_added && parent_entry != NULL && list_size != 0U &&
				view->dir_entry[0].name != parent_entry->name)
		{
			fentry_free(view, parent_entry);
		}
	}
	if(add)
	{
		view->list_rows = list_size;
		view->filtered = view->local_filter.prefiltered_count
		               + view->local_filter.unfiltered_count - list_size;
		ensure_filtered_list_not_empty(view, parent_entry);
		return list_size == 0U
		    || (list_size == 1U && parent_added &&
						(filter_matches(&view->local_filter.filter, "../") == 0));
	}
	return 0;
}
コード例 #11
0
ファイル: filesystem.C プロジェクト: beequ7et/cinelerra-cv
int FileSystem::update(const char *new_dir)
{
	DIR *dirstream;
	struct dirent64 *new_filename;
	struct stat ostat;
	struct tm *mod_time;
	int i, j, k, include_this;
	FileItem *new_file;
	char full_path[BCTEXTLEN], name_only[BCTEXTLEN];
	ArrayList<FileItem*>directories;
	ArrayList<FileItem*>files;
	int result = 0;

	delete_directory();
	if(new_dir != 0) strcpy(current_dir, new_dir);
	dirstream = opendir(current_dir);
	if(!dirstream) return 1;          // failed to open directory

	while(new_filename = readdir64(dirstream))
	{
		include_this = 1;

// File is directory heirarchy
		if(!strcmp(new_filename->d_name, ".") || 
			!strcmp(new_filename->d_name, "..")) include_this = 0;

// File is hidden and we don't want all files
		if(include_this && !show_all_files && new_filename->d_name[0] == '.') include_this = 0;

// file not hidden
  		if(include_this)
    	{
			new_file = new FileItem;
			sprintf(full_path, "%s", current_dir);
			if(!is_root_dir(current_dir)) strcat(full_path, "/");
			strcat(full_path, new_filename->d_name);
			strcpy(name_only, new_filename->d_name);
			new_file->set_path(full_path);
			new_file->set_name(name_only);

// Get information about the file.
			if(!stat(full_path, &ostat))
			{
				new_file->size = ostat.st_size;
				mod_time = localtime(&(ostat.st_mtime));
				new_file->month = mod_time->tm_mon + 1;
				new_file->day = mod_time->tm_mday;
				new_file->year = mod_time->tm_year + 1900;
				new_file->calendar_time = ostat.st_mtime;

				if(S_ISDIR(ostat.st_mode))
				{
					strcat(name_only, "/"); // is a directory
					new_file->is_dir = 1;
				}

// File is excluded from filter
				if(include_this && test_filter(new_file)) include_this = 0;
//printf("FileSystem::update 3 %d %d\n", include_this, test_filter(new_file));

// File is not a directory and we just want directories
				if(include_this && want_directory && !new_file->is_dir) include_this = 0;
			}
			else
			{
//printf("FileSystem::update 3 %s\n", full_path);
				include_this = 0;
			}

// add to list
			if(include_this)
			{
				if(new_file->is_dir) directories.append(new_file);
 				else files.append(new_file);
			}
			else
				delete new_file;
		}
	}

	closedir(dirstream);
// combine the directories and files in the master list
	combine(&directories, &files);
// remove pointers
	directories.remove_all();
	files.remove_all();

	return result;
// success
}