Browse Source

use -c argument of minishell for subshells

master
narnaud 3 years ago
parent
commit
5189fe863b
  1. 14
      minishell.c
  2. 5
      parser.c
  3. 4
      utils.c

14
minishell.c

@ -6,7 +6,7 @@
/* By: mea <mea@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 12:14:09 by narnaud #+# #+# */
/* Updated: 2022/05/18 15:50:52 by narnaud@stude ### ########.fr */
/* Updated: 2022/05/24 08:23:21 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -77,8 +77,7 @@ int main(int argc, char **argv, char **envp)
static t_datas datas;
static int i = 0;
datas.silent = argc > 1;
(void)argc;
datas.silent = (argc > 2 && !ft_strncmp(argv[1], "-c", 3));
datas.envp = ft_calloc(ENVP_MAX_SIZE, sizeof(char *));
while (*envp)
datas.envp[i++] = ft_strdup(*(envp++));
@ -87,14 +86,7 @@ int main(int argc, char **argv, char **envp)
getcwd(NULL, 0));
datas.exit_code = 0;
if (datas.silent)
{
i = 1;
while (i < argc)
{
prompt(&datas, argv[i]);
i++;
}
}
prompt(&datas, argv[2]);
else
while (1)
prompt(&datas, NULL);

5
parser.c

@ -6,7 +6,7 @@
/* By: mea <mea@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 16:09:25 by narnaud #+# #+# */
/* Updated: 2022/05/18 14:58:51 by narnaud@stude ### ########.fr */
/* Updated: 2022/05/24 08:25:06 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -54,7 +54,7 @@ static size_t count_arguments(t_token *tok)
if (tok->type == WORD)
ret++;
if (tok->value[0] == '(')
ret++;
ret += 2;
tok = tok->next;
}
return (ret);
@ -69,6 +69,7 @@ static t_token *parse_cmd(t_datas *datas, t_token *tok, t_command *cmd)
if (tok->value[0] == '(')
{
cmd->argv[cmd->argc++] = get_var_value(datas, "MINISH", 7);
cmd->argv[cmd->argc++] = ft_strdup("-c");
cmd->argv[cmd->argc++] = ft_substr(tok->value,
1, ft_strlen(tok->value) - 2);
}

4
utils.c

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_1.c :+: :+: :+: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */
/* Updated: 2022/05/16 08:18:23 by narnaud ### ########.fr */
/* Updated: 2022/05/24 08:30:44 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */

Loading…
Cancel
Save