updated for version 7.0-111
diff --git a/src/eval.c b/src/eval.c
index f2abba7..d32efaa 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -622,6 +622,7 @@
static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
static void f_sort __ARGS((typval_T *argvars, typval_T *rettv));
static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7146,6 +7147,7 @@
{"setreg", 2, 3, f_setreg},
{"settabwinvar", 4, 4, f_settabwinvar},
{"setwinvar", 3, 3, f_setwinvar},
+ {"shellescape", 1, 1, f_shellescape},
{"simplify", 1, 1, f_simplify},
{"sort", 1, 2, f_sort},
{"soundfold", 1, 1, f_soundfold},
@@ -14605,6 +14607,18 @@
}
/*
+ * "shellescape({string})" function
+ */
+ static void
+f_shellescape(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv;
+{
+ rettv->vval.v_string = vim_strsave_shellescape(get_tv_string(&argvars[0]));
+ rettv->v_type = VAR_STRING;
+}
+
+/*
* "simplify()" function
*/
static void
diff --git a/src/misc2.c b/src/misc2.c
index 5d80427..04f34e9 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -1229,6 +1229,94 @@
return escaped_string;
}
+#if defined(FEAT_EVAL) || defined(PROTO)
+/*
+ * Escape "string" for use as a shell argument with system().
+ * This uses single quotes, except when we know we need to use double qoutes
+ * (MS-DOS and MS-Windows without 'shellslash' set).
+ * Returns the result in allocated memory, NULL if we have run out.
+ */
+ char_u *
+vim_strsave_shellescape(string)
+ char_u *string;
+{
+ unsigned length;
+ char_u *p;
+ char_u *d;
+ char_u *escaped_string;
+
+ /* First count the number of extra bytes required. */
+ length = STRLEN(string) + 3; /* two quotes and the trailing NUL */
+ for (p = string; *p != NUL; mb_ptr_adv(p))
+ {
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ {
+ if (*p == '"')
+ ++length; /* " -> "" */
+ }
+ else
+# endif
+ if (*p == '\'')
+ length += 3; /* ' => '\'' */
+ }
+
+ /* Allocate memory for the result and fill it. */
+ escaped_string = alloc(length);
+ if (escaped_string != NULL)
+ {
+ d = escaped_string;
+
+ /* add opening quote */
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ *d++ = '"';
+ else
+# endif
+ *d++ = '\'';
+
+ for (p = string; *p != NUL; )
+ {
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ {
+ if (*p == '"')
+ {
+ *d++ = '"';
+ *d++ = '"';
+ ++p;
+ continue;
+ }
+ }
+ else
+# endif
+ if (*p == '\'')
+ {
+ *d++='\'';
+ *d++='\\';
+ *d++='\'';
+ *d++='\'';
+ ++p;
+ continue;
+ }
+
+ MB_COPY_CHAR(p, d);
+ }
+
+ /* add terminating quote and finish with a NUL */
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ *d++ = '"';
+ else
+# endif
+ *d++ = '\'';
+ *d = NUL;
+ }
+
+ return escaped_string;
+}
+#endif
+
/*
* Like vim_strsave(), but make all characters uppercase.
* This uses ASCII lower-to-upper case translation, language independent.
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index adee787..64637db 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -29,6 +29,7 @@
extern char_u *vim_strnsave __ARGS((char_u *string, int len));
extern char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
extern char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
+extern char_u *vim_strsave_shellescape __ARGS((char_u *string));
extern char_u *vim_strsave_up __ARGS((char_u *string));
extern char_u *vim_strnsave_up __ARGS((char_u *string, int len));
extern void vim_strup __ARGS((char_u *p));
diff --git a/src/version.c b/src/version.c
index d5ba905..f508b37 100644
--- a/src/version.c
+++ b/src/version.c
@@ -667,6 +667,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 111,
+/**/
110,
/**/
109,