maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
tokeniser_helpers.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* tokeniser_helpers.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rocky <marvin@42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/06/14 10:38:28 by rocky #+# #+# */
9/* Updated: 2024/09/09 15:47:48 by dmdemirk ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "tokens.h"
14
15void print_tokens(t_token *tokens, char *name);
16void print_ast_args(t_ast *node);
17void append_word_if_valid(char *start, char *str, t_token **tokens);
18
19void print_tokens(t_token *tokens, char *name)
20{
21 t_token *token;
22 int i;
23
24 i = 0;
25 token = tokens;
26 if (ft_strlen(name) > 0)
27 ft_printf(GRN"----- %s[] -----\n"RESET, name);
28 while (token != NULL)
29 {
30 ft_printf(GRN"input[%d] -> %s at add: %p\n"RESET, \
31 i, token->data, &token->data);
32 token = token->next;
33 i++;
34 }
35}
36
38{
39 int i;
40
41 i = 0;
42 while (node->args[i] != NULL)
43 {
44 ft_printf("ast arg[%d] -> %s \n", i, node->args[i]);
45 i++;
46 }
47}
48
49void append_word_if_valid(char *start, char *str, t_token **tokens)
50{
51 char *word;
52
53 if (str > start)
54 {
55 word = ft_strndup(start, str - start);
56 if (word)
57 {
58 append_token(tokens, new_token(word, PHRASE));
59 free(word);
60 }
61 else
62 ft_printf("Error: unable to allocate memory for token\n");
63 }
64}
int ft_printf(const char *format,...)
Definition ft_printf.c:37
char * ft_strndup(const char *s, size_t n)
Definition ft_strndup.c:23
#define RESET
Definition libft.h:111
size_t ft_strlen(const char *s)
Definition ft_strlen.c:15
#define GRN
Definition libft.h:115
Definition tokens.h:50
char ** args
Definition tokens.h:52
struct s_token * next
Definition tokens.h:45
char * data
Definition tokens.h:44
void append_word_if_valid(char *start, char *str, t_token **tokens)
void print_tokens(t_token *tokens, char *name)
void print_ast_args(t_ast *node)
t_token * new_token(char *value, t_token_type type)
Definition tokeniser.c:67
void append_token(t_token **tokens, t_token *new_token)
Definition tokeniser.c:85
@ PHRASE
Definition tokens.h:31