1 |
commit: dde59df4c102af140d45ba77d6b64544da541adb |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 1 09:16:42 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jun 2 11:37:58 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=dde59df4 |
7 |
|
8 |
Builtin: support eval built-in |
9 |
|
10 |
--- |
11 |
Makefile.am | 2 + |
12 |
scripts/command_execution.bash | 2 + |
13 |
scripts/command_execution.bash.result | 2 + |
14 |
src/builtins/eval_builtin.cpp | 39 +++++++++++++++++++++++++++ |
15 |
src/builtins/eval_builtin.h | 47 +++++++++++++++++++++++++++++++++ |
16 |
src/cppbash_builtin.cpp | 2 + |
17 |
6 files changed, 94 insertions(+), 0 deletions(-) |
18 |
|
19 |
diff --git a/Makefile.am b/Makefile.am |
20 |
index e511111..d4614cf 100644 |
21 |
--- a/Makefile.am |
22 |
+++ b/Makefile.am |
23 |
@@ -179,6 +179,8 @@ libcppbash_la_SOURCES = src/common.h \ |
24 |
src/builtins/continue_builtin.h \ |
25 |
src/builtins/echo_builtin.cpp \ |
26 |
src/builtins/echo_builtin.h \ |
27 |
+ src/builtins/eval_builtin.cpp \ |
28 |
+ src/builtins/eval_builtin.h \ |
29 |
src/builtins/declare_builtin.cpp \ |
30 |
src/builtins/declare_builtin.h \ |
31 |
src/builtins/boolean_builtins.h \ |
32 |
|
33 |
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash |
34 |
index 8005a23..c8faf7f 100644 |
35 |
--- a/scripts/command_execution.bash |
36 |
+++ b/scripts/command_execution.bash |
37 |
@@ -47,3 +47,5 @@ declare -F unset_outer |
38 |
echo '$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...' |
39 |
echo "abc $(echo def) ghi" |
40 |
FOO008="abc $(echo def) ghi" |
41 |
+eval "FOO009=10" |
42 |
+eval "echo abc" "def" "xyz" |
43 |
|
44 |
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result |
45 |
index d47650d..4113c12 100644 |
46 |
--- a/scripts/command_execution.bash.result |
47 |
+++ b/scripts/command_execution.bash.result |
48 |
@@ -15,6 +15,7 @@ FOO006= in global |
49 |
unset_outer |
50 |
$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ... |
51 |
abc def ghi |
52 |
+abc def xyz |
53 |
DEFAULTED=yes |
54 |
FOO001=hello |
55 |
FOO002=Hello World |
56 |
@@ -22,3 +23,4 @@ FOO003=1 |
57 |
FOO004=abc |
58 |
FOO005=1 2 3 |
59 |
FOO008=abc def ghi |
60 |
+FOO009=10 |
61 |
|
62 |
diff --git a/src/builtins/eval_builtin.cpp b/src/builtins/eval_builtin.cpp |
63 |
new file mode 100644 |
64 |
index 0000000..5e5a61b |
65 |
--- /dev/null |
66 |
+++ b/src/builtins/eval_builtin.cpp |
67 |
@@ -0,0 +1,39 @@ |
68 |
+/* |
69 |
+ Please use git log for copyright holder and year information |
70 |
+ |
71 |
+ This file is part of libbash. |
72 |
+ |
73 |
+ libbash is free software: you can redistribute it and/or modify |
74 |
+ it under the terms of the GNU General Public License as published by |
75 |
+ the Free Software Foundation, either version 2 of the License, or |
76 |
+ (at your option) any later version. |
77 |
+ |
78 |
+ libbash is distributed in the hope that it will be useful, |
79 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of |
80 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
81 |
+ GNU General Public License for more details. |
82 |
+ |
83 |
+ You should have received a copy of the GNU General Public License |
84 |
+ along with libbash. If not, see <http://www.gnu.org/licenses/>. |
85 |
+*/ |
86 |
+/// |
87 |
+/// \file eval_builtin.h |
88 |
+/// \author Mu Qiao |
89 |
+/// \brief class that implements the eval builtin |
90 |
+/// |
91 |
+ |
92 |
+#include "builtins/eval_builtin.h" |
93 |
+ |
94 |
+#include <sstream> |
95 |
+ |
96 |
+#include <boost/algorithm/string/join.hpp> |
97 |
+ |
98 |
+#include "core/bash_ast.h" |
99 |
+#include "core/interpreter.h" |
100 |
+ |
101 |
+int eval_builtin::exec(const std::vector<std::string>& bash_args) |
102 |
+{ |
103 |
+ std::stringstream script(boost::algorithm::join(bash_args, " ")); |
104 |
+ bash_ast(script).interpret_with(_walker); |
105 |
+ return _walker.get_status(); |
106 |
+} |
107 |
|
108 |
diff --git a/src/builtins/eval_builtin.h b/src/builtins/eval_builtin.h |
109 |
new file mode 100644 |
110 |
index 0000000..87746e9 |
111 |
--- /dev/null |
112 |
+++ b/src/builtins/eval_builtin.h |
113 |
@@ -0,0 +1,47 @@ |
114 |
+/* |
115 |
+ Please use git log for copyright holder and year information |
116 |
+ |
117 |
+ This file is part of libbash. |
118 |
+ |
119 |
+ libbash is free software: you can redistribute it and/or modify |
120 |
+ it under the terms of the GNU General Public License as published by |
121 |
+ the Free Software Foundation, either version 2 of the License, or |
122 |
+ (at your option) any later version. |
123 |
+ |
124 |
+ libbash is distributed in the hope that it will be useful, |
125 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of |
126 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
127 |
+ GNU General Public License for more details. |
128 |
+ |
129 |
+ You should have received a copy of the GNU General Public License |
130 |
+ along with libbash. If not, see <http://www.gnu.org/licenses/>. |
131 |
+*/ |
132 |
+/// |
133 |
+/// \file eval_builtin.h |
134 |
+/// \author Mu Qiao |
135 |
+/// \brief class that implements the eval builtin |
136 |
+/// |
137 |
+ |
138 |
+#ifndef LIBBASH_BUILTINS_eval_BUILTIN_H_ |
139 |
+#define LIBBASH_BUILTINS_eval_BUILTIN_H_ |
140 |
+ |
141 |
+#include "cppbash_builtin.h" |
142 |
+ |
143 |
+/// |
144 |
+/// \class eval_builtin |
145 |
+/// \brief the eval builtin for bash |
146 |
+/// |
147 |
+class eval_builtin: public virtual cppbash_builtin |
148 |
+{ |
149 |
+ public: |
150 |
+ BUILTIN_CONSTRUCTOR(eval) |
151 |
+ |
152 |
+ /// |
153 |
+ /// \brief runs the eval builtin on the supplied arguments |
154 |
+ /// \param bash_args the arguments to the eval builtin |
155 |
+ /// \return exit status of eval |
156 |
+ /// |
157 |
+ virtual int exec(const std::vector<std::string>& bash_args); |
158 |
+}; |
159 |
+ |
160 |
+#endif |
161 |
|
162 |
diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp |
163 |
index c762f5f..a66622e 100644 |
164 |
--- a/src/cppbash_builtin.cpp |
165 |
+++ b/src/cppbash_builtin.cpp |
166 |
@@ -28,6 +28,7 @@ |
167 |
#include "builtins/continue_builtin.h" |
168 |
#include "builtins/declare_builtin.h" |
169 |
#include "builtins/echo_builtin.h" |
170 |
+#include "builtins/eval_builtin.h" |
171 |
#include "builtins/inherit_builtin.h" |
172 |
#include "builtins/let_builtin.h" |
173 |
#include "builtins/return_builtin.h" |
174 |
@@ -43,6 +44,7 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() { |
175 |
static boost::scoped_ptr<builtins_type> p(new builtins_type { |
176 |
{"continue", boost::factory<continue_builtin*>()}, |
177 |
{"echo", boost::factory<echo_builtin*>()}, |
178 |
+ {"eval", boost::factory<eval_builtin*>()}, |
179 |
{"declare", boost::factory<declare_builtin*>()}, |
180 |
{"source", boost::factory<source_builtin*>()}, |
181 |
{"shopt", boost::factory<shopt_builtin*>()}, |