[Simh] [PATCH 00 of 14] introduce sim_printf_log()

Peter Lund firefly at vax64.dk
Mon Sep 10 17:09:34 EDT 2007


The code is littered with statements like "if (sim_log) fprintf(sim_log, ...)".
Much of it is even preceded by "printf(...)" so there's lots of code
duplication.

This patch series introduces the function sim_printf_log() and converts
most of the code to use it.  The function first writes to stdout and then
if sim_log is != NULL, writes to sim_log.

The trick is to use a C feature called varargs and a header called
stdarg.h and the macros va_start/va_end, and the functions vprintf()/
vfprintf().  All of these are C89 so we should be safe there.

The code uses an optional gcc feature to allow gcc to check that the
parameters match the format string.  This is guarded by an #ifdef __GNUC__
so portability should not be affected.

For the time being the new function lives in sim_console.c and is exported
by sim_console.h.  I have made the users #include the file rather than use
unaesthetic extern declarations (which would also lose the format string/
parameter checks).

The first patch defines the function, the next moves the core code over,
and the rest each move a single architecture over.

There are still a few uglies here and there that use sim_log but they
aren't as easy to fix.  I figured that the perfect should not be the
enemy of the good.

-Peter

PS: Each patch is prefixed with some information that comes from the source
    code control system I use (Mercurial aka hg).  The patch utility will
    ignore it completely as can you.  It's there to uniquely identify each
    patch and its place in the change list for my repository.  You can play
    along at http://vax64.dyndns.org/repo/hg  (it may be change a bit in the
    next hour or so).

28 files changed, 112 insertions(+), 220 deletions(-)
H316/h316_cpu.c       |   22 +++------------
HP2100/hp2100_cpu.c   |   14 +++-------
HP2100/hp2100_ipl.c   |   11 ++-----
I1620/i1620_cpu.c     |    7 +----
Ibm1130/ibm1130_gui.c |   20 +++++---------
Interdata/id_io.c     |    9 +-----
NOVA/nova_qty.c       |    9 ++----
PDP10/pdp10_ksio.c    |    7 +----
PDP11/pdp11_cpu.c     |    1 
PDP11/pdp11_cpumod.c  |    5 +--
PDP11/pdp11_dz.c      |    8 ++---
PDP11/pdp11_io.c      |   12 ++------
PDP11/pdp11_rh.c      |    9 ++----
PDP11/pdp11_vh.c      |    1 
PDP11/pdp11_xu.c      |    7 +----
PDP18B/pdp18b_cpu.c   |    7 +----
PDP8/pdp8_cpu.c       |    7 +----
SDS/sds_io.c          |    7 +----
VAX/vax780_mba.c      |    7 +----
VAX/vax780_sbi.c      |   10 ++-----
VAX/vax780_uba.c      |   13 ++-------
VAX/vax_io.c          |   12 ++------
VAX/vax_sysdev.c      |    6 +---
scp.c                 |   22 +++++----------
sim_console.c         |   17 ++++++++++++
sim_console.h         |    6 ++++
sim_ether.c           |   68 +++++++++++--------------------------------------
sim_timer.c           |    8 ++---




More information about the Simh mailing list