minishell
Minishell Project for École 42
Loading...
Searching...
No Matches
tokenize.c File Reference

Functions for tokenizing the input string and creating a lexer list. More...

#include "minishell.h"
Include dependency graph for tokenize.c:

Functions

t_token assign_type (char tok)
 Assign a type based on the input char.
 
t_token which_type (char *s)
 Set the type of token.
 
t_lexer_listcreate_lexer_list (char **input_array)
 Allocates memory for the lexer list.
 
t_lexer_listfill_lexer_list (char **input_array)
 Fills the lexer list using the input array.
 
t_lexer_listtokenize (t_shell *shell)
 Tokenizes the input string and creates the lexer list.
 

Detailed Description

Functions for tokenizing the input string and creating a lexer list.

Function Documentation

◆ assign_type()

t_token assign_type ( char  tok)

Assign a type based on the input char.

Parameters
tokThe input char to assign a tyoe for.
Returns
The assigned type for the the input char.

◆ create_lexer_list()

t_lexer_list * create_lexer_list ( char **  input_array)

Allocates memory for the lexer list.

Creates a double-linked list using the size of the input array. Calculates size of input array. and allocates memory for the lexer list. If malloc fails, displays error message, returns NULL.

Parameters
input_arrayThe array with the substrings('tokens').
Returns
A pointer to the head of the allocated list, or NULL if allocation failed.

◆ fill_lexer_list()

t_lexer_list * fill_lexer_list ( char **  input_array)

Fills the lexer list using the input array.

Calls create_lexer_list() to allocates a double-linked list with as many nodes as substrings in input_array. Fills each node of the list with information about each 'token'.

Parameters
input_arrayThe array with the substrings('tokens').
Returns
A pointer to the head of the filled lexer list, or NULL on failure.

◆ tokenize()

t_lexer_list * tokenize ( t_shell shell)

Tokenizes the input string and creates the lexer list.

Tokenizes the input by creating an array of substrings. Creates a linked list of lexer tokens using the substrings. Returns a pointer to the head of the lexer linked list. if malloc fails for input_array or lexer list, display message and return NULL.

Parameters
shellThe shell data structure (main data structure). @ return The head of the lexer list if successful, otherwise NULL.

◆ which_type()

t_token which_type ( char *  s)

Set the type of token.

Takes an input string('token') and chooses the type of token it represents. Only sets if the token is a pipe or some redirection, otherwise sets type to NONE.

Parameters
sThe input string ('token') to identify the type for.
Returns
The type of token identified.