-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken_is.c
79 lines (70 loc) · 2.06 KB
/
token_is.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_is.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ekinnune <ekinnune@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 12:09:30 by ekinnune #+# #+# */
/* Updated: 2023/07/18 13:38:16 by ekinnune ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_token *is_pipe(const char *input)
{
return (make_token(input, 1, PIPE));
}
t_token *is_var(const char *input)
{
size_t size;
if (*(input + 1) == '?')
return (make_token(input, 2, EXVAR));
size = 0;
while (*(input + size) != '=' && *(input + size) != ' ' && *(input + size))
size++;
return (make_token(input, size, ENVAR));
}
t_token *is_quote(const char *input)
{
enum e_type token_type;
size_t size;
if (*input == '\'')
token_type = SQUOTE;
else
token_type = DQUOTE;
size = 1;
while (*(input + size) != *input)
{
if (!*(input + size))
return (NULL);
size++;
}
size++;
return (make_token(input, size, token_type));
}
t_token *is_progname(const char *input)
{
size_t size;
size = 0;
while (!special_symbol(*(input + size)) || *(input + size) == '$')
size++;
return (make_token(input, size, NAME));
}
t_token *is_redir(const char *input)
{
if (*input == '<')
{
if (*(input + 1) == '<')
return (make_token(input, 2, RDIRDOC));
else
return (make_token(input, 1, RDIRIN));
}
if (*input == '>')
{
if (*(input + 1) == '>')
return (make_token(input, 2, RDIRAPP));
else
return (make_token(input, 1, RDIROUT));
}
return (NULL);
}