blob: fca0f820f4557f95caa2eaacbc84604389ce7f0a (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
Please use git log for copyright holder and year information
This file is part of libbash.
libbash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
libbash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libbash. If not, see <http://www.gnu.org/licenses/>.
*/
///
/// \file set_builtin.cpp
/// \brief class that implements the set builtin
///
#include "builtins/set_builtin.h"
#include "core/interpreter.h"
#include "exceptions.h"
int set_builtin::exec(const std::vector<std::string>& bash_args)
{
if(bash_args.empty())
{
throw libbash::unsupported_exception("set: variables printing are not supported");
return 1;
}
if(bash_args[0][0] != '-' && bash_args[0][0] != '+')
{
throw libbash::illegal_argument_exception("set: invalid option");
return 1;
}
switch(bash_args[0][1])
{
case '-':
if(bash_args[0][0] != '-') {
throw libbash::unsupported_exception("set: invalid option");
return 1;
}
else
{
_walker.define_positional_arguments(bash_args.begin() + 1, bash_args.end());
return 0;
}
case 'a':
case 'b':
case 'e':
case 'f':
case 'h':
case 'k':
case 'm':
case 'n':
case 'p':
case 't':
case 'u':
case 'v':
case 'x':
case 'B':
case 'C':
case 'E':
case 'H':
case 'P':
case 'T':
throw libbash::unsupported_exception("set " + bash_args[0] + " is not supported yet");
return 1;
default:
throw libbash::illegal_argument_exception("set: unrecognized option: " + bash_args[0]);
return 1;
}
}
|