Browse Source

leaks blocked

master
narnaud 3 years ago
parent
commit
da54110a37
  1. 18
      README.md
  2. 12
      built-in.c
  3. 2
      lexer.c
  4. 3
      minishell.c
  5. 2
      parser.c
  6. 27
      utils_2.c

18
README.md

@ -2,17 +2,17 @@
---
## TODO :
- free stack,
- protect mallocs,
- Norminette
- Finish check_builtin();
- Protect mallocs,
- [WIP]Norminette
- [WIP]Free heap
- export : edit datas->env
- unset : idem,
- exit: handle arguments
- export : edit datas->env
- unset : idem,
- exit: handle arguments
- setup correct ext_codes
https://wiki.bash-hackers.org/scripting/basics?s[]=variables#exit_codes
- setup correct ext_codes
https://wiki.bash-hackers.org/scripting/basics?s[]=variables#exit_codes
## Issues :
- error using unknow command with valgrind

12
built-in.c

@ -16,20 +16,22 @@ int ft_echo(t_command *cmd)
{
int no_nl;
int fd_out;
int i;
if (cmd->fd[1])
fd_out = cmd->fd[1];
else
fd_out = 1;
no_nl = 0;
if (*(++cmd->argv))
i = 1;
if (cmd->argv[1])
{
if (ft_strncmp(*(cmd->argv), "-n", 3) == 0 && cmd->argv++)
if (ft_strncmp(cmd->argv[1], "-n", 3) == 0 && i++)
no_nl = 1;
while (*(cmd->argv))
while (cmd->argv[i])
{
ft_putstr_fd(*(cmd->argv), fd_out);
if (*(++cmd->argv))
ft_putstr_fd(cmd->argv[i], fd_out);
if (cmd->argv[++i])
ft_putstr_fd(" ", fd_out);
}
}

2
lexer.c

@ -133,7 +133,7 @@ t_token *lexer(t_datas *datas, char *line)
continue;
if (lex->state != S_QUOTE_ST && *line == '$')
tmp_i = replace_var(datas, &line, tmp, tmp_i);
if (check_register(lex, &line, tmp))
else if (check_register(lex, &line, tmp))
tmp_i = (ft_bzero(tmp, 1024), 0);
else
tmp[tmp_i++] = *(line++);

3
minishell.c

@ -40,6 +40,8 @@ void free_cmd(t_command *cmd)
{
int i;
if (!cmd)
return ;
i = 0;
while (cmd->argv[i])
{
@ -47,6 +49,7 @@ void free_cmd(t_command *cmd)
i++;
}
free(cmd->argv);
free_cmd(cmd->next);
free(cmd);
}

2
parser.c

@ -100,7 +100,7 @@ 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);
if (tok && tok->type == PIPE)
if (tok)
{
cmd->next = parser(datas, tok->next, cmd);
free(tok->value);

27
utils_2.c

@ -24,32 +24,29 @@ int file_error(char *cmd, char *file, char *msg)
return (0);
}
char *get_var_value(t_datas *datas, char **line, int *name_len)
char *get_var_value(t_datas *datas, char **line, int name_len)
{
int i;
char **env;
char *name;
char *value;
i = 1;
while (ft_isalpha((*line)[i]) || ft_isdigit((*line)[i]) || (*line)[i] == '_')
i++;
name = ft_substr(*line, 1, i - 1);
name = ft_substr(*line, 1, name_len - 1);
i = 0;
*name_len = ft_strlen(name);
value = NULL;
while (datas->envp[i] && !value)
{
env = ft_split(datas->envp[i], '=');
if (!ft_strncmp(name, env[0], *name_len + 1))
if (!ft_strncmp(name, env[0], name_len + 1))
value = (free(env[0]), env[1]);
else if (++i)
ft_free_split(env);
}
if (!datas->envp[i])
value = strdup("");
else
free(name);
if (value)
free(env);
else
value = strdup("");
return (value);
}
@ -65,12 +62,18 @@ int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i)
name_len = 2;
}
else
value = get_var_value(datas, line, &name_len);
{
name_len = 1;
while (ft_isalpha((*line)[name_len]) \
|| ft_isdigit((*line)[name_len]) || (*line)[name_len] == '_')
name_len++;
value = get_var_value(datas, line, name_len);
}
i = 0;
while (value[i])
tmp[tmp_i++] = value[i++];
tmp[tmp_i] = 0;
*line += name_len + 1;
*line += name_len;
free(value);
return (tmp_i);
}

Loading…
Cancel
Save