Empty rules point to a null byte
This commit is contained in:
parent
ff0c53cf68
commit
170cfde437
25
src/modal.c
25
src/modal.c
|
@ -222,13 +222,11 @@ apply_rule(Rule *r, char *s)
|
||||||
c = *s;
|
c = *s;
|
||||||
if(!spacer(c)) return 0;
|
if(!spacer(c)) return 0;
|
||||||
/* phase: write rule */
|
/* phase: write rule */
|
||||||
if(b != NULL) {
|
while((c = *b++))
|
||||||
while((c = *b++))
|
if(c == '?' && (rid = *b) && (reg = regs[rid]))
|
||||||
if(c == '?' && (rid = *b) && (reg = regs[rid]))
|
write_reg(rid, reg), b++;
|
||||||
write_reg(rid, reg), b++;
|
else
|
||||||
else
|
*dst_++ = c;
|
||||||
*dst_++ = c;
|
|
||||||
}
|
|
||||||
if(dst_ == origin) {
|
if(dst_ == origin) {
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
|
if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
|
||||||
|
@ -243,11 +241,8 @@ parse_frag(char **side, char *s)
|
||||||
char c, *cap;
|
char c, *cap;
|
||||||
while((c = *s) && c == ' ') s++;
|
while((c = *s) && c == ' ') s++;
|
||||||
if(c == ')' || (c == '<' && s[1] == '>') || (c == '>' && s[1] == '<')) {
|
if(c == ')' || (c == '<' && s[1] == '>') || (c == '>' && s[1] == '<')) {
|
||||||
*side = NULL;
|
*side = dict_, *dict_++ = 0;
|
||||||
return s;
|
return s;
|
||||||
} else if((c == '(' && s[1] == ')')) {
|
|
||||||
*side = NULL;
|
|
||||||
return s + 2;
|
|
||||||
} else {
|
} else {
|
||||||
cap = walk(s), *side = dict_;
|
cap = walk(s), *side = dict_;
|
||||||
if(c == '(')
|
if(c == '(')
|
||||||
|
@ -277,14 +272,14 @@ static void
|
||||||
remove_rule(Rule *r)
|
remove_rule(Rule *r)
|
||||||
{
|
{
|
||||||
if(r < rules_ - 1) {
|
if(r < rules_ - 1) {
|
||||||
int distance = slen(r->a) + (r->b != NULL ? slen(r->b) : 0);
|
int distance = slen(r->a) + slen(r->b);
|
||||||
char *memsrc = (r + 1)->a;
|
char *memsrc = (r + 1)->a;
|
||||||
copy(memsrc, r->a, dict_ - memsrc);
|
copy(memsrc, r->a, dict_ - memsrc);
|
||||||
while(r < rules_ - 1) {
|
while(r < rules_ - 1) {
|
||||||
Rule *next = r + 1;
|
Rule *next = r + 1;
|
||||||
r->id = next->id, r->refs = next->refs;
|
r->id = next->id, r->refs = next->refs;
|
||||||
r->a = next->a - distance;
|
r->a = next->a - distance;
|
||||||
r->b = next->b == NULL ? NULL : next->b - distance;
|
r->b = next->b - distance;
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +310,7 @@ rewrite(void)
|
||||||
if(c == '<' && s[1] == '>') {
|
if(c == '<' && s[1] == '>') {
|
||||||
r = rules_, r->id = rules_ - rules;
|
r = rules_, r->id = rules_ - rules;
|
||||||
s = parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
s = parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
||||||
if(r->a != NULL) {
|
if(*r->a) {
|
||||||
if(!quiet) fprintf(stderr, "<> (%s) (%s)\n", r->a ? r->a : "", r->b ? r->b : "");
|
if(!quiet) fprintf(stderr, "<> (%s) (%s)\n", r->a ? r->a : "", r->b ? r->b : "");
|
||||||
rules_++;
|
rules_++;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +325,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(r->a == NULL || !apply_rule(r, s)) write_tail(s);
|
if(!(*r->a) || !apply_rule(r, s)) write_tail(s);
|
||||||
dict_ = d;
|
dict_ = d;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue