Mercurial > hg > octave-lyh
diff libinterp/interpfcn/input.cc @ 16098:24b3800d30e7
move octave_read to lex.ll
* lex.ll (octave_read): Move here from input.cc and make static.
Return YY_NULL when no more characters are available. Error here if
eof is not set when no more characters are available instead of in
YY_INPUT macro.
* input.h, input.cc (get_user_input): Now extern.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 25 Feb 2013 01:04:15 -0500 |
parents | 2f4fa62089b3 |
children | 229eb14653fd |
line wrap: on
line diff
--- a/libinterp/interpfcn/input.cc +++ b/libinterp/interpfcn/input.cc @@ -343,7 +343,7 @@ // Read a line from the input stream. -static std::string +std::string get_user_input (bool& eof) { octave_quit (); @@ -372,67 +372,6 @@ return retval; } -int -octave_read (char *buf, unsigned max_size) -{ - // FIXME -- is this a safe way to buffer the input? - - static const char * const eol = "\n"; - static std::string input_buf; - static const char *pos = 0; - static size_t chars_left = 0; - static bool eof = false; - - int status = 0; - - if (chars_left == 0) - { - pos = 0; - - input_buf = get_user_input (eof); - - chars_left = input_buf.length (); - - pos = input_buf.c_str (); - } - - if (chars_left > 0) - { - size_t len = max_size > chars_left ? chars_left : max_size; - assert (len > 0); - - memcpy (buf, pos, len); - - chars_left -= len; - pos += len; - - // Make sure input ends with a new line character. - if (chars_left == 0 && buf[len-1] != '\n') - { - if (len < max_size) - { - // There is enough room to plug the newline character in - // the buffer. - buf[len++] = '\n'; - } - else - { - // There isn't enough room to plug the newline character - // in the buffer so make sure it is returned on the next - // octave_read call. - pos = eol; - chars_left = 1; - } - } - - status = len; - } - else - status = eof ? 0 : -1; - - return status; -} - // Fix things up so that input can come from file 'name', printing a // warning if the file doesn't exist.