]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.397 v7.3.397
authorBram Moolenaar <Bram@vim.org>
Tue, 10 Jan 2012 15:28:45 +0000 (16:28 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 10 Jan 2012 15:28:45 +0000 (16:28 +0100)
Problem:    ":helpgrep" does not work properly when 'encoding' is not utf-8 or
            latin1.
Solution:   Convert non-ascii lines to 'encoding'. (Yasuhiro Matsumoto)

src/misc2.c
src/proto/misc2.pro
src/quickfix.c
src/spell.c
src/version.c

index 784e4889f1e097505ec92865567c7152d0ac2c8d..96c3a3638a68adf6f3e1bc9f78ef4d715c94ab0f 100644 (file)
@@ -6541,3 +6541,23 @@ put_time(fd, the_time)
 #endif
 
 #endif
+
+#if (defined(FEAT_MBYTE) && defined(FEAT_QUICKFIX)) \
+       || defined(FEAT_SPELL) || defined(PROTO)
+/*
+ * Return TRUE if string "s" contains a non-ASCII character (128 or higher).
+ * When "s" is NULL FALSE is returned.
+ */
+    int
+has_non_ascii(s)
+    char_u     *s;
+{
+    char_u     *p;
+
+    if (s != NULL)
+       for (p = s; *p != NUL; ++p)
+           if (*p >= 128)
+               return TRUE;
+    return FALSE;
+}
+#endif
index d8d3cc374b0221634e1c90de3cdf2f60bda310c3..16c591831be69d816c79fb9a66a5c60b62ef85a7 100644 (file)
@@ -116,4 +116,5 @@ time_t get8ctime __ARGS((FILE *fd));
 char_u *read_string __ARGS((FILE *fd, int cnt));
 int put_bytes __ARGS((FILE *fd, long_u nr, int len));
 void put_time __ARGS((FILE *fd, time_t the_time));
+int has_non_ascii __ARGS((char_u *s));
 /* vim: set ft=c : */
index a2935bea97460646c4cc62c3d43637ce8a1dc295..794c49380d79c521e64645b3fd516e464ee974da 100644 (file)
@@ -3914,6 +3914,16 @@ ex_helpgrep(eap)
     regmatch.rm_ic = FALSE;
     if (regmatch.regprog != NULL)
     {
+#ifdef FEAT_MBYTE
+       vimconv_T vc;
+
+       /* Help files are in utf-8 or latin1, convert lines when 'encoding'
+        * differs. */
+       vc.vc_type = CONV_NONE;
+       if (!enc_utf8)
+           convert_setup(&vc, (char_u *)"utf-8", p_enc);
+#endif
+
        /* create a new quickfix list */
        qf_new_list(qi, *eap->cmdlinep);
 
@@ -3948,21 +3958,33 @@ ex_helpgrep(eap)
                        lnum = 1;
                        while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
                        {
-                           if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
+                           char_u    *line = IObuff;
+#ifdef FEAT_MBYTE
+                           /* Convert a line if 'encoding' is not utf-8 and
+                            * the line contains a non-ASCII character. */
+                           if (vc.vc_type != CONV_NONE
+                                                  && has_non_ascii(IObuff)) {
+                               line = string_convert(&vc, IObuff, NULL);
+                               if (line == NULL)
+                                   line = IObuff;
+                           }
+#endif
+
+                           if (vim_regexec(&regmatch, line, (colnr_T)0))
                            {
-                               int     l = (int)STRLEN(IObuff);
+                               int     l = (int)STRLEN(line);
 
                                /* remove trailing CR, LF, spaces, etc. */
-                               while (l > 0 && IObuff[l - 1] <= ' ')
-                                    IObuff[--l] = NUL;
+                               while (l > 0 && line[l - 1] <= ' ')
+                                    line[--l] = NUL;
 
                                if (qf_add_entry(qi, &prevp,
                                            NULL,       /* dir */
                                            fnames[fi],
                                            0,
-                                           IObuff,
+                                           line,
                                            lnum,
-                                           (int)(regmatch.startp[0] - IObuff)
+                                           (int)(regmatch.startp[0] - line)
                                                                + 1, /* col */
                                            FALSE,      /* vis_col */
                                            NULL,       /* search pattern */
@@ -3972,9 +3994,17 @@ ex_helpgrep(eap)
                                            ) == FAIL)
                                {
                                    got_int = TRUE;
+#ifdef FEAT_MBYTE
+                                   if (line != IObuff)
+                                       vim_free(line);
+#endif
                                    break;
                                }
                            }
+#ifdef FEAT_MBYTE
+                           if (line != IObuff)
+                               vim_free(line);
+#endif
                            ++lnum;
                            line_breakcheck();
                        }
@@ -3984,7 +4014,12 @@ ex_helpgrep(eap)
                FreeWild(fcount, fnames);
            }
        }
+
        vim_free(regmatch.regprog);
+#ifdef FEAT_MBYTE
+       if (vc.vc_type != CONV_NONE)
+           convert_setup(&vc, NULL, NULL);
+#endif
 
        qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
        qi->qf_lists[qi->qf_curlist].qf_ptr =
index 464d4d0d18b6f5fff0244428ebeec0f9e26aa50d..f7ec0c735f154aa561587087fa86ad1fe3d04c95 100644 (file)
@@ -5020,7 +5020,6 @@ static void aff_check_string __ARGS((char_u *spinval, char_u *affval, char *name
 static int str_equal __ARGS((char_u *s1, char_u        *s2));
 static void add_fromto __ARGS((spellinfo_T *spin, garray_T *gap, char_u        *from, char_u *to));
 static int sal_to_bool __ARGS((char_u *s));
-static int has_non_ascii __ARGS((char_u *s));
 static void spell_free_aff __ARGS((afffile_T *aff));
 static int spell_read_dic __ARGS((spellinfo_T *spin, char_u *fname, afffile_T *affile));
 static int get_affix_flags __ARGS((afffile_T *affile, char_u *afflist));
@@ -6484,23 +6483,6 @@ sal_to_bool(s)
     return STRCMP(s, "1") == 0 || STRCMP(s, "true") == 0;
 }
 
-/*
- * Return TRUE if string "s" contains a non-ASCII character (128 or higher).
- * When "s" is NULL FALSE is returned.
- */
-    static int
-has_non_ascii(s)
-    char_u     *s;
-{
-    char_u     *p;
-
-    if (s != NULL)
-       for (p = s; *p != NUL; ++p)
-           if (*p >= 128)
-               return TRUE;
-    return FALSE;
-}
-
 /*
  * Free the structure filled by spell_read_aff().
  */
index e0d926def207736a276348df1c9e6fb720eb54c3..777c15ec6cd17baff013ae487254bf092a53d31d 100644 (file)
@@ -714,6 +714,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    397,
 /**/
     396,
 /**/