diff --git a/src/modal.c b/src/modal.c index 3944cc6..641dc90 100644 --- a/src/modal.c +++ b/src/modal.c @@ -153,54 +153,45 @@ find_register(Rule *r, char reg) { int i; for(i = 0; i < (int)r->ptr; i++) - if(r->key[i] == reg) - return i; + if(r->key[i] == reg) return i; return -1; } static char * compile_rule(Rule *r, int id, char *src) { - int wrapped, reg; char c, *cap; + int wrapped, reg; r->id = id, r->ptr = 0, r->a = &empty, r->b = ∅ /* phase: left */ while((c = *src) && c == ' ') src++; if(c == ')' || (c == '<' && src[1] == '>')) return src; - r->a = dict_; - cap = walk(src); - wrapped = c == '('; + r->a = dict_, cap = walk(src), wrapped = c == '('; if(wrapped) src++, cap--; while(src < cap) { - if(*src == '?') { - *dict_++ = *src++; + c = *src, *dict_++ = *src++; + if(c == '?') { reg = find_register(r, *src); - if(reg < 0 && *src != '(') + if(reg == -1 && *src != '(') r->key[r->ptr] = *src, reg = r->ptr++; *dict_++ = '0' + reg; - } else - *dict_++ = *src++; + } } - src += wrapped; - *dict_++ = 0; + src += wrapped, *dict_++ = 0; /* phase: right */ while((c = *src) && c == ' ') src++; if(c == ')' || (c == '<' && src[1] == '>')) return src; - r->b = dict_; - cap = walk(src); - wrapped = c == '('; + r->b = dict_, cap = walk(src), wrapped = c == '('; if(wrapped) src++, cap--; while(src < cap) { - if(*src == '?') { - *dict_++ = *src++; + c = *src, *dict_++ = *src++; + if(c == '?') { reg = find_register(r, *src); - *dict_++ = reg >= 0 ? ('0' + reg) : *src; + *dict_++ = reg != -1 ? '0' + reg : *src; src++; - } else - *dict_++ = *src++; + } } - src += wrapped; - *dict_++ = 0; + src += wrapped, *dict_++ = 0; return src; }