-
Notifications
You must be signed in to change notification settings - Fork 0
/
executils.c
67 lines (59 loc) · 1.92 KB
/
executils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* executils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dcelsa <dcelsa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 16:02:07 by dcelsa #+# #+# */
/* Updated: 2022/04/16 13:58:11 by dcelsa ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void writecdpath(t_head *head, t_list *args, int stat_lock)
{
char *path;
if (head->fds.envfds)
readenv(&head->env, head->path, ft_strjoin(":", head->path),
((int *)ft_lstlast(head->fds.envfds)->content)[0]);
if (ft_strncmp(args->content, "cd", -1) || stat_lock)
return ;
if (ft_lstsize(args) > 1)
path = args->next->content;
else
path = findenv("HOME", ft_strlen("HOME"), head, FALSE);
ft_putendl_fd(path, head->fds.path[1]);
cd(head->prog, path, &head->env);
if (ft_lstsize(args) == 1)
free(path);
}
char **cmdarr(t_list *args)
{
char **arr;
int i;
arr = malloc(sizeof(*arr) * (ft_lstsize(args) + 1));
i = 0;
while (args)
{
arr[i++] = args->content;
args = args->next;
}
arr[i] = NULL;
return (arr);
}
t_list *getprevstruct(t_list *begin, t_list *crnt)
{
if (begin == crnt)
return (NULL);
while (begin->next != crnt)
begin = begin->next;
return (begin);
}
int structindex(t_list *begin, t_list *curcmd)
{
int i;
i = 0;
while (begin != curcmd && (++i || !i))
begin = begin->next;
return (i);
}