-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_utils.c
More file actions
76 lines (69 loc) · 2.13 KB
/
parser_utils.c
File metadata and controls
76 lines (69 loc) · 2.13 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adurusoy <adurusoy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/20 22:14:01 by adurusoy #+# #+# */
/* Updated: 2023/12/27 21:25:27 by adurusoy ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include <stdlib.h>
void parse_utils(t_shell **shell, t_parse *parse, char *str)
{
parse->cmd = ft_strdup(str);
if (!parse->cmd)
malloc_error(5, shell);
}
void parse_text_typer(t_parse *parse, char *str, int *j, int *flag)
{
parse->text[*j] = ft_strdup(str);
*j += 1;
parse->text[*j] = NULL;
*flag = 1;
}
void option_check(t_parse *parse, int flag)
{
if (flag == 0)
{
free_parse_text(parse->text);
parse->text = NULL;
}
}
void parse_type_typer(t_parse **parse, const char *str)
{
if (str[0] == '|')
(*parse)->type = PIPE;
else if (str[0] == '>' && str[1] == '>')
(*parse)->type = GREATER;
else if (str[0] == '<' && str[1] == '<')
{
(*parse)->type = HEREDOC;
g_check_heredoc = 1;
}
else if (str[0] == '>')
(*parse)->type = GREAT;
else if (str[0] == '<')
(*parse)->type = LESS;
}
t_parse *initialize_parse(size_t len, t_shell **shell)
{
t_parse *parse;
parse = malloc(sizeof(t_parse));
if (!parse)
malloc_error(5, shell);
(parse)->next = NULL;
(parse)->cmd = NULL;
(parse)->text = ft_calloc(sizeof(char *), len + 1);
if (!(parse)->text)
malloc_error(5, shell);
(parse)->type = 0;
(parse)->infile = STDINN;
(parse)->outfile = STDOUT;
(parse)->fd = 1;
(parse)->pid = 0;
(parse)->control = 0;
return (parse);
}