maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
tokeniser_helpers.c File Reference
#include "tokens.h"
Include dependency graph for tokeniser_helpers.c:

Go to the source code of this file.

Functions

void print_tokens (t_token *tokens, char *name)
 
void print_ast_args (t_ast *node)
 
void append_word_if_valid (char *start, char *str, t_token **tokens)
 

Function Documentation

◆ append_word_if_valid()

void append_word_if_valid ( char *  start,
char *  str,
t_token **  tokens 
)

Definition at line 49 of file tokeniser_helpers.c.

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
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

References append_token(), ft_printf(), ft_strndup(), new_token(), and PHRASE.

Referenced by handle_phrase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_ast_args()

void print_ast_args ( t_ast node)

Definition at line 37 of file tokeniser_helpers.c.

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}
char ** args
Definition tokens.h:52

References s_ast::args, and ft_printf().

Here is the call graph for this function:

◆ print_tokens()

void print_tokens ( t_token tokens,
char *  name 
)

Definition at line 19 of file tokeniser_helpers.c.

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}
#define RESET
Definition libft.h:111
size_t ft_strlen(const char *s)
Definition ft_strlen.c:15
#define GRN
Definition libft.h:115
struct s_token * next
Definition tokens.h:45
char * data
Definition tokens.h:44

References s_token::data, ft_printf(), ft_strlen(), GRN, s_token::next, and RESET.

Here is the call graph for this function: