const char *buf;
size_t i;
size_t line;
- const char *f;
size_t len;
bool newline;
bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub,
};
-static const char bc_program_stdin_name[] = "<stdin>";
-
static void fflush_and_check(void)
{
fflush_all();
static NOINLINE int bc_error_fmt(const char *fmt, ...)
{
+ const char *sv;
va_list p;
+ sv = applet_name;
+ if (G.prog.file)
+ applet_name = G.prog.file;
+
va_start(p, fmt);
bb_verror_msg(fmt, p, NULL);
va_end(p);
+ applet_name = sv;
+
if (!G.ttyin)
exit(1);
return BC_STATUS_FAILURE;
static NOINLINE int bc_posix_error_fmt(const char *fmt, ...)
{
+ const char *sv;
va_list p;
// Are non-POSIX constructs totally ok?
if (!(option_mask32 & (BC_FLAG_S|BC_FLAG_W)))
return BC_STATUS_SUCCESS; // yes
+ sv = applet_name;
+ if (G.prog.file)
+ applet_name = G.prog.file;
+
va_start(p, fmt);
bb_verror_msg(fmt, p, NULL);
va_end(p);
+ applet_name = sv;
// Do we treat non-POSIX constructs as errors?
if (!(option_mask32 & BC_FLAG_S))
bc_vec_free(&l->t.v);
}
-static void bc_lex_file(BcLex *l, const char *file)
+static void bc_lex_file(BcLex *l)
{
l->line = 1;
l->newline = false;
- l->f = file;
}
static BcStatus bc_lex_next(BcLex *l)
static BcStatus bc_program_read(void)
{
+ const char *sv_file;
BcStatus s;
BcParse parse;
BcVec buf;
bc_vec_pop_all(&f->code);
bc_char_vec_init(&buf);
+ sv_file = G.prog.file;
+ G.prog.file = NULL;
+
s = bc_read_line(&buf, "read> ");
if (s) goto io_err;
common_parse_init(&parse, BC_PROG_READ);
- bc_lex_file(&parse.l, bc_program_stdin_name);
+ bc_lex_file(&parse.l);
s = bc_parse_text(&parse, buf.v);
if (s) goto exec_err;
bc_vec_push(&G.prog.stack, &ip);
exec_err:
+ G.prog.file = sv_file;
bc_parse_free(&parse);
io_err:
bc_vec_free(&buf);
static BcStatus bc_vm_file(const char *file)
{
- BcStatus s;
+ const char *sv_file;
char *data;
+ BcStatus s;
BcFunc *main_func;
BcInstPtr *ip;
- G.prog.file = file;
data = bc_read_file(file);
if (!data) return bc_error_fmt("file '%s' is not text", file);
- bc_lex_file(&G.prs.l, file);
+ sv_file = G.prog.file;
+ G.prog.file = file;
+ bc_lex_file(&G.prs.l);
s = bc_vm_process(data);
if (s) goto err;
s = bc_error_fmt("file '%s' is not executable", file);
err:
+ G.prog.file = sv_file;
free(data);
return s;
}
size_t len, i, str = 0;
bool comment = false;
- G.prog.file = bc_program_stdin_name;
- bc_lex_file(&G.prs.l, bc_program_stdin_name);
+ G.prog.file = NULL;
+ bc_lex_file(&G.prs.l);
bc_char_vec_init(&buffer);
bc_char_vec_init(&buf);
// We know that internal library is not buggy,
// thus error checking is normally disabled.
# define DEBUG_LIB 0
- bc_lex_file(&G.prs.l, "");
+ bc_lex_file(&G.prs.l);
s = bc_parse_text(&G.prs, bc_lib);
if (DEBUG_LIB && s) return s;