aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 97adeaa53..1c1672c00 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -786,6 +786,10 @@ struct globals {
786 BcParse prs; 786 BcParse prs;
787 BcProgram prog; 787 BcProgram prog;
788 788
789 // For error messages. Can be set to current parsed line,
790 // or [TODO] to current executing line (can be before last parsed one)
791 unsigned err_line;
792
789 BcVec files; 793 BcVec files;
790 794
791 char *env_args; 795 char *env_args;
@@ -928,19 +932,27 @@ static void quit(void)
928 exit(0); 932 exit(0);
929} 933}
930 934
935static void bc_verror_msg(const char *fmt, va_list p)
936{
937 const char *sv = sv; /* for compiler */
938 if (G.prog.file) {
939 sv = applet_name;
940 applet_name = xasprintf("%s: %s:%u", applet_name, G.prog.file, G.err_line);
941 }
942 bb_verror_msg(fmt, p, NULL);
943 if (G.prog.file) {
944 free((char*)applet_name);
945 applet_name = sv;
946 }
947}
948
931static NOINLINE int bc_error_fmt(const char *fmt, ...) 949static NOINLINE int bc_error_fmt(const char *fmt, ...)
932{ 950{
933 const char *sv;
934 va_list p; 951 va_list p;
935 952
936 sv = applet_name;
937 if (G.prog.file)
938 applet_name = G.prog.file;
939
940 va_start(p, fmt); 953 va_start(p, fmt);
941 bb_verror_msg(fmt, p, NULL); 954 bc_verror_msg(fmt, p);
942 va_end(p); 955 va_end(p);
943 applet_name = sv;
944 956
945 if (!G.ttyin) 957 if (!G.ttyin)
946 exit(1); 958 exit(1);
@@ -949,21 +961,15 @@ static NOINLINE int bc_error_fmt(const char *fmt, ...)
949 961
950static NOINLINE int bc_posix_error_fmt(const char *fmt, ...) 962static NOINLINE int bc_posix_error_fmt(const char *fmt, ...)
951{ 963{
952 const char *sv;
953 va_list p; 964 va_list p;
954 965
955 // Are non-POSIX constructs totally ok? 966 // Are non-POSIX constructs totally ok?
956 if (!(option_mask32 & (BC_FLAG_S|BC_FLAG_W))) 967 if (!(option_mask32 & (BC_FLAG_S|BC_FLAG_W)))
957 return BC_STATUS_SUCCESS; // yes 968 return BC_STATUS_SUCCESS; // yes
958 969
959 sv = applet_name;
960 if (G.prog.file)
961 applet_name = G.prog.file;
962
963 va_start(p, fmt); 970 va_start(p, fmt);
964 bb_verror_msg(fmt, p, NULL); 971 bc_verror_msg(fmt, p);
965 va_end(p); 972 va_end(p);
966 applet_name = sv;
967 973
968 // Do we treat non-POSIX constructs as errors? 974 // Do we treat non-POSIX constructs as errors?
969 if (!(option_mask32 & BC_FLAG_S)) 975 if (!(option_mask32 & BC_FLAG_S))
@@ -2877,7 +2883,7 @@ static void bc_lex_free(BcLex *l)
2877 2883
2878static void bc_lex_file(BcLex *l) 2884static void bc_lex_file(BcLex *l)
2879{ 2885{
2880 l->line = 1; 2886 G.err_line = l->line = 1;
2881 l->newline = false; 2887 l->newline = false;
2882} 2888}
2883 2889
@@ -2889,6 +2895,7 @@ static BcStatus bc_lex_next(BcLex *l)
2889 if (l->t.last == BC_LEX_EOF) return bc_error("end of file"); 2895 if (l->t.last == BC_LEX_EOF) return bc_error("end of file");
2890 2896
2891 l->line += l->newline; 2897 l->line += l->newline;
2898 G.err_line = l->line;
2892 l->t.t = BC_LEX_EOF; 2899 l->t.t = BC_LEX_EOF;
2893 2900
2894 l->newline = (l->i == l->len); 2901 l->newline = (l->i == l->len);
@@ -2971,6 +2978,7 @@ static BcStatus bc_lex_string(BcLex *l)
2971 2978
2972 l->i = i + 1; 2979 l->i = i + 1;
2973 l->line += nls; 2980 l->line += nls;
2981 G.err_line = l->line;
2974 2982
2975 return BC_STATUS_SUCCESS; 2983 return BC_STATUS_SUCCESS;
2976} 2984}
@@ -3011,6 +3019,7 @@ static BcStatus bc_lex_comment(BcLex *l)
3011 3019
3012 l->i = i + 1; 3020 l->i = i + 1;
3013 l->line += nls; 3021 l->line += nls;
3022 G.err_line = l->line;
3014 3023
3015 return BC_STATUS_SUCCESS; 3024 return BC_STATUS_SUCCESS;
3016} 3025}
@@ -3347,6 +3356,7 @@ static BcStatus dc_lex_string(BcLex *l)
3347 3356
3348 l->i = i; 3357 l->i = i;
3349 l->line += nls; 3358 l->line += nls;
3359 G.err_line = l->line;
3350 3360
3351 return BC_STATUS_SUCCESS; 3361 return BC_STATUS_SUCCESS;
3352} 3362}