-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_ter.c
82 lines (73 loc) · 2.03 KB
/
utils_ter.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
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_ter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/20 09:51:21 by zhabri #+# #+# */
/* Updated: 2023/01/02 15:27:44 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static bool str_is_op(char *needle)
{
int i;
static const char *op_tab[6] = {"<<", ">>", "|", \
">", "<", NULL};
i = 0;
while (op_tab[i])
{
if (!strncmp(op_tab[i], needle, ft_strlen(op_tab[i])))
return (true);
i++;
}
return (false);
}
char *get_first(void)
{
int i;
char *trimmed;
char *ret;
i = 0;
trimmed = ft_strtrim(g_glob->input, " \t");
if (trimmed && trimmed[0])
{
while (trimmed[i] && !str_is_op(trimmed + i))
i++;
ret = ft_substr(trimmed, 0, i);
free(trimmed);
return (ret);
}
return (NULL);
}
void eof_limiter_not_found(char *here_doc_entry, char *limiter)
{
if (here_doc_entry == NULL)
{
printf("minishell: warning: here-document");
printf(" delimited by end-of-file (wanted '%s')\n", limiter);
}
free(here_doc_entry);
}
t_cmd *init_cmd_token(int in, int out, char *str, bool reset)
{
static int idx;
t_cmd *node;
if (reset)
idx = 0;
node = NULL;
while (!node)
node = malloc(sizeof(t_cmd));
node->cmd_idx = idx;
node->fd_in = in;
node->fd_out = out;
node->str = str;
idx++;
return (node);
}
void clean_and_free(char **cmd_split)
{
free_tab(cmd_split);
clean_exit(NULL);
}