aboutsummaryrefslogtreecommitdiff
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
parent1f67e935ac7c4e8812deb97e3e81d0973634fa93 (diff)
downloadbusybox-w32-b8860a8892f077091177170fe483d545d33789a6.tar.gz
busybox-w32-b8860a8892f077091177170fe483d545d33789a6.tar.bz2
busybox-w32-b8860a8892f077091177170fe483d545d33789a6.zip
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>
-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 {
242 242
243} BcStatus; 243} BcStatus;
244 244
245#define BC_ERR_IDX_VM (0)
246#define BC_ERR_IDX_LEX (1)
247#define BC_ERR_IDX_PARSE (2)
248#define BC_ERR_IDX_MATH (3)
249#define BC_ERR_IDX_EXEC (4)
250#define BC_ERR_IDX_VEC (5)
251#if ENABLE_BC
252#define BC_ERR_IDX_POSIX (6)
253#endif
254
255#define BC_VEC_INVALID_IDX ((size_t) -1) 245#define BC_VEC_INVALID_IDX ((size_t) -1)
256#define BC_VEC_START_CAP (1 << 5) 246#define BC_VEC_START_CAP (1 << 5)
257 247
@@ -844,49 +834,10 @@ static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line,
844 834
845static void bc_vm_info(void); 835static void bc_vm_info(void);
846 836
847static const char bc_err_fmt[] = "\n%s error: %s\n"; 837static const char bc_err_fmt[] = "\nerror: %s\n";
848static const char bc_warn_fmt[] = "\n%s warning: %s\n"; 838static const char bc_warn_fmt[] = "\nwarning: %s\n";
849static const char bc_err_line[] = ":%zu\n\n"; 839static const char bc_err_line[] = ":%zu\n\n";
850 840
851static const char *bc_errs[] = {
852 "VM",
853 "Lex",
854 "Parse",
855 "Math",
856 "Runtime",
857 "Vector",
858#if ENABLE_BC
859 "POSIX",
860#endif
861};
862
863static const uint8_t bc_err_ids[] = {
864 BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM,
865 BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX, BC_ERR_IDX_LEX,
866#if ENABLE_DC
867 BC_ERR_IDX_LEX,
868#endif
869 BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
870 BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
871 BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH,
872 BC_ERR_IDX_MATH,
873#if ENABLE_DC
874 BC_ERR_IDX_MATH,
875#endif
876 BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
877 BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
878 BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
879 BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
880 BC_ERR_IDX_EXEC,
881 BC_ERR_IDX_VEC, BC_ERR_IDX_VEC,
882#if ENABLE_BC
883 BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
884 BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
885 BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
886#endif
887 BC_ERR_IDX_VM, BC_ERR_IDX_VM, BC_ERR_IDX_VM,
888};
889
890static const char *bc_err_msgs[] = { 841static const char *bc_err_msgs[] = {
891 842
892 NULL, 843 NULL,
@@ -6863,7 +6814,7 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line)
6863{ 6814{
6864 if (!s || s > BC_STATUS_VEC_ITEM_EXISTS) return s; 6815 if (!s || s > BC_STATUS_VEC_ITEM_EXISTS) return s;
6865 6816
6866 fprintf(stderr, bc_err_fmt, bc_errs[bc_err_ids[s]], bc_err_msgs[s]); 6817 fprintf(stderr, bc_err_fmt, bc_err_msgs[s]);
6867 fprintf(stderr, " %s", file); 6818 fprintf(stderr, " %s", file);
6868 fprintf(stderr, bc_err_line + 4 * !line, line); 6819 fprintf(stderr, bc_err_line + 4 * !line, line);
6869 6820
@@ -6874,17 +6825,20 @@ static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line)
6874static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line, 6825static BcStatus bc_vm_posixError(BcStatus s, const char *file, size_t line,
6875 const char *msg) 6826 const char *msg)
6876{ 6827{
6877 int p = (int) G_posix, w = (int) G_warn; 6828 const char *fmt;
6878 const char *const fmt = p ? bc_err_fmt : bc_warn_fmt;
6879 6829
6880 if (!(p || w) || s < BC_STATUS_POSIX_NAME_LEN) return BC_STATUS_SUCCESS; 6830 if (!(G.flags & (BC_FLAG_S|BC_FLAG_W))) return BC_STATUS_SUCCESS;
6831 if (s < BC_STATUS_POSIX_NAME_LEN) return BC_STATUS_SUCCESS;
6881 6832
6882 fprintf(stderr, fmt, bc_errs[bc_err_ids[s]], bc_err_msgs[s]); 6833 fmt = G_posix ? bc_err_fmt : bc_warn_fmt;
6834 fprintf(stderr, fmt, bc_err_msgs[s]);
6883 if (msg) fprintf(stderr, " %s\n", msg); 6835 if (msg) fprintf(stderr, " %s\n", msg);
6884 fprintf(stderr, " %s", file); 6836 fprintf(stderr, " %s", file);
6885 fprintf(stderr, bc_err_line + 4 * !line, line); 6837 fprintf(stderr, bc_err_line + 4 * !line, line);
6886 6838
6887 return s * (!G.ttyin && !!p); 6839 if (G.ttyin || !G_posix)
6840 s = BC_STATUS_SUCCESS;
6841 return s;
6888} 6842}
6889 6843
6890static void bc_vm_envArgs(void) 6844static void bc_vm_envArgs(void)