Mercurial > hg > octave-max
changeset 4046:7787c144d5d9
[project @ 2002-08-15 18:17:41 by jwe]
author | jwe |
---|---|
date | Thu, 15 Aug 2002 18:17:41 +0000 |
parents | b908aaa4080a |
children | 7b0c139ac8af |
files | src/input.cc test/octave.test/io/io.exp test/octave.test/linalg/qr-7.m |
diffstat | 3 files changed, 31 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/input.cc +++ b/src/input.cc @@ -281,13 +281,13 @@ { // XXX FIXME XXX -- 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; int status = 0; - - if (input_buf.empty ()) + if (chars_left == 0) { pos = 0; @@ -300,42 +300,38 @@ if (chars_left > 0) { - buf[0] = '\0'; - - size_t len = max_size > 2 ? max_size - 2 : 0; - + size_t len = max_size > chars_left ? chars_left : max_size; assert (len > 0); - strncpy (buf, pos, len); + memcpy (buf, pos, len); - if (chars_left > len) - { - chars_left -= len; + chars_left -= len; + pos += len; - pos += len; - - buf[len] = '\0'; - - status = 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; + } } - else - { - input_buf = ""; - - len = chars_left; - if (buf[len-1] != '\n') - buf[len++] = '\n'; + status = len; - buf[len] = '\0'; - - status = len; - } } else if (chars_left == 0) { - input_buf = ""; - status = 0; } else
--- a/test/octave.test/io/io.exp +++ b/test/octave.test/io/io.exp @@ -42,6 +42,10 @@ set prog_output "\n... sscanf:.*" do_test sscanf-4.m +set test sscanf-5 +set prog_output "ans = 1" +do_test sscanf-5.m + set test printf-1 set prog_output "test: 1\nans = 8" do_test printf-1.m
--- a/test/octave.test/linalg/qr-7.m +++ b/test/octave.test/linalg/qr-7.m @@ -2,9 +2,9 @@ tol = 512*eps; retval = 0; if (nargin == 3) - n1 = norm (q*r-a) - n2 = norm (q'*q-eye(columns(q))) - retval = (n1 < tol && n2 < tol) + n1 = norm (q*r-a); + n2 = norm (q'*q-eye(columns(q))); + retval = (n1 < tol && n2 < tol); else n1 = norm (q'*q-eye(columns(q))) retval = (n1 < tol);