-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_queue.c
More file actions
64 lines (58 loc) · 1.74 KB
/
token_queue.c
File metadata and controls
64 lines (58 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_queue.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: almelo <almelo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/19 12:11:59 by almelo #+# #+# */
/* Updated: 2023/04/01 22:04:01 by almelo ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_token *new_token(void *content, enum e_label label)
{
t_token *token;
token = malloc(sizeof(t_token));
token->content = content;
token->label = label;
token->next = NULL;
return (token);
}
void queue_token(t_tokenl *token_lst, t_token *new)
{
if (token_lst->head == NULL)
{
token_lst->head = new;
token_lst->tail = new;
token_lst->length = 0;
token_lst->pipe_count = 0;
}
else
{
token_lst->tail->next = new;
token_lst->tail = new;
}
token_lst->length++;
if (new->label == PIPE)
token_lst->pipe_count++;
}
t_token *dequeue_token(t_tokenl *token_lst)
{
t_token *head;
head = token_lst->head;
if (head->label == PIPE)
token_lst->pipe_count--;
if (token_lst->length > 1)
{
token_lst->head = head->next;
head->next = NULL;
}
else
{
token_lst->head = NULL;
token_lst->tail = NULL;
}
token_lst->length--;
return (head);
}