-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils1.c
99 lines (88 loc) · 2.05 KB
/
utils1.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
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ofadhel <ofadhel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/28 15:51:23 by ofadhel #+# #+# */
/* Updated: 2024/01/16 17:14:15 by ofadhel ### ########.fr */
/* */
/* ************************************************************************** */
#include "include/minishell.h"
int ft_isdigitalpha(char *c)
{
int i;
i = 0;
while (c[i])
{
if ((c[i] < 'A' || c[i] > 'Z') && (c[i] < 'a' || c[i] > 'z') && \
(c[i] < '0' || c[i] > '9'))
return (0);
i++;
}
return (1);
}
char **expand_matrix(char **matrix, char *str)
{
int i;
char **new_matrix;
i = 0;
while (matrix[i])
i++;
new_matrix = malloc(sizeof(char *) * (i + 2));
i = 0;
while (matrix[i])
{
new_matrix[i] = matrix[i];
i++;
}
new_matrix[i] = str;
new_matrix[i + 1] = NULL;
free(matrix);
return (new_matrix);
}
char **unset_cmd(char **matrix, char *str)
{
int i;
int j;
int len;
char **new_matrix;
i = 0;
j = 0;
len = ft_strlen(str);
while (matrix[i])
i++;
new_matrix = malloc(sizeof(char *) * i);
i = 0;
while (matrix[i])
{
if (ft_strncmp(matrix[i], str, len) != 0)
{
new_matrix[j] = matrix[i];
j++;
}
i++;
}
new_matrix[j] = NULL;
free(matrix);
return (new_matrix);
}
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
if (!s1 || !s2)
return (1);
while ((s1[i] && s2[i]) && (s1[i] == s2[i]))
i++;
return (s1[i] - s2[i]);
}
int ft_array_len(char **array)
{
int i;
i = 0;
while (array[i])
i++;
return (i);
}