Handle empty register writes at the register level
This commit is contained in:
parent
13ec84d7ef
commit
89f393e349
22
src/modal.c
22
src/modal.c
|
@ -123,16 +123,17 @@ file_import(char *path, char *ptr)
|
||||||
return copy("NAF", ptr, 3);
|
return copy("NAF", ptr, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
write_reg(char r, char *reg)
|
write_reg(char r, char *reg)
|
||||||
{
|
{
|
||||||
char *origin = dst_;
|
|
||||||
switch(r) {
|
switch(r) {
|
||||||
case ':': device_write(reg); break;
|
case ':': device_write(reg); break;
|
||||||
case '~': {
|
case '~': {
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
char *origin = dst_;
|
||||||
while(fread(&c, 1, 1, stdin) && c >= ' ') *dst_++ = c;
|
while(fread(&c, 1, 1, stdin) && c >= ' ') *dst_++ = c;
|
||||||
if(feof(stdin)) dst_ = copy("EOF", dst_, 3);
|
if(feof(stdin)) dst_ = copy("EOF", dst_, 3);
|
||||||
|
if(origin == dst_) dst_--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '_': {
|
case '_': {
|
||||||
|
@ -172,7 +173,6 @@ write_reg(char r, char *reg)
|
||||||
}
|
}
|
||||||
default: dst_ = copy(reg, dst_, walk(reg) - reg);
|
default: dst_ = copy(reg, dst_, walk(reg) - reg);
|
||||||
}
|
}
|
||||||
return dst_ - origin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -193,7 +193,7 @@ static int
|
||||||
apply_rule(Rule *r, char *s)
|
apply_rule(Rule *r, char *s)
|
||||||
{
|
{
|
||||||
unsigned char rid;
|
unsigned char rid;
|
||||||
char c, *a = r->a, *b = r->b, *origin = dst_, *reg, last = 0;
|
char c, *a = r->a, *b = r->b, *origin = dst_, *reg;
|
||||||
/* phase: clean regs */
|
/* phase: clean regs */
|
||||||
while(stack_ != stack) regs[(int)*(--stack_)] = 0;
|
while(stack_ != stack) regs[(int)*(--stack_)] = 0;
|
||||||
/* phase: match rule */
|
/* phase: match rule */
|
||||||
|
@ -215,16 +215,10 @@ apply_rule(Rule *r, char *s)
|
||||||
if(!spacer(c)) return 0;
|
if(!spacer(c)) return 0;
|
||||||
/* phase: write rule */
|
/* phase: write rule */
|
||||||
while((c = *b++))
|
while((c = *b++))
|
||||||
if(c == '?' && (rid = *b) && (reg = regs[rid])) {
|
if(c == '?' && (rid = *b) && (reg = regs[rid]))
|
||||||
b++;
|
write_reg(rid, reg), b++;
|
||||||
if(!write_reg(rid, reg)) {
|
else
|
||||||
if(*b == ' ')
|
*dst_++ = c;
|
||||||
b++;
|
|
||||||
else if(last == ' ')
|
|
||||||
dst_--;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
*dst_++ = last = c;
|
|
||||||
if(dst_ == origin) {
|
if(dst_ == origin) {
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
|
if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
|
||||||
|
|
Loading…
Reference in New Issue