Karsten Hopp 161f7c
To: vim_dev@googlegroups.com
Karsten Hopp 161f7c
Subject: Patch 7.4.262
Karsten Hopp 161f7c
Fcc: outbox
Karsten Hopp 161f7c
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 161f7c
Mime-Version: 1.0
Karsten Hopp 161f7c
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 161f7c
Content-Transfer-Encoding: 8bit
Karsten Hopp 161f7c
------------
Karsten Hopp 161f7c
Karsten Hopp 161f7c
Patch 7.4.262
Karsten Hopp 161f7c
Problem:    Duplicate code in regexec().
Karsten Hopp 161f7c
Solution:   Add line_lbr flag to regexec_nl().
Karsten Hopp 161f7c
Files:	    src/regexp.c, src/regexp_nfa.c, src/regexp.h
Karsten Hopp 161f7c
Karsten Hopp 161f7c
Karsten Hopp 161f7c
*** ../vim-7.4.261/src/regexp.c	2014-04-23 18:48:43.546854558 +0200
Karsten Hopp 161f7c
--- src/regexp.c	2014-04-23 18:59:38.606838773 +0200
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 3709,3733 ****
Karsten Hopp 161f7c
  /* TRUE if using multi-line regexp. */
Karsten Hopp 161f7c
  #define REG_MULTI	(reg_match == NULL)
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
! static int  bt_regexec __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
  /*
Karsten Hopp 161f7c
   * Match a regexp against a string.
Karsten Hopp 161f7c
   * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
Karsten Hopp 161f7c
   * Uses curbuf for line count and 'iskeyword'.
Karsten Hopp 161f7c
   *
Karsten Hopp 161f7c
   * Return TRUE if there is a match, FALSE if not.
Karsten Hopp 161f7c
   */
Karsten Hopp 161f7c
      static int
Karsten Hopp 161f7c
! bt_regexec(rmp, line, col)
Karsten Hopp 161f7c
      regmatch_T	*rmp;
Karsten Hopp 161f7c
      char_u	*line;	/* string to match against */
Karsten Hopp 161f7c
      colnr_T	col;	/* column to start looking for match */
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      reg_match = rmp;
Karsten Hopp 161f7c
      reg_mmatch = NULL;
Karsten Hopp 161f7c
      reg_maxline = 0;
Karsten Hopp 161f7c
!     reg_line_lbr = FALSE;
Karsten Hopp 161f7c
      reg_buf = curbuf;
Karsten Hopp 161f7c
      reg_win = NULL;
Karsten Hopp 161f7c
      ireg_ic = rmp->rm_ic;
Karsten Hopp 161f7c
--- 3709,3736 ----
Karsten Hopp 161f7c
  /* TRUE if using multi-line regexp. */
Karsten Hopp 161f7c
  #define REG_MULTI	(reg_match == NULL)
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
! static int  bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr));
Karsten Hopp 161f7c
! 
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
  /*
Karsten Hopp 161f7c
   * Match a regexp against a string.
Karsten Hopp 161f7c
   * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
Karsten Hopp 161f7c
   * Uses curbuf for line count and 'iskeyword'.
Karsten Hopp 161f7c
+  * if "line_lbr" is TRUE  consider a "\n" in "line" to be a line break.
Karsten Hopp 161f7c
   *
Karsten Hopp 161f7c
   * Return TRUE if there is a match, FALSE if not.
Karsten Hopp 161f7c
   */
Karsten Hopp 161f7c
      static int
Karsten Hopp 161f7c
! bt_regexec_nl(rmp, line, col, line_lbr)
Karsten Hopp 161f7c
      regmatch_T	*rmp;
Karsten Hopp 161f7c
      char_u	*line;	/* string to match against */
Karsten Hopp 161f7c
      colnr_T	col;	/* column to start looking for match */
Karsten Hopp 161f7c
+     int		line_lbr;
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      reg_match = rmp;
Karsten Hopp 161f7c
      reg_mmatch = NULL;
Karsten Hopp 161f7c
      reg_maxline = 0;
Karsten Hopp 161f7c
!     reg_line_lbr = line_lbr;
Karsten Hopp 161f7c
      reg_buf = curbuf;
Karsten Hopp 161f7c
      reg_win = NULL;
Karsten Hopp 161f7c
      ireg_ic = rmp->rm_ic;
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 3738,3772 ****
Karsten Hopp 161f7c
      return (bt_regexec_both(line, col, NULL) != 0);
Karsten Hopp 161f7c
  }
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
- #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
- 	|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
Karsten Hopp 161f7c
- 
Karsten Hopp 161f7c
- static int  bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
Karsten Hopp 161f7c
- 
Karsten Hopp 161f7c
- /*
Karsten Hopp 161f7c
-  * Like vim_regexec(), but consider a "\n" in "line" to be a line break.
Karsten Hopp 161f7c
-  */
Karsten Hopp 161f7c
-     static int
Karsten Hopp 161f7c
- bt_regexec_nl(rmp, line, col)
Karsten Hopp 161f7c
-     regmatch_T	*rmp;
Karsten Hopp 161f7c
-     char_u	*line;	/* string to match against */
Karsten Hopp 161f7c
-     colnr_T	col;	/* column to start looking for match */
Karsten Hopp 161f7c
- {
Karsten Hopp 161f7c
-     reg_match = rmp;
Karsten Hopp 161f7c
-     reg_mmatch = NULL;
Karsten Hopp 161f7c
-     reg_maxline = 0;
Karsten Hopp 161f7c
-     reg_line_lbr = TRUE;
Karsten Hopp 161f7c
-     reg_buf = curbuf;
Karsten Hopp 161f7c
-     reg_win = NULL;
Karsten Hopp 161f7c
-     ireg_ic = rmp->rm_ic;
Karsten Hopp 161f7c
- #ifdef FEAT_MBYTE
Karsten Hopp 161f7c
-     ireg_icombine = FALSE;
Karsten Hopp 161f7c
- #endif
Karsten Hopp 161f7c
-     ireg_maxcol = 0;
Karsten Hopp 161f7c
-     return (bt_regexec_both(line, col, NULL) != 0);
Karsten Hopp 161f7c
- }
Karsten Hopp 161f7c
- #endif
Karsten Hopp 161f7c
- 
Karsten Hopp 161f7c
  static long bt_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
  /*
Karsten Hopp 161f7c
--- 3741,3746 ----
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 7985,7995 ****
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      bt_regcomp,
Karsten Hopp 161f7c
      bt_regfree,
Karsten Hopp 161f7c
-     bt_regexec,
Karsten Hopp 161f7c
- #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
- 	|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
Karsten Hopp 161f7c
      bt_regexec_nl,
Karsten Hopp 161f7c
- #endif
Karsten Hopp 161f7c
      bt_regexec_multi
Karsten Hopp 161f7c
  #ifdef DEBUG
Karsten Hopp 161f7c
      ,(char_u *)""
Karsten Hopp 161f7c
--- 7959,7965 ----
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 8003,8013 ****
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      nfa_regcomp,
Karsten Hopp 161f7c
      nfa_regfree,
Karsten Hopp 161f7c
-     nfa_regexec,
Karsten Hopp 161f7c
- #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
- 	|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
Karsten Hopp 161f7c
      nfa_regexec_nl,
Karsten Hopp 161f7c
- #endif
Karsten Hopp 161f7c
      nfa_regexec_multi
Karsten Hopp 161f7c
  #ifdef DEBUG
Karsten Hopp 161f7c
      ,(char_u *)""
Karsten Hopp 161f7c
--- 7973,7979 ----
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 8131,8137 ****
Karsten Hopp 161f7c
      char_u      *line;  /* string to match against */
Karsten Hopp 161f7c
      colnr_T     col;    /* column to start looking for match */
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
!     return rmp->regprog->engine->regexec(rmp, line, col);
Karsten Hopp 161f7c
  }
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
  #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
--- 8097,8103 ----
Karsten Hopp 161f7c
      char_u      *line;  /* string to match against */
Karsten Hopp 161f7c
      colnr_T     col;    /* column to start looking for match */
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
!     return rmp->regprog->engine->regexec_nl(rmp, line, col, FALSE);
Karsten Hopp 161f7c
  }
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
  #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 8145,8151 ****
Karsten Hopp 161f7c
      char_u *line;
Karsten Hopp 161f7c
      colnr_T col;
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
!     return rmp->regprog->engine->regexec_nl(rmp, line, col);
Karsten Hopp 161f7c
  }
Karsten Hopp 161f7c
  #endif
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
--- 8111,8117 ----
Karsten Hopp 161f7c
      char_u *line;
Karsten Hopp 161f7c
      colnr_T col;
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
!     return rmp->regprog->engine->regexec_nl(rmp, line, col, TRUE);
Karsten Hopp 161f7c
  }
Karsten Hopp 161f7c
  #endif
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
*** ../vim-7.4.261/src/regexp_nfa.c	2014-04-06 21:33:39.675363743 +0200
Karsten Hopp 161f7c
--- src/regexp_nfa.c	2014-04-23 19:00:44.354837189 +0200
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 311,317 ****
Karsten Hopp 161f7c
  static long nfa_regexec_both __ARGS((char_u *line, colnr_T col));
Karsten Hopp 161f7c
  static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags));
Karsten Hopp 161f7c
  static void nfa_regfree __ARGS((regprog_T *prog));
Karsten Hopp 161f7c
! static int nfa_regexec __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
Karsten Hopp 161f7c
  static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
Karsten Hopp 161f7c
  static int match_follows __ARGS((nfa_state_T *startstate, int depth));
Karsten Hopp 161f7c
  static int failure_chance __ARGS((nfa_state_T *state, int depth));
Karsten Hopp 161f7c
--- 311,317 ----
Karsten Hopp 161f7c
  static long nfa_regexec_both __ARGS((char_u *line, colnr_T col));
Karsten Hopp 161f7c
  static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags));
Karsten Hopp 161f7c
  static void nfa_regfree __ARGS((regprog_T *prog));
Karsten Hopp 161f7c
! static int  nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr));
Karsten Hopp 161f7c
  static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
Karsten Hopp 161f7c
  static int match_follows __ARGS((nfa_state_T *startstate, int depth));
Karsten Hopp 161f7c
  static int failure_chance __ARGS((nfa_state_T *state, int depth));
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 7060,7078 ****
Karsten Hopp 161f7c
   * Match a regexp against a string.
Karsten Hopp 161f7c
   * "rmp->regprog" is a compiled regexp as returned by nfa_regcomp().
Karsten Hopp 161f7c
   * Uses curbuf for line count and 'iskeyword'.
Karsten Hopp 161f7c
   *
Karsten Hopp 161f7c
   * Return TRUE if there is a match, FALSE if not.
Karsten Hopp 161f7c
   */
Karsten Hopp 161f7c
      static int
Karsten Hopp 161f7c
! nfa_regexec(rmp, line, col)
Karsten Hopp 161f7c
      regmatch_T	*rmp;
Karsten Hopp 161f7c
      char_u	*line;	/* string to match against */
Karsten Hopp 161f7c
      colnr_T	col;	/* column to start looking for match */
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      reg_match = rmp;
Karsten Hopp 161f7c
      reg_mmatch = NULL;
Karsten Hopp 161f7c
      reg_maxline = 0;
Karsten Hopp 161f7c
!     reg_line_lbr = FALSE;
Karsten Hopp 161f7c
      reg_buf = curbuf;
Karsten Hopp 161f7c
      reg_win = NULL;
Karsten Hopp 161f7c
      ireg_ic = rmp->rm_ic;
Karsten Hopp 161f7c
--- 7060,7080 ----
Karsten Hopp 161f7c
   * Match a regexp against a string.
Karsten Hopp 161f7c
   * "rmp->regprog" is a compiled regexp as returned by nfa_regcomp().
Karsten Hopp 161f7c
   * Uses curbuf for line count and 'iskeyword'.
Karsten Hopp 161f7c
+  * If "line_lbr" is TRUE consider a "\n" in "line" to be a line break.
Karsten Hopp 161f7c
   *
Karsten Hopp 161f7c
   * Return TRUE if there is a match, FALSE if not.
Karsten Hopp 161f7c
   */
Karsten Hopp 161f7c
      static int
Karsten Hopp 161f7c
! nfa_regexec_nl(rmp, line, col, line_lbr)
Karsten Hopp 161f7c
      regmatch_T	*rmp;
Karsten Hopp 161f7c
      char_u	*line;	/* string to match against */
Karsten Hopp 161f7c
      colnr_T	col;	/* column to start looking for match */
Karsten Hopp 161f7c
+     int		line_lbr;
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      reg_match = rmp;
Karsten Hopp 161f7c
      reg_mmatch = NULL;
Karsten Hopp 161f7c
      reg_maxline = 0;
Karsten Hopp 161f7c
!     reg_line_lbr = line_lbr;
Karsten Hopp 161f7c
      reg_buf = curbuf;
Karsten Hopp 161f7c
      reg_win = NULL;
Karsten Hopp 161f7c
      ireg_ic = rmp->rm_ic;
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 7083,7117 ****
Karsten Hopp 161f7c
      return (nfa_regexec_both(line, col) != 0);
Karsten Hopp 161f7c
  }
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
- #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
- 	|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
Karsten Hopp 161f7c
- 
Karsten Hopp 161f7c
- static int  nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
Karsten Hopp 161f7c
- 
Karsten Hopp 161f7c
- /*
Karsten Hopp 161f7c
-  * Like nfa_regexec(), but consider a "\n" in "line" to be a line break.
Karsten Hopp 161f7c
-  */
Karsten Hopp 161f7c
-     static int
Karsten Hopp 161f7c
- nfa_regexec_nl(rmp, line, col)
Karsten Hopp 161f7c
-     regmatch_T	*rmp;
Karsten Hopp 161f7c
-     char_u	*line;	/* string to match against */
Karsten Hopp 161f7c
-     colnr_T	col;	/* column to start looking for match */
Karsten Hopp 161f7c
- {
Karsten Hopp 161f7c
-     reg_match = rmp;
Karsten Hopp 161f7c
-     reg_mmatch = NULL;
Karsten Hopp 161f7c
-     reg_maxline = 0;
Karsten Hopp 161f7c
-     reg_line_lbr = TRUE;
Karsten Hopp 161f7c
-     reg_buf = curbuf;
Karsten Hopp 161f7c
-     reg_win = NULL;
Karsten Hopp 161f7c
-     ireg_ic = rmp->rm_ic;
Karsten Hopp 161f7c
- #ifdef FEAT_MBYTE
Karsten Hopp 161f7c
-     ireg_icombine = FALSE;
Karsten Hopp 161f7c
- #endif
Karsten Hopp 161f7c
-     ireg_maxcol = 0;
Karsten Hopp 161f7c
-     return (nfa_regexec_both(line, col) != 0);
Karsten Hopp 161f7c
- }
Karsten Hopp 161f7c
- #endif
Karsten Hopp 161f7c
- 
Karsten Hopp 161f7c
  
Karsten Hopp 161f7c
  /*
Karsten Hopp 161f7c
   * Match a regexp against multiple lines.
Karsten Hopp 161f7c
--- 7085,7090 ----
Karsten Hopp 161f7c
*** ../vim-7.4.261/src/regexp.h	2013-06-11 10:53:14.000000000 +0200
Karsten Hopp 161f7c
--- src/regexp.h	2014-04-23 18:58:18.614840701 +0200
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 149,159 ****
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      regprog_T	*(*regcomp)(char_u*, int);
Karsten Hopp 161f7c
      void	(*regfree)(regprog_T *);
Karsten Hopp 161f7c
!     int		(*regexec)(regmatch_T*, char_u*, colnr_T);
Karsten Hopp 161f7c
! #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
Karsten Hopp 161f7c
! 	|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
Karsten Hopp 161f7c
!     int		(*regexec_nl)(regmatch_T*, char_u*, colnr_T);
Karsten Hopp 161f7c
! #endif
Karsten Hopp 161f7c
      long	(*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*);
Karsten Hopp 161f7c
  #ifdef DEBUG
Karsten Hopp 161f7c
      char_u	*expr;
Karsten Hopp 161f7c
--- 149,155 ----
Karsten Hopp 161f7c
  {
Karsten Hopp 161f7c
      regprog_T	*(*regcomp)(char_u*, int);
Karsten Hopp 161f7c
      void	(*regfree)(regprog_T *);
Karsten Hopp 161f7c
!     int		(*regexec_nl)(regmatch_T*, char_u*, colnr_T, int);
Karsten Hopp 161f7c
      long	(*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*);
Karsten Hopp 161f7c
  #ifdef DEBUG
Karsten Hopp 161f7c
      char_u	*expr;
Karsten Hopp 161f7c
*** ../vim-7.4.261/src/version.c	2014-04-23 18:48:43.546854558 +0200
Karsten Hopp 161f7c
--- src/version.c	2014-04-23 18:52:20.102849340 +0200
Karsten Hopp 161f7c
***************
Karsten Hopp 161f7c
*** 736,737 ****
Karsten Hopp 161f7c
--- 736,739 ----
Karsten Hopp 161f7c
  {   /* Add new patch number below this line */
Karsten Hopp 161f7c
+ /**/
Karsten Hopp 161f7c
+     262,
Karsten Hopp 161f7c
  /**/
Karsten Hopp 161f7c
Karsten Hopp 161f7c
-- 
Karsten Hopp 161f7c
From "know your smileys":
Karsten Hopp 161f7c
 ~#:-(	I just washed my hair, and I can't do nuthin' with it.
Karsten Hopp 161f7c
Karsten Hopp 161f7c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 161f7c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 161f7c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 161f7c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///