Karsten Hopp e0388c
To: vim_dev@googlegroups.com
Karsten Hopp e0388c
Subject: Patch 7.3.397
Karsten Hopp e0388c
Fcc: outbox
Karsten Hopp e0388c
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp e0388c
Mime-Version: 1.0
Karsten Hopp e0388c
Content-Type: text/plain; charset=UTF-8
Karsten Hopp e0388c
Content-Transfer-Encoding: 8bit
Karsten Hopp e0388c
------------
Karsten Hopp e0388c
Karsten Hopp e0388c
Patch 7.3.397
Karsten Hopp e0388c
Problem:    ":helpgrep" does not work properly when 'encoding' is not utf-8 or
Karsten Hopp e0388c
	    latin1.
Karsten Hopp e0388c
Solution:   Convert non-ascii lines to 'encoding'. (Yasuhiro Matsumoto)
Karsten Hopp e0388c
Files:	    src/quickfix.c, src/spell.c, src/misc2.c, src/proto/misc2.pro
Karsten Hopp e0388c
Karsten Hopp e0388c
Karsten Hopp e0388c
*** ../vim-7.3.396/src/quickfix.c	2011-12-30 15:01:55.000000000 +0100
Karsten Hopp e0388c
--- src/quickfix.c	2012-01-10 16:18:51.000000000 +0100
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 3914,3919 ****
Karsten Hopp e0388c
--- 3914,3929 ----
Karsten Hopp e0388c
      regmatch.rm_ic = FALSE;
Karsten Hopp e0388c
      if (regmatch.regprog != NULL)
Karsten Hopp e0388c
      {
Karsten Hopp e0388c
+ #ifdef FEAT_MBYTE
Karsten Hopp e0388c
+ 	vimconv_T vc;
Karsten Hopp e0388c
+ 
Karsten Hopp e0388c
+ 	/* Help files are in utf-8 or latin1, convert lines when 'encoding'
Karsten Hopp e0388c
+ 	 * differs. */
Karsten Hopp e0388c
+ 	vc.vc_type = CONV_NONE;
Karsten Hopp e0388c
+ 	if (!enc_utf8)
Karsten Hopp e0388c
+ 	    convert_setup(&vc, (char_u *)"utf-8", p_enc);
Karsten Hopp e0388c
+ #endif
Karsten Hopp e0388c
+ 
Karsten Hopp e0388c
  	/* create a new quickfix list */
Karsten Hopp e0388c
  	qf_new_list(qi, *eap->cmdlinep);
Karsten Hopp e0388c
  
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 3948,3968 ****
Karsten Hopp e0388c
  			lnum = 1;
Karsten Hopp e0388c
  			while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
Karsten Hopp e0388c
  			{
Karsten Hopp e0388c
! 			    if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
Karsten Hopp e0388c
  			    {
Karsten Hopp e0388c
! 				int	l = (int)STRLEN(IObuff);
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  				/* remove trailing CR, LF, spaces, etc. */
Karsten Hopp e0388c
! 				while (l > 0 && IObuff[l - 1] <= ' ')
Karsten Hopp e0388c
! 				     IObuff[--l] = NUL;
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  				if (qf_add_entry(qi, &prevp,
Karsten Hopp e0388c
  					    NULL,	/* dir */
Karsten Hopp e0388c
  					    fnames[fi],
Karsten Hopp e0388c
  					    0,
Karsten Hopp e0388c
! 					    IObuff,
Karsten Hopp e0388c
  					    lnum,
Karsten Hopp e0388c
! 					    (int)(regmatch.startp[0] - IObuff)
Karsten Hopp e0388c
  								+ 1, /* col */
Karsten Hopp e0388c
  					    FALSE,	/* vis_col */
Karsten Hopp e0388c
  					    NULL,	/* search pattern */
Karsten Hopp e0388c
--- 3958,3990 ----
Karsten Hopp e0388c
  			lnum = 1;
Karsten Hopp e0388c
  			while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
Karsten Hopp e0388c
  			{
Karsten Hopp e0388c
! 			    char_u    *line = IObuff;
Karsten Hopp e0388c
! #ifdef FEAT_MBYTE
Karsten Hopp e0388c
! 			    /* Convert a line if 'encoding' is not utf-8 and
Karsten Hopp e0388c
! 			     * the line contains a non-ASCII character. */
Karsten Hopp e0388c
! 			    if (vc.vc_type != CONV_NONE
Karsten Hopp e0388c
! 						   && has_non_ascii(IObuff)) {
Karsten Hopp e0388c
! 				line = string_convert(&vc, IObuff, NULL);
Karsten Hopp e0388c
! 				if (line == NULL)
Karsten Hopp e0388c
! 				    line = IObuff;
Karsten Hopp e0388c
! 			    }
Karsten Hopp e0388c
! #endif
Karsten Hopp e0388c
! 
Karsten Hopp e0388c
! 			    if (vim_regexec(&regmatch, line, (colnr_T)0))
Karsten Hopp e0388c
  			    {
Karsten Hopp e0388c
! 				int	l = (int)STRLEN(line);
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  				/* remove trailing CR, LF, spaces, etc. */
Karsten Hopp e0388c
! 				while (l > 0 && line[l - 1] <= ' ')
Karsten Hopp e0388c
! 				     line[--l] = NUL;
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  				if (qf_add_entry(qi, &prevp,
Karsten Hopp e0388c
  					    NULL,	/* dir */
Karsten Hopp e0388c
  					    fnames[fi],
Karsten Hopp e0388c
  					    0,
Karsten Hopp e0388c
! 					    line,
Karsten Hopp e0388c
  					    lnum,
Karsten Hopp e0388c
! 					    (int)(regmatch.startp[0] - line)
Karsten Hopp e0388c
  								+ 1, /* col */
Karsten Hopp e0388c
  					    FALSE,	/* vis_col */
Karsten Hopp e0388c
  					    NULL,	/* search pattern */
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 3972,3980 ****
Karsten Hopp e0388c
--- 3994,4010 ----
Karsten Hopp e0388c
  					    ) == FAIL)
Karsten Hopp e0388c
  				{
Karsten Hopp e0388c
  				    got_int = TRUE;
Karsten Hopp e0388c
+ #ifdef FEAT_MBYTE
Karsten Hopp e0388c
+ 				    if (line != IObuff)
Karsten Hopp e0388c
+ 					vim_free(line);
Karsten Hopp e0388c
+ #endif
Karsten Hopp e0388c
  				    break;
Karsten Hopp e0388c
  				}
Karsten Hopp e0388c
  			    }
Karsten Hopp e0388c
+ #ifdef FEAT_MBYTE
Karsten Hopp e0388c
+ 			    if (line != IObuff)
Karsten Hopp e0388c
+ 				vim_free(line);
Karsten Hopp e0388c
+ #endif
Karsten Hopp e0388c
  			    ++lnum;
Karsten Hopp e0388c
  			    line_breakcheck();
Karsten Hopp e0388c
  			}
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 3984,3990 ****
Karsten Hopp e0388c
--- 4014,4025 ----
Karsten Hopp e0388c
  		FreeWild(fcount, fnames);
Karsten Hopp e0388c
  	    }
Karsten Hopp e0388c
  	}
Karsten Hopp e0388c
+ 
Karsten Hopp e0388c
  	vim_free(regmatch.regprog);
Karsten Hopp e0388c
+ #ifdef FEAT_MBYTE
Karsten Hopp e0388c
+ 	if (vc.vc_type != CONV_NONE)
Karsten Hopp e0388c
+ 	    convert_setup(&vc, NULL, NULL);
Karsten Hopp e0388c
+ #endif
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  	qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
Karsten Hopp e0388c
  	qi->qf_lists[qi->qf_curlist].qf_ptr =
Karsten Hopp e0388c
*** ../vim-7.3.396/src/spell.c	2011-09-02 14:18:14.000000000 +0200
Karsten Hopp e0388c
--- src/spell.c	2012-01-10 16:19:33.000000000 +0100
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 5020,5026 ****
Karsten Hopp e0388c
  static int str_equal __ARGS((char_u *s1, char_u	*s2));
Karsten Hopp e0388c
  static void add_fromto __ARGS((spellinfo_T *spin, garray_T *gap, char_u	*from, char_u *to));
Karsten Hopp e0388c
  static int sal_to_bool __ARGS((char_u *s));
Karsten Hopp e0388c
- static int has_non_ascii __ARGS((char_u *s));
Karsten Hopp e0388c
  static void spell_free_aff __ARGS((afffile_T *aff));
Karsten Hopp e0388c
  static int spell_read_dic __ARGS((spellinfo_T *spin, char_u *fname, afffile_T *affile));
Karsten Hopp e0388c
  static int get_affix_flags __ARGS((afffile_T *affile, char_u *afflist));
Karsten Hopp e0388c
--- 5020,5025 ----
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 6485,6507 ****
Karsten Hopp e0388c
  }
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  /*
Karsten Hopp e0388c
-  * Return TRUE if string "s" contains a non-ASCII character (128 or higher).
Karsten Hopp e0388c
-  * When "s" is NULL FALSE is returned.
Karsten Hopp e0388c
-  */
Karsten Hopp e0388c
-     static int
Karsten Hopp e0388c
- has_non_ascii(s)
Karsten Hopp e0388c
-     char_u	*s;
Karsten Hopp e0388c
- {
Karsten Hopp e0388c
-     char_u	*p;
Karsten Hopp e0388c
- 
Karsten Hopp e0388c
-     if (s != NULL)
Karsten Hopp e0388c
- 	for (p = s; *p != NUL; ++p)
Karsten Hopp e0388c
- 	    if (*p >= 128)
Karsten Hopp e0388c
- 		return TRUE;
Karsten Hopp e0388c
-     return FALSE;
Karsten Hopp e0388c
- }
Karsten Hopp e0388c
- 
Karsten Hopp e0388c
- /*
Karsten Hopp e0388c
   * Free the structure filled by spell_read_aff().
Karsten Hopp e0388c
   */
Karsten Hopp e0388c
      static void
Karsten Hopp e0388c
--- 6484,6489 ----
Karsten Hopp e0388c
*** ../vim-7.3.396/src/misc2.c	2011-12-08 17:49:31.000000000 +0100
Karsten Hopp e0388c
--- src/misc2.c	2012-01-10 16:25:53.000000000 +0100
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 6541,6543 ****
Karsten Hopp e0388c
--- 6541,6563 ----
Karsten Hopp e0388c
  #endif
Karsten Hopp e0388c
  
Karsten Hopp e0388c
  #endif
Karsten Hopp e0388c
+ 
Karsten Hopp e0388c
+ #if (defined(FEAT_MBYTE) && defined(FEAT_QUICKFIX)) \
Karsten Hopp e0388c
+ 	|| defined(FEAT_SPELL) || defined(PROTO)
Karsten Hopp e0388c
+ /*
Karsten Hopp e0388c
+  * Return TRUE if string "s" contains a non-ASCII character (128 or higher).
Karsten Hopp e0388c
+  * When "s" is NULL FALSE is returned.
Karsten Hopp e0388c
+  */
Karsten Hopp e0388c
+     int
Karsten Hopp e0388c
+ has_non_ascii(s)
Karsten Hopp e0388c
+     char_u	*s;
Karsten Hopp e0388c
+ {
Karsten Hopp e0388c
+     char_u	*p;
Karsten Hopp e0388c
+ 
Karsten Hopp e0388c
+     if (s != NULL)
Karsten Hopp e0388c
+ 	for (p = s; *p != NUL; ++p)
Karsten Hopp e0388c
+ 	    if (*p >= 128)
Karsten Hopp e0388c
+ 		return TRUE;
Karsten Hopp e0388c
+     return FALSE;
Karsten Hopp e0388c
+ }
Karsten Hopp e0388c
+ #endif
Karsten Hopp e0388c
*** ../vim-7.3.396/src/proto/misc2.pro	2011-07-07 16:20:45.000000000 +0200
Karsten Hopp e0388c
--- src/proto/misc2.pro	2012-01-10 16:20:03.000000000 +0100
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 116,119 ****
Karsten Hopp e0388c
--- 116,120 ----
Karsten Hopp e0388c
  char_u *read_string __ARGS((FILE *fd, int cnt));
Karsten Hopp e0388c
  int put_bytes __ARGS((FILE *fd, long_u nr, int len));
Karsten Hopp e0388c
  void put_time __ARGS((FILE *fd, time_t the_time));
Karsten Hopp e0388c
+ int has_non_ascii __ARGS((char_u *s));
Karsten Hopp e0388c
  /* vim: set ft=c : */
Karsten Hopp e0388c
*** ../vim-7.3.396/src/version.c	2012-01-10 13:46:18.000000000 +0100
Karsten Hopp e0388c
--- src/version.c	2012-01-10 16:26:32.000000000 +0100
Karsten Hopp e0388c
***************
Karsten Hopp e0388c
*** 716,717 ****
Karsten Hopp e0388c
--- 716,719 ----
Karsten Hopp e0388c
  {   /* Add new patch number below this line */
Karsten Hopp e0388c
+ /**/
Karsten Hopp e0388c
+     397,
Karsten Hopp e0388c
  /**/
Karsten Hopp e0388c
Karsten Hopp e0388c
-- 
Karsten Hopp e0388c
Biting someone with your natural teeth is "simple assault," while biting
Karsten Hopp e0388c
someone with your false teeth is "aggravated assault."
Karsten Hopp e0388c
		[real standing law in Louisana, United States of America]
Karsten Hopp e0388c
Karsten Hopp e0388c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp e0388c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp e0388c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp e0388c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///