예제 #1
0
파일: filetype.c 프로젝트: lowtalker/vifm
/* Associates pattern with the list of viewers. */
static void
assoc_viewers(matcher_t *matcher, const assoc_records_t *viewers)
{
	const assoc_t assoc = {
		.matcher = matcher,
		.records = clone_assoc_records(viewers, matcher_get_expr(matcher),
				&fileviewers),
	};

	add_assoc(&fileviewers, assoc);
}

/* Clones list of association records.  Returns the clone. */
static assoc_records_t
clone_assoc_records(const assoc_records_t *records, const char pattern[],
		const assoc_list_t *dst)
{
	int i;
	assoc_records_t list = {};

	for(i = 0; i < records->count; ++i)
	{
		if(!ft_assoc_exists(dst, pattern, records->list[i].command))
		{
			ft_assoc_record_add(&list, records->list[i].command,
					records->list[i].description);
		}
	}

	return list;
}
예제 #2
0
파일: info.c 프로젝트: cfillion/vifm
/* Stores list of associations to the file. */
static void
write_assocs(FILE *fp, const char str[], char mark, assoc_list_t *assocs,
		int prev_count, char *prev[])
{
	int i;

	fprintf(fp, "\n# %s:\n", str);

	for(i = 0; i < assocs->count; ++i)
	{
		int j;

		assoc_t assoc = assocs->list[i];

		for(j = 0; j < assoc.records.count; ++j)
		{
			assoc_record_t ft_record = assoc.records.list[j];

			/* The type check is to prevent builtin fake associations to be written
			 * into vifminfo file. */
			if(ft_record.command[0] == '\0' || ft_record.type == ART_BUILTIN)
			{
				continue;
			}

			if(ft_record.description[0] == '\0')
			{
				fprintf(fp, "%c%s\n\t", mark, matcher_get_expr(assoc.matcher));
			}
			else
			{
				fprintf(fp, "%c%s\n\t{%s}", mark, matcher_get_expr(assoc.matcher),
						ft_record.description);
			}
			write_doubling_commas(fp, ft_record.command);
			fputc('\n', fp);
		}
	}

	for(i = 0; i < prev_count; i += 2)
	{
		fprintf(fp, "%c%s\n\t%s\n", mark, prev[i], prev[i + 1]);
	}
}
예제 #3
0
파일: filetype.c 프로젝트: lowtalker/vifm
/* Associates pattern with the list of programs either for X or non-X
 * associations and depending on current execution environment. */
static void
assoc_programs(matcher_t *matcher, const assoc_records_t *programs, int for_x,
		int in_x)
{
	const assoc_t assoc = {
		.matcher = matcher,
		.records = clone_assoc_records(programs, matcher_get_expr(matcher),
				for_x ? &xfiletypes : &filetypes),
	};

	register_assoc(assoc, for_x, in_x);
}

/* Parses comma separated list of commands into array of associations.  Returns
 * the list. */
static assoc_records_t
parse_command_list(const char cmds[], int with_descr)
{
	assoc_records_t records = {};

	char *free_this = strdup(cmds);

	char *part = free_this, *state = NULL;
	while((part = split_and_get_dc(part, &state)) != NULL)
	{
		const char *description = "";

		if(with_descr && *part == '{')
		{
			char *p = strchr(part + 1, '}');
			if(p != NULL)
			{
				*p = '\0';
				description = part + 1;
				part = skip_whitespace(p + 1);
			}
		}

		if(part[0] != '\0')
		{
			ft_assoc_record_add(&records, part, description);
		}
	}

	free(free_this);

	return records;
}
예제 #4
0
파일: filtering.c 프로젝트: vifm/vifm
void
name_filters_remove(view_t *view)
{
	if(name_filters_empty(view))
	{
		return;
	}

	(void)replace_string(&view->prev_manual_filter,
			matcher_get_expr(view->manual_filter));
	(void)replace_string(&view->prev_auto_filter, view->auto_filter.raw);
	view->prev_invert = view->invert;

	name_filters_drop(view);
	view->invert = cfg.filter_inverted_by_default ? 1 : 0;

	ui_view_schedule_reload(view);
}
예제 #5
0
파일: filetype.c 프로젝트: lowtalker/vifm
int
ft_assoc_exists(const assoc_list_t *assocs, const char pattern[],
		const char cmd[])
{
	int i;
	char *undoubled;

	if(*cmd == '{')
	{
		const char *const descr_end = strchr(cmd + 1, '}');
		if(descr_end != NULL)
		{
			cmd = descr_end + 1;
		}
	}

	undoubled = strdup(cmd);
	undouble_commas(undoubled);

	for(i = 0; i < assocs->count; ++i)
	{
		int j;

		const assoc_t assoc = assocs->list[i];
		if(strcmp(matcher_get_expr(assoc.matcher), pattern) != 0)
		{
			continue;
		}

		for(j = 0; j < assoc.records.count; ++j)
		{
			const assoc_record_t ft_record = assoc.records.list[j];
			if(strcmp(ft_record.command, undoubled) == 0)
			{
				free(undoubled);
				return 1;
			}
		}
	}

	free(undoubled);
	return 0;
}