From 506b303c3cfb228a129ae9b6da4f2ce9a1982b9a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 24 Sep 2008 22:40:37 +0000 Subject: [PATCH] Added printf device support for stringout record => stdout or stderr --- src/dev/softDev/Makefile | 1 + src/dev/softDev/devSoStdio.c | 67 ++++++++++++++++++++++++++++++++++++ src/dev/softDev/devSoft.dbd | 2 ++ 3 files changed, 70 insertions(+) create mode 100644 src/dev/softDev/devSoStdio.c diff --git a/src/dev/softDev/Makefile b/src/dev/softDev/Makefile index dea2c1972..d3a475011 100644 --- a/src/dev/softDev/Makefile +++ b/src/dev/softDev/Makefile @@ -48,6 +48,7 @@ LIBSRCS += devMbboDirectSoftCallback.c LIBSRCS += devSoSoftCallback.c LIBSRCS += devTimestamp.c +LIBSRCS += devSoStdio.c LIBRARY_IOC += softDevIoc softDevIoc_LIBS += miscIoc recIoc asIoc dbIoc registryIoc dbStaticIoc ca Com diff --git a/src/dev/softDev/devSoStdio.c b/src/dev/softDev/devSoStdio.c new file mode 100644 index 000000000..714bf6829 --- /dev/null +++ b/src/dev/softDev/devSoStdio.c @@ -0,0 +1,67 @@ +/*************************************************************************\ +* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* $Id$ */ + +#include +#include + +#include "dbCommon.h" +#include "devSup.h" +#include "recGbl.h" +#include "recSup.h" +#include "epicsExport.h" + +#include "stringoutRecord.h" + +static long add(dbCommon *pcommon) { + stringoutRecord *prec = (stringoutRecord *) pcommon; + + 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; +} + +static long del(dbCommon *pcommon) { + stringoutRecord *prec = (stringoutRecord *) pcommon; + + prec->dpvt = NULL; + return 0; +} + +static struct dsxt dsxtSoStdio = { + add, del +}; + +static long init(int pass) +{ + if (pass == 0) devExtend(&dsxtSoStdio); + return 0; +} + +static long write(stringoutRecord *prec) +{ + if (prec->dpvt) + fprintf((FILE *)prec->dpvt, "%s\n", prec->val); + return 0; +} + +/* Create the dset for devSoStdio */ +static struct { + dset common; + DEVSUPFUN write; +} devSoStdio = { + {5, NULL, init, NULL, NULL}, write +}; +epicsExportAddress(dset, devSoStdio); diff --git a/src/dev/softDev/devSoft.dbd b/src/dev/softDev/devSoft.dbd index fbf1df315..28d235730 100644 --- a/src/dev/softDev/devSoft.dbd +++ b/src/dev/softDev/devSoft.dbd @@ -39,3 +39,5 @@ device(ai, INST_IO,devAiGeneralTime,"General Time") device(bo, INST_IO,devBoGeneralTime,"General Time") device(longin, INST_IO,devLiGeneralTime,"General Time") device(stringin,INST_IO,devSiGeneralTime,"General Time") + +device(stringout,INST_IO,devSoStdio,"stdio")