Mercurial > hg > octave-lojdl
changeset 8034:f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 19 Aug 2008 13:50:15 -0400 |
parents | 2ad5ba320b93 |
children | 1720d4fab3fa |
files | src/ChangeLog src/load-save.cc src/oct-obj.cc src/oct-obj.h |
diffstat | 4 files changed, 43 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2008-08-19 Jaroslav Hajek <highegg@gmail.com> + + * oct-obj.cc, oct-obj.h (octave_value_list::make_argv): + Allow calling without fcn_name. + * load-save.cc (parse_save_options (const string_vector&, ...)): + Return string_vector with parsed arguments removed instead. + (parse_save_options (const std::string&, ...)): Dtto. + (Fsave): Fix calls to parse_save_options. + 2008-08-19 John W. Eaton <jwe@octave.org> * parse.y (Feval): Return value produced by evaluating CATCH string.
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -1038,13 +1038,15 @@ return saved; } -static int -parse_save_options (const string_vector &argv, int argc, +static string_vector +parse_save_options (const string_vector &argv, load_save_format &format, bool &append, - bool &save_as_floats, bool &use_zlib, int start_arg) + bool &save_as_floats, bool &use_zlib) { - int i; - for (i = start_arg; i < argc; i++) + string_vector retval; + int argc = argv.length (); + + for (int i = 0; i < argc; i++) { if (argv[i] == "-append") { @@ -1109,31 +1111,29 @@ } #endif else - break; + retval.append (argv[i]); } - return i; + return retval; } -static int +static string_vector parse_save_options (const std::string &arg, load_save_format &format, bool &append, bool &save_as_floats, - bool &use_zlib, int start_arg) + bool &use_zlib) { std::istringstream is (arg); std::string str; - int argc = 0; string_vector argv; while (! is.eof ()) { is >> str; argv.append (str); - argc++; } - return parse_save_options (argv, argc, format, append, save_as_floats, - use_zlib, start_arg); + return parse_save_options (argv, format, append, save_as_floats, + use_zlib); } void @@ -1346,7 +1346,7 @@ bool use_zlib = false; parse_save_options (Voctave_core_file_options, format, append, - save_as_floats, use_zlib, 0); + save_as_floats, use_zlib); std::ios::openmode mode = std::ios::out; @@ -1546,9 +1546,9 @@ { octave_value_list retval; - int argc = args.length () + 1; + int argc = args.length (); - string_vector argv = args.make_argv ("save"); + string_vector argv = args.make_argv (); if (error_state) return retval; @@ -1564,19 +1564,15 @@ bool use_zlib = false; - load_save_format user_file_format = LS_UNKNOWN; - bool dummy; - - // Get user file format - parse_save_options (argv, argc, user_file_format, dummy, - dummy, dummy, 1); + // get default options + parse_save_options (Vdefault_save_options, format, append, save_as_floats, + use_zlib); - if (user_file_format == LS_UNKNOWN) - parse_save_options (Vdefault_save_options, format, append, save_as_floats, - use_zlib, 0); - - int i = parse_save_options (argv, argc, format, append, save_as_floats, - use_zlib, 1); + // override from command line + argv = parse_save_options (argv, format, append, save_as_floats, + use_zlib); + argc = argv.length (); + int i = 0; if (error_state) return retval;
--- a/src/oct-obj.cc +++ b/src/oct-obj.cc @@ -206,11 +206,16 @@ total_nr += n ? n : 1; } - argv.resize (total_nr+1); + octave_idx_type k = 0; + if (! fcn_name.empty ()) + { + argv.resize (total_nr+1); + argv[0] = fcn_name; + k = 1; + } + else + argv.resize (total_nr); - argv[0] = fcn_name; - - octave_idx_type k = 1; for (octave_idx_type i = 0; i < len; i++) { octave_idx_type nr = elem(i).rows ();