aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-03 00:26:12 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 15:43:35 +0100
commitb8860a8892f077091177170fe483d545d33789a6 (patch)
tree3ef26855f8e9547523eea971d6f8ea1ce63d440f /miscutils
parent1f67e935ac7c4e8812deb97e3e81d0973634fa93 (diff)
downloadbusybox-b8860a8892f077091177170fe483d545d33789a6.tar.gz
bc: remove "error ids": serve no useful purpose, error message should be explanatory enough
function old new delta bc_warn_fmt 17 14 -3 bc_err_fmt 15 12 -3 bc_vm_posixError 205 189 -16 bc_vm_error 156 138 -18 bc_errs 28 - -28 bc_err_ids 58 - -58 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/4 up/down: 0/-126) Total: -126 bytes text data bss dec hex filename 988288 485 7296 996069 f32e5 busybox_old 988122 485 7296 995903 f323f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c68
1 files changed, 11 insertions, 57 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e224c8dd4..a8b170f0c 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -242,16 +242,6 @@ typedef enum BcStatus {
} BcStatus;
-#define BC_ERR_IDX_VM (0)
-#define BC_ERR_IDX_LEX (1)
-#define BC_ERR_IDX_PARSE (2)
-#define BC_ERR_IDX_MATH (3)
-#define BC_ERR_IDX_EXEC (4)
-#define BC_ERR_IDX_VEC (5)
-#if ENABLE_BC
-#define BC_ERR_IDX_POSIX (6)
-#endif
-
#define BC_VEC_INVALID_IDX ((size_t) -1)
#define BC_VEC_START_CAP (1 << 5)
@@ -844,49 +834,10 @@ static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line,
static void bc_vm_info(void);
-static const char bc_err_fmt[] = "\n%s error: %s\n";
-static const char bc_warn_fmt[] = "\n%s warning: %s\n";
+static const char bc_err_fmt[] = "\nerror: %s\n";
+static const char bc_warn_fmt[] = "\nwarning: %s\n";
static const char bc_err_line[] = ":%zu\n\n";
-static const char *bc_errs[] = {
- "VM",
- "Lex",
- "Parse",
- "Math",
- "Runtime",
- "Vector",
-#if ENABLE_BC
- "POSIX",
-#endif
-};
-
-static const uint8_t bc_err_ids[] = {
- BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM,
- BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX,
-#if ENABLE_DC
- BC_ERR_IDX_LEX,
-#endif
- BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
- BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
- BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH,
- BC_ERR_IDX_MATH,
-#if ENABLE_DC
- BC_ERR_IDX_MATH,
-#endif
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
- BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
- BC_ERR_IDX_EXEC,
- BC_ERR_IDX_VEC, BC_ERR_IDX_VEC,
-#if ENABLE_BC
- BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
- BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
- BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
-#endif
- BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM,
-};
-
static const char *bc_err_msgs[] = {
NULL,
@@ -6863,7 +6814,7 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line)
{
if (!s || s > BC_STATUS_VEC_ITEM_EXISTS) return s;
- fprintf(stderr, bc_err_fmt, bc_errs[bc_err_ids[s]], bc_err_msgs[s]);
+ fprintf(stderr, bc_err_fmt, bc_err_msgs[s]);
fprintf(stderr, " %s", file);
fprintf(stderr, bc_err_line + 4 * !line, line);
@@ -6874,17 +6825,20 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line)
static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line,
const char *msg)
{
- int p = (int) G_posix, w = (int) G_warn;
- const char *const fmt = p ? bc_err_fmt : bc_warn_fmt;
+ const char *fmt;
- if (!(p || w) || s < BC_STATUS_POSIX_NAME_LEN) return BC_STATUS_SUCCESS;
+ if (!(G.flags & (BC_FLAG_S|BC_FLAG_W))) return BC_STATUS_SUCCESS;
+ if (s < BC_STATUS_POSIX_NAME_LEN) return BC_STATUS_SUCCESS;
- fprintf(stderr, fmt, bc_errs[bc_err_ids[s]], bc_err_msgs[s]);
+ fmt = G_posix ? bc_err_fmt : bc_warn_fmt;
+ fprintf(stderr, fmt, bc_err_msgs[s]);
if (msg) fprintf(stderr, " %s\n", msg);
fprintf(stderr, " %s", file);
fprintf(stderr, bc_err_line + 4 * !line, line);
- return s * (!G.ttyin && !!p);
+ if (G.ttyin || !G_posix)
+ s = BC_STATUS_SUCCESS;
+ return s;
}
static void bc_vm_envArgs(void)