changeset 4143:62afb31c1f85

[project @ 2002-11-01 17:27:38 by jwe]
author jwe
date Fri, 01 Nov 2002 17:27:38 +0000
parents 0739d46e778c
children b02ada83de67
files liboctave/ChangeLog liboctave/cmd-edit.cc liboctave/cmd-edit.h liboctave/oct-rl-edit.c liboctave/oct-rl-edit.h src/ChangeLog src/input.cc src/load-save.cc src/pt-idx.cc src/pt-idx.h src/utils.cc src/utils.h src/variables.cc
diffstat 13 files changed, 133 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- 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  <jwe@bevo.che.wisc.edu>
 
+	* 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<T>::get_size): #define MALLOC_OVERHEAD to
 	avoid OS X linker bug.
 	* ArrayN.cc (ArrayN<T>::get_size): Likewise.
--- 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: 
 //   
--- 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);
--- 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)
 {
--- 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 *);
--- 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  <jwe@bevo.che.wisc.edu>
+
+	* 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  <jwe@bevo.che.wisc.edu>
 
 	* DLD-FUNCTIONS/odessa.cc (odessa_user_f, odessa_user_j,
--- 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 ();
--- 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 "_":
--- 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 ();
--- 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);
 
--- 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
--- 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);
--- 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 ());
     }