updated for version 7.0011
diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak
index 23e6997..63a99f2 100644
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -852,13 +852,17 @@
 
 $(OUTDIR)/glbl_ime.obj:	$(OUTDIR) glbl_ime.cpp  dimm.h $(INCL)
 
+# $CFLAGS may contain backslashes and double quotes, escape them both.
+E0_CFLAGS = $(CFLAGS:\=\\)
+E_CFLAGS = $(E0_CFLAGS:"=\")
+
 auto/pathdef.c: auto
 	@echo creating auto/pathdef.c
 	@echo /* pathdef.c */ > auto\pathdef.c
 	@echo #include "vim.h" >> auto\pathdef.c
 	@echo char_u *default_vim_dir = (char_u *)"$(VIMRCLOC:\=\\)"; >> auto\pathdef.c
 	@echo char_u *default_vimruntime_dir = (char_u *)"$(VIMRUNTIMEDIR:\=\\)"; >> auto\pathdef.c
-	@echo char_u *all_cflags = (char_u *)"$(CC:\=\\) $(CFLAGS:\=\\)"; >> auto\pathdef.c
+	@echo char_u *all_cflags = (char_u *)"$(CC:\=\\) $(E_CFLAGS)"; >> auto\pathdef.c
 	@echo char_u *all_lflags = (char_u *)"$(link:\=\\) $(LINKARGS1:\=\\) $(LINKARGS2:\=\\)"; >> auto\pathdef.c
 	@echo char_u *compiled_user = (char_u *)"$(USERNAME)"; >> auto\pathdef.c
 	@echo char_u *compiled_sys = (char_u *)"$(USERDOMAIN)"; >> auto\pathdef.c
diff --git a/src/eval.c b/src/eval.c
index 21c10fd..b2955ff 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -279,6 +279,9 @@
 static void f_expand __ARGS((VAR argvars, VAR retvar));
 static void f_filereadable __ARGS((VAR argvars, VAR retvar));
 static void f_filewritable __ARGS((VAR argvars, VAR retvar));
+static void f_finddir __ARGS((VAR argvars, VAR retvar));
+static void f_findfile __ARGS((VAR argvars, VAR retvar));
+static void f_findfilendir __ARGS((VAR argvars, VAR retvar, int dir));
 static void f_fnamemodify __ARGS((VAR argvars, VAR retvar));
 static void f_foldclosed __ARGS((VAR argvars, VAR retvar));
 static void f_foldclosedend __ARGS((VAR argvars, VAR retvar));
@@ -2836,6 +2839,8 @@
     {"file_readable",	1, 1, f_filereadable},	/* obsolete */
     {"filereadable",	1, 1, f_filereadable},
     {"filewritable",	1, 1, f_filewritable},
+    {"finddir",		1, 3, f_finddir},
+    {"findfile",	1, 3, f_findfile},
     {"fnamemodify",	2, 2, f_fnamemodify},
     {"foldclosed",	1, 1, f_foldclosed},
     {"foldclosedend",	1, 1, f_foldclosedend},
@@ -2886,9 +2891,9 @@
     {"localtime",	0, 0, f_localtime},
     {"maparg",		1, 2, f_maparg},
     {"mapcheck",	1, 2, f_mapcheck},
-    {"match",		2, 3, f_match},
-    {"matchend",	2, 3, f_matchend},
-    {"matchstr",	2, 3, f_matchstr},
+    {"match",		2, 4, f_match},
+    {"matchend",	2, 4, f_matchend},
+    {"matchstr",	2, 4, f_matchstr},
     {"mode",		0, 0, f_mode},
     {"nextnonblank",	1, 1, f_nextnonblank},
     {"nr2char",		1, 1, f_nr2char},
@@ -4168,6 +4173,71 @@
 }
 
 /*
+ * "finddir({fname}[, {path}[, {count}]])" function
+ */
+    static void
+f_finddir(argvars, retvar)
+    VAR		argvars;
+    VAR		retvar;
+{
+    f_findfilendir(argvars, retvar, TRUE);
+}
+
+/*
+ * "findfile({fname}[, {path}[, {count}]])" function
+ */
+    static void
+f_findfile(argvars, retvar)
+    VAR		argvars;
+    VAR		retvar;
+{
+    f_findfilendir(argvars, retvar, FALSE);
+}
+
+    static void
+f_findfilendir(argvars, retvar, dir)
+    VAR		argvars;
+    VAR		retvar;
+    int		dir;
+{
+#ifdef FEAT_SEARCHPATH
+    char_u	*fname;
+    char_u	*fresult = NULL;
+    char_u	*path = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path;
+    char_u	*p;
+    char_u	pathbuf[NUMBUFLEN];
+    int		count = 1;
+    int		first = TRUE;
+
+    fname = get_var_string(&argvars[0]);
+
+    if (argvars[1].var_type != VAR_UNKNOWN)
+    {
+	p = get_var_string_buf(&argvars[1], pathbuf);
+	if (*p != NUL)
+	    path = p;
+
+	if (argvars[2].var_type != VAR_UNKNOWN)
+	    count = get_var_number(&argvars[2]);
+    }
+
+    do
+    {
+	vim_free(fresult);
+	fresult = find_file_in_path_option(first ? fname : NULL,
+					    first ? (int)STRLEN(fname) : 0,
+					    0, first, path, dir, NULL);
+	first = FALSE;
+    } while (--count > 0 && fresult != NULL);
+
+    retvar->var_val.var_string = fresult;
+#else
+    retvar->var_val.var_string = NULL;
+#endif
+    retvar->var_type = VAR_STRING;
+}
+
+/*
  * "fnamemodify({fname}, {mods})" function
  */
     static void
@@ -5858,17 +5928,20 @@
     int		type;
 {
     char_u	*str;
+    char_u	*expr;
     char_u	*pat;
     regmatch_T	regmatch;
     char_u	patbuf[NUMBUFLEN];
     char_u	*save_cpo;
     long	start = 0;
+    long	nth = 1;
+    int		match;
 
     /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
     save_cpo = p_cpo;
     p_cpo = (char_u *)"";
 
-    str = get_var_string(&argvars[0]);
+    expr = str = get_var_string(&argvars[0]);
     pat = get_var_string_buf(&argvars[1], patbuf);
 
     if (type == 2)
@@ -5887,13 +5960,30 @@
 	if (start > (long)STRLEN(str))
 	    goto theend;
 	str += start;
+
+	if (argvars[3].var_type != VAR_UNKNOWN)
+	    nth = get_var_number(&argvars[3]);
     }
 
     regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
     if (regmatch.regprog != NULL)
     {
 	regmatch.rm_ic = p_ic;
-	if (vim_regexec_nl(&regmatch, str, (colnr_T)0))
+
+	while (1)
+	{
+	    match = vim_regexec_nl(&regmatch, str, (colnr_T)0);
+	    if (!match || --nth <= 0)
+		break;
+	    /* Advance to just after the match. */
+#ifdef FEAT_MBYTE
+	    str = regmatch.startp[0] + mb_ptr2len_check(regmatch.startp[0]);
+#else
+	    str = regmatch.startp[0] + 1;
+#endif
+	}
+
+	if (match)
 	{
 	    if (type == 2)
 		retvar->var_val.var_string = vim_strnsave(regmatch.startp[0],
@@ -5906,7 +5996,7 @@
 		else
 		    retvar->var_val.var_number =
 					(varnumber_T)(regmatch.endp[0] - str);
-		retvar->var_val.var_number += start;
+		retvar->var_val.var_number += str - expr;
 	    }
 	}
 	vim_free(regmatch.regprog);
diff --git a/src/gui_mac.c b/src/gui_mac.c
index cf7da53..645e0b5 100644
--- a/src/gui_mac.c
+++ b/src/gui_mac.c
@@ -4251,12 +4251,12 @@
 {
 
     Handle	textOfClip;
+    int		flavor = 0;
 #ifdef USE_CARBONIZED
     Size	scrapSize;
     ScrapFlavorFlags	scrapFlags;
     ScrapRef    scrap = nil;
     OSStatus	error;
-    int		flavor;
 #else
     long	scrapOffset;
     long	scrapSize;
@@ -4271,7 +4271,6 @@
     if (error != noErr)
 	return;
 
-    flavor = 0;
     error = GetScrapFlavorFlags(scrap, VIMSCRAPFLAVOR, &scrapFlags);
     if (error == noErr)
     {
@@ -4315,15 +4314,16 @@
 #else
 	scrapSize = GetScrap(textOfClip, 'TEXT', &scrapOffset);
 #endif
+	scrapSize -= flavor;
 
 	if (flavor)
 	    type = **textOfClip;
 	else
 	    type = (strchr(*textOfClip, '\r') != NULL) ? MLINE : MCHAR;
 
-	tempclip = lalloc(scrapSize+1, TRUE);
-	STRNCPY(tempclip, *textOfClip + flavor, scrapSize - flavor);
-	tempclip[scrapSize - flavor] = 0;
+	tempclip = lalloc(scrapSize + 1, TRUE);
+	STRNCPY(tempclip, *textOfClip + flavor, scrapSize);
+	tempclip[scrapSize] = 0;
 
 	searchCR = (char *)tempclip;
 	while (searchCR != NULL)
diff --git a/src/misc2.c b/src/misc2.c
index 817f56d..dbc5166 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -3457,10 +3457,6 @@
 static int ff_path_in_stoplist __ARGS((char_u *, int, char_u **));
 #endif
 
-#ifdef FEAT_SEARCHPATH
-static char_u *find_file_in_path_option __ARGS((char_u *ptr, int len, int options, int first, char_u *path_option, int need_dir, char_u *rel_fname));
-#endif
-
 #if 0
 /*
  * if someone likes findfirst/findnext, here are the functions
@@ -4860,7 +4856,7 @@
 							     TRUE, rel_fname);
 }
 
-    static char_u *
+    char_u *
 find_file_in_path_option(ptr, len, options, first, path_option, need_dir, rel_fname)
     char_u	*ptr;		/* file name */
     int		len;		/* length of file name */
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index a04154a..6419740 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -82,6 +82,7 @@
 void vim_findfile_free_visited __ARGS((void *search_ctx));
 char_u *find_file_in_path __ARGS((char_u *ptr, int len, int options, int first, char_u *rel_fname));
 char_u *find_directory_in_path __ARGS((char_u *ptr, int len, int options, char_u *rel_fname));
+char_u *find_file_in_path_option __ARGS((char_u *ptr, int len, int options, int first, char_u *path_option, int need_dir, char_u *rel_fname));
 int vim_chdir __ARGS((char_u *new_dir));
 int get_user_name __ARGS((char_u *buf, int len));
 void sort_strings __ARGS((char_u **files, int count));
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index b09db81..57de3ab 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -32,7 +32,7 @@
 $(SCRIPTS) $(SCRIPTS_GUI): $(VIMPROG)
 
 clean:
-	-rm -rf *.out *.rej *.orig test.log tiny.vim small.vim mbyte.vim test.ok X* viminfo
+	-rm -rf *.out *.failed *.rej *.orig test.log tiny.vim small.vim mbyte.vim test.ok X* viminfo
 
 test1.out: test1.in
 	-rm -f $*.failed tiny.vim small.vim mbyte.vim test.ok X* viminfo
diff --git a/src/testdir/test37.in b/src/testdir/test37.in
index daaea32..8ca1125 100644
--- a/src/testdir/test37.in
+++ b/src/testdir/test37.in
@@ -1,4 +1,4 @@
-Test for 'scrollbind'. <eralston@computer.org>
+Test for 'scrollbind'. <eralston@computer.org>   Do not add a line below!
 STARTTEST
 :so small.vim
 :set noscrollbind
diff --git a/src/testdir/test44.in b/src/testdir/test44.in
index d90a962..2748e3d 100644
--- a/src/testdir/test44.in
+++ b/src/testdir/test44.in
@@ -1,4 +1,5 @@
 Tests for regexp with multi-byte encoding and various magic settings.
+Test matchstr() with a count and multi-byte chars.
 
 STARTTEST
 :so mbyte.vim
@@ -21,6 +22,12 @@
 x:" find word by change of word class
 /ち\<カヨ\>は
 x:?^1?,$w! test.out
+:e! test.out
+G:put =matchstr(\"אבגד\", \".\", 0, 2) " ב
+:put =matchstr(\"אבגד\", \"..\", 0, 2) " בג
+:put =matchstr(\"אבגד\", \".\", 0, 0) " א
+:put =matchstr(\"אבגד\", \".\", 4, -1) " ג
+:w!
 :qa!
 ENDTEST
 
diff --git a/src/testdir/test44.ok b/src/testdir/test44.ok
index af85076..86f79d4 100644
--- a/src/testdir/test44.ok
+++ b/src/testdir/test44.ok
@@ -9,3 +9,7 @@
 9 หม่x อx
 a อมx หx
 b カヨは

+בג


diff --git a/src/testdir/test53.in b/src/testdir/test53.in
index d2c0ad5..29f7a70 100644
--- a/src/testdir/test53.in
+++ b/src/testdir/test53.in
@@ -1,5 +1,9 @@
 Tests for string text objects. vim: set ft=vim :
 
+Note that the end-of-line moves the cursor to the next test line.
+
+Also test match() and matchstr()
+
 STARTTEST
 :so small.vim
 /^start:/
@@ -11,6 +15,12 @@
 :set quoteescape=+*-
 di`
 $F"va"oha"i"rz
+k:put =matchstr(\"abcd\", \".\", 0, 2) " b
+:put =matchstr(\"abcd\", \"..\", 0, 2) " bc
+:put =matchstr(\"abcd\", \".\", 2, 0) " c (zero and negative -> first match)
+:put =matchstr(\"abcd\", \".\", 0, -1) " a
+:put =match(\"abcd\", \".\", 0, 5) " -1
+:put =match(\"abcd\", \".\", 0, -1) " 0
 :/^start:/,/^end:/wq! test.out
 ENDTEST
 
diff --git a/src/testdir/test53.ok b/src/testdir/test53.ok
index 577bad1..7cbd6e7 100644
--- a/src/testdir/test53.ok
+++ b/src/testdir/test53.ok
@@ -5,4 +5,10 @@
 "'" 'blah'yyyyy'buh'
 bla `` b`la
 voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd
+b
+bc
+c
+a
+-1
+0
 end: