Exemple #1
0
void load_command_list(const char *prefix,
		struct cmdnames *main_cmds,
		struct cmdnames *other_cmds)
{
	const char *env_path = getenv("PATH");
	const char *exec_path = git_exec_path();

	if (exec_path) {
		list_commands_in_dir(main_cmds, exec_path, prefix);
		qsort(main_cmds->names, main_cmds->cnt,
		      sizeof(*main_cmds->names), cmdname_compare);
		uniq(main_cmds);
	}

	if (env_path) {
		char *paths, *path, *colon;
		path = paths = xstrdup(env_path);
		while (1) {
			if ((colon = strchr(path, PATH_SEP)))
				*colon = 0;
			if (!exec_path || strcmp(path, exec_path))
				list_commands_in_dir(other_cmds, path, prefix);

			if (!colon)
				break;
			path = colon + 1;
		}
		free(paths);

		qsort(other_cmds->names, other_cmds->cnt,
		      sizeof(*other_cmds->names), cmdname_compare);
		uniq(other_cmds);
	}
	exclude_cmds(other_cmds, main_cmds);
}
Exemple #2
0
void			list_commands(t_context *context)
{
	char		*path;
	char		**dirs;
	size_t		i;

	commands_delete(context->commands);
	path = environ_get(context, VAR_PATH);
	if (path)
	{
		dirs = ft_strsplit(path, PATH_DIR_SEPARATOR);
		i = 0;
		while (dirs[i])
		{
			list_commands_in_dir(context->commands, dirs[i]);
			++i;
		}
		char_array_free(dirs);
	}
}