blob: 8d29bb5df71ab443b53177af4a376ca697fcd65b (
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
56
57
58
59
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tok_lst.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/27 09:32:58 by charles #+# #+# */
/* Updated: 2020/08/27 18:40:05 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
t_tok_lst *tok_lst_new(enum e_tok tag, char *content)
{
return (tok_lst_new_until(tag, content, content == NULL ? 0 : ft_strlen(content)));
}
t_tok_lst *tok_lst_new_until(enum e_tok tag, char *content, size_t n)
{
t_tok_lst *ret;
if ((ret = malloc(sizeof(t_tok_lst))) == NULL)
return (NULL);
if (content == NULL)
ret->content = NULL;
else if ((ret->content = ft_strndup(content, n)) == NULL)
{
free(ret);
return (NULL);
}
ret->tag = tag;
return (ret);
}
void tok_lst_push_back(t_tok_lst **tokens, t_tok_lst *pushed)
{
ft_lstpush_back((t_ftlst**)tokens, (t_ftlst*)pushed);
}
t_tok_lst *tok_lst_push_front(t_tok_lst **tokens, t_tok_lst *pushed)
{
if (pushed == NULL)
return (NULL);
ft_lstpush_front((t_ftlst**)tokens, (t_ftlst*)pushed);
return (*tokens);
}
void *tok_lst_destroy(t_tok_lst **tokens, void (*del)(void*))
{
ft_lstdestroy((t_ftlst**)tokens, del);
return (NULL);
}
t_tok_lst *tok_lst_last(t_tok_lst *tokens)
{
return ((t_tok_lst*)ft_lstlast((t_ftlst*)tokens));
}
|