Mercurial > hg > octave-terminal
changeset 2902:c5b7a019b9ed
[project @ 1997-04-30 03:46:53 by jwe]
author | jwe |
---|---|
date | Wed, 30 Apr 1997 03:49:42 +0000 |
parents | e6d25bc478dd |
children | facd9d10e5c1 |
files | src/file-io.cc src/oct-stream.cc src/oct-stream.h src/syscalls.cc |
diffstat | 4 files changed, 46 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -66,6 +66,10 @@ #include "utils.h" #include "variables.h" +static octave_value stdin_file; +static octave_value stdout_file; +static octave_value stderr_file; + void initialize_file_io (void) { @@ -81,9 +85,9 @@ octave_ostream *stderr_stream = new octave_ostream (&cerr, "stderr"); - octave_stream_list::insert (stdin_stream); - octave_stream_list::insert (stdout_stream); - octave_stream_list::insert (stderr_stream); + stdin_file = octave_stream_list::insert (stdin_stream); + stdout_file = octave_stream_list::insert (stdout_stream); + stderr_file = octave_stream_list::insert (stderr_stream); } void @@ -405,8 +409,7 @@ if (os->ok () && ! error_state) { retval(1) = ""; - retval(0) - = static_cast<double> (octave_stream_list::insert (os)); + retval(0) = octave_stream_list::insert (os); } else { @@ -1206,7 +1209,7 @@ \"r\" : connect stdout of process to pipe\n\ \"w\" : connect stdin of process to pipe") { - double retval = -1.0; + octave_value retval = -1.0; int nargin = args.length (); @@ -1378,13 +1381,13 @@ DEFCONST (SEEK_END, 1.0, 0, 0, "used with fseek to position file relative to the end"); - DEFCONSTX ("stdin", SBV_stdin, 0.0, 0, 0, + DEFCONSTX ("stdin", SBV_stdin, stdin_file, 0, 0, "file number of the standard input stream"); - DEFCONSTX ("stdout", SBV_stdout, 1.0, 0, 0, + DEFCONSTX ("stdout", SBV_stdout, stdout_file, 0, 0, "file number of the standard output stream"); - DEFCONSTX ("stderr", SBV_stderr, 2.0, 0, 0, + DEFCONSTX ("stderr", SBV_stderr, stderr_file, 0, 0, "file number of the standard error stream"); }
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -42,9 +42,8 @@ // Possible values for conv_err: // // 1 : not a real scalar -// 2 : error extracting scalar value (should not happen) -// 3 : value is NaN -// 4 : value is not an integer +// 2 : value is NaN +// 3 : value is not an integer static int convert_to_valid_int (const octave_value& tc, int& conv_err) @@ -53,21 +52,16 @@ conv_err = 0; - if (tc.is_real_scalar ()) + double dval = tc.double_value (); + + if (! error_state) { - double dval = tc.double_value (); - - if (! error_state) + if (! xisnan (dval)) { - if (! xisnan (dval)) - { - int ival = NINT (dval); - - if (ival == dval) - retval = ival; - else - conv_err = 4; - } + int ival = NINT (dval); + + if (ival == dval) + retval = ival; else conv_err = 3; } @@ -2372,14 +2366,16 @@ octave_stream_list *octave_stream_list::instance = 0; -int +octave_value octave_stream_list::do_insert (octave_base_stream *obs) { - int retval = -1; + int stream_number = -1; + + octave_stream *os = 0; if (obs) { - octave_stream *os = new octave_stream (obs); + os = new octave_stream (obs); // Insert item in first open slot, increasing size of list if // necessary. @@ -2391,12 +2387,12 @@ if (! tmp) { list (i) = os; - retval = i; + stream_number = i; break; } } - if (retval < 0) + if (stream_number < 0) { int total_len = list.length (); @@ -2404,20 +2400,20 @@ list.resize (total_len * 2); list (curr_len) = os; - retval = curr_len; + stream_number = curr_len; curr_len++; } } else ::error ("octave_stream_list: attempt to insert invalid stream"); - return retval; + return octave_value (os, stream_number); } -int +octave_value octave_stream_list::insert (octave_base_stream *obs) { - int retval = -1; + octave_value retval = -1.0; if (! instance) instance = new octave_stream_list ();
--- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -434,6 +434,10 @@ static string mode_as_string (int mode); + istream *input_stream (void) { return rep->input_stream (); } + + ostream *output_stream (void) { return rep->output_stream (); } + private: // The actual representation of this stream. @@ -490,7 +494,7 @@ ~octave_stream_list (void) { } - static int insert (octave_base_stream *obs); + static octave_value insert (octave_base_stream *obs); static octave_stream *lookup (int fid); static octave_stream *lookup (const octave_value& fid); @@ -517,7 +521,7 @@ static octave_stream_list *instance; - int do_insert (octave_base_stream *obs); + octave_value do_insert (octave_base_stream *obs); octave_stream *do_lookup (int fid) const; octave_stream *do_lookup (const octave_value& fid) const;
--- a/src/syscalls.cc +++ b/src/syscalls.cc @@ -547,10 +547,10 @@ } DEFUN (pipe, args, , - "[FILE_IDS, STATUS, MSG] = pipe (): create an interprocess channel.\n\ + "[FILE_LIST, STATUS, MSG] = pipe (): create an interprocess channel.\n\ \n\ -Return the FILE_IDS corresponding to the reading and writing ends of\n\ -the pipe, as a vector.\n\ +Return the file objects corresponding to the reading and writing ends of\n\ +the pipe, as a two-element list.\n\ \n\ If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\ STATUS is nonzero and MSG contains a system-dependent error message.") @@ -585,13 +585,13 @@ octave_ostdiostream *os = new octave_ostdiostream (string (), out_file); - Matrix file_ids (1, 2); + octave_value_list file_ids; - file_ids (0, 0) = octave_stream_list::insert (is); - file_ids (0, 1) = octave_stream_list::insert (os); + file_ids(1) = octave_stream_list::insert (os); + file_ids(0) = octave_stream_list::insert (is); - retval(0) = file_ids; retval(1) = static_cast<double> (status); + retval(0) = octave_value (file_ids); } #else gripe_not_supported ("pipe");