-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_bonus.c
72 lines (66 loc) · 2.08 KB
/
utils_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aconceic <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/01 18:49:55 by aconceic #+# #+# */
/* Updated: 2024/04/09 10:19:37 by aconceic ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/pipex_bonus.h"
/**
* @brief Verify the arguments are valid
* @param argc arguments counter.
* @param argv arguments vector".
* @return 1 for true(valid) - 0 for false(invalid)
*/
int arg_isvalid_bonus(int argc, char **argv)
{
int i;
int return_value;
return_value = 1;
i = 0;
while (argv[i])
{
if (!argv[i] || !ft_strcmp(argv[i], ""))
{
return_value = 0;
break ;
}
i ++;
}
if (argc < 5)
return_value = 0;
return (return_value);
}
/**
* @brief Initialize and allocate memory for struct of pipex bonus
* @attention Allocate memory.
* @param argc
* @param argv
* @return The struct with values initialized
*/
t_data *init_bonus_struct(int argc, char **argv)
{
t_data *bonus_data;
bonus_data = ft_calloc(sizeof(t_data), 1);
if (!bonus_data)
return (NULL);
if (!ft_strcmp(argv[1], "here_doc"))
bonus_data->is_heredoc = 1;
else
bonus_data->is_heredoc = 0;
bonus_data->processes = (argc - 3) - bonus_data->is_heredoc;
return (bonus_data);
}
/**
* @brief Display an error message to fd2 and exit the program with EXIT_FAILURE
* @param message The message to be displayed;
*/
void error_message(char *message)
{
write(2, message, ft_strlen(message));
exit(EXIT_FAILURE);
}