# HG changeset patch # User jwe # Date 862372182 0 # Node ID c5b7a019b9ed55c10b84fd3eb01c871d897cedc1 # Parent e6d25bc478dd3a02177e015dc7b5d7e6e7f63e6b [project @ 1997-04-30 03:46:53 by jwe] diff --git a/src/file-io.cc b/src/file-io.cc --- 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 (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"); } diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- 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 (); diff --git a/src/oct-stream.h b/src/oct-stream.h --- 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; diff --git a/src/syscalls.cc b/src/syscalls.cc --- 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 (status); + retval(0) = octave_value (file_ids); } #else gripe_not_supported ("pipe");