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 *
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 = &empty;
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);
}