-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
68 lines (60 loc) · 1.77 KB
/
init.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: llacaze <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/02 16:58:55 by llacaze #+# #+# */
/* Updated: 2018/02/24 18:30:49 by llacaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_info *init_info(void)
{
t_info *info;
if (!(info = (t_info *)malloc(sizeof(t_info))))
return (NULL);
info->prev = NULL;
info->command = NULL;
info->line = NULL;
info->do_ret = 0;
info->line_tab = NULL;
info->next = NULL;
return (info);
}
t_info *refresh_info(t_info *info)
{
t_info *tmp;
tmp = info;
info = info->next;
if (!(info = (t_info *)malloc(sizeof(t_info) + 5120000)))
return (NULL);
info->prev = tmp;
info->command = NULL;
info->line_tab = NULL;
info->line = NULL;
info->next = NULL;
return (info);
}
t_info *go_begin(t_info *info)
{
t_info *tmp;
while (info && info->prev != NULL)
{
tmp = info;
info = info->prev;
info->next = tmp;
tmp = NULL;
}
return (info);
}
void free_info(t_info *info)
{
if (info->command)
free(info->command);
if (info->line)
free(info->line);
if (info->line_tab[0] != NULL)
free_tab(info->line_tab);
}