From d07ad6a1491f5d8b137e414f01ce573b4bb14416 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Tue, 4 Aug 2015 18:20:06 +0200 Subject: [PATCH] Added more tests and fixed some border-case errors on the extglob translator --- samples/tests/pattern.sh | 7 +++++-- src/extmatch.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/samples/tests/pattern.sh b/samples/tests/pattern.sh index 3d2a505..09996f1 100755 --- a/samples/tests/pattern.sh +++ b/samples/tests/pattern.sh @@ -1,7 +1,10 @@ -#!/bin/sh +#!/bin/sh -e ./simple --pattern '*/passing' ./simple --pattern '!(*/passing)' ./simple --pattern '[pf]a@(ss|il)ing' ./simple --pattern '@(+(nest)ed))' ./simple --pattern '?(*(a|b))' -./simple --pattern '?(malformed' +! ./simple --pattern '?(malformed' +./simple --pattern '[!azerty]assing' +./simple --pattern '|pipe' +./simple --pattern '\!(escaped' diff --git a/src/extmatch.c b/src/extmatch.c index f03154d..205a148 100644 --- a/src/extmatch.c +++ b/src/extmatch.c @@ -13,7 +13,7 @@ struct context { char old, cur; int eos; const char **errmsg; - jmp_buf jmp; + jmp_buf *jmp; }; void transform_impl(struct context *ctx); @@ -25,6 +25,8 @@ static inline void transform_rec(struct context *ctx) { .src = ctx->src, .old = ctx->old, .eos = ctx->eos, + .errmsg = ctx->errmsg, + .jmp = ctx->jmp, }; transform_impl(&new_ctx); ctx->dst = new_ctx.dst; @@ -154,6 +156,8 @@ void transform_impl(struct context *ctx) { ['('] = escape_char, [')'] = escape_char, ['|'] = escape_pipe, + + [255] = NULL, }; for (char c = read_char(ctx); !ctx->eos; c = read_char(ctx)) { f_handler handler = handlers[(unsigned char) c]; @@ -171,17 +175,19 @@ void transform_impl(struct context *ctx) { } if (ctx->depth > 0) { *ctx->errmsg = "mismatching parenthesis"; - longjmp(ctx->jmp, -1); // abort operation + longjmp(*ctx->jmp, -1); // abort operation } } static int transform(const char *pattern, char *result, const char **errmsg) { + jmp_buf jmp; struct context ctx = { .src = pattern, .dst = result, .errmsg = errmsg, + .jmp = &jmp, }; - if (!setjmp(ctx.jmp)) { + if (!setjmp(*ctx.jmp)) { copy_char(&ctx, '^'); transform_impl(&ctx); copy_char(&ctx, '$');