bc: further simplification in zbc_vm_stdin()
function old new delta bc_vm_run 500 523 +23 bc_vec_concat 66 - -66 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 23/-66) Total: -43 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -7058,50 +7058,49 @@ static BC_STATUS zbc_vm_stdin(void)
|
|||||||
comment = false;
|
comment = false;
|
||||||
str = 0;
|
str = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t len;
|
char *string;
|
||||||
|
|
||||||
bc_read_line(&buf);
|
bc_read_line(&buf);
|
||||||
len = buf.len - 1;
|
if (buf.len <= 1) // "" buf means EOF
|
||||||
if (len == 0) // "" buf means EOF
|
|
||||||
break;
|
break;
|
||||||
if (len == 1) {
|
|
||||||
if (str && buf.v[0] == G.send)
|
string = buf.v;
|
||||||
str -= 1;
|
while (*string) {
|
||||||
else if (buf.v[0] == G.sbgn)
|
char c = *string;
|
||||||
str += 1;
|
if (string == buf.v || string[-1] != '\\') {
|
||||||
} else {
|
// checking applet type is cheaper than accessing sbgn/send
|
||||||
char *string = buf.v;
|
if (IS_BC) // bc: sbgn = send = '"'
|
||||||
while (*string) {
|
str ^= (c == '"');
|
||||||
char c = *string;
|
else { // dc: sbgn = '[', send = ']'
|
||||||
if (string == buf.v || string[-1] != '\\') {
|
if (c == ']')
|
||||||
// checking applet type is cheaper than accessing sbgn/send
|
str -= 1;
|
||||||
if (IS_BC) // bc: sbgn = send = '"'
|
else if (c == '[')
|
||||||
str ^= (c == '"');
|
str += 1;
|
||||||
else { // dc: sbgn = '[', send = ']'
|
|
||||||
if (c == ']')
|
|
||||||
str -= 1;
|
|
||||||
else if (c == '[')
|
|
||||||
str += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
string++;
|
|
||||||
if (c == '/' && *string == '*') {
|
|
||||||
comment = true;
|
|
||||||
string++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c == '*' && *string == '/') {
|
|
||||||
comment = false;
|
|
||||||
string++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str || comment || string[-2] == '\\') {
|
string++;
|
||||||
bc_vec_concat(&buffer, buf.v);
|
if (c == '/' && *string == '*') {
|
||||||
|
comment = true;
|
||||||
|
string++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (c == '*' && *string == '/') {
|
||||||
|
comment = false;
|
||||||
|
string++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bc_vec_concat(&buffer, buf.v);
|
bc_vec_concat(&buffer, buf.v);
|
||||||
|
if (str || comment)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Check for backslash+newline.
|
||||||
|
// we do not check that last char is '\n' -
|
||||||
|
// if it is not, then it's EOF, and looping back
|
||||||
|
// to bc_read_line() will detect it:
|
||||||
|
string -= 2;
|
||||||
|
if (string >= buf.v && *string == '\\')
|
||||||
|
continue;
|
||||||
|
|
||||||
s = zbc_vm_process(buffer.v);
|
s = zbc_vm_process(buffer.v);
|
||||||
if (s) {
|
if (s) {
|
||||||
if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) {
|
if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) {
|
||||||
|
Reference in New Issue
Block a user