Esempio n. 1
0
/* Clones all records which pattern matches the file.  Returns list of records
 * composed of clones. */
static assoc_records_t
clone_all_matching_records(const char file[], const assoc_list_t *record_list)
{
	int i;
	assoc_records_t result = {};

	for(i = 0; i < record_list->count; ++i)
	{
		assoc_t *const assoc = &record_list->list[i];
		if(matcher_matches(assoc->matcher, file))
		{
			ft_assoc_record_add_all(&result, &assoc->records);
		}
	}

	return result;
}
Esempio n. 2
0
int
filters_file_is_visible(view_t *view, const char dir[], const char name[],
		int is_dir, int apply_local_filter)
{
	/* FIXME: some very long file names won't be matched against some regexps. */
	char name_with_slash[NAME_MAX + 1 + 1];
	char path[PATH_MAX + sizeof(name_with_slash)];

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

	if(filter_matches(&view->auto_filter, name) > 0)
	{
		return 0;
	}

	if(apply_local_filter &&
			filter_matches(&view->local_filter.filter, name) == 0)
	{
		return 0;
	}

	if(matcher_is_empty(view->manual_filter))
	{
		return 1;
	}

	if(matcher_is_full_path(view->manual_filter))
	{
		const size_t nchars = copy_str(path, sizeof(path) - 1, dir);
		path[nchars - 1U] = '/';
		copy_str(path + nchars, sizeof(path) - nchars, name);
		name = path;
	}

	return matcher_matches(view->manual_filter, name)
	     ? !view->invert
	     : view->invert;
}
Esempio n. 3
0
const col_attr_t *
get_file_hi(const col_scheme_t *cs, const char fname[], int *hi_hint)
{
	int i;

	if(*hi_hint != -1)
	{
		assert(*hi_hint >= 0 && "Wrong index.");
		assert(*hi_hint < cs->file_hi_count && "Wrong index.");
		return &cs->file_hi[*hi_hint].hi;
	}

	for(i = 0; i < cs->file_hi_count; ++i)
	{
		const file_hi_t *const file_hi = &cs->file_hi[i];
		if(matcher_matches(file_hi->matcher, fname))
		{
			*hi_hint = i;
			return &file_hi->hi;
		}
	}
	return NULL;
}
Esempio n. 4
0
/* Finds first existing command which pattern matches given file.  Returns the
 * command (it's lifetime is managed by this unit) or NULL on failure. */
static const char *
find_existing_cmd(const assoc_list_t *record_list, const char file[])
{
	int i;

	for(i = 0; i < record_list->count; ++i)
	{
		assoc_record_t prog;
		assoc_t *const assoc = &record_list->list[i];

		if(!matcher_matches(assoc->matcher, file))
		{
			continue;
		}

		prog = find_existing_cmd_record(&assoc->records);
		if(!is_assoc_record_empty(&prog))
		{
			return prog.command;
		}
	}

	return NULL;
}