Use copy() in parse_frag

This commit is contained in:
Devine Lu Linvega 2024-05-10 09:31:09 -07:00
parent 0de5bb473b
commit f6d0cc8ece
1 changed files with 9 additions and 10 deletions

View File

@ -221,20 +221,19 @@ apply_rule(Rule *r, char *s)
} }
static char * static char *
parse_frag(char **side, char *src) parse_frag(char **side, char *s)
{ {
int wrapped; int wrapped;
char c, *cap; char c, *cap;
while((c = *src) && c == ' ') src++; while((c = *s) && c == ' ') s++;
if(c == ')' || (c == '<' && src[1] == '>')) { if(c == ')' || (c == '<' && s[1] == '>')) {
*side = &empty; *side = &empty;
return src; return s;
} }
*side = dict_, cap = walk(src), wrapped = c == '('; *side = dict_, cap = walk(s), wrapped = c == '(';
if(wrapped) src++, cap--; if(wrapped) s++, cap--;
while(src < cap) *dict_++ = *src++; dict_ = copy(s, dict_, cap - s), s = cap + wrapped, *dict_++ = 0;
src += wrapped, *dict_++ = 0; return s;
return src;
} }
static Rule * static Rule *
@ -291,7 +290,7 @@ rewrite(void)
parse_frag(&r->b, parse_frag(&r->a, s + 2)); parse_frag(&r->b, parse_frag(&r->a, s + 2));
s = cap; s = cap;
while(*s == ' ') s++; 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; if(!quiet) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
write_tail(s); write_tail(s);
} }