Mercurial > hg > octave-terminal
changeset 3657:a908150a3a32
[project @ 2000-04-11 19:02:03 by jwe]
author | jwe |
---|---|
date | Tue, 11 Apr 2000 19:02:05 +0000 |
parents | 96679fb690a4 |
children | 808f399398c9 |
files | liboctave/Array.cc liboctave/ChangeLog src/ChangeLog src/DLD-FUNCTIONS/minmax.cc src/sysdep.cc src/sysdep.h |
diffstat | 6 files changed, 73 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -85,7 +85,6 @@ } #ifdef HEAVYWEIGHT_INDEXING - max_indices = 1; idx_count = 0; idx = 0; #endif
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2000-04-06 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Array.cc (Array<T>::operator =): Don't set max_indices to 1 here. + 2000-03-23 John W. Eaton <jwe@bevo.che.wisc.edu> * lo-sysdep.h: octave_chdir returns int, not bool.
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2000-04-11 Joao Cardoso <jcardoso@inescn.pt> + + * sysdep.cc (kbhit): New arg, wait. + (raw_mode): Ditto. + (Fkbhit): If given an arg, call kbhit with wait = false. + + * DLD-FUNCTIONS/minmax.cc (Fmax, Fmin): Fix doc string. + 2000-04-04 John W. Eaton <jwe@bevo.che.wisc.edu> * dynamic-ld.cc (octave_dynamic_loader::do_load): Undo previous change.
--- a/src/DLD-FUNCTIONS/minmax.cc +++ b/src/DLD-FUNCTIONS/minmax.cc @@ -287,7 +287,16 @@ returns the smallest element of @var{x}.\n\ \n\ For complex arguments, the magnitude of the elements are used for\n\ -comparison.") +comparison.\n\ +\n\ +If called with two output arguments, also returns the index of the\n\ +minimum value(s). Thus,\n\ +@example\n +[x, ix] = min ([1, 3, 0, 2, 5])\n\ +@end example\n\ +\n\ +@noindent\n\ +returns @var{x} = 0 and @var{ix} = 3.") { octave_value_list retval; @@ -514,7 +523,16 @@ returns the largest element of @var{x}.\n\ \n\ For complex arguments, the magnitude of the elements are used for\n\ -comparison.") +comparison. +\n\ +If called with two output arguments, also returns the index of the\n\ +maximum value(s). Thus,\n\ +@example\n +[x, ix] = max([1, 3, 5, 2, 5])\n\ +@end example\n\ +\n\ +@noindent\n\ +returns @var{x} = 5 and @var{ix} = 3.") { octave_value_list retval;
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -169,9 +169,9 @@ // It doesn't matter whether an input \n is mapped to \r, or vice versa. void -raw_mode (int on) +raw_mode (bool on, bool wait) { - static int curr_on = 0; + static bool curr_on = false; int tty_fd = STDIN_FILENO; if (! isatty (tty_fd)) @@ -215,7 +215,10 @@ #if defined (ONLRET) s.c_oflag &= ~(ONLRET); #endif - s.c_cc[VMIN] = 1; + if (wait) + s.c_cc[VMIN] = 1; + else + s.c_cc[VMIN] = 0; s.c_cc[VTIME] = 0; } else @@ -257,7 +260,10 @@ #if defined (ONLRET) s.c_oflag &= ~(ONLRET); #endif - s.c_cc[VMIN] = 1; + if (wait) + s.c_cc[VMIN] = 1; + else + s.c_cc[VMIN] = 0; s.c_cc[VTIME] = 0; } else @@ -309,12 +315,14 @@ // Read one character from the terminal. int -kbhit (void) +kbhit (bool wait) { int c; - raw_mode (1); + raw_mode (1, wait); c = std::cin.get (); - raw_mode (0); + if (std::cin.fail()) + std::cin.clear (); + raw_mode (0, 1); return c; } @@ -396,10 +404,11 @@ // XXX FIXME XXX -- perhaps kbhit should also be able to print a prompt? -DEFUN (kbhit, , , +DEFUN (kbhit, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} kbhit ()\n\ -Read a single keystroke from the keyboard. For example,\n\ +Read a single keystroke from the keyboard. If called with one\n\ +argument, don't wait for a keypress. For example,\n\ \n\ @example\n\ x = kbhit ();\n\ @@ -408,15 +417,34 @@ @noindent\n\ will set @var{x} to the next character typed at the keyboard as soon as\n\ it is typed.\n\ +\n\ +@example\n\ +x = kbhit (1);\n\ +@end example\n\ +\n\ +@noindent\n\ +identical to the above example, but don't wait for a keypress,\n\ +returning the empty string if no key is available.\n\ @end deftypefn") { octave_value_list retval; // XXX FIXME XXX -- add timeout and default value args? + int nargin = args.length (); + if (interactive) { - int c = kbhit (); + int c; + + if (nargin == 1) + c = kbhit (false); + else + c = kbhit (true); + + if (c == -1) + c = 0; + char *s = new char [2]; s[0] = c; s[1] = '\0';