Added tmxr_linemsgf api to send formatted messages to a multiplexer line.

This commit is contained in:
Mark Pizzolato 2013-04-24 09:00:36 -07:00
parent 9a172154f0
commit d364571c2c
2 changed files with 70 additions and 3 deletions

View file

@ -85,6 +85,7 @@
tmxr_dep - (null) deposit tmxr_dep - (null) deposit
tmxr_msg - send message to socket tmxr_msg - send message to socket
tmxr_linemsg - send message to line tmxr_linemsg - send message to line
tmxr_linemsgf - send formatted message to line
tmxr_fconns - output connection status tmxr_fconns - output connection status
tmxr_fstats - output connection statistics tmxr_fstats - output connection statistics
tmxr_set_log - enable logging for line tmxr_set_log - enable logging for line
@ -490,9 +491,7 @@ static void tmxr_report_disconnection (TMLN *lp)
{ {
if (lp->notelnet) if (lp->notelnet)
return; return;
tmxr_linemsg (lp, "\r\nDisconnected from the "); /* report disconnection */ tmxr_linemsgf (lp, "\nDisconnected from the %s simulator\n\n", sim_name);/* report disconnection */
tmxr_linemsg (lp, sim_name);
tmxr_linemsg (lp, " simulator\r\n\n");
return; return;
} }
@ -2988,6 +2987,73 @@ return;
} }
/* Write a formatted message to a line */
void tmxr_linemsgf (TMLN *lp, const char *fmt, ...)
{
char stackbuf[STACKBUFSIZE];
int32 bufsize = sizeof(stackbuf);
char *buf = stackbuf;
va_list arglist;
int32 i, len;
buf[bufsize-1] = '\0';
while (1) { /* format passed string, args */
va_start (arglist, fmt);
#if defined(NO_vsnprintf)
#if defined(HAS_vsprintf_void)
/* Note, this could blow beyond the buffer, and we couldn't tell */
/* That is a limitation of the C runtime library available on this platform */
vsprintf (buf, fmt, arglist);
for (len = 0; len < bufsize-1; len++)
if (buf[len] == 0) break;
#else
len = vsprintf (buf, fmt, arglist);
#endif /* HAS_vsprintf_void */
#else /* NO_vsnprintf */
#if defined(HAS_vsnprintf_void)
vsnprintf (buf, bufsize-1, fmt, arglist);
for (len = 0; len < bufsize-1; len++)
if (buf[len] == 0) break;
#else
len = vsnprintf (buf, bufsize-1, fmt, arglist);
#endif /* HAS_vsnprintf_void */
#endif /* NO_vsnprintf */
va_end (arglist);
/* If the formatted result didn't fit into the buffer, then grow the buffer and try again */
if ((len < 0) || (len >= bufsize-1)) {
if (buf != stackbuf)
free (buf);
bufsize = bufsize * 2;
buf = (char *) malloc (bufsize);
if (buf == NULL) /* out of memory */
return;
buf[bufsize-1] = '\0';
continue;
}
break;
}
/* Output the formatted data expanding newlines where they exist */
for (i = 0; i < len; ++i) {
if ('\n' == buf[i]) {
tmxr_putc_ln (lp, '\r');
tmxr_putc_ln (lp, buf[i]);
}
else
tmxr_putc_ln (lp, buf[i]);
}
if (buf != stackbuf)
free (buf);
return;
}
/* Print connections - used only in named SHOW command */ /* Print connections - used only in named SHOW command */
void tmxr_fconns (FILE *st, TMLN *lp, int32 ln) void tmxr_fconns (FILE *st, TMLN *lp, int32 ln)

View file

@ -174,6 +174,7 @@ t_stat tmxr_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw);
t_stat tmxr_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw); t_stat tmxr_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw);
void tmxr_msg (SOCKET sock, char *msg); void tmxr_msg (SOCKET sock, char *msg);
void tmxr_linemsg (TMLN *lp, char *msg); void tmxr_linemsg (TMLN *lp, char *msg);
void tmxr_linemsgf (TMLN *lp, const char *fmt, ...);
void tmxr_fconns (FILE *st, TMLN *lp, int32 ln); void tmxr_fconns (FILE *st, TMLN *lp, int32 ln);
void tmxr_fstats (FILE *st, TMLN *lp, int32 ln); void tmxr_fstats (FILE *st, TMLN *lp, int32 ln);
t_stat tmxr_set_log (UNIT *uptr, int32 val, char *cptr, void *desc); t_stat tmxr_set_log (UNIT *uptr, int32 val, char *cptr, void *desc);