bc: remove "error ids": serve no useful purpose, error message should be explanatory...
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 2 Dec 2018 23:26:12 +0000 (00:26 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 5 Dec 2018 14:43:35 +0000 (15:43 +0100)
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>
miscutils/bc.c

index e224c8dd4af9af5709e615d279fb1397e49509a5..a8b170f0c895d0e1e1aa6c48d0e1cce65309a53e 100644 (file)
@@ -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)