Ajout du fichier pour afficher l'historique

This commit is contained in:
Gautier WOJDA 2017-01-24 15:38:10 +01:00
parent c0d7d5cfd0
commit 5d09281cb1
6 changed files with 60 additions and 11 deletions

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/01/23 15:14:03 by gwojda ### ########.fr */
/* Updated: 2017/01/24 15:14:05 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,12 +49,6 @@
# define TOUCHE_F5 892427035
# define TOUCHE_F6 925981467
typedef struct s_line
{
char *input;
int prompt_size;
} t_line;
typedef struct s_list_history
{
char *str;
@ -62,6 +56,16 @@ typedef struct s_list_history
struct s_list_history *next;
} t_list_history;
typedef struct s_line
{
char *input;
int prompt_size;
int list_size;
t_list_history *list_end;
} t_line;
void ft_history_builtin(void);
int ft_nbr_len(int nbr);
int ft_found_next_char(char *str, size_t i);
void ft_check_end_of_line(char *str, size_t pos);
void ft_printall(char *str, size_t *pos);

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_history.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */
/* Updated: 2017/01/24 15:26:28 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_history_builtin(void)
{
size_t len;
t_list_history *head;
head = data_singleton()->line.list_end;
len = 1;
if (!head)
return ;
if (head && !head->str)
head = head->next;
while (head && head->str)
{
ft_putnc(' ', ft_nbr_len(data_singleton()->line.list_size) - ft_nbr_len(len));
ft_printf("%zu %s\n", len, head->str);
++len;
head = head->nextm;
}
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */
/* Updated: 2017/01/19 16:42:57 by gwojda ### ########.fr */
/* Updated: 2017/01/24 15:19:04 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,6 +30,7 @@ t_list_history *ft_create_history_list(char *str)
void ft_push_back_history(t_list_history **head, t_list_history *new)
{
++(data_singleton()->line.list_size);
if (!*head)
{
*head = new;
@ -38,6 +39,7 @@ void ft_push_back_history(t_list_history **head, t_list_history *new)
(*head)->next = ft_create_history_list(NULL);
(*head)->next->prev = (*head);
(*head) = (*head)->next;
(data_singleton())->line.list_end = new;
return ;
}
while ((*head)->next)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/01/22 14:57:05 by gwojda ### ########.fr */
/* Updated: 2017/01/24 15:29:59 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,8 @@ void ft_init_line(void)
{
data_singleton()->line.input = NULL;
data_singleton()->line.prompt_size = 0;
data_singleton()->line.list_size = 0;
data_singleton()->line.list_end = NULL;
}
struct termios *ft_save_stats_term(void)

View file

@ -6,12 +6,20 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */
/* Updated: 2017/01/20 12:36:28 by gwojda ### ########.fr */
/* Updated: 2017/01/24 15:00:16 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_nbr_len(int nbr)
{
if (nbr % 10 != nbr)
return (ft_nbr_len(nbr / 10) + 1);
else
return (1);
}
void ft_puttermcaps(char *str)
{
char *res;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/01/19 16:46:55 by gwojda ### ########.fr */
/* Updated: 2017/01/24 15:04:06 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */