Karsten Hopp 6d666b
To: vim_dev@googlegroups.com
Karsten Hopp 6d666b
Subject: Patch 7.3.1005
Karsten Hopp 6d666b
Fcc: outbox
Karsten Hopp 6d666b
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6d666b
Mime-Version: 1.0
Karsten Hopp 6d666b
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6d666b
Content-Transfer-Encoding: 8bit
Karsten Hopp 6d666b
------------
Karsten Hopp 6d666b
Karsten Hopp 6d666b
Patch 7.3.1005
Karsten Hopp 6d666b
Problem:    Get stuck on regexp "\n*" and on "%s/^\n\+/\r".
Karsten Hopp 6d666b
Solution:   Fix handling of matching a line break. (idea by Hirohito Higashi)
Karsten Hopp 6d666b
Files:	    src/regexp_nfa.c
Karsten Hopp 6d666b
Karsten Hopp 6d666b
Karsten Hopp 6d666b
*** ../vim-7.3.1004/src/regexp_nfa.c	2013-05-21 22:00:42.000000000 +0200
Karsten Hopp 6d666b
--- src/regexp_nfa.c	2013-05-22 22:53:08.000000000 +0200
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 2462,2468 ****
Karsten Hopp 6d666b
      List		*l;	/* runtime state list */
Karsten Hopp 6d666b
      nfa_state_T		*state;	/* state to update */
Karsten Hopp 6d666b
      regsub_T		*m;	/* pointers to subexpressions */
Karsten Hopp 6d666b
!     int			off;
Karsten Hopp 6d666b
      int			lid;
Karsten Hopp 6d666b
      int			*match;	/* found match? */
Karsten Hopp 6d666b
  {
Karsten Hopp 6d666b
--- 2462,2468 ----
Karsten Hopp 6d666b
      List		*l;	/* runtime state list */
Karsten Hopp 6d666b
      nfa_state_T		*state;	/* state to update */
Karsten Hopp 6d666b
      regsub_T		*m;	/* pointers to subexpressions */
Karsten Hopp 6d666b
!     int			off;	/* byte offset, when -1 go to next line */
Karsten Hopp 6d666b
      int			lid;
Karsten Hopp 6d666b
      int			*match;	/* found match? */
Karsten Hopp 6d666b
  {
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 2585,2592 ****
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
  		save.startpos[subidx] = m->startpos[subidx];
Karsten Hopp 6d666b
  		save.endpos[subidx] = m->endpos[subidx];
Karsten Hopp 6d666b
! 		m->startpos[subidx].lnum = reglnum;
Karsten Hopp 6d666b
! 		m->startpos[subidx].col = (colnr_T)(reginput - regline + off);
Karsten Hopp 6d666b
  	    }
Karsten Hopp 6d666b
  	    else
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
--- 2585,2601 ----
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
  		save.startpos[subidx] = m->startpos[subidx];
Karsten Hopp 6d666b
  		save.endpos[subidx] = m->endpos[subidx];
Karsten Hopp 6d666b
! 		if (off == -1)
Karsten Hopp 6d666b
! 		{
Karsten Hopp 6d666b
! 		    m->startpos[subidx].lnum = reglnum + 1;
Karsten Hopp 6d666b
! 		    m->startpos[subidx].col = 0;
Karsten Hopp 6d666b
! 		}
Karsten Hopp 6d666b
! 		else
Karsten Hopp 6d666b
! 		{
Karsten Hopp 6d666b
! 		    m->startpos[subidx].lnum = reglnum;
Karsten Hopp 6d666b
! 		    m->startpos[subidx].col =
Karsten Hopp 6d666b
! 					  (colnr_T)(reginput - regline + off);
Karsten Hopp 6d666b
! 		}
Karsten Hopp 6d666b
  	    }
Karsten Hopp 6d666b
  	    else
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 2633,2640 ****
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
  		save.startpos[subidx] = m->startpos[subidx];
Karsten Hopp 6d666b
  		save.endpos[subidx] = m->endpos[subidx];
Karsten Hopp 6d666b
! 		m->endpos[subidx].lnum = reglnum;
Karsten Hopp 6d666b
! 		m->endpos[subidx].col = (colnr_T)(reginput - regline + off);
Karsten Hopp 6d666b
  	    }
Karsten Hopp 6d666b
  	    else
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
--- 2642,2657 ----
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
  		save.startpos[subidx] = m->startpos[subidx];
Karsten Hopp 6d666b
  		save.endpos[subidx] = m->endpos[subidx];
Karsten Hopp 6d666b
! 		if (off == -1)
Karsten Hopp 6d666b
! 		{
Karsten Hopp 6d666b
! 		    m->endpos[subidx].lnum = reglnum + 1;
Karsten Hopp 6d666b
! 		    m->endpos[subidx].col = 0;
Karsten Hopp 6d666b
! 		}
Karsten Hopp 6d666b
! 		else
Karsten Hopp 6d666b
! 		{
Karsten Hopp 6d666b
! 		    m->endpos[subidx].lnum = reglnum;
Karsten Hopp 6d666b
! 		    m->endpos[subidx].col = (colnr_T)(reginput - regline + off);
Karsten Hopp 6d666b
! 		}
Karsten Hopp 6d666b
  	    }
Karsten Hopp 6d666b
  	    else
Karsten Hopp 6d666b
  	    {
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 2834,2840 ****
Karsten Hopp 6d666b
      int		match = FALSE;
Karsten Hopp 6d666b
      int		flag = 0;
Karsten Hopp 6d666b
      int		old_reglnum = -1;
Karsten Hopp 6d666b
!     int		reginput_updated = FALSE;
Karsten Hopp 6d666b
      thread_T	*t;
Karsten Hopp 6d666b
      char_u	*old_reginput = NULL;
Karsten Hopp 6d666b
      char_u	*old_regline = NULL;
Karsten Hopp 6d666b
--- 2851,2857 ----
Karsten Hopp 6d666b
      int		match = FALSE;
Karsten Hopp 6d666b
      int		flag = 0;
Karsten Hopp 6d666b
      int		old_reglnum = -1;
Karsten Hopp 6d666b
!     int		go_to_nextline;
Karsten Hopp 6d666b
      thread_T	*t;
Karsten Hopp 6d666b
      char_u	*old_reginput = NULL;
Karsten Hopp 6d666b
      char_u	*old_regline = NULL;
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 2917,2924 ****
Karsten Hopp 6d666b
      /*
Karsten Hopp 6d666b
       * Run for each character.
Karsten Hopp 6d666b
       */
Karsten Hopp 6d666b
!     do {
Karsten Hopp 6d666b
! again:
Karsten Hopp 6d666b
  #ifdef FEAT_MBYTE
Karsten Hopp 6d666b
  	if (has_mbyte)
Karsten Hopp 6d666b
  	{
Karsten Hopp 6d666b
--- 2934,2941 ----
Karsten Hopp 6d666b
      /*
Karsten Hopp 6d666b
       * Run for each character.
Karsten Hopp 6d666b
       */
Karsten Hopp 6d666b
!     for (;;)
Karsten Hopp 6d666b
!     {
Karsten Hopp 6d666b
  #ifdef FEAT_MBYTE
Karsten Hopp 6d666b
  	if (has_mbyte)
Karsten Hopp 6d666b
  	{
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 2932,2938 ****
Karsten Hopp 6d666b
--- 2949,2958 ----
Karsten Hopp 6d666b
  	    n = 1;
Karsten Hopp 6d666b
  	}
Karsten Hopp 6d666b
  	if (c == NUL)
Karsten Hopp 6d666b
+ 	{
Karsten Hopp 6d666b
  	    n = 0;
Karsten Hopp 6d666b
+ 	    go_to_nextline = FALSE;
Karsten Hopp 6d666b
+ 	}
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	/* swap lists */
Karsten Hopp 6d666b
  	thislist = &list[flag];
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 3007,3013 ****
Karsten Hopp 6d666b
  				(char *)t->sub.end[j]);
Karsten Hopp 6d666b
  		fprintf(log_fd, "\n");
Karsten Hopp 6d666b
  #endif
Karsten Hopp 6d666b
! 		goto nextchar;		/* found the left-most longest match */
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	    case NFA_END_INVISIBLE:
Karsten Hopp 6d666b
  		/* This is only encountered after a NFA_START_INVISIBLE node.
Karsten Hopp 6d666b
--- 3027,3035 ----
Karsten Hopp 6d666b
  				(char *)t->sub.end[j]);
Karsten Hopp 6d666b
  		fprintf(log_fd, "\n");
Karsten Hopp 6d666b
  #endif
Karsten Hopp 6d666b
! 		/* Found the left-most longest match, do not look at any other
Karsten Hopp 6d666b
! 		 * states at this position. */
Karsten Hopp 6d666b
! 		goto nextchar;
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	    case NFA_END_INVISIBLE:
Karsten Hopp 6d666b
  		/* This is only encountered after a NFA_START_INVISIBLE node.
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 3206,3220 ****
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	    case NFA_NEWL:
Karsten Hopp 6d666b
  		if (!reg_line_lbr && REG_MULTI
Karsten Hopp 6d666b
! 				&& c == NUL && reglnum <= reg_maxline)
Karsten Hopp 6d666b
  		{
Karsten Hopp 6d666b
! 		    if (reginput_updated == FALSE)
Karsten Hopp 6d666b
! 		    {
Karsten Hopp 6d666b
! 			reg_nextline();
Karsten Hopp 6d666b
! 			reginput_updated = TRUE;
Karsten Hopp 6d666b
! 		    }
Karsten Hopp 6d666b
! 		    addstate(nextlist, t->state->out, &t->sub, n, listid + 1,
Karsten Hopp 6d666b
! 								    &match);
Karsten Hopp 6d666b
  		}
Karsten Hopp 6d666b
  		break;
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
--- 3228,3240 ----
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	    case NFA_NEWL:
Karsten Hopp 6d666b
  		if (!reg_line_lbr && REG_MULTI
Karsten Hopp 6d666b
! 					&& c == NUL && reglnum <= reg_maxline)
Karsten Hopp 6d666b
  		{
Karsten Hopp 6d666b
! 		    go_to_nextline = TRUE;
Karsten Hopp 6d666b
! 		    /* Pass -1 for the offset, which means taking the position
Karsten Hopp 6d666b
! 		     * at the start of the next line. */
Karsten Hopp 6d666b
! 		    addstate(nextlist, t->state->out, &t->sub, -1,
Karsten Hopp 6d666b
! 							  listid + 1, &match);
Karsten Hopp 6d666b
  		}
Karsten Hopp 6d666b
  		break;
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 3247,3254 ****
Karsten Hopp 6d666b
  		break;
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	    case NFA_ANY:
Karsten Hopp 6d666b
! 		/* Any printable char, not just any char. '\0' (end of input)
Karsten Hopp 6d666b
! 		 * must not match */
Karsten Hopp 6d666b
  		if (c > 0)
Karsten Hopp 6d666b
  		    addstate(nextlist, t->state->out, &t->sub, n, listid + 1,
Karsten Hopp 6d666b
  								    &match);
Karsten Hopp 6d666b
--- 3267,3273 ----
Karsten Hopp 6d666b
  		break;
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  	    case NFA_ANY:
Karsten Hopp 6d666b
! 		/* Any char except '\0', (end of input) does not match. */
Karsten Hopp 6d666b
  		if (c > 0)
Karsten Hopp 6d666b
  		    addstate(nextlist, t->state->out, &t->sub, n, listid + 1,
Karsten Hopp 6d666b
  								    &match);
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 3433,3444 ****
Karsten Hopp 6d666b
  	    addstate(nextlist, start, m, n, listid + 1, &match);
Karsten Hopp 6d666b
  	}
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
- 	if (reginput_updated)
Karsten Hopp 6d666b
- 	{
Karsten Hopp 6d666b
- 	    reginput_updated = FALSE;
Karsten Hopp 6d666b
- 	    goto again;
Karsten Hopp 6d666b
- 	}
Karsten Hopp 6d666b
- 
Karsten Hopp 6d666b
  #ifdef ENABLE_LOG
Karsten Hopp 6d666b
  	fprintf(log_fd, ">>> Thislist had %d states available: ", thislist->n);
Karsten Hopp 6d666b
  	for (i = 0; i< thislist->n; i++)
Karsten Hopp 6d666b
--- 3452,3457 ----
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 3447,3454 ****
Karsten Hopp 6d666b
  #endif
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  nextchar:
Karsten Hopp 6d666b
! 	reginput += n;
Karsten Hopp 6d666b
!     } while (c || reginput_updated);
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  #ifdef ENABLE_LOG
Karsten Hopp 6d666b
      if (log_fd != stderr)
Karsten Hopp 6d666b
--- 3460,3474 ----
Karsten Hopp 6d666b
  #endif
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  nextchar:
Karsten Hopp 6d666b
! 	/* Advance to the next character, or advance to the next line, or
Karsten Hopp 6d666b
! 	 * finish. */
Karsten Hopp 6d666b
! 	if (n != 0)
Karsten Hopp 6d666b
! 	    reginput += n;
Karsten Hopp 6d666b
! 	else if (go_to_nextline)
Karsten Hopp 6d666b
! 	    reg_nextline();
Karsten Hopp 6d666b
! 	else
Karsten Hopp 6d666b
! 	    break;
Karsten Hopp 6d666b
!     }
Karsten Hopp 6d666b
  
Karsten Hopp 6d666b
  #ifdef ENABLE_LOG
Karsten Hopp 6d666b
      if (log_fd != stderr)
Karsten Hopp 6d666b
*** ../vim-7.3.1004/src/version.c	2013-05-21 22:38:14.000000000 +0200
Karsten Hopp 6d666b
--- src/version.c	2013-05-22 22:57:59.000000000 +0200
Karsten Hopp 6d666b
***************
Karsten Hopp 6d666b
*** 730,731 ****
Karsten Hopp 6d666b
--- 730,733 ----
Karsten Hopp 6d666b
  {   /* Add new patch number below this line */
Karsten Hopp 6d666b
+ /**/
Karsten Hopp 6d666b
+     1005,
Karsten Hopp 6d666b
  /**/
Karsten Hopp 6d666b
Karsten Hopp 6d666b
-- 
Karsten Hopp 6d666b
"Lisp has all the visual appeal of oatmeal with nail clippings thrown in."
Karsten Hopp 6d666b
                                                         -- Larry Wall
Karsten Hopp 6d666b
Karsten Hopp 6d666b
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6d666b
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6d666b
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 6d666b
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///