public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/
@ 2011-05-23 14:34 Petteri Räty
  0 siblings, 0 replies; 3+ messages in thread
From: Petteri Räty @ 2011-05-23 14:34 UTC (permalink / raw
  To: gentoo-commits

commit:     ec95a2f25d72a177609b38cf72e01309039641c5
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri May 20 07:23:43 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 15:04:44 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ec95a2f2

Builtin: support let built-in

---
 Makefile.am                        |    2 +
 scripts/arithmetic_assignment.bash |    2 +-
 scripts/function_def.bash          |    4 +++
 scripts/function_def.bash.result   |    1 +
 src/builtins/let_builtin.cpp       |   37 ++++++++++++++++++++++++++++++++++++
 src/builtins/let_builtin.h         |   35 ++++++++++++++++++++++++++++++++++
 src/cppbash_builtin.cpp            |    4 ++-
 7 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index b680cd0..33dbe51 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,6 +179,8 @@ libcppbash_la_SOURCES = src/common.h \
 						src/builtins/source_builtin.cpp \
 						src/builtins/return_builtin.h \
 						src/builtins/return_builtin.cpp \
+						src/builtins/let_builtin.h \
+						src/builtins/let_builtin.cpp \
 						src/builtins/inherit_builtin.h \
 						src/builtins/inherit_builtin.cpp \
 						src/builtins/builtin_exceptions.h \

diff --git a/scripts/arithmetic_assignment.bash b/scripts/arithmetic_assignment.bash
index 27e2ee5..7f77ec7 100644
--- a/scripts/arithmetic_assignment.bash
+++ b/scripts/arithmetic_assignment.bash
@@ -11,4 +11,4 @@ FOO009="$((value^=5))"
 FOO010="$((value|=10))"
 FOO011=("CREATED" 2)
 FOO012="$((${FOO011[0]}=10))"
-value="$((100))"
+let "value=100"

diff --git a/scripts/function_def.bash b/scripts/function_def.bash
index bcf5a4b..60337ac 100644
--- a/scripts/function_def.bash
+++ b/scripts/function_def.bash
@@ -52,3 +52,7 @@ func_nested2() {
     func_nested1
 }
 func_nested2
+let() {
+    echo "overloaded let"
+}
+let "1 + 2"

diff --git a/scripts/function_def.bash.result b/scripts/function_def.bash.result
index 2c5783c..677c3d8 100644
--- a/scripts/function_def.bash.result
+++ b/scripts/function_def.bash.result
@@ -1,4 +1,5 @@
 hi 1
+overloaded let
 ARG1=100
 ARG2=2
 ARG3=3

diff --git a/src/builtins/let_builtin.cpp b/src/builtins/let_builtin.cpp
new file mode 100644
index 0000000..dc4be13
--- /dev/null
+++ b/src/builtins/let_builtin.cpp
@@ -0,0 +1,37 @@
+/*
+   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 let_builtin.h
+/// \author Mu Qiao
+/// \brief implementation for the let builtin
+///
+#include <boost/algorithm/string/join.hpp>
+
+#include "core/bash_ast.h"
+
+#include "builtins/let_builtin.h"
+
+int let_builtin::exec(const std::vector<std::string>& bash_args)
+{
+  std::string expression(boost::algorithm::join(bash_args, " "));
+  bash_ast ast(expression, &bash_ast::parser_arithmetics);
+  ast.interpret_with(_walker, &bash_ast::walker_arithmetics);
+
+  return ast.get_error_count();
+}

diff --git a/src/builtins/let_builtin.h b/src/builtins/let_builtin.h
new file mode 100644
index 0000000..9dba7d6
--- /dev/null
+++ b/src/builtins/let_builtin.h
@@ -0,0 +1,35 @@
+/*
+   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 let_builtin.h
+/// \brief implementation for the let builtin
+///
+#ifndef LIBBASH_BUILTINS_LET_BUILTIN_H_
+#define LIBBASH_BUILTINS_LET_BUILTIN_H_
+
+#include "cppbash_builtin.h"
+
+class let_builtin : public virtual cppbash_builtin
+{
+public:
+  BUILTIN_CONSTRUCTOR(let)
+  virtual int exec(const std::vector<std::string>& );
+};
+
+#endif

diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp
index aee18c9..7334a8e 100644
--- a/src/cppbash_builtin.cpp
+++ b/src/cppbash_builtin.cpp
@@ -27,6 +27,7 @@
 #include "builtins/boolean_builtins.h"
 #include "builtins/echo_builtin.h"
 #include "builtins/inherit_builtin.h"
+#include "builtins/let_builtin.h"
 #include "builtins/return_builtin.h"
 #include "builtins/source_builtin.h"
 
@@ -42,7 +43,8 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
       {":", boost::factory<true_builtin*>()},
       {"true", boost::factory<true_builtin*>()},
       {"false", boost::factory<false_builtin*>()},
-      {"return", boost::factory<return_builtin*>()}
+      {"return", boost::factory<return_builtin*>()},
+      {"let", boost::factory<let_builtin*>()},
   });
   return *p;
 }



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/
@ 2011-05-27 23:03 Petteri Räty
  0 siblings, 0 replies; 3+ messages in thread
From: Petteri Räty @ 2011-05-27 23:03 UTC (permalink / raw
  To: gentoo-commits

commit:     545417a9c8286a81642a3750df4af7cd977a3be0
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu May 26 12:18:30 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri May 27 14:38:07 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=545417a9

Builtin: support unset built-in

We do not support unsetting array indexes currently. In addition,
read-only functions can be unset for now. Note that if no options are
supplied, or the -v option is given, each name refers to a shell
variable(This behavior is supported by bash 3.2, bash-4.1 tries to
unset function if the name doesn't match a variable).

---
 Makefile.am                           |    2 +
 scripts/command_execution.bash        |   24 +++++++++++++
 scripts/command_execution.bash.result |    7 ++++
 src/builtins/unset_builtin.cpp        |   59 +++++++++++++++++++++++++++++++++
 src/builtins/unset_builtin.h          |   35 +++++++++++++++++++
 src/cppbash_builtin.cpp               |    2 +
 6 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3b72d46..ebe12ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -189,6 +189,8 @@ libcppbash_la_SOURCES = src/common.h \
 						src/builtins/let_builtin.cpp \
 						src/builtins/inherit_builtin.h \
 						src/builtins/inherit_builtin.cpp \
+						src/builtins/unset_builtin.h \
+						src/builtins/unset_builtin.cpp \
 						src/builtins/builtin_exceptions.h \
 						$(GENERATED_PARSER_C) \
 						$(GENERATED_PARSER_H) \

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 95e1594..b1670f2 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -19,3 +19,27 @@ FOO="abc" echo "command environment"
 export FOO003=1 FOO004=abc FOO005=(1 2 3) FOO002
 abc=1 export foo
 true > /dev/null
+
+function unset_inner()
+{
+    local FOO006=3 
+    unset FOO006 FOO007
+}
+function unset_outer()
+{
+    local FOO006=1 FOO007=2
+    unset_inner
+    echo "FOO006=$FOO006 in unset_outer"
+    echo "FOO007=$FOO007 in unset_outer"
+    unset FOO006
+    echo "FOO006=$FOO006 in unset_outer"
+}
+unset_outer
+echo "FOO006=$FOO006 in global"
+FOO006=0
+echo "FOO006=$FOO006 in global"
+unset FOO006
+echo "FOO006=$FOO006 in global"
+declare -F unset_outer
+unset -f unset_outer
+declare -F unset_outer

diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index ae71fa5..d941a6d 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -6,6 +6,13 @@ end
 command environment
 We do not support command env before the export builtin.
 Redirection is not supported yet
+FOO006=1 in unset_outer
+FOO007= in unset_outer
+FOO006= in unset_outer
+FOO006= in global
+FOO006=0 in global
+FOO006= in global
+unset_outer
 DEFAULTED=yes
 FOO001=hello
 FOO002=Hello World

diff --git a/src/builtins/unset_builtin.cpp b/src/builtins/unset_builtin.cpp
new file mode 100644
index 0000000..1490013
--- /dev/null
+++ b/src/builtins/unset_builtin.cpp
@@ -0,0 +1,59 @@
+/*
+   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 unset_builtin.h
+/// \author Mu Qiao
+/// \brief implementation for the unset builtin
+///
+#include <functional>
+
+#include "core/interpreter.h"
+#include "core/unset_exception.h"
+
+#include "builtins/unset_builtin.h"
+
+int unset_builtin::exec(const std::vector<std::string>& bash_args)
+{
+  if(bash_args.empty())
+    return 0;
+
+  if(bash_args[0] == "-f")
+    for_each(bash_args.begin() + 1,
+             bash_args.end(),
+             std::bind(&interpreter::unset_function, &_walker, std::placeholders::_1));
+  else
+  /* POSIX says if neither -f nor -v is specified, name refers to a variable;
+   * if a variable by that name does not exist, it is unspecified whether a
+   * function by that name, if any, shall be unset.
+   *
+   * >=bash-4.1: without options, unset first tries to unset a variable, and
+   * if that fails, tries to unset a function.
+   * (We haven't checked bash-4.0)
+   *
+   * bash-3.2: if no options are supplied, or the -v option is given, each
+   * name refers to a shell variable.
+   *
+   * We addhere to bash-3.2
+   * */
+    for_each(bash_args.front() == "-v" ? bash_args.begin() + 1 : bash_args.begin(),
+             bash_args.end(),
+             [&](const std::string& name) { _walker.unset(name); });
+
+  return 0;
+}

diff --git a/src/builtins/unset_builtin.h b/src/builtins/unset_builtin.h
new file mode 100644
index 0000000..202e78a
--- /dev/null
+++ b/src/builtins/unset_builtin.h
@@ -0,0 +1,35 @@
+/*
+   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 unset_builtin.h
+/// \brief implementation for the unset builtin
+///
+#ifndef LIBBASH_BUILTINS_UNSET_BUILTIN_H_
+#define LIBBASH_BUILTINS_UNSET_BUILTIN_H_
+
+#include "cppbash_builtin.h"
+
+class unset_builtin : public virtual cppbash_builtin
+{
+public:
+  BUILTIN_CONSTRUCTOR(unset)
+  virtual int exec(const std::vector<std::string>& bash_args);
+};
+
+#endif

diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp
index 9308ebb..98d3acc 100644
--- a/src/cppbash_builtin.cpp
+++ b/src/cppbash_builtin.cpp
@@ -32,6 +32,7 @@
 #include "builtins/return_builtin.h"
 #include "builtins/shopt_builtin.h"
 #include "builtins/source_builtin.h"
+#include "builtins/unset_builtin.h"
 
 cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_stream(&out), _err_stream(&err), _inp_stream(&in), _walker(walker)
 {
@@ -49,6 +50,7 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
       {"false", boost::factory<false_builtin*>()},
       {"return", boost::factory<return_builtin*>()},
       {"let", boost::factory<let_builtin*>()},
+      {"unset", boost::factory<unset_builtin*>()},
   });
   return *p;
 }



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/
@ 2011-06-02 11:48 Petteri Räty
  0 siblings, 0 replies; 3+ messages in thread
From: Petteri Räty @ 2011-06-02 11:48 UTC (permalink / raw
  To: gentoo-commits

commit:     dde59df4c102af140d45ba77d6b64544da541adb
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  1 09:16:42 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun  2 11:37:58 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=dde59df4

Builtin: support eval built-in

---
 Makefile.am                           |    2 +
 scripts/command_execution.bash        |    2 +
 scripts/command_execution.bash.result |    2 +
 src/builtins/eval_builtin.cpp         |   39 +++++++++++++++++++++++++++
 src/builtins/eval_builtin.h           |   47 +++++++++++++++++++++++++++++++++
 src/cppbash_builtin.cpp               |    2 +
 6 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index e511111..d4614cf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,6 +179,8 @@ libcppbash_la_SOURCES = src/common.h \
 						src/builtins/continue_builtin.h \
 						src/builtins/echo_builtin.cpp \
 						src/builtins/echo_builtin.h \
+						src/builtins/eval_builtin.cpp \
+						src/builtins/eval_builtin.h \
 						src/builtins/declare_builtin.cpp \
 						src/builtins/declare_builtin.h \
 						src/builtins/boolean_builtins.h \

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 8005a23..c8faf7f 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -47,3 +47,5 @@ declare -F unset_outer
 echo '$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...'
 echo "abc $(echo def) ghi"
 FOO008="abc $(echo def) ghi"
+eval "FOO009=10"
+eval "echo abc" "def" "xyz"

diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index d47650d..4113c12 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -15,6 +15,7 @@ FOO006= in global
 unset_outer
 $FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...
 abc def ghi
+abc def xyz
 DEFAULTED=yes
 FOO001=hello
 FOO002=Hello World
@@ -22,3 +23,4 @@ FOO003=1
 FOO004=abc
 FOO005=1 2 3
 FOO008=abc def ghi
+FOO009=10

diff --git a/src/builtins/eval_builtin.cpp b/src/builtins/eval_builtin.cpp
new file mode 100644
index 0000000..5e5a61b
--- /dev/null
+++ b/src/builtins/eval_builtin.cpp
@@ -0,0 +1,39 @@
+/*
+   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 eval_builtin.h
+/// \author Mu Qiao
+/// \brief class that implements the eval builtin
+///
+
+#include "builtins/eval_builtin.h"
+
+#include <sstream>
+
+#include <boost/algorithm/string/join.hpp>
+
+#include "core/bash_ast.h"
+#include "core/interpreter.h"
+
+int eval_builtin::exec(const std::vector<std::string>& bash_args)
+{
+  std::stringstream script(boost::algorithm::join(bash_args, " "));
+  bash_ast(script).interpret_with(_walker);
+  return _walker.get_status();
+}

diff --git a/src/builtins/eval_builtin.h b/src/builtins/eval_builtin.h
new file mode 100644
index 0000000..87746e9
--- /dev/null
+++ b/src/builtins/eval_builtin.h
@@ -0,0 +1,47 @@
+/*
+   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 eval_builtin.h
+/// \author Mu Qiao
+/// \brief class that implements the eval builtin
+///
+
+#ifndef LIBBASH_BUILTINS_eval_BUILTIN_H_
+#define LIBBASH_BUILTINS_eval_BUILTIN_H_
+
+#include "cppbash_builtin.h"
+
+///
+/// \class eval_builtin
+/// \brief the eval builtin for bash
+///
+class eval_builtin: public virtual cppbash_builtin
+{
+  public:
+    BUILTIN_CONSTRUCTOR(eval)
+
+    ///
+    /// \brief runs the eval builtin on the supplied arguments
+    /// \param bash_args the arguments to the eval builtin
+    /// \return exit status of eval
+    ///
+    virtual int exec(const std::vector<std::string>& bash_args);
+};
+
+#endif

diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp
index c762f5f..a66622e 100644
--- a/src/cppbash_builtin.cpp
+++ b/src/cppbash_builtin.cpp
@@ -28,6 +28,7 @@
 #include "builtins/continue_builtin.h"
 #include "builtins/declare_builtin.h"
 #include "builtins/echo_builtin.h"
+#include "builtins/eval_builtin.h"
 #include "builtins/inherit_builtin.h"
 #include "builtins/let_builtin.h"
 #include "builtins/return_builtin.h"
@@ -43,6 +44,7 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
   static boost::scoped_ptr<builtins_type> p(new builtins_type {
       {"continue", boost::factory<continue_builtin*>()},
       {"echo", boost::factory<echo_builtin*>()},
+      {"eval", boost::factory<eval_builtin*>()},
       {"declare", boost::factory<declare_builtin*>()},
       {"source", boost::factory<source_builtin*>()},
       {"shopt", boost::factory<shopt_builtin*>()},



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-02 11:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-23 14:34 [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/ Petteri Räty
  -- strict thread matches above, loose matches on Subject: below --
2011-05-27 23:03 Petteri Räty
2011-06-02 11:48 Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox