From 8702b6472b07a57f18aa0088b77e296729f70634 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 19:55:05 -0700 Subject: [PATCH] Exit after match in rewrite --- src/modal.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/modal.c b/src/modal.c index 61431c0..108efbf 100644 --- a/src/modal.c +++ b/src/modal.c @@ -73,10 +73,10 @@ save(void) static int rewrite(void) { - int success = 0; + char c, *p = prog; while((c = *p)) { - int i, found = 0; + int i; for(i = 0; i < rules_len; i++) { Rule *r = &rules[i]; char *res = match(p, r); @@ -88,19 +88,18 @@ rewrite(void) else *outp_++ = cc; } - found = success = 1; - p = res; + while((*outp_++ = *res++)) + ; + *outp_++ = 0; + save(); + return 1; } } - if(!found) { - *outp_++ = c; - p++; - } + *outp_++ = c; + p++; } *outp_++ = 0; - if(success) - save(); - return success; + return 0; } static void