From f6d0cc8eceb3a47ae5c7b315abe5f9205a211235 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 10 May 2024 09:31:09 -0700 Subject: [PATCH] Use copy() in parse_frag --- src/modal.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/modal.c b/src/modal.c index 4a94246..c18da75 100644 --- a/src/modal.c +++ b/src/modal.c @@ -221,20 +221,19 @@ apply_rule(Rule *r, char *s) } static char * -parse_frag(char **side, char *src) +parse_frag(char **side, char *s) { int wrapped; char c, *cap; - while((c = *src) && c == ' ') src++; - if(c == ')' || (c == '<' && src[1] == '>')) { + while((c = *s) && c == ' ') s++; + if(c == ')' || (c == '<' && s[1] == '>')) { *side = ∅ - return src; + return s; } - *side = dict_, cap = walk(src), wrapped = c == '('; - if(wrapped) src++, cap--; - while(src < cap) *dict_++ = *src++; - src += wrapped, *dict_++ = 0; - return src; + *side = dict_, cap = walk(s), wrapped = c == '('; + if(wrapped) s++, cap--; + dict_ = copy(s, dict_, cap - s), s = cap + wrapped, *dict_++ = 0; + return s; } static Rule * @@ -291,7 +290,7 @@ rewrite(void) parse_frag(&r->b, parse_frag(&r->a, s + 2)); s = cap; while(*s == ' ') s++; - if(!apply_rule(r, s)) { + if(r->a && !apply_rule(r, s)) { if(!quiet) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs; write_tail(s); }