Example #1
0
void	manage_env(t_group *grp)
{
	int		i;
	int		j;
	int		pos;

	i = -1;
	j = -1;
	pos = list_to_tab(0, grp->first, NULL);
	while (++i < grp->define_cmd[namenv] &&
		CMD(cmd_split)[i + grp->define_cmd[e_opt] + 1])
		pos += 1;
	grp->env = (char **)malloc(sizeof(char *) * (pos + 1));
	grp->env_save = (char **)malloc(sizeof(char *) * (pos + 1));
	while (++j < pos + 1)
	{
		grp->env[j] = NULL;
		grp->env_save[j] = NULL;
	}
	i = -1;
	pos = list_to_tab(1, grp->first, &(grp->env));
	while (++i < grp->define_cmd[namenv] &&
		CMD(cmd_split)[i + grp->define_cmd[e_opt] + 1])
	{
		grp->env[pos + i] =
		SDUP(CMD(cmd_split)[i + grp->define_cmd[e_opt] + 1]);
	}
}
Example #2
0
File: exec.c Project: elyl/mysh
void exec(char *tmp, t_com *com, t_list *env)
{
  int	pid;
  int	fd[2] = {0, 0};

  if (com->op & OP_PIPE)
    {
      pipe(fd);
      com->next->fd[0] = fd[0];
      com->next->fd[1] = fd[1];
    }
  if ((pid = fork()) == 0)
    {
      if (com->op & OP_PIPE)
	{
	  close(1);
	  close(fd[0]);
	  dup(fd[1]);
	}
      if (com->fd[0] != 0)
	{
	  close(0);
	  dup(com->fd[0]);
	}
      execve(tmp, list_to_tab(com->com), list_to_tab(env));
    }
  else if (pid != -1)
    {
      if (fd[1] != 0)
	close(fd[1]);
      if (com->fd[0] != 0)
	close(com->fd[0]);
      run_com(com->next, env);
      if (!(com->op & OP_BG) && com->next == NULL)
	waitpid(pid, NULL, 0);
    }
  else
    printf("An error occured while running the program\n");
}
Example #3
0
t_shell				*init(char **env)
{
	t_shell			*shell;

	if ((shell = shellnew()))
	{
		if ((shell->env = env_to_list(env)))
			shell->envc = list_to_tab(shell->env);
		if (!(shell->prompt = get_env(shell->env, "USER")))
			shell->prompt = ft_strdup("~>");
		return (shell);
	}
	return (shell);
}
Example #4
0
void		main_manager(char *s, t_main **my_env)
{
  t_main	*list;
  char		**env;

  env = list_to_tab(*my_env);
  list = NULL;
  parsing_entree(&list, s);
  if (list != NULL)
    {
      if (execution(list, my_env, env) != -1)
	my_free_list(list);
    }
  my_free_tab(env);
}
Example #5
0
int					re_init(t_shell *shell)
{
	char			*str;

	if (shell && shell->env)
	{
		ft_deltab(&(shell->envc));
		shell->envc = list_to_tab(shell->env);
		ft_memdel((void **)&(shell->prompt));
		if (!(shell->prompt = get_env(shell->env, "USER")))
			shell->prompt = ft_strdup("~>");
		ft_deltab(&shell->path);
		str = get_env(shell->env, "PATH");
		shell->path = ft_strsplit(str, ':');
		ft_memdel((void *)&str);
		return (1);
	}
	return (0);
}