-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
97 lines (86 loc) · 2 KB
/
utils.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
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: olabrecq <olabrecq@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/14 20:54:17 by jemartel #+# #+# */
/* Updated: 2022/02/01 16:13:18 by jemartel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* should clean all the data structures left
on the heap also return a status?*/
int ft_isspace(char elm)
{
if (!elm)
return (0);
if (elm == ' ' || elm == '\t' || elm == '\n')
return (1);
else if (elm == '\v' || elm == '\v' || elm == '\f' || elm == '\r')
return (1);
return (0);
}
int until_space(char *str)
{
int inc;
inc = 0;
if (!str)
return (-1);
while (!ft_isspace(str[inc]) && str[inc])
{
inc++;
}
return (inc);
}
void freelist(char **list)
{
int index;
index = 0;
if (list)
{
while (list[index])
{
if (list[index])
{
free((void *)list[index]);
}
index++;
}
free(list);
}
}
// return la longueur d'un char** devrais s'appler list_len
int ft_tab_len(char **tab)
{
int i;
i = 0;
while (tab[i])
i++;
return (i);
}
//Cette fonction trie un tableau de char en ordre ascii
char **ft_sort_tab(char **tab)
{
char *temp;
int i;
int j;
i = 0;
while (tab[i])
{
j = i + 1;
while (tab[j])
{
if (ft_strncmp(tab[i], tab[j], ft_strlen(tab[i])) > 0)
{
temp = tab[i];
tab[i] = tab[j];
tab[j] = temp;
}
j++;
}
i++;
}
return (tab);
}