From bc80fd0e3501cfe40d2b4f7b14c7e731344d2951 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 26 Sep 2008 15:23:13 +0000 Subject: [PATCH] Added errlog to the stringout stdio device support. Release notes updated. --- documentation/RELEASE_NOTES.html | 8 ++++++ src/dev/softDev/devSoStdio.c | 48 ++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index 24821a288..2d7ddaa55 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -12,6 +12,14 @@

Changes between 3.14.9 and 3.14.10

+

New "stdio" stringout device support

+ +

A new device support has been added that allows a stringout record to output +one-line messages to stdout, stderr or the errlog subsystem. Use DTYP="stdio" +and set the OUT field to one of "@stdout", "@stderr" or "@errlog" to control the +message destination. A newline is appended to the contents of the record's VAL +field before printing.

+

General Time subsystem

The way in which EPICS gets the time has been significantly revised since diff --git a/src/dev/softDev/devSoStdio.c b/src/dev/softDev/devSoStdio.c index 588077755..6a4d9bbae 100644 --- a/src/dev/softDev/devSoStdio.c +++ b/src/dev/softDev/devSoStdio.c @@ -12,25 +12,54 @@ #include "dbCommon.h" #include "devSup.h" +#include "errlog.h" #include "recGbl.h" #include "recSup.h" #include "epicsExport.h" #include "stringoutRecord.h" +typedef int (*PRINTFFUNC)(const char *fmt, ...); + +static int stderrPrintf(const char *fmt, ...); + + +static struct outStream { + const char *name; + PRINTFFUNC print; +} outStreams[] = { + {"stdout", printf}, + {"stderr", stderrPrintf}, + {"errlog", errlogPrintf}, + {NULL, NULL} +}; + +static int stderrPrintf(const char *fmt, ...) { + va_list pvar; + int retval; + + va_start(pvar, fmt); + retval = vfprintf(stderr, fmt, pvar); + va_end (pvar); + + return retval; +} + static long add(dbCommon *pcommon) { stringoutRecord *prec = (stringoutRecord *) pcommon; + struct outStream *pstream; if (prec->out.type != INST_IO) return S_dev_badOutType; - if (strcmp(prec->out.value.instio.string, "stdout") == 0) { - prec->dpvt = stdout; - } else if (strcmp(prec->out.value.instio.string, "stderr") == 0) { - prec->dpvt = stderr; - } else - return -1; - return 0; + for (pstream = outStreams; pstream->name; ++pstream) { + if (strcmp(prec->out.value.instio.string, pstream->name) == 0) { + prec->dpvt = pstream; + return 0; + } + } + prec->dpvt = NULL; + return -1; } static long del(dbCommon *pcommon) { @@ -52,8 +81,9 @@ static long init(int pass) static long write_string(stringoutRecord *prec) { - if (prec->dpvt) - fprintf((FILE *)prec->dpvt, "%s\n", prec->val); + struct outStream *pstream = (struct outStream *)prec->dpvt; + if (pstream) + pstream->print("%s\n", prec->val); return 0; }