From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/
Date: Wed, 25 May 2011 19:42:36 +0000 (UTC) [thread overview]
Message-ID: <a4da23bd461a004396138e889ca1111a3cfc5d9d.betelgeuse@gentoo> (raw)
commit: a4da23bd461a004396138e889ca1111a3cfc5d9d
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed May 25 08:22:48 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 25 10:13:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a4da23bd
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 @@
#include "libbashWalker.h"
+interpreter::interpreter(): out(&std::cout), err(&std::cerr), in(&std::cin), 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 = 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 = bash_options.find(name);
+ if(iter == bash_options.end())
+ throw interpreter_exception("Invalid bash option");
+
+ return iter->second;
+}
+
+void interpreter::set_option(const std::string& name, bool value)
+{
+ auto iter = bash_options.find(name);
+ if(iter == bash_options.end())
+ throw interpreter_exception("Invalid bash option");
+
+ iter->second = 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
std::istream* in;
+ std::unordered_map<std::string, bool> bash_options;
+
/// \brief calculate the correct offset when offset < 0 and check whether
/// the real offset is in legal range
/// \param[in,out] a value/result argument referring to offset
@@ -114,10 +116,7 @@ public:
}
};
- interpreter(): out(&std::cout), err(&std::cerr), in(&std::cin)
- {
- define("IFS", " \t\n");
- }
+ interpreter();
///
/// \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<std::string>& output);
+ /// \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/interpreter_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_exception);
+ 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"));
+}
next reply other threads:[~2011-05-25 19:42 UTC|newest]
Thread overview: 16+ 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 --
2011-05-27 23:03 [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/ Petteri Räty
2011-05-23 14:34 Petteri Räty
2011-05-23 14:34 Petteri Räty
2011-05-08 13:07 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-06 7:43 Petteri Räty
2011-04-04 16:09 Petteri Räty
2011-04-04 15:52 Petteri Räty
2011-04-04 15:52 Petteri Räty
2011-03-30 12:48 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=a4da23bd461a004396138e889ca1111a3cfc5d9d.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