Mercurial > hg > octave-nkf
changeset 6316:a3a2580435c2
[project @ 2007-02-16 07:23:49 by jwe]
author | jwe |
---|---|
date | Fri, 16 Feb 2007 07:23:49 +0000 |
parents | cf52583fe055 |
children | 8c67f8be341d |
files | scripts/ChangeLog scripts/specfun/nchoosek.m src/ChangeLog src/oct-procbuf.h src/procstream.h src/toplev.cc |
diffstat | 6 files changed, 63 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2007-02-16 Muthiah Annamalai <muthuspost@gmail.com> + + * specfun/nchoosek.m: Check nargin. + 2007-02-15 John W. Eaton <jwe@octave.org> * path/addpath.m, path/rmpath.m: Delete
--- a/scripts/specfun/nchoosek.m +++ b/scripts/specfun/nchoosek.m @@ -49,30 +49,34 @@ ## resulting @var{c} has size @code{[nchoosek (length (@var{n}), ## @var{k}), @var{k}]}. ## +## @seealso{bincoeff} ## @end deftypefn -##AUTHORS Rolf Fabian <fabian@tu-cottbus.de> -## Paul Kienzle <pkienzle@users.sf.net> +## Author: Rolf Fabian <fabian@tu-cottbus.de> +## Author: Paul Kienzle <pkienzle@users.sf.net> -## XXX FIXME XXX This function is identical to bincoeff for scalar +## FIXME -- This function is identical to bincoeff for scalar ## values, and so should probably be combined with bincoeff. function A = nchoosek (v, k) - n = length (v); - - if (n == 1) - A = round (exp (sum (log (k+1:v)) - sum (log (2:v-k)))); - elseif (k == 0) - A = []; - elseif (k == 1) - A = v(:); - elseif (k == n) - A = v(:).'; + if (nargin == 2) + n = length (v); + if (n == 1) + A = round (exp (sum (log (k+1:v)) - sum (log (2:v-k)))); + elseif (k == 0) + A = []; + elseif (k == 1) + A = v(:); + elseif (k == n) + A = v(:).'; + else + m = round (exp (sum (log (k:n-1)) - sum (log (2:n-k)))); + A = [v(1)*ones(m,1), nchoosek(v(2:n),k-1); + nchoosek(v(2:n),k)]; + endif else - m = round (exp (sum (log (k:n-1)) - sum (log (2:n-k)))); - A = [v(1)*ones(m,1), nchoosek(v(2:n),k-1); - nchoosek(v(2:n),k)]; + print_usage (); endif endfunction
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2007-02-16 John W. Eaton <jwe@octave.org> + + * toplev.cc (wait_for_input): New function. + (run_command_and_return_output): Use it instead of napping. + + * oct-procbuf.h (octave_procbuf::pid): Now const. + * procstream.h (procstreambase::pid): Now const. + (procstreambase::file_number): New function. + 2007-02-15 John W. Eaton <jwe@octave.org> * mxarray.h (mxChar): Use char instead of unsigned short.
--- a/src/oct-procbuf.h +++ b/src/oct-procbuf.h @@ -56,7 +56,7 @@ bool is_open (void) const { return open_p; } - pid_t pid (void) { return proc_pid; } + pid_t pid (void) const { return proc_pid; } protected:
--- a/src/procstream.h +++ b/src/procstream.h @@ -56,7 +56,9 @@ int close (void); - pid_t pid (void) { return pb.pid (); } + pid_t pid (void) const { return pb.pid (); } + + int file_number (void) const { return pb.file_number (); } private:
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -397,6 +397,28 @@ delete cmd; } +static int +wait_for_input (int fid) +{ + int retval = -1; + +#if defined (HAVE_SELECT) + if (fid >= 0) + { + fd_set set; + + FD_ZERO (&set); + FD_SET (fid, &set); + + retval = select (FD_SETSIZE, &set, 0, 0, 0); + } +#else + retval = 1; +#endif + + return retval; +} + static octave_value_list run_command_and_return_output (const std::string& cmd_str) { @@ -410,15 +432,9 @@ if (*cmd) { - std::ostringstream output_buf; + int fid = cmd->file_number (); - // FIXME -- Perhaps we should read more than one - // character at a time and find a way to avoid the call to - // octave_usleep as well? - - // This is a bit of a kluge... - - octave_usleep (100); + std::ostringstream output_buf; char ch; @@ -432,7 +448,8 @@ { cmd->clear (); - octave_usleep (100); + if (wait_for_input (fid) != 1) + break; } else break;