-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils3.c
76 lines (68 loc) · 1.85 KB
/
utils3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akhalid <akhalid@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/25 03:31:22 by akhalid #+# #+# */
/* Updated: 2022/03/03 02:16:39 by akhalid ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int syntax_error(t_token **tokens)
{
t_type prev;
t_type curr;
int i;
i = 0;
prev = -1;
curr = 0;
g_all.exit_status = 258;
while (tokens[i])
{
curr = tokens[i]->type;
if (prev != WRD && i != 0 && curr != WRD
&& prev != PIPE && curr != PIPE)
return (0);
if (i == 0 && curr == PIPE)
return (0);
prev = curr;
i++;
}
if (curr != WRD)
return (0);
g_all.exit_status = 0;
return (1);
}
int check_line(void)
{
if (g_all.line == NULL)
{
write(1, "exit\n", 6);
return (0);
}
return (1);
}
char *concatenate(char *str, char *cmd, char *path)
{
str = ft_strdup(path);
str = ft_strjoin(str, ft_strdup("/"));
str = ft_strjoin(str, ft_strdup(cmd));
return (str);
}
void check_exec(char *path)
{
struct stat buf;
if (stat(path, &buf) && S_ISDIR(buf.st_mode))
{
write(2, path, ft_strlen(path));
write(2, ": is a directory\n", ft_strlen(": is a directory\n"));
exit(126);
}
}
t_token *free_val(char *val)
{
free(val);
return (0);
}