-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils4.c
87 lines (77 loc) · 1.86 KB
/
utils4.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
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mazaroua <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/06 16:20:11 by mazaroua #+# #+# */
/* Updated: 2023/05/11 19:43:09 by mazaroua ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_lstclear(t_token_list **lst)
{
t_token_list *tmp;
if (!*lst)
return ;
tmp = *lst;
while (tmp)
{
tmp = tmp->next;
free(*lst);
*lst = tmp;
}
*lst = NULL;
}
void addback(t_token_list **tokens, char *value, int type)
{
t_token_list *curr;
curr = *tokens;
if ((!value || !*value))
return ;
if (!*tokens)
*tokens = new_token(value, type);
else
{
while (curr->next)
curr = curr->next;
curr->next = new_token(value, type);
}
}
t_token_list *new_token(char *value, int type)
{
t_token_list *new;
new = (t_token_list *)ft_malloc(sizeof(t_token_list), 1);
new->type = type;
new->value = value;
new->next = NULL;
return (new);
}
int count(char *line)
{
int i;
int j;
int c;
i = 0;
j = ft_strlen(line) - 1;
c = 0;
while (line[i] && line[i] == 32)
i++;
while (line[j] && line[j] == 32)
{
j--;
c++;
}
return (c + i);
}
int all_spaces(char *line, int i)
{
while (line[i])
{
if (line[i] != 32)
return (0);
i++;
}
return (1);
}