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

Go to the source code of this file.

Functions

void add_node (t_token **head, char *str)
 
void print_stack (t_token **stack)
 
void free_stack (t_token **stack)
 
int calc_stack_size (t_token *stack)
 
char ** list_to_array (t_token *head)
 

Function Documentation

◆ add_node()

void add_node ( t_token **  head,
char *  str 
)

Definition at line 15 of file stack_control.c.

16{
17 t_token *new_node;
18 t_token *curr_node;
19
20 new_node = (t_token *)malloc(sizeof(t_token));
21 if (!new_node)
22 return ;
23 new_node->data = str;
24 new_node->next = NULL;
25 if (*head == NULL)
26 {
27 *head = new_node;
28 return ;
29 }
30 curr_node = *head;
31 while (curr_node->next != NULL)
32 curr_node = curr_node->next;
33 curr_node->next = new_node;
34}
struct s_token * next
Definition tokens.h:45
char * data
Definition tokens.h:44

References s_token::data, and s_token::next.

Referenced by build_linked_list().

Here is the caller graph for this function:

◆ calc_stack_size()

int calc_stack_size ( t_token stack)

Definition at line 65 of file stack_control.c.

66{
67 int size;
68 t_token *current;
69
70 size = 0;
71 current = stack;
72 while (current != NULL)
73 {
74 size++;
75 current = current->next;
76 }
77 return (size);
78}

References s_token::next.

Referenced by list_to_array().

Here is the caller graph for this function:

◆ free_stack()

void free_stack ( t_token **  stack)

Definition at line 51 of file stack_control.c.

52{
53 t_token *current;
54 t_token *next;
55
56 current = *stack;
57 while (current != NULL)
58 {
59 next = current->next;
60 free(current);
61 current = next;
62 }
63}

References s_token::next.

◆ list_to_array()

char ** list_to_array ( t_token head)

Definition at line 80 of file stack_control.c.

81{
82 int count;
83 int i;
84 char **arr;
85 t_token *current;
86
87 current = head;
88 count = calc_stack_size(current);
89 arr = (char **)malloc((count + 1) * sizeof(char *));
90 if (!arr)
91 return (NULL);
92 current = head;
93 i = 0;
94 while (i < count)
95 {
96 arr[i] = ft_strdup(current->data);
97 current = current->next;
98 i++;
99 }
100 arr[count] = NULL;
101 return (arr);
102}
char * ft_strdup(const char *s)
Definition ft_strdup.c:23
int calc_stack_size(t_token *stack)

References calc_stack_size(), s_token::data, ft_strdup(), and s_token::next.

Here is the call graph for this function:

◆ print_stack()

void print_stack ( t_token **  stack)

Definition at line 36 of file stack_control.c.

37{
38 t_token *current_node;
39 int i;
40
41 i = 0;
42 current_node = *stack;
43 while (current_node != NULL)
44 {
45 ft_printf("input[%d] -> %s \n", i, current_node->data);
46 current_node = current_node->next;
47 i++;
48 }
49}
int ft_printf(const char *format,...)
Definition ft_printf.c:37

References s_token::data, ft_printf(), and s_token::next.

Here is the call graph for this function: