2011-11-05 22:38:03 +04:00
|
|
|
#include "tests-common.h"
|
|
|
|
#include "openscad.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "handle_dep.h"
|
2012-05-02 20:07:56 +04:00
|
|
|
#include "boosty.h"
|
2011-11-05 22:38:03 +04:00
|
|
|
|
|
|
|
#include <sstream>
|
2012-05-02 20:07:56 +04:00
|
|
|
#include <fstream>
|
2011-11-05 22:38:03 +04:00
|
|
|
|
2013-05-09 14:12:58 +04:00
|
|
|
/*!
|
|
|
|
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)
|
2011-11-05 22:38:03 +04:00
|
|
|
{
|
2013-04-20 01:52:01 +04:00
|
|
|
FileModule *root_module = NULL;
|
2011-11-05 22:38:03 +04:00
|
|
|
|
|
|
|
handle_dep(filename);
|
2012-05-02 20:07:56 +04:00
|
|
|
std::ifstream ifs(filename);
|
|
|
|
if (!ifs.is_open()) {
|
2011-11-05 22:38:03 +04:00
|
|
|
fprintf(stderr, "Can't open input file `%s'!\n", filename);
|
2012-05-02 20:07:56 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
|
|
|
text += "\n" + commandline_commands;
|
2013-05-09 14:12:58 +04:00
|
|
|
std::string pathname;
|
|
|
|
if (fakepath) pathname = fakepath;
|
|
|
|
else pathname = boosty::stringy(fs::path(filename).parent_path());
|
2012-05-02 20:07:56 +04:00
|
|
|
root_module = parse(text.c_str(), pathname.c_str(), false);
|
2012-02-04 04:43:53 +04:00
|
|
|
if (root_module) {
|
|
|
|
root_module->handleDependencies();
|
|
|
|
}
|
2011-11-05 22:38:03 +04:00
|
|
|
}
|
|
|
|
return root_module;
|
|
|
|
}
|