Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 307849 Details for
Bug 410831
Read builtin implementation
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
read builtin patch
0001-Builtin-implement-read-builtin.patch (text/plain), 5.54 KB, created by
Aparicio
on 2012-04-05 01:29:05 UTC
(
hide
)
Description:
read builtin patch
Filename:
MIME Type:
Creator:
Aparicio
Created:
2012-04-05 01:29:05 UTC
Size:
5.54 KB
patch
obsolete
>From ea2085d8d32497f7f6d403e9e0b745443ad1f43d Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Andr=C3=A9=20Apar=C3=ADcio?= <aparicio99@gmail.com> >Date: Thu, 5 Apr 2012 02:19:28 +0100 >Subject: [PATCH] Builtin: implement read builtin > >--- > Makefile.am | 2 + > src/builtins/read_builtin.cpp | 83 +++++++++++++++++++++++++++++++++++++++++ > src/builtins/read_builtin.h | 46 ++++++++++++++++++++++ > src/cppbash_builtin.cpp | 2 + > 4 files changed, 133 insertions(+), 0 deletions(-) > create mode 100644 src/builtins/read_builtin.cpp > create mode 100644 src/builtins/read_builtin.h > >diff --git a/Makefile.am b/Makefile.am >index cbc9f3b..c923675 100644 >--- a/Makefile.am >+++ b/Makefile.am >@@ -236,6 +236,8 @@ libbash_la_SOURCES = include/common.h \ > src/builtins/inherit_builtin.cpp \ > src/builtins/unset_builtin.h \ > src/builtins/unset_builtin.cpp \ >+ src/builtins/read_builtin.h \ >+ src/builtins/read_builtin.cpp \ > src/builtins/builtin_exceptions.h \ > $(GENERATED_PARSER_C) \ > $(GENERATED_PARSER_H) \ >diff --git a/src/builtins/read_builtin.cpp b/src/builtins/read_builtin.cpp >new file mode 100644 >index 0000000..7d656d1 >--- /dev/null >+++ b/src/builtins/read_builtin.cpp >@@ -0,0 +1,83 @@ >+/* >+ 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 <http://www.gnu.org/licenses/>. >+*/ >+/// >+/// \file read_builtin.cpp >+/// \brief class that implements the read builtin >+/// >+ >+#include "builtins/read_builtin.h" >+ >+#include <string.h> >+ >+#include "core/interpreter.h" >+#include "builtins/builtin_exceptions.h" >+ >+int read_builtin::exec(const std::vector<std::string>& bash_args) >+{ >+ std::string input; >+ std::stringstream formated_input; >+ >+ getline(this->input_buffer(), input); >+ >+ while(input[input.length()-1] == '\\') { >+ input.erase(input.end()-1); >+ std::string input_line; >+ getline(this->input_buffer(), input_line); >+ input += input_line; >+ } >+ >+ cppbash_builtin::transform_escapes(input, formated_input, false); >+ >+ if(bash_args.empty()) >+ { >+ _walker.set_value("REPLY", formated_input.str()); >+ return 0; >+ } >+ >+ char *cstr, *token; >+ cstr = new char[formated_input.str().size() + 1]; >+ strcpy(cstr, formated_input.str().c_str()); >+ >+ for(auto i = bash_args.begin(); i != bash_args.end(); i++) >+ { >+ if(i != bash_args.end() - 1) >+ { >+ if(i == bash_args.begin()) >+ token = strtok(cstr, " "); >+ else >+ token = strtok(NULL, " "); >+ >+ if(token == NULL) >+ return 0; >+ } >+ else >+ { >+ if(i == bash_args.begin()) >+ token = cstr; >+ else >+ token += strlen(token) + 1; >+ } >+ >+ _walker.set_value(*i, token); >+ } >+ >+ free(cstr); >+ >+ return 0; >+} >diff --git a/src/builtins/read_builtin.h b/src/builtins/read_builtin.h >new file mode 100644 >index 0000000..5e67f6d >--- /dev/null >+++ b/src/builtins/read_builtin.h >@@ -0,0 +1,46 @@ >+/* >+ 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 <http://www.gnu.org/licenses/>. >+*/ >+/// >+/// \file read_builtin.h >+/// \brief class that implements the read builtin >+/// >+ >+#ifndef LIBBASH_BUILTINS_READ_BUILTIN_H_ >+#define LIBBASH_BUILTINS_READ_BUILTIN_H_ >+ >+#include "../cppbash_builtin.h" >+ >+/// >+/// \class read_builtin >+/// \brief the read builtin for bash >+/// >+class read_builtin: public virtual cppbash_builtin >+{ >+ public: >+ BUILTIN_CONSTRUCTOR(read) >+ >+ /// >+ /// \brief runs the read builtin on the supplied arguments >+ /// \param bash_args the arguments to the read builtin >+ /// \return exit status of read >+ /// >+ virtual int exec(const std::vector<std::string>& bash_args); >+}; >+ >+#endif >diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp >index 452fe64..c93b94a 100644 >--- a/src/cppbash_builtin.cpp >+++ b/src/cppbash_builtin.cpp >@@ -44,6 +44,7 @@ > #include "builtins/shopt_builtin.h" > #include "builtins/source_builtin.h" > #include "builtins/unset_builtin.h" >+#include "builtins/read_builtin.h" > > namespace qi = boost::spirit::qi; > namespace karma = boost::spirit::karma; >@@ -73,6 +74,7 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() { > {"printf", boost::factory<printf_builtin*>()}, > {"let", boost::factory<let_builtin*>()}, > {"unset", boost::factory<unset_builtin*>()}, >+ {"read", boost::factory<read_builtin*>()}, > }); > return *p; > } >-- >1.7.3.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 410831
: 307849