// file : tests/variable/driver.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #include // ios_base::failbit, ios_base::badbit #include #include #include // size_t #include #include // operator<<(ostream,exception) #include using namespace std; using namespace butl; using namespace bbot; // Usage: argv[0] [-u] // // Read variables from STDIN (one per line) and serialize them to STDOUT (also // one per line). // // -u output variables being unquoted beforehand // int main (int argc, char* argv[]) { assert (argc <= 2); bool unquote (false); if (argc == 2) { assert (argv[1] == string ("-u")); unquote = true; } cin.exceptions (ios_base::badbit); cout.exceptions (ios_base::failbit | ios_base::badbit); string s; for (size_t l (1); getline (cin, s); ++l) { try { variable v (move (s)); cout << (unquote ? v.unquoted () : static_cast (v)) << '\n'; } catch (const invalid_variable& e) { cerr << l << ':' << 1 + e.pos << ": error: " << e << endl; return 1; } } return 0; }