octave-maintainers
[Top][All Lists]
Advanced

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

Re: MSVC 2.9.13 and path completion with spaces


From: David Bateman
Subject: Re: MSVC 2.9.13 and path completion with spaces
Date: Tue, 02 Oct 2007 18:58:51 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Michael Goffioul wrote:
> On 10/2/07, David Bateman <address@hidden> wrote:
>   
>> Michael,
>>
>> Jean-Luc in cc to this e-mail spotted an issue with your MSVC installer
>> to do with readline path completion and paths with spaces. To observe
>> this issue try
>>
>> cd c:
>> cd Doc<tab>
>>
>> This will then complete the path with
>>
>> cd Documents and Settings
>>     
>
> Isn't it the same under Linux?
>   
Humm, yes it is. I hadn't noticed.. I don't like directories with spaces
in them and never use them. So the problem is more general and needs a
more general solution

>   
>> will occur. Has this issue been addressed? Is there a means of getting
>> the readline path completion to instead write that as
>>
>> cd Documents\ and\ Settings
>>     
>
> Typing this at octave prompt produces the same error. It's not a solution.
>   
Yes, the only workaround I see at the moment is

cd("Documents and Settings")

The equivalent

cd "Documents and Settings"

also works. Readline has the capability to do the filename quoting
through the rl_filename_quoting_desired variable and family, and we
should probably use that to address this issue. I took a shot at
implementing this and came up with the attached patch. I still doesn't
work as the quoting function is not called, for reasons unknown (note
that there is some std::cerr code for debugging in this patch).. I'll
try to fix that a send an updated version, but if anyone can see why its
not working and knows readline better than I do then a fix would be
appreciated..

D.


> Michael.
>
>   


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./liboctave/cmd-edit.h.orig17       2007-10-02 16:38:21.677920959 +0200
--- ./liboctave/cmd-edit.h      2007-10-02 18:23:13.049332941 +0200
***************
*** 48,53 ****
--- 48,57 ----
  
    typedef std::string (*completion_fcn) (const std::string&, int);
  
+   typedef std::string (*quoting_fcn) (const std::string&);
+ 
+   typedef std::string (*dequoting_fcn) (const std::string&, int);
+ 
    virtual ~command_editor (void) { }
  
    static void set_name (const std::string& n);
***************
*** 84,95 ****
--- 88,109 ----
  
    static void set_basic_quote_characters (const std::string& s);
  
+   static void set_filename_quote_characters (const std::string& s);
+ 
    static void set_completion_append_character (char c);
  
    static void set_completion_function (completion_fcn f);
  
+   static void set_quoting_function (quoting_fcn f);
+ 
+   static void set_dequoting_function (dequoting_fcn f);
+ 
    static completion_fcn get_completion_function (void);
  
+   static quoting_fcn get_quoting_function (void);
+ 
+   static dequoting_fcn get_dequoting_function (void);
+ 
    static string_vector generate_filename_completions (const std::string& 
text);
  
    static void insert_text (const std::string& text);
***************
*** 110,115 ****
--- 124,131 ----
  
    static bool filename_completion_desired (bool);
  
+   static bool filename_quoting_desired (bool);
+ 
    static int current_command_number (void);
  
    static void reset_current_command_number (int n);
***************
*** 192,203 ****
--- 208,229 ----
  
    virtual void do_set_basic_quote_characters (const std::string&) { }
  
+   virtual void do_set_filename_quote_characters (const std::string&) { }
+ 
    virtual void do_set_completion_append_character (char) { }
  
    virtual void do_set_completion_function (completion_fcn) { }
  
+   virtual void do_set_quoting_function (quoting_fcn) { }
+ 
+   virtual void do_set_dequoting_function (dequoting_fcn) { }
+ 
    virtual completion_fcn do_get_completion_function (void) const { return 0; }
  
+   virtual quoting_fcn do_get_quoting_function (void) const { return 0; }
+ 
+   virtual dequoting_fcn do_get_dequoting_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;
***************
*** 218,223 ****
--- 244,251 ----
  
    virtual bool do_filename_completion_desired (bool) { return false; }
  
+   virtual bool do_filename_quoting_desired (bool) { return false; }
+ 
    int read_octal (const std::string& s);
  
    void error (int);
*** ./liboctave/cmd-edit.cc.orig17      2007-10-02 16:38:32.671365414 +0200
--- ./liboctave/cmd-edit.cc     2007-10-02 18:45:38.590351231 +0200
***************
*** 107,118 ****
--- 107,128 ----
  
    void do_set_basic_quote_characters (const std::string& s);
  
+   void do_set_filename_quote_characters (const std::string& s);
+ 
    void do_set_completion_append_character (char c);
  
    void do_set_completion_function (completion_fcn f);
  
+   void do_set_quoting_function (quoting_fcn f);
+ 
+   void do_set_dequoting_function (dequoting_fcn f);
+ 
    completion_fcn do_get_completion_function (void) const;
  
+   quoting_fcn do_get_quoting_function (void) const;
+ 
+   dequoting_fcn do_get_dequoting_function (void) const;
+ 
    string_vector
    do_generate_filename_completions (const std::string& text);
  
***************
*** 136,141 ****
--- 146,153 ----
  
    bool do_filename_completion_desired (bool);
  
+   bool do_filename_quoting_desired (bool);
+ 
    static int operate_and_get_next (int, int);
  
    static int history_search_backward (int, int);
***************
*** 150,157 ****
--- 162,177 ----
  
    completion_fcn completion_function;
  
+   quoting_fcn quoting_function;
+ 
+   dequoting_fcn dequoting_function;
+ 
    static char *command_generator (const char *text, int state);
  
+   static char *command_quoter (char *text, int match_type, char 
*quote_pointer);
+ 
+   static char *command_dequoter (char *text, int match_type);
+ 
    static char **command_completer (const char *text, int start, int end);
  };
  
***************
*** 319,324 ****
--- 339,350 ----
  }
  
  void
+ gnu_readline::do_set_filename_quote_characters (const std::string& s)
+ {
+   ::octave_rl_set_filename_quote_characters (s.c_str ());
+ }
+ 
+ void
  gnu_readline::do_set_completion_append_character (char c)
  {
    ::octave_rl_set_completion_append_character (c);
***************
*** 335,346 ****
--- 361,406 ----
    ::octave_rl_set_completion_function (fp);
  }
  
+ void
+ gnu_readline::do_set_quoting_function (quoting_fcn f)
+ {
+   quoting_function = f;
+ 
+   rl_quoting_fcn_ptr fp
+     = f ? gnu_readline::command_quoter : 0;
+ 
+   ::octave_rl_set_quoting_function (fp);
+ }
+ 
+ void
+ gnu_readline::do_set_dequoting_function (dequoting_fcn f)
+ {
+   dequoting_function = f;
+ 
+   rl_dequoting_fcn_ptr fp
+     = f ? gnu_readline::command_dequoter : 0;
+ 
+   ::octave_rl_set_dequoting_function (fp);
+ }
+ 
  gnu_readline::completion_fcn
  gnu_readline::do_get_completion_function (void) const
  {
    return completion_function;
  }
  
+ gnu_readline::quoting_fcn
+ gnu_readline::do_get_quoting_function (void) const
+ {
+   return quoting_function;
+ }
+ 
+ gnu_readline::dequoting_fcn
+ gnu_readline::do_get_dequoting_function (void) const
+ {
+   return dequoting_function;
+ }
+ 
  string_vector
  gnu_readline::do_generate_filename_completions (const std::string& text)
  {
***************
*** 439,444 ****
--- 499,510 ----
    return ::octave_rl_filename_completion_desired (arg);
  }
  
+ bool
+ gnu_readline::do_filename_quoting_desired (bool arg)
+ {
+   return ::octave_rl_filename_quoting_desired (arg);
+ }
+ 
  int
  gnu_readline::operate_and_get_next (int /* count */, int /* c */)
  {
***************
*** 497,502 ****
--- 563,610 ----
    return retval;
  }
  
+ char *
+ gnu_readline::command_quoter (char *text, int, char *)
+ {
+   char *retval = 0;
+ 
+   quoting_fcn f = command_editor::get_quoting_function ();
+ 
+   std::string tmp = f (text);
+ 
+   size_t len = tmp.length ();
+ 
+   if (len > 0)
+     {
+       retval = static_cast<char *> (malloc (len+1));
+ 
+       strcpy (retval, tmp.c_str ());
+     }
+ 
+   return retval;
+ }
+ 
+ char *
+ gnu_readline::command_dequoter (char *text, int quote)
+ {
+   char *retval = 0;
+ 
+   dequoting_fcn f = command_editor::get_dequoting_function ();
+ 
+   std::string tmp = f (text, quote);
+ 
+   size_t len = tmp.length ();
+ 
+   if (len > 0)
+     {
+       retval = static_cast<char *> (malloc (len+1));
+ 
+       strcpy (retval, tmp.c_str ());
+     }
+ 
+   return retval;
+ }
+ 
  char **
  gnu_readline::command_completer (const char *text, int, int)
  {
***************
*** 794,799 ****
--- 902,914 ----
  }
  
  void
+ command_editor::set_filename_quote_characters (const std::string& s)
+ {
+   if (instance_ok ())
+     instance->do_set_filename_quote_characters (s);
+ }
+ 
+ void
  command_editor::set_completion_append_character (char c)
  {
    if (instance_ok ())
***************
*** 807,812 ****
--- 922,941 ----
      instance->do_set_completion_function (f);
  }
  
+ void
+ command_editor::set_quoting_function (quoting_fcn f)
+ {
+   if (instance_ok ())
+     instance->do_set_quoting_function (f);
+ }
+ 
+ void
+ command_editor::set_dequoting_function (dequoting_fcn f)
+ {
+   if (instance_ok ())
+     instance->do_set_dequoting_function (f);
+ }
+ 
  command_editor::completion_fcn
  command_editor::get_completion_function (void)
  {
***************
*** 814,819 ****
--- 943,962 ----
      ? instance->do_get_completion_function () : 0;
  }
  
+ command_editor::quoting_fcn
+ command_editor::get_quoting_function (void)
+ {
+   return (instance_ok ())
+     ? instance->do_get_quoting_function () : 0;
+ }
+ 
+ command_editor::dequoting_fcn
+ command_editor::get_dequoting_function (void)
+ {
+   return (instance_ok ())
+     ? instance->do_get_dequoting_function () : 0;
+ }
+ 
  string_vector
  command_editor::generate_filename_completions (const std::string& text)
  {
***************
*** 912,917 ****
--- 1055,1067 ----
      ? instance->do_filename_completion_desired (arg) : false;
  }
  
+ bool
+ command_editor::filename_quoting_desired (bool arg)
+ {
+   return (instance_ok ())
+     ? instance->do_filename_quoting_desired (arg) : false;
+ }
+ 
  // Return a string which will be printed as a prompt.  The string may
  // contain special characters which are decoded as follows: 
  //   
*** ./liboctave/oct-rl-edit.h.orig17    2007-10-02 16:38:49.699504882 +0200
--- ./liboctave/oct-rl-edit.h   2007-10-02 18:26:02.736747115 +0200
***************
*** 34,39 ****
--- 34,43 ----
  
  typedef char * (*rl_completer_fcn_ptr) (const char *, int);
  
+ typedef char * (*rl_quoting_fcn_ptr) (char *, int, char *);
+ 
+ typedef char * (*rl_dequoting_fcn_ptr) (char *, int);
+ 
  #ifdef __cplusplus
  extern "C"
  {
***************
*** 75,80 ****
--- 79,86 ----
  
  extern int octave_rl_filename_completion_desired (int);
  
+ extern int octave_rl_filename_quoting_desired (int);
+ 
  extern char *octave_rl_filename_completion_function (const char *, int);
  
  extern void octave_rl_set_basic_word_break_characters (const char *);
***************
*** 83,93 ****
--- 89,107 ----
  
  extern void octave_rl_set_basic_quote_characters (const char *);
  
+ extern void octave_rl_set_filename_quote_characters (const char *);
+ 
  extern void octave_rl_set_completion_append_character (char);
  
  extern void
  octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr);
  
+ extern void
+ octave_rl_set_quoting_function (rl_quoting_fcn_ptr);
+ 
+ extern void
+ octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr);
+ 
  extern void octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr);
  
  extern rl_startup_hook_fcn_ptr octave_rl_get_startup_hook (void);
*** ./liboctave/oct-rl-edit.c.orig17    2007-10-02 16:38:53.541310729 +0200
--- ./liboctave/oct-rl-edit.c   2007-10-02 18:54:38.774107968 +0200
***************
*** 196,201 ****
--- 196,209 ----
    return retval;
  }
  
+ int
+ octave_rl_filename_quoting_desired (int arg)
+ {
+   int retval = rl_filename_quoting_desired;
+   rl_filename_quoting_desired = arg;
+   return retval;
+ }
+ 
  char *
  octave_rl_filename_completion_function (const char *text, int state)
  {
***************
*** 227,232 ****
--- 235,248 ----
  }
  
  void
+ octave_rl_set_filename_quote_characters (const char *s)
+ {
+   OCTAVE_RL_SAVE_STRING (ss, s);
+ 
+   rl_filename_quote_characters = ss;
+ }
+ 
+ void
  octave_rl_set_completion_append_character (char c)
  {
    rl_completion_append_character = c;
***************
*** 239,244 ****
--- 255,272 ----
  }
  
  void
+ octave_rl_set_quoting_function (rl_quoting_fcn_ptr f)
+ {
+   rl_filename_quoting_function = f;
+ }
+ 
+ void
+ octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f)
+ {
+   rl_filename_dequoting_function = f;
+ }
+ 
+ void
  octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f)
  {
    rl_startup_hook = f;
*** ./src/input.cc.orig17       2007-10-02 16:38:07.992612516 +0200
--- ./src/input.cc      2007-10-02 18:48:15.555426507 +0200
***************
*** 474,481 ****
--- 474,494 ----
  
        name_list_len = name_list.length ();
  
+       command_editor::filename_completion_desired (true);
+ 
+       command_editor::filename_quoting_desired (true);
+ 
        file_name_list = command_editor::generate_filename_completions (text);
  
+       if (file_name_list.length())
+       std::cerr << "\n\n" << file_name_list(0) << "\n";
+       else
+       std::cerr << "\n\n<NONE>\n";
+ 
+       command_editor::filename_quoting_desired (false);
+ 
+       command_editor::filename_completion_desired (false);
+ 
        name_list.append (file_name_list);
  
        name_list_total_len = name_list.length ();
***************
*** 526,531 ****
--- 539,561 ----
    return retval;
  }
  
+ std::string
+ quoting_filename (const std::string &text)
+ {
+   std::cerr << "\nQuoting\n";
+   return std::string("\"") + text + std::string("\"");
+ }
+ 
+ std::string
+ dequoting_filename (const std::string &text, int quote)
+ {
+   std::cerr << "\nDequoting\n";
+   if (quote)
+     return text.substr(1, text.length() - 2);
+   else
+     return text;
+ }
+ 
  void
  initialize_command_input (void)
  {
***************
*** 545,551 ****
--- 575,587 ----
  
    command_editor::set_basic_quote_characters ("\"");
  
+   command_editor::set_filename_quote_characters ("\t ");
+ 
    command_editor::set_completion_function (generate_completion);
+ 
+   command_editor::set_quoting_function (quoting_filename);
+ 
+   command_editor::set_dequoting_function (dequoting_filename);
  }
  
  static bool

reply via email to

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