Skip to content

Commit

Permalink
Merge pull request #44 from rick-morty-kh/Enhacement
Browse files Browse the repository at this point in the history
skip spaces in history
  • Loading branch information
R E D O N E authored Feb 10, 2023
2 parents 0859354 + 1b44725 commit 2a2072b
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions execution/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
/* ::: :::::::: */
/* shell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: relkabou <relkabou@student.42.fr> +#+ +:+ +#+ */
/* By: relkabou <relkabou@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/01 00:04:46 by relkabou #+# #+# */
/* Updated: 2023/02/05 16:52:03 by relkabou ### ########.fr */
/* Updated: 2023/02/10 12:27:49 by relkabou ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

static int is_space(char c);
static void ft_add_history(char *line);

void shell_loop(void)
{
char *line;
Expand All @@ -23,7 +26,7 @@ void shell_loop(void)
line = readline(PROMPT);
if (!line)
break ;
add_history(line);
ft_add_history(line);
cmd = parse_line(line);
if (g_global.heredoc_flag)
{
Expand All @@ -38,3 +41,23 @@ void shell_loop(void)
free(line);
}
}

static void ft_add_history(char *line)
{
char *ptr;

ptr = line;
if (!line)
return ;
while (*line && is_space(*line))
{
line++;
}
if (*line != 0)
add_history(ptr);
}

static int is_space(char c)
{
return (c == ' ' || (c >= '\t' && c <= '\r'));
}

0 comments on commit 2a2072b

Please sign in to comment.