From ca76fdd9c3dcd43b81f7a456ae1fd7dc0956f5ea Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 24 Apr 2024 15:08:09 -0700 Subject: [PATCH] Removed temporary pointers --- src/modal.c | 73 +++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/src/modal.c b/src/modal.c index 62b1191..2e1fd8a 100644 --- a/src/modal.c +++ b/src/modal.c @@ -162,66 +162,51 @@ static char * compile_rule(Rule *r, int id, char *src) { int wrapped, reg; - char c, *cap, *s2; + char c, *cap; r->id = id, r->ptr = 0; - - /* left ==================================== */ - + /* phase: left */ r->a = r->b = dict_; - s2 = src; - - while((c = *s2) && c == ' ') s2++; - if(c == ')' || (c == '<' && s2[1] == '>')) { + while((c = *src) && c == ' ') src++; + if(c == ')' || (c == '<' && src[1] == '>')) { *dict_++ = 0; - return s2; + return src; } - - cap = walk(s2); + cap = walk(src); wrapped = c == '('; - if(wrapped) s2++, cap--; - while(s2 < cap) { - if(*s2 == '?') { - *dict_++ = *s2++; - reg = find_register(r, *s2); - if(reg < 0 && *s2 != '(') - r->key[r->ptr] = *s2, reg = r->ptr++; + if(wrapped) src++, cap--; + while(src < cap) { + if(*src == '?') { + *dict_++ = *src++; + reg = find_register(r, *src); + if(reg < 0 && *src != '(') + r->key[r->ptr] = *src, reg = r->ptr++; *dict_++ = '0' + reg; } else - *dict_++ = *s2++; + *dict_++ = *src++; } - s2 += wrapped; - + src += wrapped; *dict_++ = 0; - src = s2; - - /* right ==================================== */ - + /* phase: right */ r->b = dict_; - s2 = src; - - while((c = *s2) && c == ' ') s2++; - if(c == ')' || (c == '<' && s2[1] == '>')) { + while((c = *src) && c == ' ') src++; + if(c == ')' || (c == '<' && src[1] == '>')) { *dict_++ = 0; - return s2; + return src; } - - cap = walk(s2); + cap = walk(src); wrapped = c == '('; - if(wrapped) s2++, cap--; - while(s2 < cap) { - if(*s2 == '?') { - *dict_++ = *s2++; - reg = find_register(r, *s2); - *dict_++ = reg >= 0 ? ('0' + reg) : *s2; - s2++; + if(wrapped) src++, cap--; + while(src < cap) { + if(*src == '?') { + *dict_++ = *src++; + reg = find_register(r, *src); + *dict_++ = reg >= 0 ? ('0' + reg) : *src; + src++; } else - *dict_++ = *s2++; + *dict_++ = *src++; } - s2 += wrapped; - + src += wrapped; *dict_++ = 0; - src = s2; - return src; }