From 46a95c974de475070d0eedb07212e5c5282b66bd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Apr 2016 07:26:09 +0200 Subject: Implement --buildfile option, overrides default buildfile, supports '-' --- build2/file.cxx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'build2/file.cxx') diff --git a/build2/file.cxx b/build2/file.cxx index 10461c4..b735cab 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -5,6 +5,7 @@ #include #include +#include // cin #include @@ -80,16 +81,24 @@ namespace build2 try { - ifstream ifs (bf.string ()); - if (!ifs.is_open ()) - fail << "unable to open " << bf; + bool sin (bf.string () == "-"); - ifs.exceptions (ifstream::failbit | ifstream::badbit); + ifstream ifs; + if (!sin) + { + ifs.open (bf.string ()); + + if (!ifs.is_open ()) + fail << "unable to open " << bf; + } + + istream& is (sin ? std::cin : ifs); + is.exceptions (ifstream::failbit | ifstream::badbit); l5 ([&]{trace << "sourcing " << bf;}); parser p (boot); - p.parse_buildfile (ifs, bf, root, base); + p.parse_buildfile (is, bf, root, base); } catch (const ifstream::failure&) { -- cgit v1.1