aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/builtin.cxx
blob: a83bb6d359ebf7bb3b45d33c85755afe7ed01c5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// file      : build2/test/script/builtin.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build2/test/script/builtin>

#include <butl/fdstream>

using namespace std;
using namespace butl;

namespace build2
{
  static int
  echo (const strings& args, auto_fd, auto_fd out, auto_fd err)
  try
  {
    int r (0);
    ofdstream cerr (move (err));

    try
    {
      ofdstream cout (move (out));

      for (auto b (args.begin ()), i (b), e (args.end ()); i != e; ++i)
        cout << (i != b ? " " : "") << *i;

      cout << endl;

      cout.close ();
    }
    catch (const std::exception& e)
    {
      cerr << "echo: " << e.what ();
      r = 1;
    }

    cerr.close ();
    return r;
  }
  catch (const std::exception&)
  {
    return 1;
  }

  namespace test
  {
    namespace script
    {
      const builtin_map builtins
      {
        {"echo", &echo}
      };
    }
  }
}