# HG changeset patch # User John W. Eaton # Date 1458411130 14400 # Node ID 128703a2938862fbaaf176a38c4678f8d83a2966 # Parent 7f7d7cb73e0d9deef9088713b23b0cc66916e6f7 avoid some duplicate code in file-io functions * file-io.cc (Ffscanf, Fsscanf): Share code for extracting stream and format from function arguments. diff -r 7f7d7cb73e0d -r 128703a29388 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Sat Mar 19 18:05:44 2016 +0000 +++ b/libinterp/corefcn/file-io.cc Sat Mar 19 14:12:10 2016 -0400 @@ -938,8 +938,12 @@ if (nargin == 0) print_usage (); + // We don't use octave_ostrstream::create here because need direct + // access to the OSTR object so that we can extract a string object + // from it to return. octave_ostrstream *ostr = new octave_ostrstream (); + // The octave_stream destructor will delete OSTR for us. octave_stream os (ostr); if (! os.is_valid ()) @@ -1033,22 +1037,17 @@ octave_value_list retval; + octave_stream os = octave_stream_list::lookup (args(0), who); + + if (! args(1).is_string ()) + error ("%s: format TEMPLATE must be a string", who.c_str ()); + if (nargin == 3 && args(2).is_string ()) { - octave_stream os = octave_stream_list::lookup (args(0), who); - - if (! args(1).is_string ()) - error ("%s: format TEMPLATE must be a string", who.c_str ()); - retval = ovl (os.oscanf (args(1), who)); } else { - octave_stream os = octave_stream_list::lookup (args(0), who); - - if (! args(1).is_string ()) - error ("%s: format must be a string", who.c_str ()); - octave_idx_type count = 0; Array size = (nargin == 3) @@ -1101,32 +1100,22 @@ octave_value_list retval; + std::string data = get_sscanf_data (args(0)); + + octave_stream os = octave_istrstream::create (data); + + if (! os.is_valid ()) + error ("%s: unable to create temporary input buffer", who.c_str ()); + + if (! args(1).is_string ()) + error ("%s: format TEMPLATE must be a string", who.c_str ()); + if (nargin == 3 && args(2).is_string ()) { - std::string data = get_sscanf_data (args(0)); - - octave_stream os = octave_istrstream::create (data); - - if (! os.is_valid ()) - error ("%s: unable to create temporary input buffer", who.c_str ()); - - if (! args(1).is_string ()) - error ("%s: format TEMPLATE must be a string", who.c_str ()); - retval = ovl (os.oscanf (args(1), who)); } else { - std::string data = get_sscanf_data (args(0)); - - octave_stream os = octave_istrstream::create (data); - - if (! os.is_valid ()) - error ("%s: unable to create temporary input buffer", who.c_str ()); - - if (! args(1).is_string ()) - error ("%s: format TEMPLATE must be a string", who.c_str ()); - octave_idx_type count = 0; Array size = (nargin == 3) ? args(2).vector_value ()