File: tests-common.cc

package info (click to toggle)
openscad 2015.03-2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 30,804 kB
  • ctags: 5,692
  • sloc: cpp: 39,386; sh: 3,856; ansic: 3,674; python: 1,393; yacc: 496; lex: 272; lisp: 159; makefile: 67; xml: 60
file content (36 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (2)
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
#include "tests-common.h"
#include "openscad.h"
#include "module.h"
#include "handle_dep.h"
#include "boosty.h"

#include <sstream>
#include <fstream>

/*!
	fakepath is used to force the parser to believe that the file is
	read from this location, in order to ensure that filepaths are
	eavluated relative to this path (for testing purposes).
*/
FileModule *parsefile(const char *filename, const char *fakepath)
{
	FileModule *root_module = NULL;

	handle_dep(filename);
	std::ifstream ifs(filename);
	if (!ifs.is_open()) {
		fprintf(stderr, "Can't open input file `%s'!\n", filename);
	}
	else {
		std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
		text += "\n" + commandline_commands;
		std::string pathname;
		if (fakepath) pathname = fakepath;
		else pathname = boosty::stringy(fs::path(filename).parent_path());
		root_module = parse(text.c_str(), pathname.c_str(), false);
		if (root_module) {
			root_module->handleDependencies();
		}
	}
	return root_module;
}