Exemple #1
0
int		opt_env2(int *i, char ***env, char **args)
{
	char	**split;

	split = ft_strsplit(args[*i], '=');
	if (tablen(split) > 2)
	{
		ft_putendl("Syntax error : use key=value");
		return (0);
	}
	else
		ft_setenv(env, split[0], split[1], NULL);
	return (1);
}
Exemple #2
0
int		check_cmd(char **arg)
{
	if (*arg == (void*)0)
		return (0);
	else if (ft_strcmp(arg[0], "exit") == 0)
		exit(1);
	else if (ft_strcmp(arg[0], "env") == 0)
		return (print_env());
	else if (ft_strcmp(arg[0], "cd") == 0)
		return (ft_cd(arg[1]));
	else if (ft_strcmp(arg[0], "unsetenv") == 0)
		return (ft_unsetenv(arg[1]));
	else if (ft_strcmp(arg[0], "setenv") == 0)
		return (ft_setenv(arg[1], arg[2], arg[3]));
	return (1);
}
Exemple #3
0
void						ft_stophandler(int n)
{
	char					cp[2];

	if (n == SIGTSTP)
	{
		cp[0] = 032;
		cp[1] = 0;
		signal(SIGTSTP, SIG_DFL);
		ioctl(ft_tty(), TIOCSTI, cp);
		ft_unsetenv();
	}
	if (n == SIGCONT)
	{
		signal(SIGTSTP, ft_stophandler);
		ft_setenv();
		ft_plst();
	}
}
Exemple #4
0
int		check_builtin(t_env *e)
{
	int		ret;

	if (!e->av[0])
		return (0);
	ret = (ft_strequ(e->av[0], "env") && !(e->av[1])) ? display_env(e) : 0;
	if (ret != 2)
		ret = (ft_strequ(e->av[0], "cd")) ? ft_cd(e) : 0;
	if (ret != 2)
		ret = (ft_strequ(e->av[0], "setenv")) ? ft_setenv(e) : 0;
	if (ret != 2)
		ret = (ft_strequ(e->av[0], "unsetenv")) ? ft_unsetenv(e) : 0;
	if (ret != 2)
		ret = (!(ft_strncmp(e->av[0], "./", 2))) ? ft_exec(e) : 0;
	if (ret != 2)
		ret = (ft_strcmp(e->av[0], "exit")) ? 0 : 1;
	return (ret);
}
Exemple #5
0
static void	ft_envsplitted(t_execdata *data, t_execdata *tmp, int i)
{
	char		*buff;
	char		*ptr;

	while (data->av[i] && (ptr = ft_strchr(data->av[i], '=')))
	{
		buff = ft_strndup(data->av[i], ptr - data->av[i]);
		ft_setenv(tmp, buff, ptr + 1, 1);
		free(buff);
		i++;
	}
	tmp->av = mknewav(data->av, i);
	if ((i = launchprogram(data, tmp)) == 0 || i == 2)
	{
		ft_deinit(tmp);
		exit(0);
	}
}
Exemple #6
0
int			ft_perform_cmd(t_tree *t, t_env *e)
{
	int		value;

	value = 0;
	if (!ft_strcmp(t->p->tok, "exit"))
		value = ft_exit(t->p);
	else if (!ft_strcmp(t->p->tok, "echo"))
		ft_echo(t->p);
	else if (!(ft_strcmp(t->p->tok, "cd")))
		value = ft_cd(t->p, e);
	else if (!(ft_strcmp(t->p->tok, "env")))
		value = ft_env(t->p, e);
	else if (!(ft_strcmp(t->p->tok, "unsetenv")))
		value = ft_unsetenv(t->p, &(e->env));
	else if (!(ft_strcmp(t->p->tok, "setenv")))
		value = ft_setenv(t->p, &(e->env));
	else
		value = ft_perform_exe(t->p, e);
	return (value);
}
Exemple #7
0
int implemented_function(char **cmd)
{
	if (!cmd)
		return (1);
	if (ft_strcmp(cmd[0], "exit") == 0)
	{
		free_arr(&cmd);
		return (-1);
	}
	else if (ft_strcmp(cmd[0], "env") == 0)
		ft_env(cmd);
	else if (ft_strcmp(cmd[0], "cd") == 0)
		ft_cd(cmd);
	else if (ft_strcmp(cmd[0], "setenv") == 0)
		ENVP = ft_setenv(cmd);
	else if (ft_strcmp(cmd[0], "unsetenv") == 0)
		ENVP = ft_unsetenv(cmd);
	else
		return (0);
	return (1);
}
Exemple #8
0
int		builtin_commands(char *name, char **args, t_env **env_list)
{
	int		ret;

	ret = 0;
	if (ft_strcmp(name, "cd") == 0 && (ret = 1))
		change_cwd(args, env_list);
	else if (ft_strcmp(name, "env") == 0 && (ret = 1))
		print_env(*env_list);
	else if (ft_strcmp(name, "setenv") == 0 && (ret = 1))
		ft_setenv(args[1], args[2], env_list);
	else if (ft_strcmp(name, "unsetenv") == 0 && (ret = 1))
		ft_unsetenv(args[1], env_list);
	else if (ft_strcmp(name, "echo") == 0 && (ret = 1))
		ft_echo(args, *env_list);
	else if (ft_strcmp(name, "exit") == 0)
		ret = 1;
	if (ret == 1)
		return (1);
	return (0);
}
Exemple #9
0
void	execute(t_env *env)
{
	if (ft_strcmp(env->com, "exit") == 0 || ft_strcmp(env->com, "quit") == 0)
		env->done = 1;
	else if (ft_strcmp(env->com, "clear") == 0)
		ft_printf("\033c");
	else if (ft_strcmp(env->com, "echo") == 0)
		echo(env);
	else if (ft_strcmp(env->com, "env") == 0)
		show_env(env->env_var);
	else if (ft_strcmp(env->com, "setenv") == 0)
		ft_setenv(env);
	else if (ft_strcmp(env->com, "unsetenv") == 0)
		ft_unsetenv(env);
	else if (ft_strcmp(env->com, "cd") == 0)
		ft_cd(env);
	else if (ft_strcmp(env->com, "pwd") == 0)
		ft_pwd(env);
	else
		ft_run(env);
}
Exemple #10
0
int			cd_set(char *owd, char *awd, char *cmd, t_list **env_l)
{
	t_shell	content;
	t_list	*cmd_pwd;
	char	*wd;

	if (ft_strcmp("setenv PWD=", cmd))
		wd = owd;
	else
		wd = awd;
	if (!(content.str = ft_strjoin(cmd, wd)))
	{
		free(awd);
		free(owd);
		return (1);
	}
	if (!(cmd_pwd = ft_lstnew(&content, sizeof(content))))
		return (1);
	ft_setenv(cmd_pwd, env_l);
	ft_lstdelone(&cmd_pwd, (void(*)(void*, size_t))del_content);
	return (0);
}
Exemple #11
0
void	own_command(t_env *env, char **sa, char *s)
{
	if (ft_memcmp(sa[0], "echo", 4) == 0)
		ft_echo(sa);
	else if (ft_memcmp(sa[0], "cd", 2) == 0)
		ft_cd(env, sa);
	else if (ft_memcmp(sa[0], "setenv", 6) == 0)
		ft_setenv(env, sa);
	else if (ft_memcmp(sa[0], "unsetenv", 8) == 0)
		ft_unsetenv(env, sa);
	else if (ft_memcmp(sa[0], "env", 3) == 0)
		call_env(*env, s);
	else if (ft_memcmp(sa[0], "help", 4) == 0)
		ft_help(env, sa);
	else if (ft_memcmp(sa[0], "easter", 6) == 0)
		easteregg(env, sa);
	else if (ft_memcmp(sa[0], "history", 7) == 0)
		list_history(env, sa);
	else
		ft_putstr(E_MESS05);
	FREE_(s);
}
Exemple #12
0
int					check_bultins(char **av, t_env *env)
{
	if (!ft_strcmp(av[0], "exit"))
		ft_exit(av, env);
	else if (!ft_strcmp(av[0], "cd"))
		ft_cd(av, env);
	else if (!ft_strcmp(av[0], "setenv"))
		ft_setenv(av, env);
	else if (!ft_strcmp(av[0], "unsetenv"))
		ft_unsetenv(av, env);
	else if (!ft_strcmp(av[0], "env"))
	{
		ft_env(av, env->environ);
		resumed_terminal();
	}
	else if (!ft_strcmp(av[0], "echo"))
		ft_echo(av, env->environ);
	else
		return (0);
	free_double_array(av);
	return (1);
}
void	ft_parse_input(t_shell **shell)
{
	if (*(*shell)->input)
	{
		(*shell)->argv = ft_parse_get_args((*shell)->input);
		(*shell)->argc = ft_count_arg((*shell)->argv);
		if ((*shell)->argc != 0)
		{
			if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "env") == 0)
				ft_print_environ(*shell);
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "setenv") == 0)
				ft_setenv(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]),
								"unsetenv") == 0)
				ft_unsetenv(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "exit") == 0)
				ft_exit(&(*shell));
			else if (ft_strcmp(ft_strtolower((*shell)->argv[0]), "cd") == 0)
				ft_cd(&(*shell));
			else
				ft_exec_bin(&(*shell));
		}
	}
}