-
Notifications
You must be signed in to change notification settings - Fork 1
/
hist_functions.c
80 lines (71 loc) · 1.91 KB
/
hist_functions.c
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
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hist_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlachheb <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/02 14:46:41 by mlachheb #+# #+# */
/* Updated: 2021/06/27 12:42:44 by mlachheb ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void add_back_hist(t_history **hists, t_history *new)
{
t_history *hist;
hist = *hists;
if (hist == NULL)
*hists = new;
else
{
hist = last_hist(*hists);
new->previous = hist;
hist->next = new;
}
}
void clear_hist(t_history **hists)
{
t_history *hist1;
t_history *hist2;
hist1 = *hists;
while (hist1 != NULL)
{
hist2 = hist1->previous;
if (hist1->line_orig != NULL)
free(hist1->line_orig);
if (hist1->line_chngd != NULL)
free(hist1->line_chngd);
free(hist1);
hist1 = NULL;
hist1 = hist2;
}
hists = NULL;
}
t_history *last_hist(t_history *hist)
{
if (hist != NULL)
{
while (hist->next != NULL)
hist = hist->next;
}
return (hist);
}
t_history *first_hist(t_history *hist)
{
if (hist != NULL)
{
while (hist->previous != NULL)
hist = hist->previous;
}
return (hist);
}
t_history *new_hist(void)
{
t_history *hist;
hist = (t_history *)malloc(sizeof(t_history));
hist->line_orig = NULL;
hist->line_chngd = NULL;
hist->next = NULL;
hist->previous = NULL;
return (hist);
}