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]; fd_out = cmd->fd[1];
else else
fd_out = 1; fd_out = 1;
no_nl = 0; no_nl = 0;
if (*(++cmd->argv)) if (*(++cmd->argv))
{ {

2
caller.c

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

13
lexer.c

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

2
libft/str/ft_split.c

@ -38,5 +38,5 @@ char **ft_split(const char *str, char c)
word[j++] = str[i]; word[j++] = str[i];
} }
words = ft_dlst_add(words, word); 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); 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) void prompt(t_datas *datas)
{ {
char *line; char *line;
@ -53,6 +67,7 @@ void prompt(t_datas *datas)
builtin_call(datas, cmd); builtin_call(datas, cmd);
else else
piper(datas, cmd); piper(datas, cmd);
free_cmd(cmd);
add_history(line); add_history(line);
} }

1
minishell.h

@ -37,7 +37,6 @@ typedef struct s_command
char **argv; char **argv;
int argc; int argc;
int fd[2]; int fd[2];
char *heredoc;
struct s_command *next; struct s_command *next;
struct s_command *prev; struct s_command *prev;
} t_command; } 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); free(prev_tok);
return (tok); return (tok);
} }
t_command *parser(t_datas *datas, t_token *tok, t_command *prev) t_command *parser(t_datas *datas, t_token *tok, t_command *prev)
{ {
t_command *cmd; t_command *cmd;
@ -99,7 +100,6 @@ t_command *parser(t_datas *datas, t_token *tok, t_command *prev)
cmd->argc = 0; cmd->argc = 0;
while(tok && tok->type != PIPE) while(tok && tok->type != PIPE)
tok = parse_cmd(datas, tok, cmd); tok = parse_cmd(datas, tok, cmd);
cmd->argv[cmd->argc] = NULL;
if (tok && tok->type == PIPE) if (tok && tok->type == PIPE)
{ {
cmd->next = parser(datas, tok->next, cmd); 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); return(cmd);
} }

Loading…
Cancel
Save