Mercurial > hg > octave-nkf
diff libinterp/interpfcn/load-save.cc @ 16555:04fb96f4bea1
allow double-click in file browser to load data files
* files-dock-widget.cc (files_dock_widget::display_directory): If file
looks like Octave data file, load it instead of opening with editor.
* ls-mat-ascii.h, ls-mat-ascii.cc (get_lines_and_columns): New option
to supress error messages. New option to check for numeric values.
(looks_like_mat_ascii_file): New function.
* load-save.h load-save.cc (is_octave_data_file): New function.
(get_file_format): Don't return LS_MAT_ASCII unless the file really
looks like it is a numeric data file.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 23 Apr 2013 12:57:16 -0400 |
parents | 302157614308 |
children | b04ae15530fc |
line wrap: on
line diff
--- a/libinterp/interpfcn/load-save.cc +++ b/libinterp/interpfcn/load-save.cc @@ -242,7 +242,8 @@ int32_t mopt, nr, nc, imag, len; - int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len, 1); + int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len, + true); if (! err) retval = LS_MAT_BINARY; @@ -277,7 +278,7 @@ static load_save_format get_file_format (const std::string& fname, const std::string& orig_fname, - bool &use_zlib) + bool &use_zlib, bool quiet = false) { load_save_format retval = LS_UNKNOWN; @@ -309,19 +310,16 @@ } #endif - if (retval == LS_UNKNOWN) - { - // Try reading the file as numbers only, determining the - // number of rows and columns from the data. We don't - // even bother to check to see if the first item in the - // file is a number, so that get_complete_line() can - // skip any comments that might appear at the top of the - // file. + // FIXME -- looks_like_mat_ascii_file does not check to see + // whether the file contains numbers. It just skips comments and + // checks for the same number of words on each line. We may need + // a better check here. The best way to do that might be just + // to try to read the file and see if it works. - retval = LS_MAT_ASCII; - } + if (retval == LS_UNKNOWN && looks_like_mat_ascii_file (fname)) + retval = LS_MAT_ASCII; } - else + else if (! quiet) gripe_file_open ("load", orig_fname); return retval; @@ -537,6 +535,12 @@ return fname; } +bool +is_octave_data_file (const std::string& fname) +{ + bool use_zlib = false; + return get_file_format (fname, fname, use_zlib, true) != LS_UNKNOWN; +} DEFUN (load, args, nargout, "-*- texinfo -*-\n\