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 1QSVfp-0005Mw-Bc for garchives@archives.gentoo.org; Fri, 03 Jun 2011 14:48:29 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 09B1A1C026; Fri, 3 Jun 2011 14:48:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id BB1C71C026 for ; Fri, 3 Jun 2011 14:48:21 +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 3EB021BC013 for ; Fri, 3 Jun 2011 14:48:21 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id A46128050C for ; Fri, 3 Jun 2011 14:48:20 +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: <5619617d2f23057f07fee8766998d8e01bc1a644.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g scripts/command_execution.bash scripts/command_execution.bash.result src/core/interpreter.h X-VCS-Directories: scripts/ src/core/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 5619617d2f23057f07fee8766998d8e01bc1a644 Date: Fri, 3 Jun 2011 14:48:20 +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: f75dc21255f5f186eb558b8c61a008cc commit: 5619617d2f23057f07fee8766998d8e01bc1a644 Author: Mu Qiao gentoo org> AuthorDate: Wed Jun 1 14:55:14 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Fri Jun 3 12:53:53 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D5619617d Walker: support output redirection We only support redirections for bash built-ins for now. --- bashast/libbashWalker.g | 49 +++++++++++++++++++++++++++= ------ scripts/command_execution.bash | 2 +- scripts/command_execution.bash.result | 1 - src/core/interpreter.h | 14 +++++++-- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 58de4b7..1e6f94b 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -40,6 +40,7 @@ options =20 @postinclude{ =20 + #include #include #include =20 @@ -466,10 +467,16 @@ simple_command execute_command[const std::string& name, std::vector& libba= sh_args] @declarations { interpreter::local_scope current_scope(*walker); + std::unique_ptr out; + std::unique_ptr err; + std::unique_ptr in; + bool redirection =3D false; } - :var_def[true]* redirect* { + :var_def[true]* (redirect[out, err, in]{ redirection =3D true; })* { if(walker->has_function(name)) { + if(redirection) + std::cerr << "We do not support redirection for function calls." << = std::endl; ANTLR3_MARKER command_index =3D INDEX(); try { @@ -485,7 +492,7 @@ execute_command[const std::string& name, std::vector<= std::string>& libbash_args] } else if(cppbash_builtin::is_builtin(name)) { - walker->set_status(walker->execute_builtin(name, libbash_args)); + walker->set_status(walker->execute_builtin(name, libbash_args, out.ge= t(), err.get(), in.get())); } else if(name =3D=3D "export") { @@ -500,21 +507,45 @@ execute_command[const std::string& name, std::vecto= r& libbash_args] } (BANG { walker->set_status(!walker->get_status()); })?; =20 -redirect - :^(REDIR redirect_operator redirect_destination) { +redirect[std::unique_ptr& out, std::unique_ptr& err, std::unique_ptr& in] + :^(REDIR LESS_THAN redirect_destination_input[in]) { + std::cerr << "Redirection is not supported yet" << std::endl; + } + |^(REDIR GREATER_THAN redirect_destination_output[out]) + |^(REDIR DIGIT LESS_THAN redirect_destination_input[in]) { + std::cerr << "Redirection is not supported yet" << std::endl; + } + |^(REDIR DIGIT GREATER_THAN redirect_destination_output[out]) { std::cerr << "Redirection is not supported yet" << std::endl; }; =20 -redirect_destination - :string_expr //path to a file - |FILE_DESCRIPTOR DIGIT - |FILE_DESCRIPTOR_MOVE DIGIT; - redirect_operator :LESS_THAN |GREATER_THAN |FILE_DESCRIPTOR DIGIT redirect_operator; =20 +redirect_destination_output[std::unique_ptr& out] + :string_expr { + out.reset(new std::ofstream($string_expr.libbash_value, std::ofstream:= :trunc)); + } + |FILE_DESCRIPTOR DIGIT { + std::cerr << "FILE_DESCRIPTOR redirection is not supported yet" << std= ::endl; + } + |FILE_DESCRIPTOR_MOVE DIGIT { + std::cerr << "FILE_DESCRIPTOR_MOVE redirection is not supported yet" <= < std::endl; + }; + +redirect_destination_input[std::unique_ptr& in] + :string_expr { + std::cerr << "Input redirection for file is not supported yet" << std:= :endl; + } + |FILE_DESCRIPTOR DIGIT { + std::cerr << "FILE_DESCRIPTOR redirection is not supported yet" << std= ::endl; + } + |FILE_DESCRIPTOR_MOVE DIGIT { + std::cerr << "FILE_DESCRIPTOR_MOVE redirection is not supported yet" <= < std::endl; + }; + argument[std::vector& args] : string_expr { if($string_expr.quoted) diff --git a/scripts/command_execution.bash b/scripts/command_execution.b= ash index 8005a23..a500b63 100644 --- a/scripts/command_execution.bash +++ b/scripts/command_execution.bash @@ -19,7 +19,7 @@ FOO=3D"abc" echo "command environment" export FOO003=3D1 FOO004=3Dabc FOO005=3D(1 2 3) FOO002 export foo abc=3D1 export foo -true > /dev/null +echo "hi" > /dev/null =20 function unset_inner() { diff --git a/scripts/command_execution.bash.result b/scripts/command_exec= ution.bash.result index d47650d..e0bf724 100644 --- a/scripts/command_execution.bash.result +++ b/scripts/command_execution.bash.result @@ -5,7 +5,6 @@ right end command environment We do not support command env before the export builtin. -Redirection is not supported yet FOO006=3D1 in unset_outer FOO007=3D in unset_outer FOO006=3D in unset_outer diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 3420ee4..2c5f383 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -574,9 +574,17 @@ public: /// \param builtin arguments /// \return the return value of the builtin int execute_builtin(const std::string& name, - const std::vector& args) - { - return cppbash_builtin::exec(name, args, *out, *err, *in, *this); + const std::vector& args, + std::ostream* output=3D0, + std::ostream* error=3D0, + std::istream* input=3D0) + { + return cppbash_builtin::exec(name, + args, + output =3D=3D 0 ? *out : *output, + error =3D=3D 0 ? *err : *error, + input =3D=3D 0 ? *in : *input, + *this); } =20 /// \brief perform ${parameter:=E2=88=92word} expansion