changeset 1692:5a7071eb01bb

Musl regex patch for \| support needed by toybox grep when more than one pattern specified.
author Rob Landley <rob@landley.net>
date Wed, 01 Oct 2014 19:55:04 -0500
parents 732ebb18699e
children aee8b52672d7
files sources/patches/musl-regex.patch
diffstat 1 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/patches/musl-regex.patch	Wed Oct 01 19:55:04 2014 -0500
@@ -0,0 +1,58 @@
+Make \| work in normal regexes. (Toybox grep uses this.)
+
+diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c
+index d907627..3a89305 100644
+--- a/src/regex/regcomp.c
++++ b/src/regex/regcomp.c
+@@ -1008,9 +1008,11 @@ tre_parse(tre_parse_ctx_t *ctx)
+ 	    tre_char_t c;
+ 	    if (!*ctx->re)
+ 	      break;
+-	    c = *ctx->re;
++		c = *ctx->re;
+ 		if (ctx->cflags & REG_EXTENDED && c == CHAR_PIPE)
+ 		  break;
++		else if (c == CHAR_BACKSLASH && ctx->re[1] == CHAR_PIPE)
++		  break;
+ 		if ((ctx->cflags & REG_EXTENDED
+ 		     && c == CHAR_RPAREN && depth > 0)
+ 		    || (!(ctx->cflags & REG_EXTENDED)
+@@ -1047,23 +1049,16 @@ tre_parse(tre_parse_ctx_t *ctx)
+ 	  }
+ 
+ 	case PARSE_UNION:
+-	  switch (*ctx->re)
+-	    {
+-	    case CHAR_PIPE:
++	  if (*ctx->re == CHAR_RPAREN)  ctx->re++;
++	  else if (*ctx->re == CHAR_PIPE ||
++		(*ctx->re == CHAR_BACKSLASH && ctx->re[1] == CHAR_PIPE))
++	  {
+ 	      STACK_PUSHX(stack, int, PARSE_UNION);
+ 	      STACK_PUSHX(stack, voidptr, result);
+ 	      STACK_PUSHX(stack, int, PARSE_POST_UNION);
+ 	      STACK_PUSHX(stack, int, PARSE_BRANCH);
+-	      ctx->re++;
+-	      break;
+-
+-	    case CHAR_RPAREN:
+-	      ctx->re++;
+-	      break;
+-
+-	    default:
+-	      break;
+-	    }
++	      ctx->re += 1+(*ctx->re == CHAR_BACKSLASH);
++	  }
+ 	  break;
+ 
+ 	case PARSE_POST_UNION:
+@@ -1181,6 +1176,8 @@ tre_parse(tre_parse_ctx_t *ctx)
+ 		{
+ 		  goto empty_atom;
+ 		}
++	      if (!(ctx->cflags & REG_EXTENDED) && ctx->re[1] == CHAR_PIPE)
++		goto empty_atom;
+ 
+ 	      /* If a macro is used, parse the expanded macro recursively. */
+ 	      {