Mercurial > hg > octave-nkf
changeset 2341:6ee55c0f25a9
[project @ 1996-07-24 10:33:09 by jwe]
author | jwe |
---|---|
date | Wed, 24 Jul 1996 10:33:10 +0000 |
parents | 599f8f054840 |
children | 95e511896bf5 |
files | src/ChangeLog src/file-io.cc src/oct-stream.cc |
diffstat | 3 files changed, 44 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +Wed Jul 24 05:08:07 1996 John W. Eaton <jwe@bevo.che.wisc.edu> + + * file-io.cc (symbols_of_file_io): Redefine values of SEEK_SET, + SEEK_CUR, and SEEK_END for Matlab compatibility. + * oct-stream.cc (seek): Check for compatible values of ORIGIN arg. + Also handle "bof", "cof", and "eof". + Fri Jul 19 15:24:36 1996 John W. Eaton <jwe@bevo.che.wisc.edu> * pt-const.cc: When creating octave_value_reps from ComplexMatrix @@ -5,7 +12,7 @@ Tue Jul 16 10:53:42 1996 John W. Eaton <jwe@bevo.che.wisc.edu> - * input.cc (decode_prompt_string): Swap meanings of \h anbd \H. + * input.cc (decode_prompt_string): Swap meanings of \h and \H. Mon Jul 15 16:01:51 1996 John W. Eaton <jwe@bevo.che.wisc.edu>
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -436,7 +436,13 @@ DEFUN (fseek, args, , "fseek (FILENUM, OFFSET [, ORIGIN])\n\ \n\ -set file position for reading or writing") +set file position for reading or writing.\n\ +\n\ +ORIGIN may be one of:\n\ +\n\ + SEEK_SET : offset is relative to the beginning of the file (default)\n\ + SEEK_CUR : offset is relative to the current position\n\ + SEEK_END : offset is relative to the end of the file") { double retval = -1.0; @@ -449,7 +455,7 @@ if (os) { octave_value origin_arg = (nargin == 3) - ? args(2) : octave_value (0.0); + ? args(2) : octave_value (-1.0); retval = (double) os->seek (args(1), origin_arg); } @@ -1320,13 +1326,16 @@ void symbols_of_file_io (void) { - DEFCONST (SEEK_SET, 0.0, 0, 0, + // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be + // this way for Matlab compatibility. + + DEFCONST (SEEK_SET, -1.0, 0, 0, "used with fseek to position file relative to the beginning"); - DEFCONST (SEEK_CUR, 1.0, 0, 0, + DEFCONST (SEEK_CUR, 0.0, 0, 0, "used with fseek to position file relative to the current position"); - DEFCONST (SEEK_END, 2.0, 0, 0, + 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,
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -2025,27 +2025,37 @@ if (! conv_err) { - int xorigin = convert_to_valid_int (tc_origin, conv_err); - ios::seek_dir origin = ios::beg; - // XXX FIXME XXX -- matlab allows origin to be: - // - // "bof" or -1 == ios::beg - // "cof" or 0 == ios::cur - // "eof" or 1 == ios::end - - if (! conv_err) + if (tc_origin.is_string ()) { - if (xorigin == 0) + string xorigin = tc_origin.string_value (); + + if (xorigin == "bof") origin = ios::beg; - else if (xorigin == 1) + else if (xorigin == "cof") origin = ios::cur; - else if (xorigin == 2) + else if (xorigin == "eof") origin = ios::end; else conv_err = -1; } + else + { + int xorigin = convert_to_valid_int (tc_origin, conv_err); + + if (! conv_err) + { + if (xorigin == -1) + origin = ios::beg; + else if (xorigin == 0) + origin = ios::cur; + else if (xorigin == 1) + origin = ios::end; + else + conv_err = -1; + } + } if (! conv_err) retval = seek (xoffset, origin);