From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/, /, src/builtins/tests/, src/builtins/
Date: Wed, 25 May 2011 19:42:36 +0000 (UTC) [thread overview]
Message-ID: <818ae8fb5415365640a7d08a05db21e5b94a3bf2.betelgeuse@gentoo> (raw)
commit: 818ae8fb5415365640a7d08a05db21e5b94a3bf2
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue May 24 08:29:39 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 25 08:47:10 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=818ae8fb
Builtin: first support for the shopt built-in
No logic is implemented for the built-in. Now it's just used for
the detection of shell option usage.
---
Makefile.am | 3 ++
src/builtins/shopt_builtin.cpp | 67 ++++++++++++++++++++++++++++++++++++
src/builtins/shopt_builtin.h | 35 +++++++++++++++++++
src/builtins/tests/shopt_tests.cpp | 33 +++++++++++++++++
src/cppbash_builtin.cpp | 2 +
5 files changed, 140 insertions(+), 0 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index c4605cd..86c2583 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -102,6 +102,7 @@ cppunittests_SOURCES = test/run_tests.cpp \
src/builtins/tests/declare_tests.cpp \
src/builtins/tests/boolean_tests.cpp \
src/builtins/tests/source_tests.cpp \
+ src/builtins/tests/shopt_tests.cpp \
src/builtins/tests/return_tests.cpp \
test/test.h \
test/test.cpp \
@@ -180,6 +181,8 @@ libcppbash_la_SOURCES = src/common.h \
src/builtins/boolean_builtins.h \
src/builtins/source_builtin.h \
src/builtins/source_builtin.cpp \
+ src/builtins/shopt_builtin.h \
+ src/builtins/shopt_builtin.cpp \
src/builtins/return_builtin.h \
src/builtins/return_builtin.cpp \
src/builtins/let_builtin.h \
diff --git a/src/builtins/shopt_builtin.cpp b/src/builtins/shopt_builtin.cpp
new file mode 100644
index 0000000..33ca3fc
--- /dev/null
+++ b/src/builtins/shopt_builtin.cpp
@@ -0,0 +1,67 @@
+/*
+ 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 shopt_builtin.cpp
+/// \author Mu Qiao
+/// \brief implementation for the shopt builtin
+///
+
+#include "core/interpreter_exception.h"
+#include "cppbash_builtin.h"
+
+#include "builtins/shopt_builtin.h"
+
+namespace
+{
+ int disable_opt(const std::vector<std::string>& bash_args)
+ {
+ auto iter = find(bash_args.begin() + 1, bash_args.end(), "extglob");
+ if(iter != bash_args.end())
+ throw interpreter_exception("Disabling extglob is not allowed");
+ return 0;
+ }
+}
+
+int shopt_builtin::exec(const std::vector<std::string>& bash_args)
+{
+ if(bash_args.empty())
+ {
+ *_err_stream << "Arguments required for shopt" << std::endl;
+ return 1;
+ }
+ else if(bash_args[0].size() != 2)
+ {
+ *_err_stream << "Multiple arguments are not supported" << std::endl;
+ return 1;
+ }
+
+ switch(bash_args[0][1])
+ {
+ case 'u':
+ return disable_opt(bash_args);
+ case 's':
+ case 'q':
+ case 'o':
+ *_err_stream << "shopt " << bash_args[0] << " is not supported yet" << std::endl;
+ return 1;
+ default:
+ *_err_stream << "Unrecognized option for shopt: " << bash_args[0] << std::endl;
+ return 1;
+ }
+}
diff --git a/src/builtins/shopt_builtin.h b/src/builtins/shopt_builtin.h
new file mode 100644
index 0000000..bd3291e
--- /dev/null
+++ b/src/builtins/shopt_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 shopt_builtin.h
+/// \brief implementation for the shopt builtin
+///
+#ifndef LIBBASH_BUILTINS_SHOPT_BUILTIN_H_
+#define LIBBASH_BUILTINS_SHOPT_BUILTIN_H_
+
+#include "cppbash_builtin.h"
+
+class shopt_builtin : public virtual cppbash_builtin
+{
+public:
+ BUILTIN_CONSTRUCTOR(shopt)
+ virtual int exec(const std::vector<std::string>& );
+};
+
+#endif
diff --git a/src/builtins/tests/shopt_tests.cpp b/src/builtins/tests/shopt_tests.cpp
new file mode 100644
index 0000000..5b4c45c
--- /dev/null
+++ b/src/builtins/tests/shopt_tests.cpp
@@ -0,0 +1,33 @@
+/*
+ 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 shopt_tests.cpp
+/// \brief series of unit tests for shopt builtin
+///
+#include <gtest/gtest.h>
+
+#include "builtins/builtin_exceptions.h"
+#include "core/interpreter.h"
+#include "cppbash_builtin.h"
+
+TEST(return_builtin_test, disable_extglob)
+{
+ interpreter walker;
+ EXPECT_THROW(cppbash_builtin::exec("shopt", {"-u", "extglob"}, std::cout, std::cerr, std::cin, walker), interpreter_exception);
+}
diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp
index 88fdf99..9308ebb 100644
--- a/src/cppbash_builtin.cpp
+++ b/src/cppbash_builtin.cpp
@@ -30,6 +30,7 @@
#include "builtins/inherit_builtin.h"
#include "builtins/let_builtin.h"
#include "builtins/return_builtin.h"
+#include "builtins/shopt_builtin.h"
#include "builtins/source_builtin.h"
cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_stream(&out), _err_stream(&err), _inp_stream(&in), _walker(walker)
@@ -41,6 +42,7 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
{"echo", boost::factory<echo_builtin*>()},
{"declare", boost::factory<declare_builtin*>()},
{"source", boost::factory<source_builtin*>()},
+ {"shopt", boost::factory<shopt_builtin*>()},
{"inherit", boost::factory<inherit_builtin*>()},
{":", boost::factory<true_builtin*>()},
{"true", boost::factory<true_builtin*>()},
next reply other threads:[~2011-05-25 19:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-25 19:42 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-07-08 9:31 [gentoo-commits] proj/libbash:master commit in: src/, /, src/builtins/tests/, src/builtins/ Petteri Räty
2012-07-08 9:31 Petteri Räty
2011-06-25 10:05 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-03-06 12:05 Petteri Räty
2011-03-06 12:05 Petteri Räty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=818ae8fb5415365640a7d08a05db21e5b94a3bf2.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox