-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory_utils.c
More file actions
executable file
·70 lines (61 loc) · 1.91 KB
/
history_utils.c
File metadata and controls
executable file
·70 lines (61 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* history_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hkonte <hkonte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 13:13:55 by hkonte #+# #+# */
/* Updated: 2024/11/29 13:14:27 by hkonte ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_history *list_history_init(char *cmd)
{
t_history *list_history;
list_history = malloc(sizeof(t_history));
if (!list_history)
return (NULL);
list_history->cmd = ft_strdup(cmd);
list_history->next = NULL;
return (list_history);
}
void list_history_add(t_history **history, char *cmd)
{
t_history *actual;
actual = *history;
while (actual->next != NULL)
actual = actual->next;
actual->next = malloc(sizeof(t_history));
if (!actual->next)
return ;
actual->next->cmd = ft_strdup(cmd);
actual->next->next = NULL;
}
void list_history_cleaner(t_main *main)
{
t_history *actual;
t_history *tmp;
actual = main->history;
while (actual != NULL)
{
tmp = actual;
actual = actual->next;
free(tmp->cmd);
free(tmp);
}
main->history = NULL;
}
void print_history(t_history *history)
{
t_history *actual;
int i;
actual = history;
i = 1;
while (actual != NULL)
{
printf(" %d %s\n", i, actual->cmd);
actual = actual->next;
i++;
}
}