summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2018-12-05 18:12:27 +0100
committerDenys Vlasenko2018-12-05 18:12:27 +0100
commit0064679915169dedca66a4365af7d9be7acc8153 (patch)
tree49ce592aec599eab6c45dc636bccefbe6af94f00
parent5318f81fbe5005ec048620b678064a50ba8a8e19 (diff)
downloadbusybox-0064679915169dedca66a4365af7d9be7acc8153.zip
busybox-0064679915169dedca66a4365af7d9be7acc8153.tar.gz
bc: fix inverted POSIXness test, improve messages, commonalize message strings
function old new delta bc_lex_token 1251 1285 +34 bc_POSIX_does_not_allow_bool_ops_this_is_bad - 25 +25 bc_POSIX_does_not_allow_empty_X_expression_in_for - 20 +20 bc_POSIX_does_not_allow - 20 +20 bc_parse_expr 2146 2151 +5 bc_num_ulong 103 92 -11 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 2/1 up/down: 104/-11) Total: 93 bytes text data bss dec hex filename 987210 485 7296 994991 f2eaf busybox_old 987084 485 7296 994865 f2e31 busybox_unstripped ^^^^^^^ Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 1c1672c..ff44293 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -992,6 +992,18 @@ static int bc_posix_error(const char *msg)
{
return bc_posix_error_fmt("%s", msg);
}
+static int bc_POSIX_does_not_allow(const char *msg)
+{
+ return bc_posix_error_fmt("%s%s", "POSIX does not allow ", msg);
+}
+static int bc_POSIX_does_not_allow_bool_ops_this_is_bad(const char *msg)
+{
+ return bc_posix_error_fmt("%s%s %s", "POSIX does not allow ", "boolean operators; the following is bad:", msg);
+}
+static int bc_POSIX_does_not_allow_empty_X_expression_in_for(const char *msg)
+{
+ return bc_posix_error_fmt("%san empty %s expression in a for loop", "POSIX does not allow ", msg);
+}
static int bc_error_bad_character(char c)
{
return bc_error_fmt("bad character '%c'", c);
@@ -2938,8 +2950,8 @@ static BcStatus bc_lex_identifier(BcLex *l)
match:
// buf starts with keyword bc_lex_kws[i]
l->t.t = BC_LEX_KEY_1st_keyword + i;
- if ((1 << i) & POSIX_KWORD_MASK) {
- s = bc_posix_error("POSIX does not allow the following keyword:"); // bc_lex_kws[i].name8
+ if (!((1 << i) & POSIX_KWORD_MASK)) {
+ s = bc_posix_error_fmt("%sthe following keyword: '%.8s'", "POSIX does not allow ", bc_lex_kws[i].name8);
if (s) return s;
}
@@ -2952,7 +2964,7 @@ static BcStatus bc_lex_identifier(BcLex *l)
if (s) return s;
if (l->t.v.len > 2)
- s = bc_posix_error("POSIX only allows one character names; the following is bad:"); // buf
+ s = bc_posix_error_fmt("POSIX only allows one character names; the following is bad: '%s'", buf);
return s;
}
@@ -3055,7 +3067,7 @@ static BcStatus bc_lex_token(BcLex *l)
bc_lex_assign(l, BC_LEX_OP_REL_NE, BC_LEX_OP_BOOL_NOT);
if (l->t.t == BC_LEX_OP_BOOL_NOT) {
- s = bc_posix_error("POSIX does not allow boolean operators; the following is bad:"); // "!"
+ s = bc_POSIX_does_not_allow_bool_ops_this_is_bad("!");
if (s) return s;
}
@@ -3070,7 +3082,7 @@ static BcStatus bc_lex_token(BcLex *l)
case '#':
{
- s = bc_posix_error("POSIX does not allow '#' script comments");
+ s = bc_POSIX_does_not_allow("'#' script comments");
if (s) return s;
bc_lex_lineComment(l);
@@ -3089,7 +3101,7 @@ static BcStatus bc_lex_token(BcLex *l)
c2 = l->buf[l->i];
if (c2 == '&') {
- s = bc_posix_error("POSIX does not allow boolean operators; the following is bad:"); // "&&"
+ s = bc_POSIX_does_not_allow_bool_ops_this_is_bad("&&");
if (s) return s;
++l->i;
@@ -3152,7 +3164,7 @@ static BcStatus bc_lex_token(BcLex *l)
s = bc_lex_number(l, c);
else {
l->t.t = BC_LEX_KEY_LAST;
- s = bc_posix_error("POSIX does not allow a period ('.') as a shortcut for the last result");
+ s = bc_POSIX_does_not_allow("a period ('.') as a shortcut for the last result");
}
break;
}
@@ -3279,7 +3291,7 @@ static BcStatus bc_lex_token(BcLex *l)
c2 = l->buf[l->i];
if (c2 == '|') {
- s = bc_posix_error("POSIX does not allow boolean operators; the following is bad:"); // "||"
+ s = bc_POSIX_does_not_allow_bool_ops_this_is_bad("||");
if (s) return s;
++l->i;
@@ -4213,7 +4225,7 @@ static BcStatus bc_parse_for(BcParse *p)
if (p->l.t.t != BC_LEX_SCOLON)
s = bc_parse_expr(p, 0, bc_parse_next_for);
else
- s = bc_posix_error("POSIX does not allow an empty init expression in a for loop");
+ s = bc_POSIX_does_not_allow_empty_X_expression_in_for("init");
if (s) return s;
if (p->l.t.t != BC_LEX_SCOLON) return bc_error_bad_token();
@@ -4230,7 +4242,7 @@ static BcStatus bc_parse_for(BcParse *p)
if (p->l.t.t != BC_LEX_SCOLON)
s = bc_parse_expr(p, BC_PARSE_REL, bc_parse_next_for);
else
- s = bc_posix_error("POSIX does not allow an empty condition expression in a for loop");
+ s = bc_POSIX_does_not_allow_empty_X_expression_in_for("condition");
if (s) return s;
if (p->l.t.t != BC_LEX_SCOLON) return bc_error_bad_token();
@@ -4251,7 +4263,7 @@ static BcStatus bc_parse_for(BcParse *p)
if (p->l.t.t != BC_LEX_RPAREN)
s = bc_parse_expr(p, 0, bc_parse_next_rel);
else
- s = bc_posix_error("POSIX does not allow an empty update expression in a for loop");
+ s = bc_POSIX_does_not_allow_empty_X_expression_in_for("update");
if (s) return s;
@@ -4899,7 +4911,7 @@ static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next)
ok:
if (!(flags & BC_PARSE_REL) && nrelops) {
- s = bc_posix_error("POSIX does not allow comparison operators outside if or loops");
+ s = bc_POSIX_does_not_allow("comparison operators outside if or loops");
if (s) return s;
}
else if ((flags & BC_PARSE_REL) && nrelops > 1) {