-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_parser3.c
81 lines (74 loc) · 2.16 KB
/
input_parser3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input_parser3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgober <pgober@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/14 13:05:03 by pgober #+# #+# */
/* Updated: 2024/04/17 12:08:19 by pgober ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int remove_quotes_from_cmd_table(t_input_parsing *in_pars)
{
int i;
int j;
i = 0;
while (i <= in_pars->pipenum)
{
j = 1;
while (j <= 4)
{
if (in_pars->cmd_table[i][j])
{
in_pars->cmd_table[i][j] = \
ft_remove_quotes(in_pars->cmd_table[i][j]);
if (!in_pars->cmd_table[i][j])
return (1);
}
j++;
}
i++;
}
return (0);
}
int processing_read_heredocs(t_input_parsing *in_pars, int *i, \
int curr_cmdnum)
{
char *temp;
if (ft_strlen(in_pars->m_argv[*i]) == 2)
{
if (in_pars->cmd_table[curr_cmdnum][3])
free(in_pars->cmd_table[curr_cmdnum][3]);
in_pars->cmd_table[curr_cmdnum][3] = ft_strdup(in_pars->m_argv[++(*i)]);
if (!in_pars->cmd_table[curr_cmdnum][3])
return (1);
}
else
{
temp = ft_strdup(in_pars->m_argv[(*i)++] + 2);
if (!temp)
return (1);
in_pars->cmd_table[curr_cmdnum][3] = ft_strtrim(temp, "\"\'");
free(temp);
if (!in_pars->cmd_table[curr_cmdnum][3])
return (1);
}
return (0);
}
int prr_helper_mini(char *curr_file, int outfile, int *i)
{
outfile = open(curr_file, O_RDONLY, 0777);
if (outfile == -1)
return (0);
if (outfile == -1 && \
access(curr_file, F_OK))
return (perror("minishell"), *i = -2, 0);
return (close(outfile), -1);
}
void close_if_open(int fd)
{
if (fd != -1)
close(fd);
}