示例#1
0
/* Completes name of the environment variables. */
static void
complete_envvar(const char str[])
{
	extern char **environ;
	char **p = environ;
	const size_t len = strlen(str);

	while(*p != NULL)
	{
		if(strncmp(*p, str, len) == 0)
		{
			char *const equal = strchr(*p, '=');
			/* Actually equal shouldn't be NULL unless environ content is corrupted.
			 * But the check below won't harm. */
			if(equal != NULL)
			{
				*equal = '\0';
				vle_compl_add_match(*p);
				*equal = '=';
			}
		}
		p++;
	}

	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#2
0
void
complete_colorschemes(const char name[])
{
	int i;
	size_t len;
	int schemes_len;
	char **schemes;

	len = strlen(name);
	schemes = list_color_schemes(&schemes_len);

	for(i = 0; i < schemes_len; i++)
	{
		if(schemes[i][0] != '.' || name[0] == '.')
		{
			if(strnoscmp(name, schemes[i], len) == 0)
			{
				vle_compl_add_match(schemes[i]);
			}
		}
	}

	free_string_array(schemes, schemes_len);

	vle_compl_finish_group();
	vle_compl_add_last_match(name);
}
示例#3
0
static void
complete_filetype(const char *str)
{
	const char *filename = get_current_file_name(curr_view);
	assoc_records_t ft = get_all_programs_for_file(filename);

	complete_progs(str, ft);
	free(ft.list);

	complete_progs(str, get_magic_handlers(filename));

	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#4
0
static void
complete_highlight_groups(const char *str)
{
	int i;
	const size_t len = strlen(str);
	for(i = 0; i < MAXNUM_COLOR - 2; i++)
	{
		if(strncasecmp(str, HI_GROUPS[i], len) == 0)
		{
			vle_compl_add_match(HI_GROUPS[i]);
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#5
0
/* Performs str completion using items in the list of length list_len. */
static void
complete_from_string_list(const char str[], const char *list[], size_t list_len)
{
	int i;
	const size_t len = strlen(str);
	for(i = 0; i < list_len; i++)
	{
		if(strncmp(str, list[i], len) == 0)
		{
			vle_compl_add_match(list[i]);
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#6
0
void
complete_group_name(const char *str)
{
	struct group* gr;
	size_t len = strlen(str);

	setgrent();
	while((gr = getgrent()) != NULL)
	{
		if(strncmp(gr->gr_name, str, len) == 0)
		{
			vle_compl_add_match(gr->gr_name);
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#7
0
static void
complete_winrun(const char *str)
{
	static const char *VARIANTS[] = { "^", "$", "%", ".", "," };
	const size_t len = strlen(str);
	int i;

	for(i = 0; i < ARRAY_LEN(VARIANTS); i++)
	{
		if(strncmp(str, VARIANTS[i], len) == 0)
		{
			vle_compl_add_match(VARIANTS[i]);
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#8
0
void
complete_user_name(const char *str)
{
	struct passwd* pw;
	size_t len;

	len = strlen(str);
	setpwent();
	while((pw = getpwent()) != NULL)
	{
		if(strncmp(pw->pw_name, str, len) == 0)
		{
			vle_compl_add_match(pw->pw_name);
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#9
0
文件: test.c 项目: KryDos/vifm
static int
complete_args(int id, const char *args, int argc, char **argv, int arg_pos,
		void *extra_arg)
{
	const char *arg;

	vle_compl_reset();
	vle_compl_add_match("followlinks");
	vle_compl_add_match("fastrun");
	vle_compl_finish_group();
	vle_compl_add_last_match("f");

	arg = strrchr(args, ' ');
	if(arg == NULL)
		arg = args;
	else
		arg++;
	return arg - args;
}
示例#10
0
static int
complete_chown(const char *str)
{
#ifndef _WIN32
	char *colon = strchr(str, ':');
	if(colon == NULL)
	{
		complete_user_name(str);
		return 0;
	}
	else
	{
		complete_user_name(colon + 1);
		return colon - str + 1;
	}
#else
	vle_compl_add_last_match(str);
	return 0;
#endif
}
示例#11
0
static void
complete_help(const char *str)
{
	int i;

	if(!cfg.use_vim_help)
	{
		return;
	}

	for(i = 0; tags[i] != NULL; i++)
	{
		if(strstr(tags[i], str) != NULL)
		{
			vle_compl_add_match(tags[i]);
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#12
0
文件: bmarks.c 项目: acklinr/vifm
void
bmarks_complete(int n, char *tags[], const char str[])
{
	const size_t len = strlen(str);
	size_t i;
	for(i = 0U; i < bmark_count; ++i)
	{
		char *tag = bmarks[i].tags, *state = NULL;
		while((tag = split_and_get(tag, ',', &state)) != NULL)
		{
			if(strncmp(tag, str, len) == 0 && !is_in_string_array(tags, n, tag))
			{
				vle_compl_add_match(tag, "");
			}
		}
	}

	vle_compl_finish_group();
	vle_compl_add_last_match(str);
}
示例#13
0
static int
complete_highlight_arg(const char *str)
{
	/* TODO: Refactor this function complete_highlight_arg() */
	char *equal = strchr(str, '=');
	int result = (equal == NULL) ? 0 : (equal - str + 1);
	size_t len = strlen((equal == NULL) ? str : ++equal);
	if(equal == NULL)
	{
		static const char *args[] = {
			"cterm",
			"ctermfg",
			"ctermbg",
		};

		int i;

		for(i = 0; i < ARRAY_LEN(args); i++)
		{
			if(strncmp(str, args[i], len) == 0)
			{
				vle_compl_add_match(args[i]);
			}
		}
	}
	else
	{
		if(strncmp(str, "cterm", equal - str - 1) == 0)
		{
			static const char *STYLES[] = {
				"bold",
				"underline",
				"reverse",
				"inverse",
				"standout",
				"none",
			};

			int i;

			char *comma = strrchr(equal, ',');
			if(comma != NULL)
			{
				result += comma - equal + 1;
				equal = comma + 1;
				len = strlen(equal);
			}

			for(i = 0; i < ARRAY_LEN(STYLES); i++)
			{
				if(strncasecmp(equal, STYLES[i], len) == 0)
				{
					vle_compl_add_match(STYLES[i]);
				}
			}
		}
		else
		{
			int i;

			if(strncasecmp(equal, "default", len) == 0)
			{
				vle_compl_add_match("default");
			}
			if(strncasecmp(equal, "none", len) == 0)
			{
				vle_compl_add_match("none");
			}

			for(i = 0; i < ARRAY_LEN(XTERM256_COLOR_NAMES); i++)
			{
				if(strncasecmp(equal, XTERM256_COLOR_NAMES[i], len) == 0)
				{
					vle_compl_add_match(XTERM256_COLOR_NAMES[i]);
				}
			}
			for(i = 0; i < ARRAY_LEN(LIGHT_COLOR_NAMES); i++)
			{
				if(strncasecmp(equal, LIGHT_COLOR_NAMES[i], len) == 0)
				{
					vle_compl_add_match(LIGHT_COLOR_NAMES[i]);
				}
			}
		}
	}
	vle_compl_finish_group();
	vle_compl_add_last_match((equal == NULL) ? str : equal);
	return result;
}