MiniDevil As beautiful as a shell
tokenizer_utils.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* tokenizer_utils.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/04 23:16:00 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 04:43:07 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "token.h"
14 
21 int is_operator(char c)
22 {
23  return (c == '|' || c == '<' || c == '>');
24 }
25 
32 int is_whitespace(char c)
33 {
34  return (c == ' ' || c == '\t' || c == '\n');
35 }
36 
43 int is_word_end(char c)
44 {
45  if (c == '\0')
46  return (1);
47  if (is_whitespace(c))
48  return (1);
49  if (is_operator(c))
50  return (1);
51  if (c == '\'' || c == '\"')
52  return (1);
53  return (0);
54 }
55 
64 {
65  *len = 1;
66  if (str[0] == '>' && str[1] == '>')
67  {
68  *len = 2;
69  return (TOKEN_APPEND);
70  }
71  else if (str[0] == '<' && str[1] == '<')
72  {
73  *len = 2;
74  return (TOKEN_HEREDOC);
75  }
76  else if (str[0] == '|')
77  return (TOKEN_PIPE);
78  else if (str[0] == '>')
79  return (TOKEN_REDIR_OUT);
80  else if (str[0] == '<')
81  return (TOKEN_REDIR_IN);
82  else
83  return (TOKEN_WORD);
84 }
t_token_type
Token types produced by Lexer.
Definition: structs.h:24
@ TOKEN_REDIR_OUT
Definition: structs.h:28
@ TOKEN_WORD
Definition: structs.h:25
@ TOKEN_HEREDOC
Definition: structs.h:30
@ TOKEN_PIPE
Definition: structs.h:26
@ TOKEN_REDIR_IN
Definition: structs.h:27
@ TOKEN_APPEND
Definition: structs.h:29
Lexer, tokenizer, expander, and quote handling prototypes.
int is_word_end(char c)
Check if a character ends a word token.
int is_whitespace(char c)
Check if a character is whitespace.
t_token_type get_operator_token_type(char *str, int *len)
Determine operator token type and its length in characters.
int is_operator(char c)
Check if a character is a shell operator.