forked from GroteGnoom/codam_miniRT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_general.c
More file actions
66 lines (59 loc) · 1.85 KB
/
parse_general.c
File metadata and controls
66 lines (59 loc) · 1.85 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
65
66
/* ************************************************************************** */
/* */
/* :::::::: */
/* parse_general.c :+: :+: */
/* +:+ */
/* By: dnoom <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2022/04/06 11:25:33 by dnoom #+# #+# */
/* Updated: 2022/04/06 11:25:33 by dnoom ######## odam.nl */
/* */
/* ************************************************************************** */
#include "miniRT.h"
char line_next(t_parse_line *line)
{
line->i++;
return (line->line[line->i]);
}
void skip_one_char(t_parse_line *line, char c)
{
if (line->line[line->i] != c)
{
printf("Expected '%c' (as number: %d) at line %d, \
column %d, found '%c' (as number: %d) \n", \
c, c, line->line_nr, line->i + 1, \
line->line[line->i], line->line[line->i]);
error("Parse error");
}
line->i++;
}
void skip_zero_or_more_char(t_parse_line *line, char c)
{
while (line->line[line->i] == c)
line->i++;
}
void skip_one_or_more_char(t_parse_line *line, char c)
{
skip_one_char(line, c);
skip_zero_or_more_char(line, c);
}
void parse_string(t_parse_line *line, char *buffer, int size)
{
int i;
char c;
c = line->line[line->i];
i = 0;
while (c && c != ' ' && c != '\n')
{
if (i >= size)
{
printf("String too long at line %d, \
column %d\n", line->line_nr, line->i + 1);
error("Parse error");
}
buffer[i] = c;
c = line_next(line);
i++;
}
buffer[i] = 0;
}