octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #58127] -append does not automatically detect/


From: Rik
Subject: [Octave-bug-tracker] [bug #58127] -append does not automatically detect/check file type for save
Date: Tue, 21 Apr 2020 13:34:45 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Follow-up Comment #9, bug #58127 (project octave):

Don't know if it's worth it, but one thing to do in the meantime would be to
issue an error message if "-append" is used WITHOUT also specifying a file
type.  The code for that is in the function parse_save_options located in the
file libinterp/corefcn/load-save.cc.

The function is


string_vector
load_save_system::parse_save_options (const string_vector& argv,
                                      load_save_format& fmt, bool& append,
                                      bool& save_as_floats, bool& use_zlib)
{
#if ! defined (HAVE_ZLIB)
  octave_unused_parameter (use_zlib);
#endif

  string_vector retval;
  int argc = argv.numel ();

  bool do_double = false;
  bool do_tabs = false;

  for (int i = 0; i < argc; i++)
    {
      if (argv[i] == "-append")
        {
          append = true;
        }
      else if (argv[i] == "-ascii" || argv[i] == "-a")
        {
          fmt.set_type (MAT_ASCII);
        }
      else if (argv[i] == "-double")
        {
          do_double = true;
        }
      else if (argv[i] == "-tabs")
        {
          do_tabs = true;
        }
      else if (argv[i] == "-text" || argv[i] == "-t")
        {
          fmt.set_type (TEXT);
        }
      else if (argv[i] == "-binary" || argv[i] == "-b")
        {
          fmt.set_type (BINARY);
        }
      else if (argv[i] == "-hdf5" || argv[i] == "-h")
        {
#if defined (HAVE_HDF5)
          fmt.set_type (HDF5);
#else
          err_disabled_feature ("save", "HDF5");
#endif
        }
      else if (argv[i] == "-v7.3" || argv[i] == "-V7.3" || argv[i] == "-7.3")
        {
          error ("save: Matlab file format -v7.3 is not yet implemented");
        }
#if defined (HAVE_ZLIB)
      else if (argv[i] == "-v7" || argv[i] == "-V7" || argv[i] == "-7"
               || argv[i] == "-mat7-binary")
        {
          fmt.set_type (MAT7_BINARY);
        }
#endif
      else if (argv[i] == "-mat" || argv[i] == "-m"
               || argv[i] == "-v6" || argv[i] == "-V6" || argv[i] == "-6"
               || argv[i] == "-mat-binary")
        {
          fmt.set_type (MAT5_BINARY);
        }
      else if (argv[i] == "-v4" || argv[i] == "-V4" || argv[i] == "-4"
               || argv[i] == "-mat4-binary")
        {
          fmt.set_type (MAT_BINARY);
        }
      else if (argv[i] == "-float-binary" || argv[i] == "-f")
        {
          fmt.set_type (BINARY);
          save_as_floats = true;
        }
      else if (argv[i] == "-float-hdf5")
        {
#if defined (HAVE_HDF5)
          fmt.set_type (HDF5);
          save_as_floats = true;
#else
          err_disabled_feature ("save", "HDF5");
#endif
        }
#if defined (HAVE_ZLIB)
      else if (argv[i] == "-zip" || argv[i] == "-z")
        {
          use_zlib = true;
        }
#endif
      else if (argv[i] == "-struct")
        {
          retval.append (argv[i]);
        }
      else if (argv[i][0] == '-' && argv[i] != "-")
        {
          error ("save: Unrecognized option '%s'", argv[i].c_str ());
        }
      else
        retval.append (argv[i]);
    }


It's a reasonably straightforward change, although it would cause the code to
grow quite a bit.  One would need to define a bool variable at the start,
something like have_fmt, as false.  Then, in every else if branch where
fmt.set_type is called you would need to set have_fmt to true.  At the end of
this one could check whether "append" was true, but "have_fmt" was false and
issue an error in that case.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58127>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]