From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QPJyk-0004Bp-SR for garchives@archives.gentoo.org; Wed, 25 May 2011 19:42:51 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0CD321C1BF; Wed, 25 May 2011 19:42:37 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id BFBE71C17D for ; Wed, 25 May 2011 19:42:37 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3D0811B4033 for ; Wed, 25 May 2011 19:42:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 9670180505 for ; Wed, 25 May 2011 19:42:36 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <818ae8fb5415365640a7d08a05db21e5b94a3bf2.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: src/, /, src/builtins/tests/, src/builtins/ X-VCS-Repository: proj/libbash X-VCS-Files: Makefile.am src/builtins/shopt_builtin.cpp src/builtins/shopt_builtin.h src/builtins/tests/shopt_tests.cpp src/cppbash_builtin.cpp X-VCS-Directories: src/ / src/builtins/tests/ src/builtins/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 818ae8fb5415365640a7d08a05db21e5b94a3bf2 Date: Wed, 25 May 2011 19:42:36 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 5e0518ffeae4b60c5d67d5f0e07bc046 commit: 818ae8fb5415365640a7d08a05db21e5b94a3bf2 Author: Mu Qiao gentoo org> AuthorDate: Tue May 24 08:29:39 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed May 25 08:47:10 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D818ae8fb 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 =3D 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 =3D 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 . +*/ +/// +/// \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& bash_args) + { + auto iter =3D find(bash_args.begin() + 1, bash_args.end(), "extglob"= ); + if(iter !=3D bash_args.end()) + throw interpreter_exception("Disabling extglob is not allowed"); + return 0; + } +} + +int shopt_builtin::exec(const std::vector& bash_args) +{ + if(bash_args.empty()) + { + *_err_stream << "Arguments required for shopt" << std::endl; + return 1; + } + else if(bash_args[0].size() !=3D 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 . +*/ +/// +/// \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& ); +}; + +#endif diff --git a/src/builtins/tests/shopt_tests.cpp b/src/builtins/tests/shop= t_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 . +*/ +/// +/// \file shopt_tests.cpp +/// \brief series of unit tests for shopt builtin +/// +#include + +#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::co= ut, 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" =20 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::builti= ns() { {"echo", boost::factory()}, {"declare", boost::factory()}, {"source", boost::factory()}, + {"shopt", boost::factory()}, {"inherit", boost::factory()}, {":", boost::factory()}, {"true", boost::factory()},