summaryrefslogtreecommitdiff
path: root/other/burneye/src/conf/tmp/compiler-test.c
blob: 969ae4de9f8e4fcc2889fe86ae4f8f34cdf3483b (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
/* fornax - distributed network
 *
 * by team teso
 *
 * compiler test program
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../shared/common.h"
#include "element.h"
#include "compiler.h"
#include "script.h"


extern void	scr_elem_exec (element **el);
char *		file_read (char *filename);


char *
file_read (char *filename)
{
	FILE			*fp;
	char			*array = NULL;
	unsigned long int	readbytes = 0;
	size_t			rb;

	fp = fopen (filename, "r");
	if (fp == NULL)
		return (NULL);

	do {
		array = xrealloc (array, readbytes + 1024);
		rb = fread (array + readbytes, 1, 1024, fp);
		readbytes += rb;
	} while (rb > 0);

	fclose (fp);

	return (array);
}


int
main (int argc, char **argv)
{
	element **	script_c;
	char *		script;

	if (argc != 2) {
		printf ("usage: %s <inputfile>\n\n", argv[0]);
		exit (EXIT_FAILURE);
	}

	script = file_read (argv[1]);
	if (script == NULL) {
		fprintf (stderr, "couldn't open %s, aborting\n", argv[1]);
		exit (EXIT_FAILURE);
	}

	script_c = cp_compile (script, strlen (script));
	printf ("-------------------------------------------------------------------------------\n");
	printf ("compilation of script %s %s.\n\n", argv[1], (script_c == NULL) ? "failed" : "successful");

	printf ("\ntrying to run it...\n");
	scr_elem_exec (script_c);

	elem_list_free (script_c);

	exit (EXIT_SUCCESS);
}