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-0004Bl-RU 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 319BD1C17D; Wed, 25 May 2011 19:42:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id E77EB1C17D 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 71B4C1BC012 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 CC1C78050A 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: Subject: [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/ X-VCS-Repository: proj/libbash X-VCS-Files: src/core/interpreter.cpp src/core/interpreter.h src/core/tests/interpreter_test.cpp X-VCS-Directories: src/core/ src/core/tests/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: a4da23bd461a004396138e889ca1111a3cfc5d9d 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: 87947b99a503af5d96e02816c0e5e0b9 commit: a4da23bd461a004396138e889ca1111a3cfc5d9d Author: Mu Qiao gentoo org> AuthorDate: Wed May 25 08:22:48 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed May 25 10:13:52 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3Da4da23bd Core: support setting and getting bash option --- src/core/interpreter.cpp | 64 +++++++++++++++++++++++++++++= ++++++ src/core/interpreter.h | 18 ++++++++-- src/core/tests/interpreter_test.cpp | 12 ++++++ 3 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp index 7e7de9c..2337e87 100644 --- a/src/core/interpreter.cpp +++ b/src/core/interpreter.cpp @@ -39,6 +39,52 @@ =20 #include "libbashWalker.h" =20 +interpreter::interpreter(): out(&std::cout), err(&std::cerr), in(&std::c= in), bash_options( + { + {"autocd", false}, + {"cdable_vars", false}, + {"cdspell", false}, + {"checkhash", false}, + {"checkjobs", false}, + {"checkwinsize", false}, + {"cmdhist", false}, + {"compat31", false}, + {"dirspell", false}, + {"dotglob", false}, + {"execfail", false}, + {"expand_aliases", false}, + {"extdebug", false}, + {"extglob", false}, + {"extquote", false}, + {"failglob", false}, + {"force_fignore", false}, + {"globstar", false}, + {"gnu_errfmt", false}, + {"histappend", false}, + {"histreedit", false}, + {"histverify", false}, + {"hostcomplete", false}, + {"huponexit", false}, + {"interactive", false}, + {"lithist", false}, + {"login_shell", false}, + {"mailwarn", false}, + {"no_empty_cmd_completion", false}, + {"nocaseglob", false}, + {"nocasematch", false}, + {"nullglob", false}, + {"progcomp", false}, + {"promptvars", false}, + {"restricted", false}, + {"shift_verbose", false}, + {"sourcepath", false}, + {"xpg_echo", false}, + } + ) +{ + define("IFS", " \t\n"); +} + std::string interpreter::get_string(pANTLR3_BASE_TREE node) { pANTLR3_COMMON_TOKEN token =3D node->getToken(node); @@ -315,3 +361,21 @@ void interpreter::unset(const std::string& name, else iter->second->unset_value(index); } + +bool interpreter::get_option(const std::string& name) const +{ + auto iter =3D bash_options.find(name); + if(iter =3D=3D bash_options.end()) + throw interpreter_exception("Invalid bash option"); + + return iter->second; +} + +void interpreter::set_option(const std::string& name, bool value) +{ + auto iter =3D bash_options.find(name); + if(iter =3D=3D bash_options.end()) + throw interpreter_exception("Invalid bash option"); + + iter->second =3D value; +} diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 4c6f69c..3c85450 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -68,6 +68,8 @@ class interpreter =20 std::istream* in; =20 + std::unordered_map bash_options; + /// \brief calculate the correct offset when offset < 0 and check whet= her /// the real offset is in legal range /// \param[in,out] a value/result argument referring to offset @@ -114,10 +116,7 @@ public: } }; =20 - interpreter(): out(&std::cout), err(&std::cerr), in(&std::cin) - { - define("IFS", " \t\n"); - } + interpreter(); =20 /// /// \brief return the number of variables @@ -661,6 +660,17 @@ public: //. \param[out] the splitted result will be appended to output void split_word(const std::string& word, std::vector& out= put); =20 + /// \brief get the status of shell optional behavior + /// \param the option name + /// \return zero unless the name is not a valid shell option + bool get_option(const std::string& name) const; + + /// \brief set the status of shell optional behavior + /// \param the option name + /// \param[in] true if option is enabled, false otherwise + /// \return zero unless the name is not a valid shell option + void set_option(const std::string& name, bool value); + /// \brief perform expansion like ${var//foo/bar} /// \param the value to be expanded /// \param the pattern used to match the value diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpr= eter_test.cpp index a5e4ff9..ab24449 100644 --- a/src/core/tests/interpreter_test.cpp +++ b/src/core/tests/interpreter_test.cpp @@ -189,3 +189,15 @@ TEST(interpreter, word_split) EXPECT_STREQ("foo", splitted_values[0].c_str()); EXPECT_STREQ("bar", splitted_values[1].c_str()); } + +TEST(interpreter, bash_option) +{ + interpreter walker; + + EXPECT_THROW(walker.set_option("not exist", false), interpreter_except= ion); + EXPECT_THROW(walker.get_option("not exist"), interpreter_exception); + + EXPECT_FALSE(walker.get_option("extglob")); + walker.set_option("extglob", true); + EXPECT_TRUE(walker.get_option("extglob")); +}