# HG changeset patch # User jwe # Date 1068698285 0 # Node ID cba347c642e2df19741fbf8d02eace796871ea3b # Parent 15ddd40fee90c878dd1246150eb54c7ca551bba2 [project @ 2003-11-13 04:38:05 by jwe] diff -r 15ddd40fee90 -r cba347c642e2 liboctave/ChangeLog --- a/liboctave/ChangeLog Wed Nov 12 18:54:11 2003 +0000 +++ b/liboctave/ChangeLog Thu Nov 13 04:38:05 2003 +0000 @@ -1,3 +1,16 @@ +2003-11-12 John W. Eaton + + * lo-ieee.cc (octave_ieee_init): Set octave_Inf, octave_NaN, and + octave_NA to DBL_MAX if native float format is vaxd, vaxg, or cray. + + * cmd-edit.cc (gnu_readline::do_generate_filename_completions, + default_command_editor::do_generate_filename_completions, + command_editor::generate_filename_completions): New functions. + * cmd-edit.h: Provide decls. + * oct-rl-edit.c (octave_rl_filename_completion_function): New + function. + * oct-rl-edit.h: Provide decl. + 2003-11-11 John W. Eaton * Array.h (INSTANTIATE_ARRAY_ASSIGN, INSTANTIATE_ARRAY_AND_ASSIGN, diff -r 15ddd40fee90 -r cba347c642e2 liboctave/cmd-edit.cc --- a/liboctave/cmd-edit.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/liboctave/cmd-edit.cc Thu Nov 13 04:38:05 2003 +0000 @@ -105,6 +105,9 @@ completion_fcn do_get_completion_function (void) const; + string_vector + do_generate_filename_completions (const std::string& text); + void do_insert_text (const std::string& text); void do_newline (void); @@ -320,6 +323,45 @@ return completion_function; } +string_vector +gnu_readline::do_generate_filename_completions (const std::string& text) +{ + string_vector retval; + + int n = 0; + int count = 0; + + char *fn = 0; + + while (1) + { + fn = ::octave_rl_filename_completion_function (text.c_str (), count); + + if (fn) + { + if (count == n) + { + // Famous last words: Most large directories will not + // have more than a few hundred files, so we should not + // resize too many times even if the growth is linear... + + n += 100; + retval.resize (n); + } + + retval[count++] = fn; + + free (fn); + } + else + break; + } + + retval.resize (count); + + return retval; +} + void gnu_readline::do_insert_text (const std::string& text) { @@ -467,6 +509,8 @@ FILE *do_get_output_stream (void); + string_vector do_generate_filename_completions (const std::string& text); + void do_insert_text (const std::string&); void do_newline (void); @@ -511,6 +555,13 @@ return output_stream; } +string_vector +default_command_editor::do_generate_filename_completions (const std::string& text) +{ + // XXX FIXME XXX + return string_vector (); +} + void default_command_editor::do_insert_text (const std::string&) { @@ -714,6 +765,13 @@ ? instance->do_get_completion_function () : 0; } +string_vector +command_editor::generate_filename_completions (const std::string& text) +{ + return (instance_ok ()) + ? instance->do_generate_filename_completions (text) : string_vector (); +} + void command_editor::insert_text (const std::string& text) { diff -r 15ddd40fee90 -r cba347c642e2 liboctave/cmd-edit.h --- a/liboctave/cmd-edit.h Wed Nov 12 18:54:11 2003 +0000 +++ b/liboctave/cmd-edit.h Thu Nov 13 04:38:05 2003 +0000 @@ -27,6 +27,8 @@ #include +#include "str-vec.h" + class command_editor { @@ -85,6 +87,8 @@ static completion_fcn get_completion_function (void); + static string_vector generate_filename_completions (const std::string& text); + static void insert_text (const std::string& text); static void newline (void); @@ -177,6 +181,8 @@ virtual completion_fcn do_get_completion_function (void) const { return 0; } + virtual string_vector do_generate_filename_completions (const std::string& text) = 0; + virtual void do_insert_text (const std::string&) = 0; virtual void do_newline (void) = 0; diff -r 15ddd40fee90 -r cba347c642e2 liboctave/oct-rl-edit.c --- a/liboctave/oct-rl-edit.c Wed Nov 12 18:54:11 2003 +0000 +++ b/liboctave/oct-rl-edit.c Thu Nov 13 04:38:05 2003 +0000 @@ -194,6 +194,12 @@ return retval; } +char * +octave_rl_filename_completion_function (const char *text, int state) +{ + return rl_filename_completion_function (text, state); +} + void octave_rl_set_basic_word_break_characters (const char *s) { diff -r 15ddd40fee90 -r cba347c642e2 liboctave/oct-rl-edit.h --- a/liboctave/oct-rl-edit.h Wed Nov 12 18:54:11 2003 +0000 +++ b/liboctave/oct-rl-edit.h Thu Nov 13 04:38:05 2003 +0000 @@ -74,6 +74,8 @@ extern int octave_rl_filename_completion_desired (int); +extern char *octave_rl_filename_completion_function (const char *, int); + extern void octave_rl_set_basic_word_break_characters (const char *); extern void octave_rl_set_completer_word_break_characters (const char *); diff -r 15ddd40fee90 -r cba347c642e2 src/ChangeLog --- a/src/ChangeLog Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ChangeLog Thu Nov 13 04:38:05 2003 +0000 @@ -1,3 +1,30 @@ +2003-11-12 John W. Eaton + + * ov-cell.cc (print_as_scalar): New function. + * ov-cell.h: Provide decl. + + * ov-cell.cc (octave_cell::print_name_tag): Delete. + * ov-cell.h: Delete decl. + + * ov-base-mat.cc (octave_base_matrix::print_name_tag): Delete. + * ov-base-mat.h: Delete decl. + + * ov-base.cc (octave_base_value::print_name_tag): + Use print_as_scalar here. + * ov.h (octave_base_value::print_as_scalar): New virtual function. + * ov-base.h (octave_base_value::print_as_scalar): + New default implementation. + * ov-base-mat.h (octave_base_matrix::pirnt_as_scalar): + Don't declare as virtual here. + + * ov-struct.cc (octave_struct::print_raw): If only printing keys, + also print dimensions of fields and overall array. + + * sysdep.cc (Fnative_float_format): New function. + + * input.cc (generate_possible_completions): Also append all + possible filename completions here. + 2003-11-11 John W. Eaton * oct-stream.cc: Explicitly instantiate octave_scan functions. diff -r 15ddd40fee90 -r cba347c642e2 src/input.cc --- a/src/input.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/input.cc Thu Nov 13 04:38:05 2003 +0000 @@ -386,13 +386,9 @@ { string_vector names; - command_editor::filename_completion_desired (true); - prefix = ""; - if (! text.empty () && text != "." && text != ".." - && text.find_first_of (file_ops::dir_sep_chars) == NPOS - && text.rfind ('.') != NPOS) + if (looks_like_struct (text)) names = generate_struct_completions (text, prefix, hint); else names = make_name_list (); @@ -416,7 +412,9 @@ static int list_index = 0; static int name_list_len = 0; + static int name_list_total_len = 0; static string_vector name_list; + static string_vector file_name_list; static int matches = 0; @@ -432,6 +430,12 @@ name_list_len = name_list.length (); + file_name_list = command_editor::generate_filename_completions (text); + + name_list.append (file_name_list); + + name_list_total_len = name_list.length (); + hint_len = hint.length (); matches = 0; @@ -441,9 +445,9 @@ matches++; } - if (name_list_len > 0 && matches > 0) + if (name_list_total_len > 0 && matches > 0) { - while (list_index < name_list_len) + while (list_index < name_list_total_len) { std::string name = name_list[list_index]; @@ -451,7 +455,7 @@ if (hint == name.substr (0, hint_len)) { - if (! prefix.empty ()) + if (list_index <= name_list_len && ! prefix.empty ()) retval = prefix + "." + name; else retval = name; diff -r 15ddd40fee90 -r cba347c642e2 src/ov-base-mat.cc --- a/src/ov-base-mat.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-base-mat.cc Thu Nov 13 04:38:05 2003 +0000 @@ -220,28 +220,6 @@ } template -bool -octave_base_matrix::print_name_tag (std::ostream& os, - const std::string& name) const -{ - bool retval = false; - - indent (os); - - if (print_as_scalar ()) - os << name << " = "; - else - { - os << name << " ="; - newline (os); - newline (os); - retval = true; - } - - return retval; -} - -template void octave_base_matrix::print_info (std::ostream& os, const std::string& prefix) const diff -r 15ddd40fee90 -r cba347c642e2 src/ov-base-mat.h --- a/src/ov-base-mat.h Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-base-mat.h Thu Nov 13 04:38:05 2003 +0000 @@ -111,14 +111,12 @@ bool is_true (void) const; - virtual bool print_as_scalar (void) const; + bool print_as_scalar (void) const; void print (std::ostream& os, bool pr_as_read_syntax = false) const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - bool print_name_tag (std::ostream& os, const std::string& name) const; - void print_info (std::ostream& os, const std::string& prefix) const; protected: diff -r 15ddd40fee90 -r cba347c642e2 src/ov-base.cc --- a/src/ov-base.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-base.cc Thu Nov 13 04:38:05 2003 +0000 @@ -218,11 +218,21 @@ bool octave_base_value::print_name_tag (std::ostream& os, const std::string& name) const { + bool retval = false; + indent (os); - os << name << " ="; - newline (os); - newline (os); - return true; + + if (print_as_scalar ()) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } void diff -r 15ddd40fee90 -r cba347c642e2 src/ov-base.h --- a/src/ov-base.h Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-base.h Thu Nov 13 04:38:05 2003 +0000 @@ -234,6 +234,8 @@ void convert_to_row_or_column_vector (void); + bool print_as_scalar (void) const { return false; } + void print (std::ostream& os, bool pr_as_read_syntax = false) const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; diff -r 15ddd40fee90 -r cba347c642e2 src/ov-cell.cc --- a/src/ov-cell.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-cell.cc Thu Nov 13 04:38:05 2003 +0000 @@ -325,6 +325,12 @@ return retval; } +bool +octave_cell::print_as_scalar (void) const +{ + return (ndims () > 2 || numel () == 0); +} + void octave_cell::print (std::ostream& os, bool) const { @@ -389,25 +395,6 @@ } } -bool -octave_cell::print_name_tag (std::ostream& os, const std::string& name) const -{ - indent (os); - - int nr = rows (); - int nc = columns (); - - if (nr > 0 && nc > 0) - { - os << name << " ="; - newline (os); - } - else - os << name << " = "; - - return false; -} - DEFUN (iscell, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} iscell (@var{x})\n\ diff -r 15ddd40fee90 -r cba347c642e2 src/ov-cell.h --- a/src/ov-cell.h Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-cell.h Thu Nov 13 04:38:05 2003 +0000 @@ -103,12 +103,12 @@ string_vector all_strings (bool pad = false, bool force = false) const; + bool print_as_scalar (void) const; + void print (std::ostream& os, bool pr_as_read_syntax = false) const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - bool print_name_tag (std::ostream& os, const std::string& name) const; - private: DECLARE_OCTAVE_ALLOCATOR diff -r 15ddd40fee90 -r cba347c642e2 src/ov-cs-list.cc --- a/src/ov-cs-list.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-cs-list.cc Thu Nov 13 04:38:05 2003 +0000 @@ -53,6 +53,12 @@ } void +octave_cs_list::print (std::ostream& os, bool) const +{ + print_raw (os); +} + +void octave_cs_list::print_raw (std::ostream& os, bool) const { unwind_protect::begin_frame ("octave_cs_list_print"); diff -r 15ddd40fee90 -r cba347c642e2 src/ov-cs-list.h --- a/src/ov-cs-list.h Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-cs-list.h Thu Nov 13 04:38:05 2003 +0000 @@ -77,6 +77,8 @@ octave_value_list list_value (void) const { return lst; } + void print (std::ostream& os, bool) const; + void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; private: diff -r 15ddd40fee90 -r cba347c642e2 src/ov-struct.cc --- a/src/ov-struct.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov-struct.cc Thu Nov 13 04:38:05 2003 +0000 @@ -376,6 +376,17 @@ int n = map.numel (); + if (n > 1 && print_keys_only) + { + indent (os); + dim_vector dv = dims (); + os << dv.str () << " struct array containing the fields:"; + newline (os); + newline (os); + + increment_indent_level (); + } + for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++) { std::string key = map.key (p); @@ -386,13 +397,21 @@ if (print_keys_only) { indent (os); - os << key << ": " << tmp.type_name (); + os << key; + if (n == 1) + { + dim_vector dv = tmp.dims (); + os << ": " << dv.str () << " " << tmp.type_name (); + } newline (os); } else tmp.print_with_name (os, key); } + if (n > 1 && print_keys_only) + decrement_indent_level (); + decrement_indent_level (); indent (os); diff -r 15ddd40fee90 -r cba347c642e2 src/ov.h --- a/src/ov.h Wed Nov 12 18:54:11 2003 +0000 +++ b/src/ov.h Thu Nov 13 04:38:05 2003 +0000 @@ -584,6 +584,9 @@ virtual void convert_to_row_or_column_vector (void) { rep->convert_to_row_or_column_vector (); } + virtual bool print_as_scalar (void) const + { return rep->print_as_scalar (); } + virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const { rep->print (os, pr_as_read_syntax); } diff -r 15ddd40fee90 -r cba347c642e2 src/variables.cc --- a/src/variables.cc Wed Nov 12 18:54:11 2003 +0000 +++ b/src/variables.cc Thu Nov 13 04:38:05 2003 +0000 @@ -32,6 +32,7 @@ #include "file-stat.h" #include "oct-env.h" +#include "file-ops.h" #include "glob-match.h" #include "str-vec.h" @@ -466,7 +467,11 @@ bool looks_like_struct (const std::string& text) { - bool retval = false; + bool retval = (! text.empty () + && text != "." + && text.find_first_of (file_ops::dir_sep_chars) == NPOS + && text.find ("..") == NPOS + && text.rfind ('.') != NPOS); #if 0 symbol_record *sr = curr_sym_tab->lookup (text);