Minishell 1.0
42 School Minishell Project - A simple shell implementation
Yüklüyor...
Arıyor...
Eşleşme Yok
lexer_category_utils.c
Bu dosyanın dokümantasyonuna git.
2#include <stdlib.h> // free
3
5{
6 t_quote_type q_type;
7
8 if (c == '\'')
9 q_type = QUOTE_SINGLE;
10 else if (c == '"')
11 q_type = QUOTE_DOUBLE;
12 else
13 q_type = QUOTE_NONE;
14 return (q_type);
15}
16
17int handle_quote(t_shell *shell, int i)
18{
19 char q;
20 t_quote_type q_type;
21 int start;
22 int len;
23 char *content;
24
25 q = shell->cmd_line[i];
26 q_type = assess_quote_type(shell->cmd_line[i]);
27 start = i + 1;
28 len = 0;
29 while (shell->cmd_line[start + len] && shell->cmd_line[start + len] != q)
30 len++;
31 if (!shell->cmd_line[start + len])
32 {
33 // TODO: Hata mesajı bastır
34 return (-1);
35 }
36 content = ft_substr(shell->cmd_line, start, len);
37 if (!content)
38 return (-1);
39 if (!append_token(shell, TOKEN_WORD, content, q_type))
40 {
41 free(content);
42 return (-1);
43 }
44 free(content);
45 return (len + 2);
46}
47
48int handle_word(t_shell *shell, int i)
49{
50 char *content;
51 int len;
52
53 len = 0;
54 while (!is_delimiter(shell->cmd_line[i + len]))
55 len++;
56 content = ft_substr(shell->cmd_line, i, len);
57 if (!content)
58 {
59 // TODO: Hata mesajı yazdır.
60 return (-1);
61 }
62 if (!append_token(shell, TOKEN_WORD, content, QUOTE_NONE))
63 {
64 free(content);
65 return (-1);
66 }
67 free(content);
68 return (len);
69}
70
72{
73 if (c == '\'' || c == '"')
74 return (CHAR_CATEGORY_QUOTE);
75 else if (ft_strchr("|<>(&)", c))
77 else
78 return (CHAR_CATEGORY_WORD);
79}
80
81int category_dispatcher(t_shell *shell, t_char_category category, int i)
82{
83 if (category == CHAR_CATEGORY_OPERATOR)
84 return (handle_operator(shell, i));
85 else if (category == CHAR_CATEGORY_QUOTE)
86 return (handle_quote(shell, i));
87 else if (category == CHAR_CATEGORY_WORD)
88 return (handle_word(shell, i));
89 return (-1);
90}
int handle_word(t_shell *shell, int i)
t_char_category assess_char_category(char c)
int handle_quote(t_shell *shell, int i)
int category_dispatcher(t_shell *shell, t_char_category category, int i)
t_quote_type assess_quote_type(char c)
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ı
@ CHAR_CATEGORY_OPERATOR
Definition minishell.h:64
@ CHAR_CATEGORY_QUOTE
Definition minishell.h:63
@ CHAR_CATEGORY_WORD
Definition minishell.h:62
enum e_char_category t_char_category
@ QUOTE_SINGLE
Definition minishell.h:78
@ QUOTE_NONE
Definition minishell.h:77
@ QUOTE_DOUBLE
Definition minishell.h:79
@ TOKEN_WORD
Definition minishell.h:50
enum e_quote_type t_quote_type
struct s_shell t_shell
char * cmd_line
Definition minishell.h:152
int is_delimiter(char c)
Definition utils.c:23