summaryrefslogtreecommitdiff
path: root/tests/tests-common.cc
blob: 1f19c59c59a7aff0b1b2cbb10f48889d48595a2d (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
#include "tests-common.h"
#include "openscad.h"
#include "module.h"
#include "handle_dep.h"

#include <QFile>
#include <QFileInfo>
#include <sstream>

AbstractModule *parsefile(const char *filename)
{
	AbstractModule *root_module = NULL;

	QFileInfo fileInfo(filename);
	handle_dep(filename);
	FILE *fp = fopen(filename, "rt");
	if (!fp) {
		fprintf(stderr, "Can't open input file `%s'!\n", filename);
	} else {
		std::stringstream text;
		char buffer[513];
		int ret;
		while ((ret = fread(buffer, 1, 512, fp)) > 0) {
			buffer[ret] = 0;
			text << buffer;
		}
		fclose(fp);
		text << commandline_commands;
		root_module = parse(text.str().c_str(), fileInfo.absolutePath().toLocal8Bit(), false);
	}
	return root_module;
}
contact: Jan Huwald // Impressum