diff options
author | Jan Huwald <jh@sotun.de> | 2014-02-13 12:33:46 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2014-02-13 12:33:46 (GMT) |
commit | afb6634b453cd9ad698a7b53d39d62392663be32 (patch) | |
tree | 8843d932c57264b3320c6740f1515f6d1ec17ff0 | |
parent | 78baae599b6c0fbe058071c98ebc541ed66fd030 (diff) |
allow reading .scad files from standard inputHEADmasterf_read_stdin
This patch loads the root source code form standard input if "-" is
given as file name. In this case handle_dep() is disabled for the root
module but still executed for all included files.
-rw-r--r-- | src/openscad.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/openscad.cc b/src/openscad.cc index 12e22ce..a5c56f6 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -254,17 +254,24 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c AbstractNode *absolute_root_node; CGAL_Nef_polyhedron root_N; - handle_dep(filename.c_str()); - - std::ifstream ifs(filename.c_str()); - if (!ifs.is_open()) { - PRINTB("Can't open input file '%s'!\n", filename.c_str()); - return 1; + std::string text, parentpath; + if (filename != "-") { + handle_dep(filename); + + std::ifstream ifs(filename.c_str()); + if (!ifs.is_open()) { + PRINTB("Can't open input file '%s'!\n", filename.c_str()); + return 1; + } + text = std::string((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); + fs::path abspath = boosty::absolute(filename); + parentpath = boosty::stringy(abspath.parent_path()); + }else{ + text = std::string((std::istreambuf_iterator<char>(std::cin)), std::istreambuf_iterator<char>()); + parentpath = boosty::stringy(original_path); } - std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); text += "\n" + commandline_commands; - fs::path abspath = boosty::absolute(filename); - std::string parentpath = boosty::stringy(abspath.parent_path()); + root_module = parse(text.c_str(), parentpath.c_str(), false); if (!root_module) { PRINTB("Can't parse file '%s'!\n", filename.c_str()); |