-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlst.c
More file actions
73 lines (64 loc) · 1.68 KB
/
lst.c
File metadata and controls
73 lines (64 loc) · 1.68 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
71
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lst.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbani <mbani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/11 20:12:47 by mbani #+# #+# */
/* Updated: 2020/12/03 11:51:12 by mbani ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
t_env *ft_lstnewenv(char *key, char *value)
{
t_env *ptr;
ptr = malloc(sizeof(t_env));
if (!ptr)
return (NULL);
ptr->key = key;
ptr->value = value;
ptr->next = NULL;
return (ptr);
}
void ft_lstclearcmd(t_cmd **lst)
{
t_cmd *tmp;
while (*lst)
{
tmp = (*lst)->next;
free((*lst)->string);
(*lst)->string = NULL;
free(*lst);
*lst = NULL;
*lst = tmp;
}
}
t_cmd *ft_lstnew_cmd(char *string, enum e_type t)
{
t_cmd *ptr;
ptr = malloc(sizeof(t_cmd));
if (!ptr)
return (NULL);
ptr->string = ft_strdup(string);
ptr->type = t;
ptr->next = NULL;
return (ptr);
}
void ft_lstadd_backcmd(t_cmd **alst, t_cmd *new)
{
t_cmd *p;
p = *alst;
if (*alst == NULL)
{
*alst = new;
new->next = NULL;
}
else
{
while (p->next)
p = p->next;
p->next = new;
new->next = NULL;
}
}