narnaud 3 years ago
parent
commit
cfee8bc477
  1. 1
      built-in.c
  2. 2
      caller.c
  3. 13
      lexer.c
  4. 4
      libft/dlist/ft_to_arr.c
  5. 2
      libft/str/ft_split.c
  6. 15
      minishell.c
  7. 1
      minishell.h
  8. 4
      parser.c

1
built-in.c

@ -21,7 +21,6 @@ int ft_echo(t_command *cmd)
fd_out = cmd->fd[1];
else
fd_out = 1;
no_nl = 0;
if (*(++cmd->argv))
{

2
caller.c

@ -32,7 +32,6 @@ int builtin_call(t_datas *datas, t_command *cmd)
return (-1);
}
int is_builtin(char *cmd)
{
if (!ft_strncmp(cmd, "echo", 5) ||
@ -115,4 +114,3 @@ int piper(t_datas *datas, t_command *cmd)
close(cmd->fd[0]);
return (1);
}

13
lexer.c

@ -36,7 +36,6 @@ int create_token(t_lexer *lex, char str[])
lex->tokens = tok;
else
tmp->next = tok;
ft_bzero(str, 1024);
return (1);
}
@ -119,9 +118,10 @@ int check_state(t_lexer *lex, char **line)
t_token *lexer(t_datas *datas, char *line)
{
t_lexer *lex;
char *tmp;
int tmp_i;
t_lexer *lex;
t_token *ret;
char *tmp;
int tmp_i;
lex = ft_calloc(1, sizeof *lex);
lex->state = ROOT_ST;
@ -134,12 +134,13 @@ t_token *lexer(t_datas *datas, char *line)
if (lex->state != S_QUOTE_ST && *line == '$')
tmp_i = replace_var(datas, &line, tmp, tmp_i);
if (check_register(lex, &line, tmp))
tmp_i = 0;
tmp_i = (ft_bzero(tmp, 1024), 0);
else
tmp[tmp_i++] = *(line++);
}
create_token(lex, tmp);
free(tmp);
ret = lex->tokens;
free(lex);
return (lex->tokens);
return (ret);
}

4
libft/dlist/ft_to_arr.c

@ -33,9 +33,9 @@ char **ft_dlst_to_arr(t_dlist *ptr)
while (count--)
{
ret[count] = last->content;
tmp = last;
tmp = last->previous;
free(last);
last = tmp->previous;
last = tmp;
}
return (ret);
}

2
libft/str/ft_split.c

@ -38,5 +38,5 @@ char **ft_split(const char *str, char c)
word[j++] = str[i];
}
words = ft_dlst_add(words, word);
return ((char **)ft_dlst_to_arr(words));
return (ft_dlst_to_arr(words));
}

15
minishell.c

@ -36,6 +36,20 @@ void termios(int ctl)
tcsetattr(tty, TCSANOW, &termios_p);
}
void free_cmd(t_command *cmd)
{
int i;
i = 0;
while (cmd->argv[i])
{
free(cmd->argv[i]);
i++;
}
free(cmd->argv);
free(cmd);
}
void prompt(t_datas *datas)
{
char *line;
@ -53,6 +67,7 @@ void prompt(t_datas *datas)
builtin_call(datas, cmd);
else
piper(datas, cmd);
free_cmd(cmd);
add_history(line);
}

1
minishell.h

@ -37,7 +37,6 @@ typedef struct s_command
char **argv;
int argc;
int fd[2];
char *heredoc;
struct s_command *next;
struct s_command *prev;
} t_command;

4
parser.c

@ -86,6 +86,7 @@ t_token *parse_cmd(t_datas *datas, t_token *tok, t_command *cmd)
free(prev_tok);
return (tok);
}
t_command *parser(t_datas *datas, t_token *tok, t_command *prev)
{
t_command *cmd;
@ -99,7 +100,6 @@ t_command *parser(t_datas *datas, t_token *tok, t_command *prev)
cmd->argc = 0;
while(tok && tok->type != PIPE)
tok = parse_cmd(datas, tok, cmd);
cmd->argv[cmd->argc] = NULL;
if (tok && tok->type == PIPE)
{
cmd->next = parser(datas, tok->next, cmd);
@ -108,5 +108,3 @@ t_command *parser(t_datas *datas, t_token *tok, t_command *prev)
}
return(cmd);
}

Loading…
Cancel
Save