public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, src/builtins/
@ 2011-06-09  9:41 Petteri Räty
  0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-06-09  9:41 UTC (permalink / raw
  To: gentoo-commits

commit:     9c66aca135ad5eab09b9b9710413d959298c0e13
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  8 12:26:21 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun  9 09:31:00 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9c66aca1

Builtin: support shopt -p

The container for bash_options is changed to be std::map as shopt -p
prints out sorted values.

---
 scripts/command_execution.bash        |    2 +
 scripts/command_execution.bash.result |   38 +++++++++++++++++++++++++++++++++
 src/builtins/shopt_builtin.cpp        |    9 +++++++
 src/builtins/shopt_builtin.h          |    1 +
 src/core/interpreter.h                |   20 ++++++++++++++++-
 5 files changed, 69 insertions(+), 1 deletions(-)

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index ee2b85f..3db9f42 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -51,3 +51,5 @@ echo "abc $(echo def) ghi"
 FOO008="abc $(echo def) ghi"
 eval "FOO009=10"
 eval "echo abc" "def" "xyz"
+shopt -s extglob
+shopt -p

diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index 6e8bd98..f176a71 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -15,6 +15,44 @@ unset_outer
 $FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...
 abc def ghi
 abc def xyz
+shopt -u autocd
+shopt -u cdable_vars
+shopt -u cdspell
+shopt -u checkhash
+shopt -u checkjobs
+shopt -u checkwinsize
+shopt -u cmdhist
+shopt -u compat31
+shopt -u dirspell
+shopt -u dotglob
+shopt -u execfail
+shopt -u expand_aliases
+shopt -u extdebug
+shopt -s extglob
+shopt -u extquote
+shopt -u failglob
+shopt -u force_fignore
+shopt -u globstar
+shopt -u gnu_errfmt
+shopt -u histappend
+shopt -u histreedit
+shopt -u histverify
+shopt -u hostcomplete
+shopt -u huponexit
+shopt -u interactive
+shopt -u lithist
+shopt -u login_shell
+shopt -u mailwarn
+shopt -u no_empty_cmd_completion
+shopt -u nocaseglob
+shopt -u nocasematch
+shopt -u nullglob
+shopt -u progcomp
+shopt -u promptvars
+shopt -u restricted
+shopt -u shift_verbose
+shopt -u sourcepath
+shopt -u xpg_echo
 DEFAULTED=yes
 FOO001=hello
 FOO002=Hello World

diff --git a/src/builtins/shopt_builtin.cpp b/src/builtins/shopt_builtin.cpp
index 45e564c..5c2e23d 100644
--- a/src/builtins/shopt_builtin.cpp
+++ b/src/builtins/shopt_builtin.cpp
@@ -33,6 +33,12 @@ void shopt_builtin::set_opt(const std::vector<std::string>& bash_args, bool valu
       _walker.set_option(*iter, value);
 }
 
+void shopt_builtin::print_opts() const
+{
+  for(auto iter = _walker.options_begin(); iter != _walker.options_end(); ++iter)
+      *_out_stream << "shopt " << (iter->second ? "-s " : "-u ") << iter->first << std::endl;
+}
+
 int shopt_builtin::exec(const std::vector<std::string>& bash_args)
 {
   if(bash_args.empty())
@@ -48,6 +54,9 @@ int shopt_builtin::exec(const std::vector<std::string>& bash_args)
     case 's':
       set_opt(bash_args, true);
       break;
+    case 'p':
+      print_opts();
+      break;
     case 'q':
     case 'o':
       throw interpreter_exception("shopt " + bash_args[0] + " is not supported yet");

diff --git a/src/builtins/shopt_builtin.h b/src/builtins/shopt_builtin.h
index 905e4ba..2b1f766 100644
--- a/src/builtins/shopt_builtin.h
+++ b/src/builtins/shopt_builtin.h
@@ -28,6 +28,7 @@
 class shopt_builtin : public virtual cppbash_builtin
 {
   void set_opt(const std::vector<std::string>& bash_args, bool value);
+  void print_opts() const;
 public:
   BUILTIN_CONSTRUCTOR(shopt)
   virtual int exec(const std::vector<std::string>& );

diff --git a/src/core/interpreter.h b/src/core/interpreter.h
index 39fcadf..3ed4664 100644
--- a/src/core/interpreter.h
+++ b/src/core/interpreter.h
@@ -69,7 +69,8 @@ class interpreter: public boost::noncopyable
 
   std::istream* _in;
 
-  std::unordered_map<std::string, bool> bash_options;
+  // std::map is chosen for sorted output in shopt -p
+  std::map<std::string, bool> bash_options;
 
   /// \brief calculate the correct offset when offset < 0 and check whether
   ///        the real offset is in legal range
@@ -97,6 +98,8 @@ class interpreter: public boost::noncopyable
                             const unsigned index) const;
 public:
 
+  typedef std::map<std::string, bool>::const_iterator option_iterator;
+
   ///
   /// \class local_scope
   /// \brief RAII concept for local scope management
@@ -690,6 +693,21 @@ public:
   /// \return zero unless the name is not a valid shell option
   void set_option(const std::string& name, bool value);
 
+  /// \brief return an iterator referring to the first variable
+  /// \return iterator referring to the first variable
+  option_iterator options_begin() const
+  {
+    return bash_options.begin();
+  }
+
+  /// \brief return an iterator referring to the next element after the
+  ///        last variable
+  /// \return iterator referring to he next element after the last variable
+  option_iterator options_end() const
+  {
+    return bash_options.end();
+  }
+
   /// \brief evaluate arithmetic expression and return the result
   /// \param the arithmetic expression
   /// \return the evaluated result



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-09  9:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-09  9:41 [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, src/builtins/ 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