diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 22:43:58 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 22:43:58 +0100 |
| commit | 8a89247e0a82b328958e010be5da4c815f9121be (patch) | |
| tree | 1c9754731d4c7e0317877c2d90455f1e7a3cb745 /miscutils | |
| parent | d8078a79beb665cb3c0408dbbbba132cff9fdc3b (diff) | |
| download | busybox-w32-8a89247e0a82b328958e010be5da4c815f9121be.tar.gz busybox-w32-8a89247e0a82b328958e010be5da4c815f9121be.tar.bz2 busybox-w32-8a89247e0a82b328958e010be5da4c815f9121be.zip | |
bc: remove BC_STATUS_EOF (again), the condition is detectable as len==0
function old new delta
bc_read_line 147 129 -18
bc_vm_run 618 591 -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-45) Total: -45 bytes
text data bss dec hex filename
980802 485 7296 988583 f15a7 busybox_old
980757 485 7296 988538 f157a busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 9cc29f0ea..9809fa72f 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -187,7 +187,6 @@ typedef enum BcStatus { | |||
| 187 | BC_STATUS_SUCCESS = 0, | 187 | BC_STATUS_SUCCESS = 0, |
| 188 | BC_STATUS_FAILURE = 1, | 188 | BC_STATUS_FAILURE = 1, |
| 189 | BC_STATUS_PARSE_EMPTY_EXP = 2, // bc_parse_expr_empty_ok() uses this | 189 | BC_STATUS_PARSE_EMPTY_EXP = 2, // bc_parse_expr_empty_ok() uses this |
| 190 | BC_STATUS_EOF = 3, // bc_vm_stdin() uses this | ||
| 191 | } BcStatus; | 190 | } BcStatus; |
| 192 | 191 | ||
| 193 | #define BC_VEC_INVALID_IDX ((size_t) -1) | 192 | #define BC_VEC_INVALID_IDX ((size_t) -1) |
| @@ -1364,15 +1363,10 @@ static int push_input_byte(BcVec *vec, char c) | |||
| 1364 | return 0; | 1363 | return 0; |
| 1365 | } | 1364 | } |
| 1366 | 1365 | ||
| 1367 | // This is not a "z" function: | 1366 | static void bc_read_line(BcVec *vec) |
| 1368 | // can return success (0) or BC_STATUS_EOF. | ||
| 1369 | // Exits with error message if read error is detected. | ||
| 1370 | static BcStatus bc_read_line(BcVec *vec) | ||
| 1371 | { | 1367 | { |
| 1372 | BcStatus s; | ||
| 1373 | bool bad_chars; | 1368 | bool bad_chars; |
| 1374 | 1369 | ||
| 1375 | s = BC_STATUS_SUCCESS; | ||
| 1376 | do { | 1370 | do { |
| 1377 | int c; | 1371 | int c; |
| 1378 | 1372 | ||
| @@ -1397,7 +1391,6 @@ static BcStatus bc_read_line(BcVec *vec) | |||
| 1397 | if (n <= 0) { // read errors or EOF, or ^D, or ^C | 1391 | if (n <= 0) { // read errors or EOF, or ^D, or ^C |
| 1398 | if (n == 0) // ^C | 1392 | if (n == 0) // ^C |
| 1399 | goto intr; | 1393 | goto intr; |
| 1400 | s = BC_STATUS_EOF; | ||
| 1401 | break; | 1394 | break; |
| 1402 | } | 1395 | } |
| 1403 | i = 0; | 1396 | i = 0; |
| @@ -1425,9 +1418,6 @@ static BcStatus bc_read_line(BcVec *vec) | |||
| 1425 | if (c == EOF) { | 1418 | if (c == EOF) { |
| 1426 | if (ferror(stdin)) | 1419 | if (ferror(stdin)) |
| 1427 | quit(); // this emits error message | 1420 | quit(); // this emits error message |
| 1428 | // If we had some input before EOF, do not report EOF yet: | ||
| 1429 | if (vec->len == 0) | ||
| 1430 | s = BC_STATUS_EOF; | ||
| 1431 | // Note: EOF does not append '\n', therefore: | 1421 | // Note: EOF does not append '\n', therefore: |
| 1432 | // printf 'print 123\n' | bc - works | 1422 | // printf 'print 123\n' | bc - works |
| 1433 | // printf 'print 123' | bc - fails (syntax error) | 1423 | // printf 'print 123' | bc - fails (syntax error) |
| @@ -1439,8 +1429,6 @@ static BcStatus bc_read_line(BcVec *vec) | |||
| 1439 | } while (bad_chars); | 1429 | } while (bad_chars); |
| 1440 | 1430 | ||
| 1441 | bc_vec_pushZeroByte(vec); | 1431 | bc_vec_pushZeroByte(vec); |
| 1442 | |||
| 1443 | return s; | ||
| 1444 | } | 1432 | } |
| 1445 | 1433 | ||
| 1446 | static char* bc_read_file(const char *path) | 1434 | static char* bc_read_file(const char *path) |
| @@ -5416,8 +5404,7 @@ static BC_STATUS zbc_program_read(void) | |||
| 5416 | G.prog.file = NULL; | 5404 | G.prog.file = NULL; |
| 5417 | G.in_read = 1; | 5405 | G.in_read = 1; |
| 5418 | 5406 | ||
| 5419 | s = bc_read_line(&buf); | 5407 | bc_read_line(&buf); |
| 5420 | //if (s) goto io_err; - wrong, nonzero return means EOF, not error | ||
| 5421 | 5408 | ||
| 5422 | common_parse_init(&parse, BC_PROG_READ); | 5409 | common_parse_init(&parse, BC_PROG_READ); |
| 5423 | bc_lex_file(&parse.l); | 5410 | bc_lex_file(&parse.l); |
| @@ -7091,13 +7078,18 @@ static BcStatus bc_vm_stdin(void) | |||
| 7091 | // with a backslash to the parser. The reason for that is because the parser | 7078 | // with a backslash to the parser. The reason for that is because the parser |
| 7092 | // treats a backslash+newline combo as whitespace, per the bc spec. In that | 7079 | // treats a backslash+newline combo as whitespace, per the bc spec. In that |
| 7093 | // case, and for strings and comments, the parser will expect more stuff. | 7080 | // case, and for strings and comments, the parser will expect more stuff. |
| 7081 | s = BC_STATUS_SUCCESS; | ||
| 7094 | comment = false; | 7082 | comment = false; |
| 7095 | str = 0; | 7083 | str = 0; |
| 7096 | while ((s = bc_read_line(&buf)) == BC_STATUS_SUCCESS) { | 7084 | for (;;) { |
| 7097 | size_t len; | 7085 | size_t len; |
| 7098 | char *string = buf.v; | 7086 | char *string; |
| 7099 | 7087 | ||
| 7088 | bc_read_line(&buf); | ||
| 7100 | len = buf.len - 1; | 7089 | len = buf.len - 1; |
| 7090 | if (len == 0) // "" buf means EOF | ||
| 7091 | break; | ||
| 7092 | string = buf.v; | ||
| 7101 | if (len == 1) { | 7093 | if (len == 1) { |
| 7102 | if (str && buf.v[0] == G.send) | 7094 | if (str && buf.v[0] == G.send) |
| 7103 | str -= 1; | 7095 | str -= 1; |
| @@ -7146,8 +7138,6 @@ static BcStatus bc_vm_stdin(void) | |||
| 7146 | 7138 | ||
| 7147 | bc_vec_pop_all(&buffer); | 7139 | bc_vec_pop_all(&buffer); |
| 7148 | } | 7140 | } |
| 7149 | if (s == BC_STATUS_EOF) // input EOF (^D) is not an error | ||
| 7150 | s = BC_STATUS_SUCCESS; | ||
| 7151 | 7141 | ||
| 7152 | if (str) { | 7142 | if (str) { |
| 7153 | s = bc_error("string end could not be found"); | 7143 | s = bc_error("string end could not be found"); |
