view sources/patches/musl-regex.patch @ 1737:1acbe7e78d9d draft

Switch from bz2 to gz tarball output. bz2 is slowly being replaced by lz variants, but gzip isn't going anywhere. (It retains a niche as a streaming protocol, it's the 80/20 solution optimizing for speed, low memory requirements, and simple compressor implementation.)
author Rob Landley <rob@landley.net>
date Fri, 20 Feb 2015 13:12:45 -0600
parents 5a7071eb01bb
children 9b4251fda364
line wrap: on
line source

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. */
 	      {