On 24/09/07 09:34 +0800, Dasn wrote:
>
>Hi, guys.
>I've posted on vim_use some days before:
>
>>$ vim -c "q" 'foo ~ foo'
>>$ vim -c "normal '0"
>>E20: Mark not set
>
>Filename contains '~' character which is around with path separators
>(i.e. ' ' and ',') has such problem.
>
>And the patch:
>
>Index: mark.c
>===================================================================
>RCS file: /cvsroot/vim/vim7/src/mark.c,v
>retrieving revision 1.13
>diff -u -p -r1.13 mark.c
>--- mark.c     10 May 2007 16:48:03 -0000      1.13
>+++ mark.c     24 Sep 2007 01:06:36 -0000
>@@ -499,7 +499,8 @@ getnextmark(startpos, dir, begin_line)
> fname2fnum(fm)
>     xfmark_T  *fm;
> {
>-    char_u    *p;
>+    char_u    *p; 
>+    char_u    *ep; /* escaped string pointer */
> 
>     if (fm->fname != NULL)
>     {
>@@ -507,7 +508,32 @@ fname2fnum(fm)
>        * First expand "~/" in the file name to the home directory.
>        * Try to shorten the file name.
>        */
>-      expand_env(fm->fname, NameBuff, MAXPATHL);
>+
>+      int escaped = FALSE;
>+      /* expand_env use ',' and ' ' as separators. 
>+       * if filename contains them, escape.
>+       */
>+      if (vim_strpbrk(fm->fname, ", ")) {
>+          ep = vim_strsave_escaped(fm->fname, ", ");
>+          escaped = True;
>+      }
>+      expand_env(ep, NameBuff, MAXPATHL);
>+
>+      /* Unescape ',' and ' ' should be save, since "\\, " are 
>+       * not valid in username
>+       */
>+      if ( escaped ) {
>+          
>+          char_u *uep = NameBuff;
>+          char_u *uend = uep + STRLEN(NameBuff);
>+
>+          while (*uep) {
>+              if ( uep[0] == '\\' && ( uep[1] == ' ' || uep[1] == ',' ) )
>+                  mch_memmove(uep, uep + 1, uend - uep);
>+              uep++;
>+          }
>+      }
>+
>       mch_dirname(IObuff, IOSIZE);
>       p = shorten_fname(NameBuff, IObuff);
> 

This crap aren't happy with users whose $HOME directory contain strings
like "\," or "\ ". The following patch is better:

Index: mark.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/mark.c,v
retrieving revision 1.13
diff -u -p -r1.13 mark.c
--- mark.c      10 May 2007 16:48:03 -0000      1.13
+++ mark.c      24 Sep 2007 13:56:44 -0000
@@ -507,7 +507,49 @@ fname2fnum(fm)
         * First expand "~/" in the file name to the home directory.
         * Try to shorten the file name.
         */
-       expand_env(fm->fname, NameBuff, MAXPATHL);
+
+       /* expand_env use ',' and ' ' as separators. 
+        * if filename contains them, escape.
+        */
+
+       int e_counter = 0;
+       char_u  *ep; /* escaped string pointer */
+       char_u  *tp1, *tp2; /* temp pointers */
+
+       tp2 = fm->fname;
+
+       while ((tp1 = vim_strpbrk(tp2, ",  ")) != NULL) {
+           e_counter++;
+           tp2 = ++tp1;
+       }
+
+       if (e_counter > 0) {
+           ep = vim_strsave_escaped(fm->fname, ", ");
+           expand_env(ep, NameBuff, MAXPATHL);
+       } else {
+           expand_env(fm->fname, NameBuff, MAXPATHL);
+       }
+
+       /* Unescape ',' and ' ' of the filename */
+       if (e_counter > 0) {
+           
+           char_u *begin, *end;
+
+           begin = NameBuff;
+           end = begin + STRLEN(NameBuff);
+
+           tp2 = end;
+           tp2--;
+
+           while (tp2 > begin && e_counter > 0) {
+               if ( tp2[0] == '\\' && ( tp2[1] == ' ' || tp2[1] == ',')) {
+                   mch_memmove(tp2, tp2 + sizeof(char_u),  end - tp2);
+                   e_counter--;
+               }
+               tp2--;
+           }
+       }
+
        mch_dirname(IObuff, IOSIZE);
        p = shorten_fname(NameBuff, IObuff);
 
-- 
Dasn


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui