diff --git a/src/error/Makefile b/src/error/Makefile index 1ffe2f799..c79752cc3 100644 --- a/src/error/Makefile +++ b/src/error/Makefile @@ -13,7 +13,6 @@ INC += epicsPrint.h INC += errMdef.h INC += errSymTbl.h INC += errlog.h -INC += error.h Com_SRCS += errlog.c Com_SRCS += errSymLib.c diff --git a/src/error/errMdef.h b/src/error/errMdef.h index 4dbbecaf1..4f68f7693 100644 --- a/src/error/errMdef.h +++ b/src/error/errMdef.h @@ -1,10 +1,10 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2014 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * EPICS BASE is distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* in file LICENSE that is included with this distribution. \*************************************************************************/ /* Error Handling definitions */ /* @@ -12,56 +12,36 @@ * Date: 6-1-90 */ -#ifndef INCerrMdefh -#define INCerrMdefh - -#include "shareLib.h" - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef INC_errMdef_H +#define INC_errMdef_H #define RTN_SUCCESS(STATUS) ((STATUS)==0) -#define M_dbAccess (501 <<16) /*Database Access Routines */ -#define M_drvSup (503 <<16) /*Driver Support*/ -#define M_devSup (504 <<16) /*Device Support*/ -#define M_recSup (505 <<16) /*Record Support*/ -#define M_recType (506 <<16) /*Record Type*/ -#define M_record (507 <<16) /*Database Records*/ -#define M_ar (508 <<16) /*Archiver; see arDefs.h*/ -#define M_ts (509 <<16) /*Time Stamp Routines; see tsDefs.h*/ -#define M_arAcc (510 <<16) /*Archive Access Library Routines*/ -#define M_bf (511 <<16) /*Block File Routines; see bfDefs.h*/ -#define M_syd (512 <<16) /*Sync Data Routines; see sydDefs.h*/ -#define M_ppr (513 <<16) /*Portable Plot Routines; see pprPlotDefs.h*/ -#define M_env (514 <<16) /*Environment Routines; see envDefs.h*/ -#define M_gen (515 <<16) /*General Purpose Routines; see genDefs.h*/ -#define M_gpib (516 <<16) /*Gpib driver & device support; see drvGpibInterface.h*/ -#define M_bitbus (517 <<16) /*Bitbus driver & device support; see drvBitBusInterface.h*/ -#define M_dbLib (519 <<16) /*Static Database Access */ -#define M_epvxi (520 <<16) /*VXI Driver*/ -#define M_devLib (521 <<16) /*Device Resource Registration*/ -#define M_asLib (522 <<16) /*Access Security */ -#define M_cas (523 <<16) /*CA server*/ -#define M_casApp (524 <<16) /*CA server application*/ -#define M_bucket (525 <<16) /*Bucket Hash*/ -#define M_gddFuncTbl (526 <<16) /*gdd jump table*/ -#define M_stdlib (527 <<16) /*EPICS Standard library*/ -#define M_pool (528 <<16) /*Thread pool*/ -#define M_time (529 <<16) /*epicsTime*/ +/* Module numbers start above 500 for compatibility with vxWorks errnoLib */ -epicsShareFunc void epicsShareAPI errSymLookup(long status, char *pBuf, unsigned bufLength); -epicsShareFunc const char* errSymMsg(long status); -epicsShareFunc void epicsShareAPI errSymTest(unsigned short modnum, unsigned short begErrNum, unsigned short endErrNum); -epicsShareFunc void epicsShareAPI errSymTestPrint(long errNum); -epicsShareFunc int epicsShareAPI errSymBld(void); -epicsShareFunc int epicsShareAPI errSymbolAdd (long errNum,char *name); -epicsShareFunc void epicsShareAPI errSymDump(void); -epicsShareFunc void epicsShareAPI tstErrSymFind(void); +/* FIXME: M_xxx values could be declared as integer variables and set + * at runtime from registration routines; the S_xxx definitions would + * still work with that change, with careful initialization. + */ -#ifdef __cplusplus -} -#endif +/* libCom */ +#define M_asLib (501 << 16) /* Access Security */ +#define M_bucket (502 << 16) /* Bucket Hash */ +#define M_devLib (503 << 16) /* Hardware RegisterAccess */ +#define M_stdlib (504 << 16) /* EPICS Standard library */ +#define M_pool (505 << 16) /* Thread pool */ +#define M_time (506 << 16) /* epicsTime */ -#endif /*INCerrMdefh*/ +/* ioc */ +#define M_dbAccess (511 << 16) /* Database Access Routines */ +#define M_dbLib (512 << 16) /* Static Database Access */ +#define M_drvSup (513 << 16) /* Driver Support */ +#define M_devSup (514 << 16) /* Device Support */ +#define M_recSup (515 << 16) /* Record Support */ + +/* cas */ +#define M_cas (521 << 16) /* CA server */ +#define M_gddFuncTbl (522 << 16) /* gdd jump table */ +#define M_casApp (523 << 16) /* CA server application */ + +#endif /*INC_errMdef_H*/ diff --git a/src/error/errSymLib.c b/src/error/errSymLib.c index 99d81829d..b220f2bc0 100644 --- a/src/error/errSymLib.c +++ b/src/error/errSymLib.c @@ -3,25 +3,15 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /* * errSymLib.c * Author: Marty Kraimer * Date: 6-1-90 - * - *************************************************************************** - * This must ultimately be replaced by a facility that allows remote - * nodes access to the error messages. A message handling communication - * task should be written that allows multiple remote nodes to request - * notification of all error messages. - * For now lets just print messages and last errno via logMsg or printf - *************************************************************************** */ -#include #include #include #include @@ -32,28 +22,29 @@ #define epicsExportSharedSymbols #include "cantProceed.h" #include "epicsAssert.h" +#include "epicsStdio.h" #include "errMdef.h" #include "errSymTbl.h" #include "ellLib.h" #include "errlog.h" -static unsigned short errhash(long errNum); - -typedef struct errnumnode { - ELLNODE node; - long errNum; - struct errnumnode *hashnode; - char *message; - long pad; -} ERRNUMNODE; #define NHASH 256 +static epicsUInt16 errhash(long errNum); + +typedef struct errnumnode { + ELLNODE node; + long errNum; + struct errnumnode *hashnode; + const char *message; + long pad; +} ERRNUMNODE; static ELLLIST errnumlist = ELLLIST_INIT; static ERRNUMNODE **hashtable; static int initialized = 0; extern ERRSYMTAB_ID errSymTbl; - + /**************************************************************** * ERRSYMBLD * @@ -62,7 +53,7 @@ extern ERRSYMTAB_ID errSymTbl; * ell nodes that have a common hash number. * ***************************************************************/ -int epicsShareAPI errSymBld(void) +int errSymBld(void) { ERRSYMBOL *errArray = errSymTbl->symbols; ERRNUMNODE *perrNumNode = NULL; @@ -70,124 +61,87 @@ int epicsShareAPI errSymBld(void) ERRNUMNODE **phashnode = NULL; int i; int modnum; - unsigned short hashInd; - if(initialized) return(0); + if (initialized) + return(0); + hashtable = (ERRNUMNODE**)callocMustSucceed (NHASH, sizeof(ERRNUMNODE*),"errSymBld"); for (i = 0; i < errSymTbl->nsymbols; i++, errArray++) { - modnum = errArray->errNum >> 16; - if (modnum < 501) { - fprintf(stderr, "errSymBld: ERROR - Module number in errSymTbl < 501 was Module=%lx Name=%s\n", - errArray->errNum, errArray->name); - continue; - } - if ((errSymbolAdd(errArray->errNum, errArray->name)) <0 ) { - fprintf(stderr, "errSymBld: ERROR - errSymbolAdd() failed \n"); - continue; - } + modnum = errArray->errNum >> 16; + if (modnum < 501) { + fprintf(stderr, "errSymBld: ERROR - Module number in errSymTbl < 501 was Module=%lx Name=%s\n", + errArray->errNum, errArray->name); + continue; + } + if ((errSymbolAdd(errArray->errNum, errArray->name)) < 0) { + fprintf(stderr, "errSymBld: ERROR - errSymbolAdd() failed \n"); + continue; + } } perrNumNode = (ERRNUMNODE *) ellFirst(&errnumlist); while (perrNumNode) { - /* hash each perrNumNode->errNum */ - hashInd = errhash(perrNumNode->errNum); - phashnode = (ERRNUMNODE**)&hashtable[hashInd]; - pNextNode = (ERRNUMNODE*) *phashnode; - /* search for last node (NULL) of hashnode linked list */ - while (pNextNode) { - phashnode = &pNextNode->hashnode; - pNextNode = *phashnode; - } - *phashnode = perrNumNode; - perrNumNode = (ERRNUMNODE *) ellNext((ELLNODE *) perrNumNode); + /* hash each perrNumNode->errNum */ + epicsUInt16 hashInd = errhash(perrNumNode->errNum); + + phashnode = (ERRNUMNODE**)&hashtable[hashInd]; + pNextNode = (ERRNUMNODE*) *phashnode; + /* search for last node (NULL) of hashnode linked list */ + while (pNextNode) { + phashnode = &pNextNode->hashnode; + pNextNode = *phashnode; + } + *phashnode = perrNumNode; + perrNumNode = (ERRNUMNODE *) ellNext((ELLNODE *) perrNumNode); } initialized = 1; return(0); } - - /**************************************************************** * HASH * returns the hash index of errNum ****************************************************************/ -static unsigned short errhash(long errNum) +static epicsUInt16 errhash(long errNum) { -unsigned short modnum; -unsigned short errnum; + epicsUInt16 modnum; + epicsUInt16 errnum; - modnum = (unsigned short) (errNum >> 16); - errnum = (unsigned short) (errNum & 0xffff); - return((unsigned short)(((modnum - 500) * 20) + errnum) % NHASH); + modnum = (unsigned short) (errNum >> 16); + errnum = (unsigned short) (errNum & 0xffff); + return (((modnum - 500) * 20) + errnum) % NHASH; } - + /**************************************************************** * ERRSYMBOLADD * adds symbols to the master errnumlist as compiled from errSymTbl.c ***************************************************************/ -int epicsShareAPI errSymbolAdd (long errNum,char *name) +int errSymbolAdd(long errNum, const char *name) { - ERRNUMNODE *pNew; + ERRNUMNODE *pNew = (ERRNUMNODE*) callocMustSucceed(1, + sizeof(ERRNUMNODE), "errSymbolAdd"); - pNew = (ERRNUMNODE*)callocMustSucceed(1,sizeof(ERRNUMNODE),"errSymbolAdd"); pNew->errNum = errNum; pNew->message = name; - ellAdd(&errnumlist,(ELLNODE*)pNew); - return(0); + ellAdd(&errnumlist, (ELLNODE*)pNew); + return 0; } /**************************************************************** * errRawCopy ***************************************************************/ -static void errRawCopy ( long statusToDecode, char *pBuf, unsigned bufLength ) +static void errRawCopy(long statusToDecode, char *pBuf, size_t bufLength) { - unsigned modnum, errnum; - unsigned nChar; - int status; + epicsUInt16 modnum = (statusToDecode >>= 16) & 0xffff; + epicsUInt16 errnum = statusToDecode & 0xffff; - modnum = (unsigned) statusToDecode; - modnum >>= 16; - modnum &= 0xffff; - errnum = (unsigned) statusToDecode; - errnum &= 0xffff; + assert(bufLength > 20); - if ( bufLength ) { - if ( modnum == 0 ) { - if ( bufLength > 11 ) { - status = sprintf ( pBuf, "err = %d", errnum ); - } - else if ( bufLength > 5 ) { - status = sprintf ( pBuf, "%d", errnum ); - } - else { - strncpy ( pBuf,"", bufLength ); - pBuf[bufLength-1] = '\0'; - status = 0; - } - } - else { - if ( bufLength > 50 ) { - status = sprintf ( pBuf, - "status = (%d,%d) not in symbol table", modnum, errnum ); - } - else if ( bufLength > 25 ) { - status = sprintf ( pBuf, - "status = (%d,%d)", modnum, errnum ); - } - else if ( bufLength > 15 ) { - status = sprintf ( pBuf, - "(%d,%d)", modnum, errnum ); - } - else { - strncpy ( pBuf, - "", bufLength); - pBuf[bufLength-1] = '\0'; - status = 0; - } - } - assert (status >= 0 ); - nChar = (unsigned) status; - assert ( nChar < bufLength ); + if (modnum == 0) { + epicsSnprintf(pBuf, bufLength, "Error #%u", errnum); + } + else { + epicsSnprintf(pBuf, bufLength, "Error (%u,%u)", modnum, errnum); } } @@ -195,27 +149,27 @@ static const char* errSymLookupInternal(long status) { unsigned modNum; - unsigned hashInd; ERRNUMNODE *pNextNode; ERRNUMNODE **phashnode = NULL; - if(!initialized) errSymBld(); + if (!initialized) + errSymBld(); modNum = (unsigned) status; modNum >>= 16; modNum &= 0xffff; - if ( modNum <= 500 ) { + if (modNum <= 500) { const char * pStr = strerror ((int) status); - if ( pStr ) { + if (pStr) { return pStr; } } else { - hashInd = errhash(status); + unsigned hashInd = errhash(status); phashnode = (ERRNUMNODE**)&hashtable[hashInd]; pNextNode = *phashnode; - while(pNextNode) { - if(pNextNode->errNum==status){ + while (pNextNode) { + if (pNextNode->errNum==status){ return pNextNode->message; } phashnode = &pNextNode->hashnode; @@ -234,7 +188,7 @@ const char* errSymMsg(long status) /**************************************************************** * errSymLookup ***************************************************************/ -void epicsShareAPI errSymLookup (long status, char * pBuf, unsigned bufLength) +void errSymLookup(long status, char * pBuf, size_t bufLength) { const char* msg = errSymLookupInternal(status); if(msg) { @@ -248,56 +202,52 @@ void epicsShareAPI errSymLookup (long status, char * pBuf, unsigned bufLength) /**************************************************************** * errSymDump ***************************************************************/ -void epicsShareAPI errSymDump(void) +void errSymDump(void) { -ERRNUMNODE **phashnode = NULL; -ERRNUMNODE *pNextNode; -int i; -int modnum; -int errnum; -int msgcount; -int firstTime; + int i; + int msgcount = 0; - if (!initialized) errSymBld(); + if (!initialized) errSymBld(); - msgcount = 0; - printf("errSymDump: number of hash slots=%d\n", NHASH); - for ( i=0; i < NHASH; i++) { - phashnode = &hashtable[i]; - pNextNode = *phashnode; - firstTime=1; - while (pNextNode) { - if (firstTime) { - printf("HASHNODE=%d\n", i); - firstTime=0; - } - modnum = pNextNode->errNum >> 16; - errnum = pNextNode->errNum & 0xffff; - printf("\tmod %d num %d \"%s\"\n" - , modnum , errnum , pNextNode->message); - msgcount++; - phashnode = &pNextNode->hashnode; - pNextNode = *phashnode; - } - } - printf("\nerrSymDump: total number of error messages=%d\n", msgcount); + msgcount = 0; + printf("errSymDump: number of hash slots = %d\n", NHASH); + for (i = 0; i < NHASH; i++) { + ERRNUMNODE **phashnode = &hashtable[i]; + ERRNUMNODE *pNextNode = *phashnode; + int count = 0; + + while (pNextNode) { + int modnum = pNextNode->errNum >> 16; + int errnum = pNextNode->errNum & 0xffff; + + if (!count++) { + printf("HASHNODE = %d\n", i); + } + printf("\tmod %d num %d \"%s\"\n", + modnum , errnum , pNextNode->message); + phashnode = &pNextNode->hashnode; + pNextNode = *phashnode; + } + msgcount += count; + } + printf("\nerrSymDump: total number of error messages = %d\n", msgcount); } /**************************************************************** * errSymTestPrint ***************************************************************/ -void epicsShareAPI errSymTestPrint(long errNum) +void errSymTestPrint(long errNum) { - char message[256]; - unsigned short modnum; - unsigned short errnum; + char message[256]; + epicsUInt16 modnum; + epicsUInt16 errnum; if (!initialized) errSymBld(); message[0] = '\0'; - modnum = (unsigned short) (errNum >> 16); - errnum = (unsigned short) (errNum & 0xffff); + modnum = (epicsUInt16) (errNum >> 16); + errnum = (epicsUInt16) (errNum & 0xffff); if (modnum < 501) { fprintf(stderr, "Usage: errSymTestPrint(long errNum) \n"); fprintf(stderr, "errSymTestPrint: module number < 501 \n"); @@ -306,27 +256,27 @@ void epicsShareAPI errSymTestPrint(long errNum) errSymLookup(errNum, message, sizeof(message)); if ( message[0] == '\0' ) return; printf("module %hu number %hu message=\"%s\"\n", - modnum, errnum, message); + modnum, errnum, message); return; } /**************************************************************** * ERRSYMTEST ****************************************************************/ -void epicsShareAPI errSymTest(unsigned short modnum, - unsigned short begErrNum, unsigned short endErrNum) +void errSymTest(epicsUInt16 modnum, epicsUInt16 begErrNum, + epicsUInt16 endErrNum) { - long errNum; - unsigned short errnum; + long errNum; + epicsUInt16 errnum; - if(!initialized) errSymBld(); + if (!initialized) errSymBld(); if (modnum < 501) - return; + return; /* print range of error messages */ for (errnum = begErrNum; errnum <= endErrNum; errnum++) { - errNum = modnum << 16; - errNum |= (errnum & 0xffff); - errSymTestPrint(errNum); + errNum = modnum << 16; + errNum |= (errnum & 0xffff); + errSymTestPrint(errNum); } } diff --git a/src/error/errSymTbl.h b/src/error/errSymTbl.h index 2b1712621..7fc25f733 100644 --- a/src/error/errSymTbl.h +++ b/src/error/errSymTbl.h @@ -1,33 +1,50 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ -#ifndef INCerrSymTblh -#define INCerrSymTblh 1 +#ifndef INC_errSymTbl_H +#define INC_errSymTbl_H -#ifndef NELEMENTS -#define NELEMENTS(array) /* number of elements in an array */ \ - (sizeof (array) / sizeof ((array) [0])) -#endif -#define LOCAL static +#include + +#include "shareLib.h" +#include "epicsTypes.h" + +/* ERRSYMBOL - entry in symbol table */ +typedef struct { + long errNum; /* errMessage symbol number */ + const char *name; /* pointer to symbol name */ +} ERRSYMBOL; + +/* ERRSYMTAB - symbol table */ +typedef struct { + int nsymbols; /* current number of symbols in table */ + ERRSYMBOL *symbols; /* ptr to array of symbol entries */ +} ERRSYMTAB; -typedef struct /* ERRSYMBOL - entry in symbol table */ - { - char *name; /* pointer to symbol name */ - long errNum; /* errMessage symbol number */ - } ERRSYMBOL; -typedef struct /* ERRSYMTAB - symbol table */ - { - int nsymbols; /* current number of symbols in table */ - ERRSYMBOL *symbols; /* ptr to array of symbol entries */ - } ERRSYMTAB; typedef ERRSYMTAB *ERRSYMTAB_ID; -#endif /* INCerrSymTblh */ +#ifdef __cplusplus +extern "C" { +#endif + +epicsShareFunc void errSymLookup(long status, char *pBuf, size_t bufLength); +epicsShareFunc const char* errSymMsg(long status); +epicsShareFunc void errSymTest(epicsUInt16 modnum, epicsUInt16 begErrNum, + epicsUInt16 endErrNum); +epicsShareFunc void errSymTestPrint(long errNum); +epicsShareFunc int errSymBld(void); +epicsShareFunc int errSymbolAdd(long errNum, const char *name); +epicsShareFunc void errSymDump(void); + +#ifdef __cplusplus +} +#endif + +#endif /* INC_errSymTbl_H */ diff --git a/src/error/errlog.c b/src/error/errlog.c index b6789978a..8445a5a7e 100644 --- a/src/error/errlog.c +++ b/src/error/errlog.c @@ -28,7 +28,7 @@ #include "epicsEvent.h" #include "epicsInterrupt.h" #include "errMdef.h" -#include "error.h" +#include "errSymTbl.h" #include "ellLib.h" #include "errlog.h" #include "epicsStdio.h" @@ -103,7 +103,7 @@ static int tvsnPrint(char *str, size_t size, const char *format, va_list ap) return nchar; } -epicsShareFunc int errlogPrintf(const char *pFormat, ...) +int errlogPrintf(const char *pFormat, ...) { va_list pvar; char *pbuffer; @@ -142,8 +142,7 @@ epicsShareFunc int errlogPrintf(const char *pFormat, ...) return nchar; } -epicsShareFunc int errlogVprintf( - const char *pFormat,va_list pvar) +int errlogVprintf(const char *pFormat,va_list pvar) { int nchar; char *pbuffer; @@ -179,13 +178,13 @@ epicsShareFunc int errlogVprintf( return nchar; } -epicsShareFunc int epicsShareAPI errlogMessage(const char *message) +int errlogMessage(const char *message) { errlogPrintf("%s", message); return 0; } -epicsShareFunc int errlogPrintfNoConsole( const char *pFormat, ...) +int errlogPrintfNoConsole(const char *pFormat, ...) { va_list pvar; int nchar; @@ -203,8 +202,7 @@ epicsShareFunc int errlogPrintfNoConsole( const char *pFormat, ...) return nchar; } -epicsShareFunc int errlogVprintfNoConsole( - const char *pFormat,va_list pvar) +int errlogVprintfNoConsole(const char *pFormat, va_list pvar) { int nchar; char *pbuffer; @@ -229,8 +227,7 @@ epicsShareFunc int errlogVprintfNoConsole( } -epicsShareFunc int errlogSevPrintf( - const errlogSevEnum severity,const char *pFormat, ...) +int errlogSevPrintf(errlogSevEnum severity, const char *pFormat, ...) { va_list pvar; int nchar; @@ -263,8 +260,7 @@ epicsShareFunc int errlogSevPrintf( return nchar; } -epicsShareFunc int errlogSevVprintf( - const errlogSevEnum severity,const char *pFormat,va_list pvar) +int errlogSevVprintf(errlogSevEnum severity, const char *pFormat, va_list pvar) { char *pnext; int nchar; @@ -299,8 +295,7 @@ epicsShareFunc int errlogSevVprintf( } -epicsShareFunc char * epicsShareAPI errlogGetSevEnumString( - const errlogSevEnum severity) +const char * errlogGetSevEnumString(errlogSevEnum severity) { errlogInit(0); if (severity > 3) @@ -308,21 +303,19 @@ epicsShareFunc char * epicsShareAPI errlogGetSevEnumString( return errlogSevEnumString[severity]; } -epicsShareFunc void epicsShareAPI errlogSetSevToLog( - const errlogSevEnum severity) +void errlogSetSevToLog(errlogSevEnum severity) { errlogInit(0); pvtData.sevToLog = severity; } -epicsShareFunc errlogSevEnum epicsShareAPI errlogGetSevToLog(void) +errlogSevEnum errlogGetSevToLog(void) { errlogInit(0); return pvtData.sevToLog; } -epicsShareFunc void epicsShareAPI errlogAddListener( - errlogListener listener, void *pPrivate) +void errlogAddListener(errlogListener listener, void *pPrivate) { listenerNode *plistenerNode; @@ -339,8 +332,7 @@ epicsShareFunc void epicsShareAPI errlogAddListener( epicsMutexUnlock(pvtData.listenerLock); } -epicsShareFunc int epicsShareAPI errlogRemoveListeners( - errlogListener listener, void *pPrivate) +int errlogRemoveListeners(errlogListener listener, void *pPrivate) { listenerNode *plistenerNode; int count = 0; @@ -374,7 +366,7 @@ epicsShareFunc int epicsShareAPI errlogRemoveListeners( return count; } -epicsShareFunc int epicsShareAPI eltc(int yesno) +int eltc(int yesno) { errlogInit(0); errlogFlush(); @@ -382,15 +374,15 @@ epicsShareFunc int epicsShareAPI eltc(int yesno) return 0; } -epicsShareFunc int errlogSetConsole(FILE *stream) +int errlogSetConsole(FILE *stream) { errlogInit(0); pvtData.console = stream; return 0; } -epicsShareFunc void errPrintf(long status, const char *pFileName, - int lineno, const char *pformat, ...) +void errPrintf(long status, const char *pFileName, int lineno, + const char *pformat, ...) { va_list pvar; char *pnext; @@ -506,7 +498,7 @@ static void errlogInitPvt(void *arg) } -epicsShareFunc int epicsShareAPI errlogInit2(int bufsize, int maxMsgSize) +int errlogInit2(int bufsize, int maxMsgSize) { static epicsThreadOnceId errlogOnceFlag = EPICS_THREAD_ONCE_INIT; struct initArgs config; @@ -530,12 +522,12 @@ epicsShareFunc int epicsShareAPI errlogInit2(int bufsize, int maxMsgSize) return 0; } -epicsShareFunc int epicsShareAPI errlogInit(int bufsize) +int errlogInit(int bufsize) { return errlogInit2(bufsize, MAX_MESSAGE_SIZE); } -epicsShareFunc void epicsShareAPI errlogFlush(void) +void errlogFlush(void) { int count; @@ -598,7 +590,7 @@ static void errlogThread(void) } -static msgNode *msgbufGetNode(void) +static msgNode * msgbufGetNode(void) { char *pbuffer = pvtData.pbuffer; char *pnextFree; @@ -631,7 +623,7 @@ static msgNode *msgbufGetNode(void) return pnextSend; } -static char *msgbufGetFree(int noConsoleMessage) +static char * msgbufGetFree(int noConsoleMessage) { msgNode *pnextSend; diff --git a/src/error/errlog.h b/src/error/errlog.h index 14061bb87..e8a4fb557 100644 --- a/src/error/errlog.h +++ b/src/error/errlog.h @@ -1,5 +1,5 @@ /*************************************************************************\ -* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne +* Copyright (c) 2014 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. @@ -7,10 +7,11 @@ * in file LICENSE that is included with this distribution. \*************************************************************************/ -#ifndef INCerrlogh -#define INCerrlogh +#ifndef INC_errlog_H +#define INC_errlog_H #include +#include #include #include "shareLib.h" @@ -20,69 +21,71 @@ extern "C" { #endif - -/* define errMessage with a macro so we can print the file and line number*/ -#define errMessage(S, PM) \ - errPrintf(S, __FILE__, __LINE__, "%s", PM) -/* epicsPrintf and epicsVprintf old versions of errlog routines*/ -#define epicsPrintf errlogPrintf -#define epicsVprintf errlogVprintf - typedef void (*errlogListener)(void *pPrivate, const char *message); -typedef enum {errlogInfo, errlogMinor, errlogMajor, errlogFatal} errlogSevEnum; - -#ifdef ERRLOG_INIT -epicsShareDef char * errlogSevEnumString[] = {"info","minor","major","fatal"}; -#else -epicsShareExtern char * errlogSevEnumString[]; -#endif - -epicsShareFunc int errlogPrintf( - const char *pformat, ...) EPICS_PRINTF_STYLE(1,2); -epicsShareFunc int errlogVprintf( - const char *pformat,va_list pvar); -epicsShareFunc int errlogSevPrintf( - const errlogSevEnum severity,const char *pformat, ...) EPICS_PRINTF_STYLE(2,3); -epicsShareFunc int errlogSevVprintf( - const errlogSevEnum severity,const char *pformat,va_list pvar); -epicsShareFunc int epicsShareAPI errlogMessage( - const char *message); - -epicsShareFunc char * epicsShareAPI errlogGetSevEnumString( - const errlogSevEnum severity); -epicsShareFunc void epicsShareAPI errlogSetSevToLog( - const errlogSevEnum severity ); -epicsShareFunc errlogSevEnum epicsShareAPI errlogGetSevToLog(void); - -epicsShareFunc void epicsShareAPI errlogAddListener( - errlogListener listener, void *pPrivate); -epicsShareFunc int epicsShareAPI errlogRemoveListeners( - errlogListener listener, void *pPrivate); - -epicsShareFunc int epicsShareAPI eltc(int yesno); -epicsShareFunc int errlogSetConsole(FILE *stream); - -epicsShareFunc int epicsShareAPI errlogInit(int bufsize); -epicsShareFunc int epicsShareAPI errlogInit2(int bufsize, int maxMsgSize); -epicsShareFunc void epicsShareAPI errlogFlush(void); - -/*other routines that write to log file*/ -epicsShareFunc void errPrintf(long status, const char *pFileName, - int lineno, const char *pformat, ...) EPICS_PRINTF_STYLE(4,5); +typedef enum { + errlogInfo, + errlogMinor, + errlogMajor, + errlogFatal +} errlogSevEnum; epicsShareExtern int errVerbose; -/* The following are added so that logMsg on vxWorks does not cause - * the message to appear twice on the console - */ -epicsShareFunc int errlogPrintfNoConsole( - const char *pformat, ...) EPICS_PRINTF_STYLE(1,2); -epicsShareFunc int errlogVprintfNoConsole( - const char *pformat,va_list pvar); + +#ifdef ERRLOG_INIT + epicsShareDef const char *errlogSevEnumString[] = { + "info", + "minor", + "major", + "fatal" + }; +#else + epicsShareExtern const char * errlogSevEnumString[]; +#endif + +/* errMessage is a macro so it can get the file and line number */ +#define errMessage(S, PM) \ + errPrintf(S, __FILE__, __LINE__, "%s", PM) +/* epicsPrintf and epicsVprintf are old names for errlog routines*/ +#define epicsPrintf errlogPrintf +#define epicsVprintf errlogVprintf + +epicsShareFunc int errlogPrintf(const char *pformat, ...) + EPICS_PRINTF_STYLE(1,2); +epicsShareFunc int errlogVprintf(const char *pformat, va_list pvar); +epicsShareFunc int errlogSevPrintf(const errlogSevEnum severity, + const char *pformat, ...) EPICS_PRINTF_STYLE(2,3); +epicsShareFunc int errlogSevVprintf(const errlogSevEnum severity, + const char *pformat, va_list pvar); +epicsShareFunc int errlogMessage(const char *message); + +epicsShareFunc const char * errlogGetSevEnumString(errlogSevEnum severity); +epicsShareFunc void errlogSetSevToLog(errlogSevEnum severity); +epicsShareFunc errlogSevEnum errlogGetSevToLog(void); + +epicsShareFunc void errlogAddListener(errlogListener listener, void *pPrivate); +epicsShareFunc int errlogRemoveListeners(errlogListener listener, + void *pPrivate); + +epicsShareFunc int eltc(int yesno); +epicsShareFunc int errlogSetConsole(FILE *stream); + +epicsShareFunc int errlogInit(int bufsize); +epicsShareFunc int errlogInit2(int bufsize, int maxMsgSize); +epicsShareFunc void errlogFlush(void); + +epicsShareFunc void errPrintf(long status, const char *pFileName, int lineno, + const char *pformat, ...) EPICS_PRINTF_STYLE(4,5); + +epicsShareFunc int errlogPrintfNoConsole(const char *pformat, ...) + EPICS_PRINTF_STYLE(1,2); +epicsShareFunc int errlogVprintfNoConsole(const char *pformat,va_list pvar); + +epicsShareFunc void errSymLookup(long status, char *pBuf, size_t bufLength); #ifdef __cplusplus } #endif -#endif /*INCerrlogh*/ +#endif /*INC_errlog_H*/ diff --git a/src/error/error.h b/src/error/error.h deleted file mode 100644 index 18cf7eebd..000000000 --- a/src/error/error.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne -* National Laboratory. -* Copyright (c) 2002 The Regents of the University of California, as -* Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. -\*************************************************************************/ -/* error.h - errMessage symbol table header */ - -/* - * Author: Marty Kraimer - * Date: 6-1-90 - */ - - -#ifndef INCerrorh -#define INCerrorh 1 - -#define NELEMENTS(array) /* number of elements in an array */ \ - (sizeof (array) / sizeof ((array) [0])) - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct /* ERRSYMBOL - entry in symbol table */ - { - char *name; /* pointer to symbol name */ - long errNum; /* errMessage symbol number */ - } ERRSYMBOL; -typedef struct /* ERRSYMTAB - symbol table */ - { - short nsymbols; /* current number of symbols in table */ - ERRSYMBOL *symbols; /* ptr to array of symbol entries */ - } ERRSYMTAB; -typedef ERRSYMTAB *ERRSYMTAB_ID; - -/*************************************************************/ -struct errSet { /* This defines one module error set */ - long number; /* dimension of err strings */ - char **papName; /* ptr to arr of ptr to error string */ -}; -struct errDes { /* An array of error sets for modules */ - long number; /* number of err modules */ - struct errSet **papErrSet; /* ptr to arr of ptr to errSet */ -}; -extern struct errDes *dbErrDes; -/*************************************************************/ - -#ifdef __cplusplus -} -#endif - -#endif /*INCerrorh*/ diff --git a/src/error/makeStatTbl.pl b/src/error/makeStatTbl.pl index 4f53901f3..f6a021835 100644 --- a/src/error/makeStatTbl.pl +++ b/src/error/makeStatTbl.pl @@ -2,126 +2,114 @@ #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. -# Copyright (c) 2002 The Regents of the University of California, as +# Copyright (c) 2014 The Regents of the University of California, as # Operator of Los Alamos National Laboratory. -# EPICS BASE Versions 3.13.7 -# and higher are distributed subject to a Software License Agreement found +# EPICS BASE is distributed subject to a Software License Agreement found # in file LICENSE that is included with this distribution. #************************************************************************* # -# makeStatTbl.pl - Create Error Symbol Table +# makeStatTbl.pl - Create Error Symbol Table # -# Kay-Uwe Kasemir, 1-31-97, -# based on makeStatTbl shell script. +# Original Author: Kay-Uwe Kasemir, 1-31-97 # # SYNOPSIS -# perl makeStatTbl.pl hdir [...] +# perl makeStatTbl.pl files.h... # # DESCRIPTION # This tool creates a symbol table (ERRSYMTAB) structure which contains the -# names and values of all the status codes defined in the .h files in the -# specified directory(s). The status codes must be prefixed with "S_" +# names and values of all the status codes defined in the .h files named in +# its input arguments. The status codes must be prefixed with "S_" # in order to be included in this table. -# A "err.h" file must exist in each hdir which defines the module -# numbers, eg. "M_". The table is created on standard output. +# Module numbers definitions prefixed with "M_" are also read from the input +# files and included in the output. # # This tool's primary use is for creating an error status table used # by errPrint, and errSymLookup. # # FILES -# errMdef.h module number file for each h directory +# errMdef.h Module number file for each h directory +# errSymTbl.c Source file generated by tool in the cwd # # SEE ALSO: errnoLib(1), symLib(1) -#*/ -use Cwd; +use strict; +use Getopt::Std; -die "No args (files to parse) given" if ($#ARGV < 0); +my $tool = 'makeStatTbl.pl'; -# parse all lines of all files given: -while (<>) -{ - if (m'^#define[ /t]*S_') - { - chomp; - push @err_sym_line, $_; - } - if (m'^#[ \t]*define[ /t]+M_') - { - chomp; - push @err_facility_line, $_; - } +our ($opt_h); +our $opt_o = 'errSymTbl.c'; + +$Getopt::Std::OUTPUT_HELP_VERSION = 1; + +&HELP_MESSAGE unless getopts('ho:') && @ARGV; +&HELP_MESSAGE if $opt_h; + +my (@syms, %vals, %msgs); + +# Extract names, values and comments from all S_ and M_ symbol definitions +while (<>) { + chomp; + next unless m/^ \s* \# \s* define \s+ ([SM]_[A-Za-z0-9_]+) + \s++ (.*?) \s* \/ \* \s*+ (.*?) \s* \* \/ \s* $/x; + push @syms, $1; + $vals{$1} = $2; + $msgs{$1} = $3; } -$out_name = "errSymTbl.c"; -$dir = cwd(); +open my $out, '>', $opt_o or + die "Can't create $opt_o: $!\n"; -open OUT, ">$out_name" or die "Cannot open $out_name"; +print $out <<"END"; +/* Generated file $opt_o */ -print OUT "/*\n"; -print OUT " * status code symbol table\n"; -print OUT " *\n"; -print OUT " * CREATED BY makeStatTbl.pl\n"; -print OUT " * FROM $dir\n"; -print OUT " * ON " . localtime() . "\n"; -print OUT " */\n"; -print OUT "\n"; -print OUT "#include \"errMdef.h\"\n"; -print OUT "#include \"errSymTbl.h\"\n"; -print OUT "\n"; +#include "errMdef.h" +#include "errSymTbl.h" +#include "dbDefs.h" +END -foreach $line ( @err_facility_line ) -{ - if ($line =~ m'^#[ \t]*define[ \t]+(M_[A-Za-z0-9_]+)[ \t]+(.*)') - { - printf OUT "#ifndef %s\n", $1; - printf OUT "#define %s %s\n", $1, $2; - printf OUT "#endif /* ifdef %s */\n", $1; - } +my @mods = grep {/^M_/} @syms; +my @errs = grep {/^S_/} @syms; + +foreach my $mod (@mods) { + my $val = $vals{$mod}; + my $msg = $msgs{$mod}; + print $out + "#ifndef $mod\n", + "#define $mod $val /* $msg */\n", + "#endif\n"; } -$count = 0; -foreach $line ( @err_sym_line ) -{ - print OUT "$line\n"; - # define S_symbol /* comment */ - if ($line =~ m'[ \t#]define[ \t]*(S_[A-Za-z0-9_]+).*\/\* ?(.+?) ?\*\/') - { - $symbol[$count] = $1; - $comment[$count]= $2; - ++$count; - } - else - { - # Some status values for '0' (=OK) have no comment: - unless ($line =~ m'[ \t#]define[ \t]*(S_[A-Za-z0-9_]+)') - { - die "cannot decode this line:\n$line\n"; - } - } +print $out + "\n", + "static ERRSYMBOL symbols[] = {\n"; + +foreach my $err (@errs) { + my $msg = escape($msgs{$err}); + my $val = $vals{$err}; + print $out + " { $val, \"$msg\"},\n"; } +print $out <<"END"; +}; -print OUT "\n"; -print OUT "static ERRSYMBOL symbols[] =\n"; -print OUT "{\n"; +static ERRSYMTAB symTbl = { + NELEMENTS(symbols), symbols +}; -for ($i=0; $i<$count; ++$i) -{ - printf OUT "\t{ \"%s\", (long) %s },\n", - $comment[$i], $symbol[$i]; +ERRSYMTAB_ID errSymTbl = &symTbl; + +END + +sub HELP_MESSAGE { + print STDERR "Usage: $tool [-o file.c] files.h ...\n"; + exit 2; } -print OUT "};\n"; -print OUT "\n"; -print OUT "static ERRSYMTAB symTbl =\n"; -print OUT "{\n"; -print OUT "\tNELEMENTS(symbols), /* current number of symbols in table */\n"; -print OUT "\tsymbols, /* ptr to symbol array */\n"; -print OUT "};\n"; -print OUT "\n"; -print OUT "ERRSYMTAB_ID errSymTbl = &symTbl;\n"; -print OUT "\n"; -print OUT "/*\tEOF $out_name */\n"; - +sub escape { + $_ = shift; + s/"/\\"/g; + return $_; +}