From 23eaf2f57e4ea4797c6605b81c0bfb9ebd7aedba Mon Sep 17 00:00:00 2001 From: zimoch Date: Mon, 29 Aug 2011 15:13:58 +0000 Subject: [PATCH] make function available on softioc --- listRecords.c | 97 +++++++++++++++++++++++++++---------------- listRecords.dbd | 1 + updateMenuConvert.c | 42 ++++++++++++++++--- updateMenuConvert.dbd | 1 + 4 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 listRecords.dbd create mode 100644 updateMenuConvert.dbd diff --git a/listRecords.c b/listRecords.c index 39f3aea..e2eed4f 100644 --- a/listRecords.c +++ b/listRecords.c @@ -1,53 +1,80 @@ -/* listRecords is a wrapper function for dbl - it is required because of the changed syntax of dbl in R3.14. - */ +/* listRecords.c +* +* listRecords is a wrapper function for dbl +* it hides the changed syntax of dbl in R3.14. +* +* $Author: zimoch $ +* +* $Source: /cvs/G/DRV/misc/listRecords.c,v $ +* +*/ -#include #include #include - +#include #ifdef BASE_VERSION -/* This is R3.13 */ +#define EPICS_3_13 #include long dbl(char *precordTypename, char *filename, char *fields); #else -/* This is R3.14 */ +#define EPICS_3_14 #include #include #include +#include +#include #endif -int listRecords(char* file, char* fields) +int listRecords(char* filename, char* fields) { -#ifndef BASE_VERSION -/* This is R3.14 */ - FILE* oldStdout; - FILE* newStdout; -#endif - - if (!file) - { - printf ("usage: listRecords \"filename\", \"field field ...\"\n"); - return -1; - } - -#ifdef BASE_VERSION -/* This is R3.13 */ - return dbl(0L, file, fields); +#ifdef EPICS_3_13 + return dbl(NULL, filename, fields); #else -/* This is R3.14 */ - newStdout = fopen(file, "w"); - if (!newStdout) { - fprintf (stderr, "Can't open %s for writing: %s\n", - file, strerror(errno)); - return errno; + FILE* oldStdout = NULL; + FILE* newStdout = NULL; + + if (filename && *filename) + { + newStdout = fopen(filename, "w"); + if (!newStdout) + { + fprintf (stderr, "Can't open %s for writing: %s\n", + filename, strerror(errno)); + return errno; + } + oldStdout = epicsGetThreadStdout(); + epicsSetThreadStdout(newStdout); + } + dbl(0L, fields); + if (newStdout) + { + fclose(newStdout); + epicsSetThreadStdout(oldStdout); + } + return 0; } - oldStdout = epicsGetThreadStdout(); - epicsSetThreadStdout(newStdout); - dbl(0L, fields); - fclose(newStdout); - epicsSetThreadStdout(oldStdout); - return 0; #endif } + +#ifdef EPICS_3_14 +static const iocshArg listRecordsArg0 = { "filename", iocshArgString }; +static const iocshArg listRecordsArg1 = { "fields", iocshArgString }; +static const iocshArg * const listRecordsArgs[2] = { &listRecordsArg0, &listRecordsArg1 }; +static const iocshFuncDef listRecordsDef = { "listRecords", 2, listRecordsArgs }; +static void listRecordsFunc (const iocshArgBuf *args) +{ + listRecords(args[0].sval, args[1].sval); +} +static void listRecordsRegister(void) +{ + static int firstTime = 1; + if (firstTime) { + iocshRegister (&listRecordsDef, listRecordsFunc); + firstTime = 0; + } +} +epicsExportRegistrar(listRecordsRegister); +#endif + + diff --git a/listRecords.dbd b/listRecords.dbd new file mode 100644 index 0000000..c54e1ed --- /dev/null +++ b/listRecords.dbd @@ -0,0 +1 @@ +registrar(listRecordsRegister) diff --git a/updateMenuConvert.c b/updateMenuConvert.c index 91d440e..d1fe01b 100644 --- a/updateMenuConvert.c +++ b/updateMenuConvert.c @@ -5,18 +5,25 @@ * * $Author: zimoch $ * -* $Log: updateMenuConvert.c,v $ -* Revision 1.1 2005/04/14 11:25:49 zimoch -* add breakpoint tabled to menu convert +* $Source: /cvs/G/DRV/misc/updateMenuConvert.c,v $ * */ -#include #include #include #include - +#include +#include +#include +#include +#ifdef BASE_VERSION +#define EPICS_3_13 extern DBBASE *pdbbase; +#else +#define EPICS_3_14 +#include +#include +#endif typedef struct node { ELLNODE node; @@ -24,7 +31,7 @@ typedef struct node { char *value; } node; -int epicsShareAPI updateMenuConvert () +int updateMenuConvert () { brkTable *pbrkTable; dbMenu *menuConvert; @@ -34,6 +41,11 @@ int epicsShareAPI updateMenuConvert () char **papChoiceName; char **papChoiceValue; + if (interruptAccept) + { + fprintf(stderr, "updateMenuConvert: Can update menuConvert only before iocInit!\n"); + return -1; + } menuConvert = dbFindMenu(pdbbase,"menuConvert"); ellInit(&missing); for(pbrkTable = (brkTable *)ellFirst(&pdbbase->bptList); @@ -87,3 +99,21 @@ int epicsShareAPI updateMenuConvert () } return 0; } + +#ifdef EPICS_3_14 +static const iocshFuncDef updateMenuConvertDef = { "updateMenuConvert", 0, NULL }; +static void updateMenuConvertFunc (const iocshArgBuf *args) +{ + updateMenuConvert(); +} +static void updateMenuConvertRegister(void) +{ + static int firstTime = 1; + if (firstTime) { + iocshRegister (&updateMenuConvertDef, updateMenuConvertFunc); + firstTime = 0; + } +} +epicsExportRegistrar(updateMenuConvertRegister); +#endif + diff --git a/updateMenuConvert.dbd b/updateMenuConvert.dbd new file mode 100644 index 0000000..1e54da4 --- /dev/null +++ b/updateMenuConvert.dbd @@ -0,0 +1 @@ +registrar(updateMenuConvertRegister)