Karsten Hopp 0723cf
To: vim_dev@googlegroups.com
Karsten Hopp 0723cf
Subject: Patch 7.3.1014
Karsten Hopp 0723cf
Fcc: outbox
Karsten Hopp 0723cf
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 0723cf
Mime-Version: 1.0
Karsten Hopp 0723cf
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 0723cf
Content-Transfer-Encoding: 8bit
Karsten Hopp 0723cf
------------
Karsten Hopp 0723cf
Karsten Hopp 0723cf
Patch 7.3.1014
Karsten Hopp 0723cf
Problem:    New regexp state dump is hard to read.
Karsten Hopp 0723cf
Solution:   Make the state dump more pretty. (Taro Muraoka)
Karsten Hopp 0723cf
Files:	    src/regexp_nfa.c
Karsten Hopp 0723cf
Karsten Hopp 0723cf
Karsten Hopp 0723cf
*** ../vim-7.3.1013/src/regexp_nfa.c	2013-05-25 12:18:34.000000000 +0200
Karsten Hopp 0723cf
--- src/regexp_nfa.c	2013-05-25 12:25:43.000000000 +0200
Karsten Hopp 0723cf
***************
Karsten Hopp 0723cf
*** 183,189 ****
Karsten Hopp 0723cf
  #ifdef DEBUG
Karsten Hopp 0723cf
  static void nfa_set_code __ARGS((int c));
Karsten Hopp 0723cf
  static void nfa_postfix_dump __ARGS((char_u *expr, int retval));
Karsten Hopp 0723cf
! static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state, int ident));
Karsten Hopp 0723cf
  static void nfa_dump __ARGS((nfa_regprog_T *prog));
Karsten Hopp 0723cf
  #endif
Karsten Hopp 0723cf
  static int *re2post __ARGS((void));
Karsten Hopp 0723cf
--- 183,190 ----
Karsten Hopp 0723cf
  #ifdef DEBUG
Karsten Hopp 0723cf
  static void nfa_set_code __ARGS((int c));
Karsten Hopp 0723cf
  static void nfa_postfix_dump __ARGS((char_u *expr, int retval));
Karsten Hopp 0723cf
! static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state));
Karsten Hopp 0723cf
! static void nfa_print_state2 __ARGS((FILE *debugf, nfa_state_T *state, garray_T *indent));
Karsten Hopp 0723cf
  static void nfa_dump __ARGS((nfa_regprog_T *prog));
Karsten Hopp 0723cf
  #endif
Karsten Hopp 0723cf
  static int *re2post __ARGS((void));
Karsten Hopp 0723cf
***************
Karsten Hopp 0723cf
*** 1811,1839 ****
Karsten Hopp 0723cf
   * Print the NFA starting with a root node "state".
Karsten Hopp 0723cf
   */
Karsten Hopp 0723cf
      static void
Karsten Hopp 0723cf
! nfa_print_state(debugf, state, ident)
Karsten Hopp 0723cf
      FILE *debugf;
Karsten Hopp 0723cf
      nfa_state_T *state;
Karsten Hopp 0723cf
-     int ident;
Karsten Hopp 0723cf
  {
Karsten Hopp 0723cf
!     int i;
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      if (state == NULL)
Karsten Hopp 0723cf
  	return;
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      fprintf(debugf, "(%2d)", abs(state->id));
Karsten Hopp 0723cf
!     for (i = 0; i < ident; i++)
Karsten Hopp 0723cf
! 	fprintf(debugf, "%c", ' ');
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      nfa_set_code(state->c);
Karsten Hopp 0723cf
!     fprintf(debugf, "%s %s (%d) (id=%d)\n",
Karsten Hopp 0723cf
! 		 state->negated ? "NOT" : "", code, state->c, abs(state->id));
Karsten Hopp 0723cf
      if (state->id < 0)
Karsten Hopp 0723cf
  	return;
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      state->id = abs(state->id) * -1;
Karsten Hopp 0723cf
!     nfa_print_state(debugf, state->out, ident + 4);
Karsten Hopp 0723cf
!     nfa_print_state(debugf, state->out1, ident + 4);
Karsten Hopp 0723cf
  }
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
  /*
Karsten Hopp 0723cf
--- 1812,1885 ----
Karsten Hopp 0723cf
   * Print the NFA starting with a root node "state".
Karsten Hopp 0723cf
   */
Karsten Hopp 0723cf
      static void
Karsten Hopp 0723cf
! nfa_print_state(debugf, state)
Karsten Hopp 0723cf
      FILE *debugf;
Karsten Hopp 0723cf
      nfa_state_T *state;
Karsten Hopp 0723cf
  {
Karsten Hopp 0723cf
!     garray_T indent;
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     ga_init2(&indent, 1, 64);
Karsten Hopp 0723cf
!     ga_append(&indent, '\0');
Karsten Hopp 0723cf
!     nfa_print_state2(debugf, state, &indent);
Karsten Hopp 0723cf
!     ga_clear(&indent);
Karsten Hopp 0723cf
! }
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     static void
Karsten Hopp 0723cf
! nfa_print_state2(debugf, state, indent)
Karsten Hopp 0723cf
!     FILE *debugf;
Karsten Hopp 0723cf
!     nfa_state_T *state;
Karsten Hopp 0723cf
!     garray_T *indent;
Karsten Hopp 0723cf
! {
Karsten Hopp 0723cf
!     char_u  *p;
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      if (state == NULL)
Karsten Hopp 0723cf
  	return;
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      fprintf(debugf, "(%2d)", abs(state->id));
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     /* Output indent */
Karsten Hopp 0723cf
!     p = (char_u *)indent->ga_data;
Karsten Hopp 0723cf
!     if (indent->ga_len >= 3)
Karsten Hopp 0723cf
!     {
Karsten Hopp 0723cf
! 	int	last = indent->ga_len - 3;
Karsten Hopp 0723cf
! 	char_u	save[2];
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
! 	STRNCPY(save, &p[last], 2);
Karsten Hopp 0723cf
! 	STRNCPY(&p[last], "+-", 2);
Karsten Hopp 0723cf
! 	fprintf(debugf, " %s", p);
Karsten Hopp 0723cf
! 	STRNCPY(&p[last], save, 2);
Karsten Hopp 0723cf
!     }
Karsten Hopp 0723cf
!     else
Karsten Hopp 0723cf
! 	fprintf(debugf, " %s", p);
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      nfa_set_code(state->c);
Karsten Hopp 0723cf
!     fprintf(debugf, "%s%s (%d) (id=%d)\n",
Karsten Hopp 0723cf
! 		 state->negated ? "NOT " : "", code, state->c, abs(state->id));
Karsten Hopp 0723cf
      if (state->id < 0)
Karsten Hopp 0723cf
  	return;
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      state->id = abs(state->id) * -1;
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     /* grow indent for state->out */
Karsten Hopp 0723cf
!     indent->ga_len -= 1;
Karsten Hopp 0723cf
!     if (state->out1)
Karsten Hopp 0723cf
! 	ga_concat(indent, "| ");
Karsten Hopp 0723cf
!     else
Karsten Hopp 0723cf
! 	ga_concat(indent, "  ");
Karsten Hopp 0723cf
!     ga_append(indent, '\0');
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     nfa_print_state2(debugf, state->out, indent);
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     /* replace last part of indent for state->out1 */
Karsten Hopp 0723cf
!     indent->ga_len -= 3;
Karsten Hopp 0723cf
!     ga_concat(indent, "  ");
Karsten Hopp 0723cf
!     ga_append(indent, '\0');
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     nfa_print_state2(debugf, state->out1, indent);
Karsten Hopp 0723cf
! 
Karsten Hopp 0723cf
!     /* shrink indent */
Karsten Hopp 0723cf
!     indent->ga_len -= 3;
Karsten Hopp 0723cf
!     ga_append(indent, '\0');
Karsten Hopp 0723cf
  }
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
  /*
Karsten Hopp 0723cf
***************
Karsten Hopp 0723cf
*** 1847,1853 ****
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      if (debugf != NULL)
Karsten Hopp 0723cf
      {
Karsten Hopp 0723cf
! 	nfa_print_state(debugf, prog->start, 0);
Karsten Hopp 0723cf
  	fclose(debugf);
Karsten Hopp 0723cf
      }
Karsten Hopp 0723cf
  }
Karsten Hopp 0723cf
--- 1893,1899 ----
Karsten Hopp 0723cf
  
Karsten Hopp 0723cf
      if (debugf != NULL)
Karsten Hopp 0723cf
      {
Karsten Hopp 0723cf
! 	nfa_print_state(debugf, prog->start);
Karsten Hopp 0723cf
  	fclose(debugf);
Karsten Hopp 0723cf
      }
Karsten Hopp 0723cf
  }
Karsten Hopp 0723cf
***************
Karsten Hopp 0723cf
*** 3505,3511 ****
Karsten Hopp 0723cf
  #endif
Karsten Hopp 0723cf
  	fprintf(f, "\tInput text is \"%s\" \n", reginput);
Karsten Hopp 0723cf
  	fprintf(f, "		=======================================================\n\n\n\n\n\n\n");
Karsten Hopp 0723cf
! 	nfa_print_state(f, start, 0);
Karsten Hopp 0723cf
  	fprintf(f, "\n\n");
Karsten Hopp 0723cf
  	fclose(f);
Karsten Hopp 0723cf
      }
Karsten Hopp 0723cf
--- 3551,3557 ----
Karsten Hopp 0723cf
  #endif
Karsten Hopp 0723cf
  	fprintf(f, "\tInput text is \"%s\" \n", reginput);
Karsten Hopp 0723cf
  	fprintf(f, "		=======================================================\n\n\n\n\n\n\n");
Karsten Hopp 0723cf
! 	nfa_print_state(f, start);
Karsten Hopp 0723cf
  	fprintf(f, "\n\n");
Karsten Hopp 0723cf
  	fclose(f);
Karsten Hopp 0723cf
      }
Karsten Hopp 0723cf
*** ../vim-7.3.1013/src/version.c	2013-05-25 12:18:34.000000000 +0200
Karsten Hopp 0723cf
--- src/version.c	2013-05-25 12:27:22.000000000 +0200
Karsten Hopp 0723cf
***************
Karsten Hopp 0723cf
*** 730,731 ****
Karsten Hopp 0723cf
--- 730,733 ----
Karsten Hopp 0723cf
  {   /* Add new patch number below this line */
Karsten Hopp 0723cf
+ /**/
Karsten Hopp 0723cf
+     1014,
Karsten Hopp 0723cf
  /**/
Karsten Hopp 0723cf
Karsten Hopp 0723cf
-- 
Karsten Hopp 0723cf
Lower life forms have more fun!
Karsten Hopp 0723cf
Karsten Hopp 0723cf
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 0723cf
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 0723cf
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 0723cf
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///