summaryrefslogtreecommitdiff
path: root/other/burneye/src/conf/tmp/compiler_main.c
blob: 7a75786b43bec3f9112ddb5109ffbd5b133434e0 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* fornax distributed packet network
 *
 * by team teso
 *
 * scripting compiler routines
 */

#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include "../../shared/common.h"
#include "branch.h"
#include "call.h"
#include "compiler.h"
#include "condition.h"
#include "element.h"
#include "script.h"
#include "symbol.h"


extern int	yydebug;
extern FILE *	yyout;

element **	gl_script;

char *		cp_input_ptr;
int		cp_input_lim;

jmp_buf		cp_yy_error_jmp;

extern int	yyparse (void);


/* yacc functions
 */

int
yyerror (char *str)
{
	/* to handle that errors, go to compiler
	 */
	longjmp (cp_yy_error_jmp, 1);

	exit (EXIT_FAILURE);
}


int
yywrap (void)
{
#ifdef YYDEBUG
	printf ("yywrap called\n");
#endif
	return (1);
}


/* input functions
 *
 * cp_input_lim is the number of bytes stored in the buffer pointed to by
 * cp_input_ptr. the pointer and the value of cp_input_lim will change while
 * parsing the input
 */

/* cp_parse
 *
 * parse a action string pointed to by `buf' with a length of `buf_len'
 *
 * return the parsed action structure
 */

element **
cp_compile (char *buf, int buf_len)
{
	gl_script = NULL;
	cp_input_ptr = buf;
	cp_input_lim = buf_len;

#ifdef YYDEBUG
	yydebug = 1;
#endif

	/* set compilation error jump point, if called handle the errors
	 */
	if (setjmp (cp_yy_error_jmp) != 0) {
		if (gl_script != NULL)
			elem_list_free (gl_script);

		return (NULL);
	}

	yyparse ();


	return (gl_script);
}


/* cp_yyinput
 *
 * input functions for the yacc parser to feed strings into it
 *
 * return number of bytes "read"
 */

int
cp_yyinput (char *buf, int size_max)
{
	int	n = 0;

	n = (size_max >= cp_input_lim) ?
		(cp_input_lim) :
		(size_max);

	if (n > 0) {
		memmove (buf, cp_input_ptr, n);
		cp_input_ptr += n;
		cp_input_lim -= n;
	}

	return (n);
}