This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar_print_init.c
55 lines (49 loc) · 2 KB
/
grammar_print_init.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
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* grammar_print_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgautier <mgautier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/12 12:26:17 by mgautier #+# #+# */
/* Updated: 2017/11/08 11:56:10 by mgautier ### ########.fr */
/* */
/* ************************************************************************** */
#include "grammar_defs.h"
#include "sym_interface.h"
#include "libft.h"
static void print_symbol_init(t_symbol const *symbol,
int const file, const char *prefix)
{
char *name;
name = ft_strmap(get_name(symbol), f_tolower);
ft_dprintf(file, "%s%s, ", prefix, name);
}
static void adapt_print(void const *symbol, va_list args)
{
int fd;
const char *prefix;
fd = va_arg(args, int);
prefix = va_arg(args, const char*);
print_symbol_init(symbol, fd, prefix);
}
void print_grammar_init(t_grammar const *grammar, int const file,
__attribute__((unused))char const *header_proto_name)
{
print_grammar_source(grammar, file, NULL);
ft_dprintf(file,
"\nt_symbol\t\t**create_%s_grammar(void)\n{\n"
"\tt_symbol\t**grammar;\n"
"\tsize_t\t\tindex;\n"
"\tt_symbol\t*(*init_func[])(void) = {", grammar->name);
f_fifoiter_va(grammar->sym_list, adapt_print, file, "create_");
ft_dprintf(file, "NULL};\n\n"
"\tindex = 0;\n"
"\tgrammar = malloc(sizeof(t_symbol*) * NB_SYMBOLS);\n"
"\twhile (index < NB_SYMBOLS)\n"
"\t{\n"
"\t\tgrammar[index] = init_func[index]();\n"
"\t\tindex++;\n"
"\t}\n"
"\treturn (grammar);\n}\n");
}