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