Mercurial > octave-nkf
diff src/file-io.cc @ 3341:14cfc9475fe4
[project @ 1999-11-05 08:11:58 by jwe]
author | jwe |
---|---|
date | Fri, 05 Nov 1999 08:11:59 +0000 |
parents | 585a8809fd9b |
children | d8d3700fb4ab |
line wrap: on
line diff
--- a/src/file-io.cc Fri Nov 05 07:02:36 1999 +0000 +++ b/src/file-io.cc Fri Nov 05 08:11:59 1999 +0000 @@ -94,12 +94,6 @@ octave_stream_list::clear (); } -static void -gripe_invalid_file_id (const char *fcn) -{ - ::error ("%s: invalid file id", fcn); -} - static int fopen_mode_to_ios_mode (const string& mode) { @@ -161,12 +155,8 @@ int nargin = args.length (); if (nargin == 1) - { - retval = static_cast<double> (octave_stream_list::remove (args(0))); - - if (retval < 0) - gripe_invalid_file_id ("fclose"); - } + retval = static_cast<double> (octave_stream_list::remove (args(0), + "fclose")); else print_usage ("fclose"); @@ -194,12 +184,10 @@ } else { - octave_stream os = octave_stream_list::lookup (fid); + octave_stream os = octave_stream_list::lookup (fid, "fflush"); - if (os.is_valid ()) + if (! error_state) retval = static_cast<double> (os.flush ()); - else - gripe_invalid_file_id ("fflush"); } } else @@ -222,9 +210,9 @@ if (nargin == 1 || nargin == 2) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fgetl"); - if (os.is_valid ()) + if (! error_state) { octave_value len_arg = (nargin == 2) ? args(1) : octave_value (static_cast<double> (INT_MAX)); @@ -239,8 +227,6 @@ retval(0) = tmp; } } - else - gripe_invalid_file_id ("fgetl"); } else print_usage ("fgetl"); @@ -262,9 +248,9 @@ if (nargin == 1 || nargin == 2) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fgets"); - if (os.is_valid ()) + if (! error_state) { octave_value len_arg = (nargin == 2) ? args(1) : octave_value (static_cast<double> (INT_MAX)); @@ -279,8 +265,6 @@ retval(0) = tmp; } } - else - gripe_invalid_file_id ("fgets"); } else print_usage ("fgets"); @@ -472,12 +456,10 @@ if (nargin == 1) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "frewind"); - if (os.is_valid ()) + if (! error_state) retval = static_cast<double> (os.rewind ()); - else - gripe_invalid_file_id ("frewind"); } else print_usage ("frewind"); @@ -502,17 +484,15 @@ if (nargin == 2 || nargin == 3) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fseek"); - if (os.is_valid ()) + if (! error_state) { octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0); retval = static_cast<double> (os.seek (args(1), origin_arg)); } - else - ::error ("fseek: invalid file id"); } else print_usage ("fseek"); @@ -529,12 +509,10 @@ if (nargin == 1) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "ftell"); - if (os.is_valid ()) + if (! error_state) retval = static_cast<double> (os.tell ()); - else - gripe_invalid_file_id ("ftell"); } else print_usage ("ftell"); @@ -555,14 +533,14 @@ int fmt_n = 0; if (args(0).is_string ()) - os = octave_stream_list::lookup (1); + os = octave_stream_list::lookup (1, "fprintf"); else { fmt_n = 1; - os = octave_stream_list::lookup (args(0)); + os = octave_stream_list::lookup (args(0), "fprintf"); } - if (os.is_valid ()) + if (! error_state) { if (args(fmt_n).is_string ()) { @@ -583,8 +561,6 @@ else ::error ("fprintf: format must be a string"); } - else - gripe_invalid_file_id ("fprintf"); } else print_usage ("fprintf"); @@ -601,12 +577,10 @@ if (nargin == 2) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fputs"); - if (os.is_valid ()) + if (! error_state) retval = os.puts (args(1)); - else - gripe_invalid_file_id ("fputs"); } else print_usage ("fputs"); @@ -692,9 +666,9 @@ if (nargin == 3 && args(2).is_string ()) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fscanf"); - if (os.is_valid ()) + if (! error_state) { if (args(1).is_string ()) { @@ -705,8 +679,6 @@ else ::error ("fscanf: format must be a string"); } - else - gripe_invalid_file_id ("fscanf"); } else { @@ -715,9 +687,9 @@ if (nargin == 2 || nargin == 3) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fscanf"); - if (os.is_valid ()) + if (error_state) { if (args(1).is_string ()) { @@ -739,8 +711,6 @@ else ::error ("fscanf: format must be a string"); } - else - gripe_invalid_file_id ("fscanf"); } else print_usage ("fscanf"); @@ -983,9 +953,9 @@ retval(1) = -1.0; retval(0) = Matrix (); - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fread"); - if (os.is_valid ()) + if (! error_state) { octave_value size = (nargin > 1) ? args(1) : octave_value (octave_Inf); @@ -1006,8 +976,6 @@ retval(1) = static_cast<double> (count); retval(0) = tmp; } - else - gripe_invalid_file_id ("fread"); } else print_usage ("fread"); @@ -1111,9 +1079,9 @@ if (nargin > 1 && nargin < 6) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); - if (os.is_valid ()) + if (! error_state) { octave_value data = args(1); @@ -1130,8 +1098,6 @@ retval = status; } - else - gripe_invalid_file_id ("fwrite"); } else print_usage ("fwrite"); @@ -1151,12 +1117,10 @@ if (nargin == 1) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "feof"); - if (os.is_valid ()) + if (! error_state) retval = os.eof () ? 1.0 : 0.0; - else - gripe_invalid_file_id ("feof"); } else print_usage ("feof"); @@ -1176,9 +1140,9 @@ if (nargin == 1 || nargin == 2) { - octave_stream os = octave_stream_list::lookup (args(0)); + octave_stream os = octave_stream_list::lookup (args(0), "ferror"); - if (os.is_valid ()) + if (! error_state) { bool clear = false; @@ -1199,8 +1163,6 @@ retval(1) = static_cast<double> (error_number); retval(0) = error_message; } - else - gripe_invalid_file_id ("ferror"); } else print_usage ("ferror"); @@ -1294,12 +1256,8 @@ int nargin = args.length (); if (nargin == 1) - { - retval = static_cast<double> (octave_stream_list::remove (args(0))); - - if (retval < 0) - gripe_invalid_file_id ("pclose"); - } + retval = static_cast<double> (octave_stream_list::remove (args(0), + "pclose")); else print_usage ("pclose");