aboutsummaryrefslogtreecommitdiff
path: root/src/new_token.c
blob: 6f49681318925fa4186ccd2f6ede57798f6990ab (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   new_token.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/06/27 14:29:44 by dkaiser           #+#    #+#             */
/*   Updated: 2025/01/22 00:41:47 by chuhlig          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "token.h"

t_token	*new_token(int type, t_token *previous, t_token *next)
{
	t_token	*token;

	token = malloc(sizeof(t_token));
	if (token == NULL)
		return (NULL);
	token->type = type;
	token->previous = previous;
	token->next = next;
	if (previous != NULL)
		token->previous->next = token;
	if (next != NULL)
		token->next->previous = token;
	return (token);
}

t_token	*new_str_token(char *str, t_token *previous, t_token *next)
{
	t_token	*token;

	token = new_token(STRING_TOKEN, previous, next);
	if (token == NULL)
	{
		free(str);
		return (NULL);
	}
	token->content.string = str;
	return (token);
}

t_token	*new_redir_token(int type, t_token *previous, t_token *next)
{
	t_token	*token;

	token = new_token(REDIR_TOKEN, previous, next);
	if (token == NULL)
		return (NULL);
	token->content.redir_type = type;
	return (token);
}