aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index ee4f21364..90c3bf5d6 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1216,41 +1216,41 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
1216 , stderr); 1216 , stderr);
1217 } 1217 }
1218#endif 1218#endif
1219 if (G_ttyin && !G_posix) 1219 {
1220 fputs(prompt, stderr); 1220 if (G_ttyin && !G_posix)
1221 fputs(prompt, stderr);
1221 1222
1223 IF_FEATURE_BC_SIGNALS(errno = 0;)
1224 do {
1225 i = fgetc(stdin);
1226 if (i == EOF) {
1222#if ENABLE_FEATURE_BC_SIGNALS 1227#if ENABLE_FEATURE_BC_SIGNALS
1223 errno = 0; 1228 // Both conditions appear simultaneously, check both just in case
1229 if (errno == EINTR || bb_got_signal) {
1230 // ^C was pressed
1231 clearerr(stdin);
1232 goto intr;
1233 }
1224#endif 1234#endif
1225 do { 1235 if (ferror(stdin))
1226 i = fgetc(stdin); 1236 quit(); // this emits error message
1227 if (i == EOF) { 1237 G.eof = 1;
1228#if ENABLE_FEATURE_BC_SIGNALS 1238 // Note: EOF does not append '\n', therefore:
1229 // Both conditions appear simultaneously, check both just in case 1239 // printf 'print 123\n' | bc - works
1230 if (errno == EINTR || bb_got_signal) { 1240 // printf 'print 123' | bc - fails (syntax error)
1231 // ^C was pressed 1241 break;
1232 clearerr(stdin);
1233 goto intr;
1234 } 1242 }
1235#endif
1236 if (ferror(stdin))
1237 quit(); // this emits error message
1238 G.eof = 1;
1239 // Note: EOF does not append '\n', therefore:
1240 // printf 'print 123\n' | bc - works
1241 // printf 'print 123' | bc - fails (syntax error)
1242 break;
1243 }
1244 1243
1245 if ((i < ' ' && i != '\t' && i != '\r' && i != '\n') // also allow '\v' '\f'? 1244 if ((i < ' ' && i != '\t' && i != '\r' && i != '\n') // also allow '\v' '\f'?
1246 || i > 0x7e 1245 || i > 0x7e
1247 ) { 1246 ) {
1248 // Bad chars on this line, ignore entire line 1247 // Bad chars on this line, ignore entire line
1249 bc_error_fmt("illegal character 0x%02x", i); 1248 bc_error_fmt("illegal character 0x%02x", i);
1250 bad_chars = 1; 1249 bad_chars = 1;
1251 } 1250 }
1252 bc_vec_pushByte(vec, (char)i); 1251 bc_vec_pushByte(vec, (char)i);
1253 } while (i != '\n'); 1252 } while (i != '\n');
1253 }
1254 } while (bad_chars); 1254 } while (bad_chars);
1255 1255
1256 bc_vec_pushZeroByte(vec); 1256 bc_vec_pushZeroByte(vec);