aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-03 21:10:57 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 15:43:35 +0100
commit04a1c763a621f6995e6875f0a4674314ff21c44d (patch)
tree2ab1b75a89d27a448f0c833c314b426cac11c0d8
parenta02f84472a9508e499f0eecd748929a44f5d3869 (diff)
downloadbusybox-w32-04a1c763a621f6995e6875f0a4674314ff21c44d.tar.gz
busybox-w32-04a1c763a621f6995e6875f0a4674314ff21c44d.tar.bz2
busybox-w32-04a1c763a621f6995e6875f0a4674314ff21c44d.zip
bc: convert BC_STATUS_EXEC_MISMATCHED_PARAMS and BC_STATUS_EXEC_UNDEFINED_FUNC
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index b57f741d6..0d81e13cf 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -200,8 +200,8 @@ typedef enum BcStatus {
200 BC_STATUS_MATH_BAD_STRING, 200 BC_STATUS_MATH_BAD_STRING,
201 201
202// BC_STATUS_EXEC_FILE_ERR, 202// BC_STATUS_EXEC_FILE_ERR,
203 BC_STATUS_EXEC_MISMATCHED_PARAMS, 203// BC_STATUS_EXEC_MISMATCHED_PARAMS,
204 BC_STATUS_EXEC_UNDEFINED_FUNC, 204// BC_STATUS_EXEC_UNDEFINED_FUNC,
205 BC_STATUS_EXEC_FILE_NOT_EXECUTABLE, 205 BC_STATUS_EXEC_FILE_NOT_EXECUTABLE,
206 BC_STATUS_EXEC_NUM_LEN, 206 BC_STATUS_EXEC_NUM_LEN,
207 BC_STATUS_EXEC_NAME_LEN, 207 BC_STATUS_EXEC_NAME_LEN,
@@ -241,7 +241,7 @@ typedef enum BcStatus {
241// Keep enum above and messages below in sync! 241// Keep enum above and messages below in sync!
242static const char *const bc_err_msgs[] = { 242static const char *const bc_err_msgs[] = {
243 NULL, 243 NULL,
244 "", 244 NULL,
245// "memory allocation error", 245// "memory allocation error",
246// "I/O error", 246// "I/O error",
247// "file is not text:", 247// "file is not text:",
@@ -272,8 +272,8 @@ static const char *const bc_err_msgs[] = {
272 "bad number string", 272 "bad number string",
273 273
274// "could not open file:", 274// "could not open file:",
275 "mismatched parameters", // wrong number of them, to be exact 275// "mismatched parameters", // wrong number of them, to be exact
276 "undefined function", 276// "undefined function",
277 "file is not executable:", 277 "file is not executable:",
278 "number too long: must be [1, BC_NUM_MAX]", 278 "number too long: must be [1, BC_NUM_MAX]",
279 "name too long: must be [1, BC_NAME_MAX]", 279 "name too long: must be [1, BC_NAME_MAX]",
@@ -5990,8 +5990,12 @@ static BcStatus bc_program_call(char *code, size_t *idx)
5990 ip.func = bc_program_index(code, idx); 5990 ip.func = bc_program_index(code, idx);
5991 func = bc_vec_item(&G.prog.fns, ip.func); 5991 func = bc_vec_item(&G.prog.fns, ip.func);
5992 5992
5993 if (func->code.len == 0) return BC_STATUS_EXEC_UNDEFINED_FUNC; 5993 if (func->code.len == 0) {
5994 if (nparams != func->nparams) return BC_STATUS_EXEC_MISMATCHED_PARAMS; 5994 return bc_error("undefined function");
5995 }
5996 if (nparams != func->nparams) {
5997 return bc_error("function has %u parameters, but called with %u", func->nparams, nparams);
5998 }
5995 ip.len = G.prog.results.len - nparams; 5999 ip.len = G.prog.results.len - nparams;
5996 6000
5997 for (i = 0; i < nparams; ++i) { 6001 for (i = 0; i < nparams; ++i) {
@@ -6848,9 +6852,11 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line)
6848{ 6852{
6849 if (!s || s > BC_STATUS_BEFORE_POSIX) return s; 6853 if (!s || s > BC_STATUS_BEFORE_POSIX) return s;
6850 6854
6851 fprintf(stderr, bc_err_fmt, bc_err_msgs[s]); 6855 if (bc_err_msgs[s]) {
6852 fprintf(stderr, " %s", file); 6856 fprintf(stderr, bc_err_fmt, bc_err_msgs[s]);
6853 fprintf(stderr, bc_err_line + 4 * !line, line); 6857 fprintf(stderr, " %s", file);
6858 fprintf(stderr, bc_err_line + 4 * !line, line);
6859 }
6854 6860
6855 return s * (!G.ttyin || !!strcmp(file, bc_program_stdin_name)); 6861 return s * (!G.ttyin || !!strcmp(file, bc_program_stdin_name));
6856} 6862}