diff options
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 0943f606d..ee4f21364 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -116,7 +116,7 @@ | |||
| 116 | 116 | ||
| 117 | //See www.gnu.org/software/bc/manual/bc.html | 117 | //See www.gnu.org/software/bc/manual/bc.html |
| 118 | //usage:#define bc_trivial_usage | 118 | //usage:#define bc_trivial_usage |
| 119 | //usage: "[-sqli] FILE..." | 119 | //usage: "[-sqliw] FILE..." |
| 120 | //usage: | 120 | //usage: |
| 121 | //usage:#define bc_full_usage "\n" | 121 | //usage:#define bc_full_usage "\n" |
| 122 | //usage: "\nArbitrary precision calculator" | 122 | //usage: "\nArbitrary precision calculator" |
| @@ -127,6 +127,7 @@ | |||
| 127 | //usage: "\n -q Quiet" | 127 | //usage: "\n -q Quiet" |
| 128 | //usage: "\n -w Warn if extensions are used" | 128 | //usage: "\n -w Warn if extensions are used" |
| 129 | ///////: "\n -v Version" | 129 | ///////: "\n -v Version" |
| 130 | //usage: "\n$BC_LINE_LENGTH changes output width" | ||
| 130 | //usage: | 131 | //usage: |
| 131 | //usage:#define bc_example_usage | 132 | //usage:#define bc_example_usage |
| 132 | //usage: "3 + 4.129\n" | 133 | //usage: "3 + 4.129\n" |
| @@ -734,7 +735,7 @@ static void bc_program_reset(void); | |||
| 734 | #define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1) | 735 | #define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1) |
| 735 | 736 | ||
| 736 | struct globals { | 737 | struct globals { |
| 737 | smallint ttyin; | 738 | IF_FEATURE_BC_SIGNALS(smallint ttyin;) |
| 738 | smallint eof; | 739 | smallint eof; |
| 739 | char sbgn; | 740 | char sbgn; |
| 740 | char send; | 741 | char send; |
| @@ -761,7 +762,11 @@ struct globals { | |||
| 761 | #define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W)) | 762 | #define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W)) |
| 762 | #define G_exreg (ENABLE_DC && (option_mask32 & BC_FLAG_X)) | 763 | #define G_exreg (ENABLE_DC && (option_mask32 & BC_FLAG_X)) |
| 763 | #define G_interrupt (ENABLE_FEATURE_BC_SIGNALS ? bb_got_signal : 0) | 764 | #define G_interrupt (ENABLE_FEATURE_BC_SIGNALS ? bb_got_signal : 0) |
| 764 | 765 | #if ENABLE_FEATURE_BC_SIGNALS | |
| 766 | # define G_ttyin G.ttyin | ||
| 767 | #else | ||
| 768 | # define G_ttyin 0 | ||
| 769 | #endif | ||
| 765 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) | 770 | #define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b')) |
| 766 | 771 | ||
| 767 | #if ENABLE_BC | 772 | #if ENABLE_BC |
| @@ -904,7 +909,7 @@ static void fflush_and_check(void) | |||
| 904 | #if ENABLE_FEATURE_CLEAN_UP | 909 | #if ENABLE_FEATURE_CLEAN_UP |
| 905 | #define quit_or_return_for_exit() \ | 910 | #define quit_or_return_for_exit() \ |
| 906 | do { \ | 911 | do { \ |
| 907 | G.ttyin = 0; /* do not loop in main loop anymore */ \ | 912 | IF_FEATURE_BC_SIGNALS(G_ttyin = 0;) /* do not loop in main loop anymore */ \ |
| 908 | return BC_STATUS_FAILURE; \ | 913 | return BC_STATUS_FAILURE; \ |
| 909 | } while (0) | 914 | } while (0) |
| 910 | #else | 915 | #else |
| @@ -942,7 +947,7 @@ static NOINLINE int bc_error_fmt(const char *fmt, ...) | |||
| 942 | bc_verror_msg(fmt, p); | 947 | bc_verror_msg(fmt, p); |
| 943 | va_end(p); | 948 | va_end(p); |
| 944 | 949 | ||
| 945 | if (!ENABLE_FEATURE_CLEAN_UP && !G.ttyin) | 950 | if (!ENABLE_FEATURE_CLEAN_UP && !G_ttyin) |
| 946 | exit(1); | 951 | exit(1); |
| 947 | return BC_STATUS_FAILURE; | 952 | return BC_STATUS_FAILURE; |
| 948 | } | 953 | } |
| @@ -962,7 +967,7 @@ static NOINLINE int bc_posix_error_fmt(const char *fmt, ...) | |||
| 962 | // Do we treat non-POSIX constructs as errors? | 967 | // Do we treat non-POSIX constructs as errors? |
| 963 | if (!(option_mask32 & BC_FLAG_S)) | 968 | if (!(option_mask32 & BC_FLAG_S)) |
| 964 | return BC_STATUS_SUCCESS; // no, it's a warning | 969 | return BC_STATUS_SUCCESS; // no, it's a warning |
| 965 | if (!ENABLE_FEATURE_CLEAN_UP && !G.ttyin) | 970 | if (!ENABLE_FEATURE_CLEAN_UP && !G_ttyin) |
| 966 | exit(1); | 971 | exit(1); |
| 967 | return BC_STATUS_FAILURE; | 972 | return BC_STATUS_FAILURE; |
| 968 | } | 973 | } |
| @@ -1211,7 +1216,7 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt) | |||
| 1211 | , stderr); | 1216 | , stderr); |
| 1212 | } | 1217 | } |
| 1213 | #endif | 1218 | #endif |
| 1214 | if (G.ttyin && !G_posix) | 1219 | if (G_ttyin && !G_posix) |
| 1215 | fputs(prompt, stderr); | 1220 | fputs(prompt, stderr); |
| 1216 | 1221 | ||
| 1217 | #if ENABLE_FEATURE_BC_SIGNALS | 1222 | #if ENABLE_FEATURE_BC_SIGNALS |
| @@ -7034,7 +7039,7 @@ static BcStatus bc_vm_stdin(void) | |||
| 7034 | bc_vec_concat(&buffer, buf.v); | 7039 | bc_vec_concat(&buffer, buf.v); |
| 7035 | s = bc_vm_process(buffer.v); | 7040 | s = bc_vm_process(buffer.v); |
| 7036 | if (s) { | 7041 | if (s) { |
| 7037 | if (ENABLE_FEATURE_CLEAN_UP && !G.ttyin) { | 7042 | if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) { |
| 7038 | // Debug config, non-interactive mode: | 7043 | // Debug config, non-interactive mode: |
| 7039 | // return all the way back to main. | 7044 | // return all the way back to main. |
| 7040 | // Non-debug builds do not come here, they exit. | 7045 | // Non-debug builds do not come here, they exit. |
| @@ -7263,7 +7268,7 @@ static BcStatus bc_vm_exec(void) | |||
| 7263 | for (i = 0; !s && i < G.files.len; ++i) | 7268 | for (i = 0; !s && i < G.files.len; ++i) |
| 7264 | s = bc_vm_file(*((char **) bc_vec_item(&G.files, i))); | 7269 | s = bc_vm_file(*((char **) bc_vec_item(&G.files, i))); |
| 7265 | if (s) { | 7270 | if (s) { |
| 7266 | if (ENABLE_FEATURE_CLEAN_UP && !G.ttyin) { | 7271 | if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) { |
| 7267 | // Debug config, non-interactive mode: | 7272 | // Debug config, non-interactive mode: |
| 7268 | // return all the way back to main. | 7273 | // return all the way back to main. |
| 7269 | // Non-debug builds do not come here, they exit. | 7274 | // Non-debug builds do not come here, they exit. |
| @@ -7391,9 +7396,9 @@ static BcStatus bc_vm_run(char **argv, const char *env_len) | |||
| 7391 | bc_vm_init(); | 7396 | bc_vm_init(); |
| 7392 | bc_args(argv); | 7397 | bc_args(argv); |
| 7393 | 7398 | ||
| 7394 | G.ttyin = isatty(0); | 7399 | if (isatty(0)) { |
| 7395 | if (G.ttyin) { | ||
| 7396 | #if ENABLE_FEATURE_BC_SIGNALS | 7400 | #if ENABLE_FEATURE_BC_SIGNALS |
| 7401 | G_ttyin = 1; | ||
| 7397 | // With SA_RESTART, most system calls will restart | 7402 | // With SA_RESTART, most system calls will restart |
| 7398 | // (IOW: they won't fail with EINTR). | 7403 | // (IOW: they won't fail with EINTR). |
| 7399 | // In particular, this means ^C won't cause | 7404 | // In particular, this means ^C won't cause |
