mirror of
https://github.com/simh/simh.git
synced 2026-02-28 09:18:31 +00:00
SCP: Leverage a memory file while producing examine output
This commit is contained in:
20
scp.c
20
scp.c
@@ -2929,23 +2929,19 @@ free (*tmpname);
|
||||
static t_stat sim_snprint_sym (char *buf, size_t bufsize, t_bool vm_flag, t_addr addr, t_value *val, UNIT *uptr, int32 sw, int32 dfltinc, int32 rdx, uint32 width, uint32 fmt)
|
||||
{
|
||||
t_stat reason;
|
||||
size_t str_width;
|
||||
size_t s;
|
||||
MEMFILE mbuf;
|
||||
|
||||
rewind (sim_tmpfile);
|
||||
memset (&mbuf, 0, sizeof (mbuf));
|
||||
mbuf.buf = malloc (512); /* Pre allocate a memory buffer to avoid */
|
||||
mbuf.size = 512; /* potential double vsnprintf to expand the buffer */
|
||||
sim_mfile = &mbuf;
|
||||
if (vm_flag || ((reason = fprint_sym (sim_tmpfile, addr, val, uptr, sw)) > 0)) {
|
||||
fprint_val (sim_tmpfile, val[0], rdx, width, fmt);
|
||||
reason = dfltinc;
|
||||
}
|
||||
str_width = (size_t)ftell(sim_tmpfile);
|
||||
if (str_width > width)
|
||||
str_width = width;
|
||||
if (bufsize > str_width)
|
||||
memset (buf + str_width, 0, bufsize - width);
|
||||
rewind (sim_tmpfile);
|
||||
s = fread (buf, 1, str_width, sim_tmpfile);
|
||||
if (s < bufsize)
|
||||
buf[s] = '\0';
|
||||
sim_mfile = NULL;
|
||||
strlcpy (buf, mbuf.buf, MIN(bufsize, mbuf.pos + 1));
|
||||
free (mbuf.buf);
|
||||
return reason;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user