# HG changeset patch # User jwe # Date 1036171658 0 # Node ID 62afb31c1f852d04888d1ace698ac9b8d6282d0e # Parent 0739d46e778cab56a7fcb5469851115b749a949f [project @ 2002-11-01 17:27:38 by jwe] diff -r 0739d46e778c -r 62afb31c1f85 liboctave/ChangeLog --- a/liboctave/ChangeLog Fri Nov 01 14:10:27 2002 +0000 +++ b/liboctave/ChangeLog Fri Nov 01 17:27:38 2002 +0000 @@ -1,5 +1,11 @@ 2002-11-01 John W. Eaton + * cmd-edit.h (command_editor::filename_completion_desired): New + static function. + (command_editor::do_filename_completion_desired): New virtual function. + * oct-rl-edit.c (octave_rl_filename_completion_desired): New function. + * oct-rl-edit.h: Provide decl. + * Array2.cc (Array2::get_size): #define MALLOC_OVERHEAD to avoid OS X linker bug. * ArrayN.cc (ArrayN::get_size): Likewise. diff -r 0739d46e778c -r 62afb31c1f85 liboctave/cmd-edit.cc --- a/liboctave/cmd-edit.cc Fri Nov 01 14:10:27 2002 +0000 +++ b/liboctave/cmd-edit.cc Fri Nov 01 17:27:38 2002 +0000 @@ -121,6 +121,8 @@ void do_read_init_file (const std::string& file); + bool do_filename_completion_desired (bool); + static int operate_and_get_next (int, int); static int history_search_backward (int, int); @@ -370,6 +372,12 @@ ::octave_rl_read_init_file (file.c_str ()); } +bool +gnu_readline::do_filename_completion_desired (bool arg) +{ + return ::octave_rl_filename_completion_desired (arg); +} + int gnu_readline::operate_and_get_next (int /* count */, int /* c */) { @@ -764,6 +772,13 @@ instance->do_read_init_file (file); } +bool +command_editor::filename_completion_desired (bool arg) +{ + return (instance_ok ()) + ? instance->do_filename_completion_desired (arg) : false; +} + // Return a string which will be printed as a prompt. The string may // contain special characters which are decoded as follows: // diff -r 0739d46e778c -r 62afb31c1f85 liboctave/cmd-edit.h --- a/liboctave/cmd-edit.h Fri Nov 01 14:10:27 2002 +0000 +++ b/liboctave/cmd-edit.h Fri Nov 01 17:27:38 2002 +0000 @@ -101,6 +101,8 @@ static void read_init_file (const std::string& file = std::string ()); + static bool filename_completion_desired (bool); + static int current_command_number (void); static void reset_current_command_number (int n); @@ -191,6 +193,8 @@ virtual void do_read_init_file (const std::string&) { } + virtual bool do_filename_completion_desired (bool) { return false; } + int read_octal (const std::string& s); void error (int); diff -r 0739d46e778c -r 62afb31c1f85 liboctave/oct-rl-edit.c --- a/liboctave/oct-rl-edit.c Fri Nov 01 14:10:27 2002 +0000 +++ b/liboctave/oct-rl-edit.c Fri Nov 01 17:27:38 2002 +0000 @@ -186,6 +186,14 @@ rl_re_read_init_file (0, 0); } +int +octave_rl_filename_completion_desired (int arg) +{ + int retval = rl_filename_completion_desired; + rl_filename_completion_desired = arg; + return retval; +} + void octave_rl_set_basic_word_break_characters (const char *s) { diff -r 0739d46e778c -r 62afb31c1f85 liboctave/oct-rl-edit.h --- a/liboctave/oct-rl-edit.h Fri Nov 01 14:10:27 2002 +0000 +++ b/liboctave/oct-rl-edit.h Fri Nov 01 17:27:38 2002 +0000 @@ -72,6 +72,8 @@ extern void octave_rl_read_init_file (const char *); +extern int octave_rl_filename_completion_desired (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 0739d46e778c -r 62afb31c1f85 src/ChangeLog --- a/src/ChangeLog Fri Nov 01 14:10:27 2002 +0000 +++ b/src/ChangeLog Fri Nov 01 17:27:38 2002 +0000 @@ -1,3 +1,24 @@ +2002-11-01 John W. Eaton + + * variables.cc (generate_struct_completions): Temporarily reset + discard_error_messages and error_state + (looks_like_struct): Temporarily reset Vwarning option, + error_state, and discard_error_messages. + + * pt-idx.cc (tree_index_expression::eval_error): Now const. + (tree_index_expression::get_struct_index): Require valid identifier. + (tree_index_expression::make_arg_struct, + tree_index_expression::rvalue, tree_index_expression::lvalue): + Handle possible error from get_struct_index. + + * utils.cc (valid_identifier): Move here from load-save.cc. + * utils.h: Provide decl. + + * input.cc (generate_possible_completions): Call + command_editor::filename_completion_desired here. + (generate_possible_completions): Don't generate struct completions + if text contains directory separator or "..". + 2002-10-31 John W. Eaton * DLD-FUNCTIONS/odessa.cc (odessa_user_f, odessa_user_j, diff -r 0739d46e778c -r 62afb31c1f85 src/input.cc --- a/src/input.cc Fri Nov 01 14:10:27 2002 +0000 +++ b/src/input.cc Fri Nov 01 17:27:38 2002 +0000 @@ -381,9 +381,13 @@ { string_vector names; + command_editor::filename_completion_desired (true); + prefix = ""; - if (! text.empty () && text != "." && text.rfind ('.') != NPOS) + if (! text.empty () && text != "." && text != ".." + && text.find_first_of (file_ops::dir_sep_chars) == NPOS + && text.rfind ('.') != NPOS) names = generate_struct_completions (text, prefix, hint); else names = make_name_list (); diff -r 0739d46e778c -r 62afb31c1f85 src/load-save.cc --- a/src/load-save.cc Fri Nov 01 14:10:27 2002 +0000 +++ b/src/load-save.cc Fri Nov 01 17:27:38 2002 +0000 @@ -140,27 +140,6 @@ miMATRIX // MATLAB array }; -// Return TRUE if S is a valid identifier. - -static bool -valid_identifier (const char *s) -{ - if (! s || ! (isalnum (*s) || *s == '_')) - return false; - - while (*++s != '\0') - if (! (isalnum (*s) || *s == '_')) - return false; - - return true; -} - -static bool -valid_identifier (const std::string& s) -{ - return valid_identifier (s.c_str ()); -} - #ifdef HAVE_HDF5 // this is only used for HDF5 import // try to convert s into a valid identifier, replacing invalid chars with "_": diff -r 0739d46e778c -r 62afb31c1f85 src/pt-idx.cc --- a/src/pt-idx.cc Fri Nov 01 14:10:27 2002 +0000 +++ b/src/pt-idx.cc Fri Nov 01 17:27:38 2002 +0000 @@ -184,7 +184,12 @@ octave_value t = df->rvalue (); if (! error_state) - fn = t.string_value (); + { + fn = t.string_value (); + + if (! valid_identifier (fn)) + ::error ("invalid structure field name"); + } } else panic_impossible (); @@ -220,7 +225,12 @@ break; case '.': - subs_list(i) = get_struct_index (p_arg_nm, p_dyn_field); + { + subs_list(i) = get_struct_index (p_arg_nm, p_dyn_field); + + if (error_state) + eval_error (); + } break; default: @@ -274,7 +284,12 @@ break; case '.': - idx.append (get_struct_index (p_arg_nm, p_dyn_field)); + { + idx.append (get_struct_index (p_arg_nm, p_dyn_field)); + + if (error_state) + eval_error (); + } break; default: @@ -335,7 +350,12 @@ break; case '.': - idx.append (get_struct_index (p_arg_nm, p_dyn_field)); + { + idx.append (get_struct_index (p_arg_nm, p_dyn_field)); + + if (error_state) + eval_error (); + } break; default: @@ -362,7 +382,7 @@ } void -tree_index_expression::eval_error (void) +tree_index_expression::eval_error (void) const { int l = line (); int c = column (); diff -r 0739d46e778c -r 62afb31c1f85 src/pt-idx.h --- a/src/pt-idx.h Fri Nov 01 14:10:27 2002 +0000 +++ b/src/pt-idx.h Fri Nov 01 17:27:38 2002 +0000 @@ -87,7 +87,7 @@ octave_lvalue lvalue (void); - void eval_error (void); + void eval_error (void) const; void accept (tree_walker& tw); diff -r 0739d46e778c -r 62afb31c1f85 src/utils.cc --- a/src/utils.cc Fri Nov 01 14:10:27 2002 +0000 +++ b/src/utils.cc Fri Nov 01 17:27:38 2002 +0000 @@ -79,6 +79,27 @@ // Top level context (?) extern jmp_buf toplevel; +// Return TRUE if S is a valid identifier. + +bool +valid_identifier (const char *s) +{ + if (! s || ! (isalnum (*s) || *s == '_')) + return false; + + while (*++s != '\0') + if (! (isalnum (*s) || *s == '_')) + return false; + + return true; +} + +bool +valid_identifier (const std::string& s) +{ + return valid_identifier (s.c_str ()); +} + // Return to the main command loop in octave.cc. void diff -r 0739d46e778c -r 62afb31c1f85 src/utils.h --- a/src/utils.h Fri Nov 01 14:10:27 2002 +0000 +++ b/src/utils.h Fri Nov 01 17:27:38 2002 +0000 @@ -34,10 +34,8 @@ class octave_value_list; class string_vector; -extern std::string search_path_for_file (const std::string&, const std::string&); -extern std::string file_in_path (const std::string&, const std::string&); -extern std::string fcn_file_in_path (const std::string&); -extern std::string oct_file_in_path (const std::string&); +extern bool valid_identifier (const char *s); +extern bool valid_identifier (const std::string& s); extern void jump_to_top_level (void) GCC_ATTR_NORETURN; @@ -51,10 +49,15 @@ extern int empty_arg (const char *name, int nr, int nc); -extern const char *undo_string_escape (char c); +extern std::string search_path_for_file (const std::string&, const std::string&); +extern std::string file_in_path (const std::string&, const std::string&); +extern std::string fcn_file_in_path (const std::string&); +extern std::string oct_file_in_path (const std::string&); extern std::string do_string_escapes (const std::string& s); +extern const char *undo_string_escape (char c); + extern std::string undo_string_escapes (const std::string& s); extern int check_preference (const std::string& var); diff -r 0739d46e778c -r 62afb31c1f85 src/variables.cc --- a/src/variables.cc Fri Nov 01 14:10:27 2002 +0000 +++ b/src/variables.cc Fri Nov 01 17:27:38 2002 +0000 @@ -291,13 +291,18 @@ int parse_status; + unwind_protect::begin_frame ("generate_struct_completions"); + unwind_protect_str (Vwarning_option); + unwind_protect_bool (discard_error_messages); + unwind_protect_int (error_state); Vwarning_option = "off"; + discard_error_messages = true; octave_value tmp = eval_string (prefix, true, parse_status); - unwind_protect::run (); + unwind_protect::run_frame ("generate_struct_completions"); if (tmp.is_defined () && tmp.is_map ()) names = tmp.map_keys (); @@ -316,8 +321,19 @@ { int parse_status; + unwind_protect::begin_frame ("looks_like_struct"); + + unwind_protect_str (Vwarning_option); + unwind_protect_bool (discard_error_messages); + unwind_protect_int (error_state); + + Vwarning_option = "off"; + discard_error_messages = true; + octave_value tmp = eval_string (text, true, parse_status); + unwind_protect::run_frame ("looks_like_struct"); + retval = (tmp.is_defined () && tmp.is_map ()); }