-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipex_args.c
More file actions
62 lines (56 loc) · 1.75 KB
/
pipex_args.c
File metadata and controls
62 lines (56 loc) · 1.75 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_args.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acastrov <acastrov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 17:23:07 by acastrov #+# #+# */
/* Updated: 2025/01/09 20:36:28 by acastrov ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
int ft_parse_args(t_cmd *cmd, int argc, char **argv)
{
int i;
int j;
i = 0;
j = 0;
cmd->cmd_count = argc - 3;
cmd->cmd_arg = NULL;
cmd->cmd_1 = NULL;
cmd->cmd_2 = NULL;
cmd->cmd_arg = malloc((cmd->cmd_count + 1) * sizeof(char **));
if (!cmd->cmd_arg)
return (MALLOC_ERROR);
while (i < cmd->cmd_count)
{
cmd->cmd_arg[i] = ft_split(argv[i + 2], ' ');
if (!cmd->cmd_arg[i])
return (MALLOC_ERROR);
i++;
}
cmd->cmd_arg[i] = NULL;
return (SUCCESS);
}
int ft_get_path(t_cmd *cmd, char **envp)
{
char *path_envp;
path_envp = ft_find_path(envp);
if (path_envp == NULL)
return (FILE_ERROR);
cmd->cmd_paths = ft_split(path_envp, ':');
if (!cmd->cmd_paths)
return (MALLOC_ERROR);
return (SUCCESS);
}
char *ft_find_path(char **envp)
{
while (*envp)
{
if (ft_strncmp(*envp, "PATH=", 5) == 0)
return (*envp + 5);
envp++;
}
return (NULL);
}