-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_token.c
54 lines (50 loc) · 1.59 KB
/
get_next_token.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_token.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: Alex <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/07 14:46:10 by alex #+# #+# */
/* Updated: 2020/05/05 16:07:20 by Alex ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/lem_in.h"
static void save_line(char *line, t_input *input)
{
if (input->lines == NULL)
{
list_push(&input->lines, line);
input->last = input->lines;
}
else
{
list_push(&input->last->next, line);
input->last = input->last->next;
}
input->line_count += 1;
if (input->line_count < 0)
error("file too large");
}
void get_next_token(t_lem_in *lem, t_token *token)
{
int status;
char *line;
while ((status = ft_get_next_line(STDIN_FILENO, &line)) == 1)
{
save_line(line, &lem->input);
tokenize(line, token);
if (token->type != TOKEN_COMMENT)
return ;
}
if (status == 0)
{
token->type = TOKEN_EOF;
return ;
}
if (status == -1)
{
perror("get_next_line");
die();
}
}