Minishell 1.0
42 School Minishell Project - A simple shell implementation
Yüklüyor...
Arıyor...
Eşleşme Yok
lexer_operator_utils.c
Bu dosyanın dokümantasyonuna git.
2
4{
5 if (cmd[i] == '<' && cmd[i + 1] == '<')
6 return (OP_HEREDOC);
7 if (cmd[i] == '>' && cmd[i + 1] == '>')
8 return (OP_REDIR_APPEND);
9 if (cmd[i] == '|')
10 return (OP_PIPE);
11 if (cmd[i] == '<')
12 return (OP_REDIR_IN);
13 if (cmd[i] == '>')
14 return (OP_REDIR_OUT);
15 return (OP_NONE);
16}
17
18int consume_operator(t_shell *shell, t_token_type type, char *val, int len)
19{
20 if (!append_token(shell, type, val, QUOTE_NONE))
21 return (-1);
22 return (len);
23}
24
26{
27 if (op_type == OP_PIPE)
28 return (consume_operator(shell, TOKEN_PIPE, "|", 1));
29 else if (op_type == OP_HEREDOC)
30 return (consume_operator(shell, TOKEN_HEREDOC, "<<", 2));
31 else if (op_type == OP_REDIR_IN)
32 return (consume_operator(shell, TOKEN_REDIR_IN, "<", 1));
33 else if (op_type == OP_REDIR_OUT)
34 return (consume_operator(shell, TOKEN_REDIR_OUT, ">", 1));
35 else if (op_type == OP_REDIR_APPEND)
36 return (consume_operator(shell, TOKEN_REDIR_APPEND, ">>", 2));
37 return (-1);
38}
39
41{
42 // TODO: Desteklenmeyen tüm karakterler için genişletilebilir. ": ; \ >>> <<<"
43 if (shell->cmd_line[i] == '&')
44 handle_syntax_error(shell, "&");
45 else
46 handle_syntax_error(shell, "unknown token");
47 return (-1);
48}
49
50int handle_operator(t_shell *shell, int i)
51{
52 t_operator_type op_type;
53 int consumed_len;
54
55 op_type = assess_operator_type(shell->cmd_line, i);
56 if (op_type == OP_NONE)
57 return (handle_operator_error(shell, i));
58 consumed_len = operator_dispatcher(shell, op_type);
59 return (consumed_len);
60}
int handle_syntax_error(t_shell *shell, char *unexpected_token)
int handle_operator_error(t_shell *shell, int i)
t_operator_type assess_operator_type(char *cmd, int i)
int consume_operator(t_shell *shell, t_token_type type, char *val, int len)
int operator_dispatcher(t_shell *shell, t_operator_type op_type)
int handle_operator(t_shell *shell, int i)
int append_token(t_shell *shell, t_token_type type, char *value, t_quote_type quote_type)
Minishell ana header dosyası
@ OP_REDIR_IN
Definition minishell.h:69
@ OP_PIPE
Definition minishell.h:68
@ OP_NONE
Definition minishell.h:73
@ OP_REDIR_APPEND
Definition minishell.h:72
@ OP_HEREDOC
Definition minishell.h:71
@ OP_REDIR_OUT
Definition minishell.h:70
@ QUOTE_NONE
Definition minishell.h:77
@ TOKEN_REDIR_OUT
Definition minishell.h:53
@ TOKEN_HEREDOC
Definition minishell.h:54
@ TOKEN_PIPE
Definition minishell.h:51
@ TOKEN_REDIR_IN
Definition minishell.h:52
@ TOKEN_REDIR_APPEND
Definition minishell.h:55
enum e_token_type t_token_type
-----> LEXER <--—
enum e_operator_type t_operator_type
struct s_shell t_shell
char * cmd_line
Definition minishell.h:152