On Aug 21, 12:11 am, Ingo Karkat <[email protected]> wrote:
> On 20-Aug-2011 17:38, Hari G wrote:
>
> > The attached patch adds support for using file:// URIs in the command
> > line in most places where fiile system paths are used. Recently this
> > was asked for also.
> > (http://groups.google.com/group/vim_dev/browse_thread/thread/0ff59642a...)
>
> Does this handle percent-escaping (e.g. %20 -> <Space>) and the various ways 
> of
> specifying Windows drive letters (e.g. file:///c|/WINDOWS/clock.avi)? 
> Cp.http://en.wikipedia.org/wiki/File:URL
>
It didn't, but I've added support for URL-encoded characters in the
following modified patch. I don't know how many times the exotic
representations of file system paths as mentioned above occur or are
used, those are not supported in this.

> Why doesn't the file:// support of the netrw plugin suffice?
>
Netrw doesn't work for me for URLs like "file:///d:/foo.txt" or
"file://localhost/d:/foo.txt", (on Windows) probably because of an
extra slash in the final URL.

This is certainly not a replacement or anything, for the functionality
in netrw though :)

/harig
****************************************************************************
diff -r d3fd21498333 -r d0b41111b4ed src/ex_docmd.c
--- a/src/ex_docmd.c    Wed Aug 10 22:55:39 2011 +0530
+++ b/src/ex_docmd.c    Sun Aug 21 17:09:37 2011 +0530
@@ -2605,8 +2605,9 @@

     if (ea.argt & XFILE)
     {
-       if (expand_filename(&ea, cmdlinep, &errormsg) == FAIL)
-           goto doend;
+       if (strstr(ea.arg, "file://") == NULL)
+           if (expand_filename(&ea, cmdlinep, &errormsg) == FAIL)
+               goto doend;
     }

 #ifdef FEAT_LISTCMDS
@@ -4382,8 +4383,8 @@
        /*
         * Try to find a match at this position.
         */
-       repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum),
-                                                        errormsgp, &escaped);
+       repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum),
errormsgp, &escaped);
+
        if (*errormsgp != NULL)         /* error detected */
            return FAIL;
        if (repl == NULL)               /* no match found */
diff -r d3fd21498333 -r d0b41111b4ed src/window.c
--- a/src/window.c      Wed Aug 10 22:55:39 2011 +0530
+++ b/src/window.c      Sun Aug 21 17:09:37 2011 +0530
@@ -6142,7 +6142,67 @@
     *buf = NUL;
     if (fname == NULL)
        return FAIL;
-
+    /* Convert file:// URLs to regular file system paths */
+    if((STRNCMP(fname, "file://", 7) ==  0)
+# ifdef BACKSLASH_IN_FILENAME
+           || (STRNCMP(fname, "file:\\\\", 7) ==  0)
+# endif
+      )
+    {
+       int start = 7;
+       char_u *tmp;
+       int i = 0;
+       if(fname[7] == '/'
+# ifdef BACKSLASH_IN_FILENAME
+               || fname[7] == '\\'
+# endif
+         )
+       {
+#ifdef MSWIN
+           /* remove the f/b slash because \d:\foo won't resolve */
+           start = 8;
+#else
+           /* file:///var/foo -> /var/foo */
+           start = 7;
+#endif
+       }
+       if((STRNCMP(fname, "file://localhost/", 17) == 0)
+# ifdef BACKSLASH_IN_FILENAME
+               || (STRNCMP(fname, "file:\\\\localhost\\", 17) == 0)
+# endif
+         )
+       {
+#ifdef MSWIN
+           start = 17;
+#else
+           start = 16;
+#endif
+       }
+       tmp = alloc((unsigned)(STRLEN(fname) - start + 1));
+       while(fname[start] != NUL)
+       {
+           char_u *htmp = 0;
+           long n;
+           htmp = fname + start;
+           start++;
+           if(*htmp == '%')
+           {
+               char_u xstr[5];
+               xstr[0] = '0';
+               xstr[1] = 'x';
+               xstr[2] = fname[start++];
+               xstr[3] = fname[start++];
+               xstr[4] = NUL;
+               vim_str2nr(xstr, NULL, NULL, FALSE, TRUE, &n, NULL);
+               tmp[i++] = (char_u) n;
+           }
+           else
+               tmp[i++] = htmp[0];
+       }
+       tmp[i] = NUL;
+       STRCPY(fname,tmp);
+       vim_free(tmp);
+    }
     url = path_with_url(fname);
     if (!url)
        retval = mch_FullName(fname, buf, len, force);
****************************************************************************

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui