-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmd_list.c
74 lines (66 loc) · 1.86 KB
/
cmd_list.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/22 10:38:50 by ggiannit #+# #+# */
/* Updated: 2023/04/13 17:59:29 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* esegue una funzine su tutte le stringhe */
void ft_cmdlst_iterstr(t_cmd *cmd, char *(*parse1)(char *, t_mish *),
char *(*parse2)(char *, t_mish *), t_mish *meta)
{
int i;
while (cmd)
{
i = 0;
while (cmd->pot && cmd->pot[i])
{
cmd->pot[i] = (*parse1)(cmd->pot[i], meta);
i++;
}
i = 0;
while (cmd->red && cmd->red[i])
{
cmd->red[i] = (*parse2)(cmd->red[i], meta);
i++;
}
cmd = cmd->next;
}
}
/* pulisce tutta la lista */
void ft_cmdlst_clear(t_cmd **cmd)
{
t_cmd *tmp;
tmp = NULL;
while (*cmd)
{
tmp = (*cmd)->next;
ft_free_matrix(&((*cmd)->pot));
ft_free_matrix(&((*cmd)->red));
ft_free((void **) cmd);
(*cmd) = tmp;
}
}
/* aggiunge nodo davanti */
void ft_cmdlst_addfront(t_cmd **cmd, t_cmd *new)
{
new->next = *cmd;
*cmd = new;
}
/* crea nuovo nodo */
t_cmd *ft_cmdlst_new(char **pot)
{
t_cmd *new;
new = malloc(sizeof(t_cmd));
if (!new)
return (NULL);
new->pot = pot;
new->red = 0;
new->next = NULL;
return (new);
}