-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.cpp
49 lines (44 loc) · 1.07 KB
/
options.cpp
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
// Copyright (c) Mathieu Malaterre
// SPDX-License-Identifier: BSD-3-Clause
#include "options.h"
#include <unistd.h>
namespace jlst {
bool options::is_stdin_connected_to_terminal()
{
#ifdef HAVE_ISATTY
// No point in checking `errno`, simply ret val:
return isatty(STDIN_FILENO) == 1;
#else
#error isatty missing
#endif
}
bool options::is_stdout_connected_to_terminal()
{
#ifdef HAVE_ISATTY
// No point in checking `errno`, simply ret val:
return isatty(STDOUT_FILENO) == 1;
#else
#error isatty missing
#endif
}
std::string options::compute_type_from_filenames(std::vector<std::string> const& outputs)
{
if (outputs.empty())
throw std::runtime_error("compute_type_from_outputs is empty");
auto& ref = outputs[0];
auto pos = ref.rfind('.');
if (pos != std::string::npos)
{
return ref.substr(pos + 1);
}
throw std::runtime_error("compute_type_from_outputs no file extension");
}
source& options::get_source(int index)
{
return sources[index];
}
dest& options::get_dest(int index)
{
return dests[index];
}
} // end namespace jlst