Ejemplo n.º 1
0
Archivo: local.c Proyecto: mdugot/42sh
static char	*is_tild(char *line, t_shell *sh)
{
	char	*tmp;

	tmp = NULL;
	if (*line == '~')
	{
		tmp = replace_tild(sh->env, line);
		line = tmp;
		tmp = NULL;
	}
	else
		line = ft_strdup(line);
	return (line);
}
Ejemplo n.º 2
0
int	replace_var(t_cmd *cmd, t_shell *shell)
{
	int		ret;
	t_cmd	*tmp;

	tmp = cmd->next;
	while (tmp != cmd)
	{
		if (tmp->word[0] == '!')
			if ((ret = replace_history(tmp, shell->his)) == -1 || ret == -2)
				return (ret);
		if (tmp->word[0] == '~')
			if (replace_tild(tmp, shell->env, shell->home) == -1)
				return (-1);
		tmp = tmp->next;
	}
	return (0);
}
Ejemplo n.º 3
0
int	replace_var(t_cmd *cmd, t_data *data)
{
  int	ret;
  t_cmd	*tmp;

  tmp = cmd->next;
  while (tmp != cmd)
    {
      if (tmp->word[0] == '!')
	if ((ret = replace_history(tmp, data->his)) == -1 || ret == -2)
	  return (ret);
      if (tmp->word[0] == '$')
	if ((ret = find_and_replace(tmp, data->env, data->var)) == -1
	    || ret == -2)
	  return (ret);
      if (tmp->word[0] == '~')
	if (replace_tild(tmp, data->env, data->home) == -1)
	  return (-1);
      tmp = tmp->next;
    }
  return (0);
}
Ejemplo n.º 4
0
void		exec_cmd(t_param *param, t_cmd *cmd)
{
  int		pid;
  t_fd		save;

  if ((param->tty) && (param->debug))
    my_fprintf(2, "%[3]Exec command `%S' io [%d %d %d] %[]\n",
	       cmd->arg[0], cmd->in.fd, cmd->out.fd, cmd->err.fd);
  if (replace_tild(param, cmd))
    return;
  if (globing_substitution(cmd))
    return;
  SAVE_FD;
  DUP_FD;
  if (exec_builtins(param, cmd))
    cmd->pid = PID_BUILTIN;
  else if ((pid = fork()))
    cmd->pid = pid;
  else
    exec_cmd_low_level(param, cmd);
  RESTOR_FD;
  return;
}
Ejemplo n.º 5
0
void	run_minishell2(t_struc *s, char **tab)
{
	int		i;
	char	**tab2;

	i = 0;
	while (tab[i])
	{
		tab2 = ft_strdoublesplit(tab[i], ' ', '\t');
		if (replace_tild(s, &tab2) == -1)
			break ;
		s->argc = get_argc(tab2);
		s->cmd = tab2[0];
		if (!s->cmd)
			break ;
		s->argv = tab2;
		if (!ft_strcmp(s->cmd, "exit"))
			exec_exit(s);
		g_ctrl_c = 1;
		!is_builtin(s) ? exec_cmd(s, s->env) : exec_builtin(s, s->env);
		free(s->cmd);
		i++;
	}
}