diff options
-rw-r--r-- | miscutils/bc.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 47acd7fc3..7ab320a4d 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -758,6 +758,7 @@ struct globals { | |||
758 | # define G_exiting 0 | 758 | # define G_exiting 0 |
759 | #endif | 759 | #endif |
760 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) | 760 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) |
761 | #define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b')) | ||
761 | 762 | ||
762 | #if ENABLE_BC | 763 | #if ENABLE_BC |
763 | 764 | ||
@@ -7070,27 +7071,28 @@ static BC_STATUS zbc_vm_stdin(void) | |||
7070 | str -= 1; | 7071 | str -= 1; |
7071 | else if (buf.v[0] == G.sbgn) | 7072 | else if (buf.v[0] == G.sbgn) |
7072 | str += 1; | 7073 | str += 1; |
7073 | } | 7074 | } else { |
7074 | else if (len > 1 || comment) { | ||
7075 | size_t i; | 7075 | size_t i; |
7076 | for (i = 0; i < len; ++i) { | 7076 | for (i = 0; i < len; ++i) { |
7077 | bool notend = len > i + 1; | ||
7078 | char c = string[i]; | 7077 | char c = string[i]; |
7079 | 7078 | ||
7080 | if (i - 1 > len || string[i - 1] != '\\') { | 7079 | if (i - 1 > len || string[i - 1] != '\\') { |
7081 | if (G.sbgn == G.send) | 7080 | // checking applet type is cheaper than accessing sbgn/send |
7082 | str ^= c == G.sbgn; | 7081 | if (IS_DC) // dc: sbgn = send = '"' |
7083 | else if (c == G.send) | 7082 | str ^= (c == '"'); |
7084 | str -= 1; | 7083 | else { // bc: sbgn = '[', send = ']' |
7085 | else if (c == G.sbgn) | 7084 | if (c == ']') |
7086 | str += 1; | 7085 | str -= 1; |
7086 | else if (c == '[') | ||
7087 | str += 1; | ||
7088 | } | ||
7087 | } | 7089 | } |
7088 | 7090 | ||
7089 | if (c == '/' && notend && !comment && string[i + 1] == '*') { | 7091 | if (c == '/' && !comment && string[i + 1] == '*') { |
7090 | comment = true; | 7092 | comment = true; |
7091 | break; | 7093 | break; |
7092 | } | 7094 | } |
7093 | else if (c == '*' && notend && comment && string[i + 1] == '/') | 7095 | else if (c == '*' && comment && string[i + 1] == '/') |
7094 | comment = false; | 7096 | comment = false; |
7095 | } | 7097 | } |
7096 | 7098 | ||