fixes + valgrind

This commit is contained in:
gazhonsepaskwa
2025-02-11 10:49:27 +01:00
parent 484ec39641
commit 0c76cc2422
5 changed files with 49 additions and 22 deletions

View File

@@ -81,6 +81,7 @@ int main(int ac, char **av, char **envp)
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
{
g_sig = 0;
free(msh->input);
msh->input = powerline(msh);
if (!msh->input)
break;

View File

@@ -162,9 +162,9 @@ t_node *tokenize(char *str)
stick_quote_node(head, 39);
stick_quote_node(head, '"');
debug_token_list(head, "stick quote node");
if (!trim_nodes(head))
return (NULL);
debug_token_list(head, "trim_nodes");
// if (!trim_nodes(head))
// return (NULL);
// debug_token_list(head, "trim_nodes");
set_token(head);
del_void_nodes(&head);
debug_token_list(head, "tokenizer");

View File

@@ -12,39 +12,52 @@
#include "../includes/minishell.h"
static void handle_input(char *in, char *li, char *pr, t_msh *msh)
static void handle_input(char *in, t_msh *msh)
{
if (ft_strlen(in) > 0 && !is_only_space(in))
{
add_history(in);
ft_fprintf(msh->hist, "%s\n", in);
}
free(pr);
free(li);
}
char *get_pwd()
{
char *pwd;
char *pwd_base;
char *cpy;
char *out;
pwd = getcwd(NULL, 0);
pwd_base = pwd;
cpy = pwd;
if (ft_strncmp(pwd, "/home", 5) == 0)
{
pwd += 6;
while (*pwd && (*pwd) != '/')
pwd++;
out = ft_strjoin("~", pwd);
}
else
{
out = ft_strdup(cpy);
}
free(pwd_base);
return (out);
}
char *powerline(t_msh *msh)
{
char *pwd;
char *tilt;
char *input;
char *prompt;
char *line;
pwd = getcwd(NULL, 0);
tilt = " ";
if (ft_strncmp(pwd, "/home/", 6) == 0)
{
pwd += 6;
while (*pwd && (*pwd) != '/')
pwd ++;
tilt = " ~";
}
line = ft_sprintf("%s----------------------------------------------\
----------------------------------%s", POW5, RESET);
prompt = ft_sprintf("%s\n%s  MMOAT %s%s%s%s%s %s%s%s ",
line, POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
pwd = get_pwd();
prompt = ft_sprintf("\n%s  MMOAT %s%s %s%s %s%s%s ",
POW1, POW2, POW3, POW4, pwd, RESET, POW5, RESET);
input = readline(prompt);
handle_input(input, line, prompt, msh);
handle_input(input, msh);
free(prompt);
free(pwd);
return (input);
}