diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2011-11-06 14:26:59 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2011-11-06 14:26:59 (GMT) |
commit | 31a97f34e1122690cbad2c9bf01f3ede6d3da135 (patch) | |
tree | d34435cb6eada42b83aed18a9e83083b43efd8cb /tests/tests-common.cc | |
parent | 9ab95e6d7230dc5deb06a8e6e3f647e8b48b87c6 (diff) | |
parent | a221eeee99ca772605c0ac6473cae2466e4cc07a (diff) |
Merge remote branch 'upstream/master'
Diffstat (limited to 'tests/tests-common.cc')
-rw-r--r-- | tests/tests-common.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/tests-common.cc b/tests/tests-common.cc new file mode 100644 index 0000000..1f19c59 --- /dev/null +++ b/tests/tests-common.cc @@ -0,0 +1,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; +} |