Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bugzilla DB migration completed. Please report issues to Infra team via email via infra@gentoo.org or IRC
View | Details | Raw Unified | Return to bug 410831
Collapse All | Expand All

(-)a/Makefile.am (+2 lines)
Lines 236-241 libbash_la_SOURCES = include/common.h \ Link Here
236
					 src/builtins/inherit_builtin.cpp \
236
					 src/builtins/inherit_builtin.cpp \
237
					 src/builtins/unset_builtin.h \
237
					 src/builtins/unset_builtin.h \
238
					 src/builtins/unset_builtin.cpp \
238
					 src/builtins/unset_builtin.cpp \
239
					 src/builtins/read_builtin.h \
240
					 src/builtins/read_builtin.cpp \
239
					 src/builtins/builtin_exceptions.h \
241
					 src/builtins/builtin_exceptions.h \
240
					 $(GENERATED_PARSER_C) \
242
					 $(GENERATED_PARSER_C) \
241
					 $(GENERATED_PARSER_H) \
243
					 $(GENERATED_PARSER_H) \
(-)a/src/builtins/read_builtin.cpp (+83 lines)
Line 0 Link Here
1
/*
2
   Please use git log for copyright holder and year information
3
4
   This file is part of libbash.
5
6
   libbash is free software: you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation, either version 2 of the License, or
9
   (at your option) any later version.
10
11
   libbash is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with libbash.  If not, see <http://www.gnu.org/licenses/>.
18
*/
19
///
20
/// \file read_builtin.cpp
21
/// \brief class that implements the read builtin
22
///
23
24
#include "builtins/read_builtin.h"
25
26
#include <string.h>
27
28
#include "core/interpreter.h"
29
#include "builtins/builtin_exceptions.h"
30
31
int read_builtin::exec(const std::vector<std::string>& bash_args)
32
{
33
  std::string input;
34
  std::stringstream formated_input;
35
36
  getline(this->input_buffer(), input);
37
38
  while(input[input.length()-1] == '\\') {
39
    input.erase(input.end()-1);
40
    std::string input_line;
41
    getline(this->input_buffer(), input_line);
42
    input += input_line;
43
  }
44
45
  cppbash_builtin::transform_escapes(input, formated_input, false);
46
47
  if(bash_args.empty())
48
  {
49
    _walker.set_value("REPLY", formated_input.str());
50
    return 0;
51
  }
52
53
  char *cstr, *token;
54
  cstr = new char[formated_input.str().size() + 1];
55
  strcpy(cstr, formated_input.str().c_str());
56
57
  for(auto i = bash_args.begin(); i != bash_args.end(); i++)
58
  {
59
    if(i != bash_args.end() - 1)
60
    {
61
      if(i == bash_args.begin())
62
        token = strtok(cstr, " ");
63
      else
64
        token = strtok(NULL, " ");
65
66
      if(token == NULL)
67
        return 0;
68
    }
69
    else
70
    {
71
      if(i == bash_args.begin())
72
        token = cstr;
73
      else
74
        token += strlen(token) + 1;
75
    }
76
77
    _walker.set_value(*i, token);
78
  }
79
80
  free(cstr);
81
82
  return 0;
83
}
(-)a/src/builtins/read_builtin.h (+46 lines)
Line 0 Link Here
1
/*
2
   Please use git log for copyright holder and year information
3
4
   This file is part of libbash.
5
6
   libbash is free software: you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation, either version 2 of the License, or
9
   (at your option) any later version.
10
11
   libbash is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with libbash.  If not, see <http://www.gnu.org/licenses/>.
18
*/
19
///
20
/// \file read_builtin.h
21
/// \brief class that implements the read builtin
22
///
23
24
#ifndef LIBBASH_BUILTINS_READ_BUILTIN_H_
25
#define LIBBASH_BUILTINS_READ_BUILTIN_H_
26
27
#include "../cppbash_builtin.h"
28
29
///
30
/// \class read_builtin
31
/// \brief the read builtin for bash
32
///
33
class read_builtin: public virtual cppbash_builtin
34
{
35
  public:
36
    BUILTIN_CONSTRUCTOR(read)
37
38
    ///
39
    /// \brief runs the read builtin on the supplied arguments
40
    /// \param bash_args the arguments to the read builtin
41
    /// \return exit status of read
42
    ///
43
    virtual int exec(const std::vector<std::string>& bash_args);
44
};
45
46
#endif
(-)a/src/cppbash_builtin.cpp (-1 / +2 lines)
Lines 44-49 Link Here
44
#include "builtins/shopt_builtin.h"
44
#include "builtins/shopt_builtin.h"
45
#include "builtins/source_builtin.h"
45
#include "builtins/source_builtin.h"
46
#include "builtins/unset_builtin.h"
46
#include "builtins/unset_builtin.h"
47
#include "builtins/read_builtin.h"
47
48
48
namespace qi = boost::spirit::qi;
49
namespace qi = boost::spirit::qi;
49
namespace karma = boost::spirit::karma;
50
namespace karma = boost::spirit::karma;
Lines 73-78 cppbash_builtin::builtins_type& cppbash_builtin::builtins() { Link Here
73
      {"printf", boost::factory<printf_builtin*>()},
74
      {"printf", boost::factory<printf_builtin*>()},
74
      {"let", boost::factory<let_builtin*>()},
75
      {"let", boost::factory<let_builtin*>()},
75
      {"unset", boost::factory<unset_builtin*>()},
76
      {"unset", boost::factory<unset_builtin*>()},
77
      {"read", boost::factory<read_builtin*>()},
76
  });
78
  });
77
  return *p;
79
  return *p;
78
}
80
}
79
- 

Return to bug 410831