home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.0 / 7.0.111 < prev    next >
Encoding:
Internet Message Format  |  2006-10-02  |  10.2 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.0.111
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.0.111
  11. Problem:    The gzip plugin can't handle filenames with single quotes.
  12. Solution:   Add and use the shellescape() function. (partly by Alexey Froloff)
  13. Files:      runtime/autoload/gzip.vim, runtime/doc/eval.txt, src/eval.c,
  14.             src/mbyte.c, src/misc2.c, src/proto/misc2.pro
  15.  
  16.  
  17. *** ../vim-7.0.110/runtime/autoload/gzip.vim    Tue Aug  8 19:55:06 2006
  18. --- runtime/autoload/gzip.vim    Tue Oct  3 14:39:29 2006
  19. ***************
  20. *** 1,6 ****
  21.   " Vim autoload file for editing compressed files.
  22.   " Maintainer: Bram Moolenaar <Bram@vim.org>
  23. ! " Last Change: 2006 Jul 19
  24.   
  25.   " These functions are used by the gzip plugin.
  26.   
  27. --- 1,6 ----
  28.   " Vim autoload file for editing compressed files.
  29.   " Maintainer: Bram Moolenaar <Bram@vim.org>
  30. ! " Last Change: 2006 Oct 03
  31.   
  32.   " These functions are used by the gzip plugin.
  33.   
  34. ***************
  35. *** 68,76 ****
  36.     let tmp = tempname()
  37.     let tmpe = tmp . "." . expand("<afile>:e")
  38.     " write the just read lines to a temp file "'[,']w tmp.gz"
  39. !   execute "silent '[,']w " . tmpe
  40.     " uncompress the temp file: call system("gzip -dn tmp.gz")
  41. !   call system(a:cmd . " " . tmpe)
  42.     if !filereadable(tmp)
  43.       " uncompress didn't work!  Keep the compressed file then.
  44.       echoerr "Error: Could not read uncompressed file"
  45. --- 68,76 ----
  46.     let tmp = tempname()
  47.     let tmpe = tmp . "." . expand("<afile>:e")
  48.     " write the just read lines to a temp file "'[,']w tmp.gz"
  49. !   execute "silent '[,']w " . escape(tmpe, ' ')
  50.     " uncompress the temp file: call system("gzip -dn tmp.gz")
  51. !   call system(a:cmd . " " . s:escape(tmpe))
  52.     if !filereadable(tmp)
  53.       " uncompress didn't work!  Keep the compressed file then.
  54.       echoerr "Error: Could not read uncompressed file"
  55. ***************
  56. *** 127,135 ****
  57.       let nmt = s:tempname(nm)
  58.       if rename(nm, nmt) == 0
  59.         if exists("b:gzip_comp_arg")
  60. !     call system(a:cmd . " " . b:gzip_comp_arg . " '" . nmt . "'")
  61.         else
  62. !     call system(a:cmd . " '" . nmt . "'")
  63.         endif
  64.         call rename(nmt . "." . expand("<afile>:e"), nm)
  65.       endif
  66. --- 127,135 ----
  67.       let nmt = s:tempname(nm)
  68.       if rename(nm, nmt) == 0
  69.         if exists("b:gzip_comp_arg")
  70. !     call system(a:cmd . " " . b:gzip_comp_arg . " " . s:escape(nmt))
  71.         else
  72. !     call system(a:cmd . " " . s:escape(nmt))
  73.         endif
  74.         call rename(nmt . "." . expand("<afile>:e"), nm)
  75.       endif
  76. ***************
  77. *** 154,163 ****
  78.       if rename(nm, nmte) == 0
  79.         if &patchmode != "" && getfsize(nm . &patchmode) == -1
  80.       " Create patchmode file by creating the decompressed file new
  81. !     call system(a:cmd . " -c " . nmte . " > " . nmt)
  82.       call rename(nmte, nm . &patchmode)
  83.         else
  84. !     call system(a:cmd . " " . nmte)
  85.         endif
  86.         call rename(nmt, nm)
  87.       endif
  88. --- 154,163 ----
  89.       if rename(nm, nmte) == 0
  90.         if &patchmode != "" && getfsize(nm . &patchmode) == -1
  91.       " Create patchmode file by creating the decompressed file new
  92. !     call system(a:cmd . " -c " . s:escape(nmte) . " > " . s:escape(nmt))
  93.       call rename(nmte, nm . &patchmode)
  94.         else
  95. !     call system(a:cmd . " " . s:escape(nmte))
  96.         endif
  97.         call rename(nmt, nm)
  98.       endif
  99. ***************
  100. *** 173,178 ****
  101. --- 173,186 ----
  102.       return fn
  103.     endif
  104.     return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
  105. + endfun
  106. + fun s:escape(name)
  107. +   " shellescape() was added by patch 7.0.111
  108. +   if v:version > 700 || (v:version == 700 && has('patch111'))
  109. +     return shellescape(a:name)
  110. +   endif
  111. +   return "'" . a:name . "'"
  112.   endfun
  113.   
  114.   " vim: set sw=2 :
  115. *** ../vim-7.0.110/runtime/doc/eval.txt    Sun May  7 17:08:32 2006
  116. --- runtime/doc/eval.txt    Fri Sep 22 19:43:18 2006
  117. ***************
  118. *** 1,4 ****
  119. ! *eval.txt*      For Vim version 7.0.  Last change: 2006 May 06
  120.   
  121.   
  122.             VIM REFERENCE MANUAL    by Bram Moolenaar
  123. --- 1,4 ----
  124. ! *eval.txt*      For Vim version 7.0.  Last change: 2006 Sep 22
  125.   
  126.   
  127.             VIM REFERENCE MANUAL    by Bram Moolenaar
  128. ***************
  129. *** 1709,1714 ****
  130. --- 1715,1722 ----
  131.   settabwinvar( {tabnr}, {winnr}, {varname}, {val})    set {varname} in window
  132.                       {winnr} in tab page {tabnr} to {val}
  133.   setwinvar( {nr}, {varname}, {val})    set {varname} in window {nr} to {val}
  134. + shellescape( {string})        String    escape {string} for use as shell
  135. +                     command argument
  136.   simplify( {filename})        String    simplify filename as much as possible
  137.   sort( {list} [, {func}])    List    sort {list}, using {func} to compare
  138.   soundfold( {word})        String    sound-fold {word}
  139. ***************
  140. *** 4434,4439 ****
  141. --- 4457,4477 ----
  142.               :call setwinvar(1, "&list", 0)
  143.               :call setwinvar(2, "myvar", "foobar")
  144.   
  145. + shellescape({string})                    *shellescape()*
  146. +         Escape {string} for use as shell command argument.
  147. +         On MS-Windows and MS-DOS, when 'shellslash' is not set, it
  148. +         will enclose {string} double quotes and double all double
  149. +         quotes within {string}.
  150. +         For other systems, it will enclose {string} in single quotes
  151. +         and replace all "'" with "'\''".
  152. +         Example: >
  153. +             :echo shellescape('c:\program files\vim')
  154. + <        results in:
  155. +             "c:\program files\vim" ~
  156. +         Example usage: >
  157. +             :call system("chmod +x -- " . shellescape(expand("%")))
  158.   simplify({filename})                    *simplify()*
  159.           Simplify the file name as much as possible without changing
  160.           the meaning.  Shortcuts (on MS-Windows) or symbolic links (on
  161. *** ../vim-7.0.110/src/eval.c    Sat Sep  9 12:05:39 2006
  162. --- src/eval.c    Thu Sep 14 17:44:41 2006
  163. ***************
  164. *** 622,627 ****
  165. --- 622,628 ----
  166.   static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
  167.   static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
  168.   static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
  169. + static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
  170.   static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
  171.   static void f_sort __ARGS((typval_T *argvars, typval_T *rettv));
  172.   static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
  173. ***************
  174. *** 7146,7151 ****
  175. --- 7147,7153 ----
  176.       {"setreg",        2, 3, f_setreg},
  177.       {"settabwinvar",    4, 4, f_settabwinvar},
  178.       {"setwinvar",    3, 3, f_setwinvar},
  179. +     {"shellescape",    1, 1, f_shellescape},
  180.       {"simplify",    1, 1, f_simplify},
  181.       {"sort",        1, 2, f_sort},
  182.       {"soundfold",    1, 1, f_soundfold},
  183. ***************
  184. *** 14602,14607 ****
  185. --- 14604,14621 ----
  186.       }
  187.   #endif
  188.       }
  189. + }
  190. + /*
  191. +  * "shellescape({string})" function
  192. +  */
  193. +     static void
  194. + f_shellescape(argvars, rettv)
  195. +     typval_T    *argvars;
  196. +     typval_T    *rettv;
  197. + {
  198. +     rettv->vval.v_string = vim_strsave_shellescape(get_tv_string(&argvars[0]));
  199. +     rettv->v_type = VAR_STRING;
  200.   }
  201.   
  202.   /*
  203. *** ../vim-7.0.110/src/misc2.c    Thu May  4 23:50:56 2006
  204. --- src/misc2.c    Tue Sep 26 23:13:57 2006
  205. ***************
  206. *** 1229,1234 ****
  207. --- 1229,1322 ----
  208.       return escaped_string;
  209.   }
  210.   
  211. + #if defined(FEAT_EVAL) || defined(PROTO)
  212. + /*
  213. +  * Escape "string" for use as a shell argument with system().
  214. +  * This uses single quotes, except when we know we need to use double qoutes
  215. +  * (MS-DOS and MS-Windows without 'shellslash' set).
  216. +  * Returns the result in allocated memory, NULL if we have run out.
  217. +  */
  218. +     char_u *
  219. + vim_strsave_shellescape(string)
  220. +     char_u    *string;
  221. + {
  222. +     unsigned    length;
  223. +     char_u    *p;
  224. +     char_u    *d;
  225. +     char_u    *escaped_string;
  226. +     /* First count the number of extra bytes required. */
  227. +     length = STRLEN(string) + 3;    /* two quotes and the trailing NUL */
  228. +     for (p = string; *p != NUL; mb_ptr_adv(p))
  229. +     {
  230. + # if defined(WIN32) || defined(WIN16) || defined(DOS)
  231. +     if (!p_ssl)
  232. +     {
  233. +         if (*p == '"')
  234. +         ++length;        /* " -> "" */
  235. +     }
  236. +     else
  237. + # endif
  238. +     if (*p == '\'')
  239. +         length += 3;        /* ' => '\'' */
  240. +     }
  241. +     /* Allocate memory for the result and fill it. */
  242. +     escaped_string = alloc(length);
  243. +     if (escaped_string != NULL)
  244. +     {
  245. +     d = escaped_string;
  246. +     /* add opening quote */
  247. + # if defined(WIN32) || defined(WIN16) || defined(DOS)
  248. +     if (!p_ssl)
  249. +         *d++ = '"';
  250. +     else
  251. + # endif
  252. +         *d++ = '\'';
  253. +     for (p = string; *p != NUL; )
  254. +     {
  255. + # if defined(WIN32) || defined(WIN16) || defined(DOS)
  256. +         if (!p_ssl)
  257. +         {
  258. +         if (*p == '"')
  259. +         {
  260. +             *d++ = '"';
  261. +             *d++ = '"';
  262. +             ++p;
  263. +             continue;
  264. +         }
  265. +         }
  266. +         else
  267. + # endif
  268. +         if (*p == '\'')
  269. +         {
  270. +         *d++='\'';
  271. +         *d++='\\';
  272. +         *d++='\'';
  273. +         *d++='\'';
  274. +         ++p;
  275. +         continue;
  276. +         }
  277. +         MB_COPY_CHAR(p, d);
  278. +     }
  279. +     /* add terminating quote and finish with a NUL */
  280. + # if defined(WIN32) || defined(WIN16) || defined(DOS)
  281. +     if (!p_ssl)
  282. +         *d++ = '"';
  283. +     else
  284. + # endif
  285. +         *d++ = '\'';
  286. +     *d = NUL;
  287. +     }
  288. +     return escaped_string;
  289. + }
  290. + #endif
  291.   /*
  292.    * Like vim_strsave(), but make all characters uppercase.
  293.    * This uses ASCII lower-to-upper case translation, language independent.
  294. *** ../vim-7.0.110/src/proto/misc2.pro    Fri Mar 24 23:42:55 2006
  295. --- src/proto/misc2.pro    Thu Sep 14 18:28:43 2006
  296. ***************
  297. *** 29,34 ****
  298. --- 29,35 ----
  299.   extern char_u *vim_strnsave __ARGS((char_u *string, int len));
  300.   extern char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
  301.   extern char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
  302. + extern char_u *vim_strsave_shellescape __ARGS((char_u *string));
  303.   extern char_u *vim_strsave_up __ARGS((char_u *string));
  304.   extern char_u *vim_strnsave_up __ARGS((char_u *string, int len));
  305.   extern void vim_strup __ARGS((char_u *p));
  306. *** ../vim-7.0.110/src/version.c    Tue Sep 26 13:49:41 2006
  307. --- src/version.c    Tue Oct  3 14:36:40 2006
  308. ***************
  309. *** 668,669 ****
  310. --- 668,671 ----
  311.   {   /* Add new patch number below this line */
  312. + /**/
  313. +     111,
  314.   /**/
  315.  
  316. -- 
  317. The only way the average employee can speak to an executive is by taking a
  318. second job as a golf caddie.
  319.                 (Scott Adams - The Dilbert principle)
  320.  
  321.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  322. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  323. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  324.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  325.