From d38eaf82cdb37f3d8605d6887c345f06a115f29c Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Fri, 17 Feb 1995 20:55:09 +0000 Subject: [PATCH] Clean up errPrintf stuff --- src/libCom/Makefile.Unix | 4 +- src/libCom/Makefile.Vx | 4 +- src/libCom/errPrintfUNIX.c | 78 +++++++++++ src/libCom/errPrintfVX.c | 255 +++++++++++++++++++++++++++++++++++ src/libCom/errSymLib.c | 160 ---------------------- src/libCom/error/errSymLib.c | 160 ---------------------- 6 files changed, 337 insertions(+), 324 deletions(-) create mode 100644 src/libCom/errPrintfUNIX.c create mode 100644 src/libCom/errPrintfVX.c diff --git a/src/libCom/Makefile.Unix b/src/libCom/Makefile.Unix index 6624251ba..45edfbffe 100644 --- a/src/libCom/Makefile.Unix +++ b/src/libCom/Makefile.Unix @@ -11,7 +11,7 @@ SRCS.c = \ ../gpHashLib.c ../memDebugLib.c \ ../nextFieldSubr.c ../postfix.c \ ../tsSubr.c errSymTbl.c ../errInc.c \ - ../realpath.c ../mprintf.c + ../realpath.c ../errPrintfUNIX.c LIBOBJS = \ tsSubr.o bucketLib.o calcPerform.o\ @@ -19,7 +19,7 @@ LIBOBJS = \ envSubr.o errMtst.o errSymLib.o errSymTbl.o fdmgr.o \ freeListLib.o gpHashLib.o \ memDebugLib.o nextFieldSubr.o postfix.o \ - realpath.o mprintf.o + realpath.o errPrintfUNIX.o LIBNAME = libCom.a diff --git a/src/libCom/Makefile.Vx b/src/libCom/Makefile.Vx index 8fccebff3..148a33578 100644 --- a/src/libCom/Makefile.Vx +++ b/src/libCom/Makefile.Vx @@ -8,14 +8,14 @@ SRCS.c = \ ../envSubr.c ../errSymLib.c \ ../nextFieldSubr.c ../postfix.c \ ../bucketLib.c ../memDebugLib.c ../tsSubr.c ../pal.c \ - ../paldef.c ../mprintf.c errSymTbl.c + ../paldef.c errSymTbl.c ../errPrintfVX.c OBJS = \ calcPerform.o cvtBpt.o cvtFast.o ellLib.o envSubr.o errSymLib.o \ errSymTbl.o nextFieldSubr.o postfix.o \ bucketLib.o tsSubr.o gpHashLib.o freeListLib.o pal.o paldef.o \ - mprintf.o + errPrintfVX.o PROD = libCom diff --git a/src/libCom/errPrintfUNIX.c b/src/libCom/errPrintfUNIX.c new file mode 100644 index 000000000..cabdec142 --- /dev/null +++ b/src/libCom/errPrintfUNIX.c @@ -0,0 +1,78 @@ +/* $Id$ + * errPrintfUNIX.c + * Author: Marty Kraimer + * Date: 02-16-95 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: errPrintfUNIX.c + * ----------------- + * .01 02-16-95 mrk Extracted from errSymLib.c + *************************************************************************** + * 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 +#include +#include "errSymTbl.h" + + +/**************************************************************** + * ERRMESSAGE - now a macro to call errPrintf + * ERRPRINTF - print an error symbol message + ***************************************************************/ +void errPrintf(long status, char *pFileName, int lineno, char *pformat, ...) +{ + va_list pvar; + + va_start(pvar, pformat); + if(pFileName && errVerbose){ + printf("filename=\"%s\" line number=%d\n", pFileName, lineno); + } + if(status==0) status = errno; + if(status>0) { + int rtnval; + unsigned short modnum,errnum; + char name[256]; + + rtnval = errSymFind(status,name); + modnum = status >> 16; + errnum = status & 0xffff; + if(rtnval) { + printf( "Error status (module %hu, number %hu) not in symbol table", + modnum, errnum); + } else { + printf("%s ",name); + } + } + vprintf(pformat,pvar); + printf("\n"); +} diff --git a/src/libCom/errPrintfVX.c b/src/libCom/errPrintfVX.c new file mode 100644 index 000000000..1e32293a8 --- /dev/null +++ b/src/libCom/errPrintfVX.c @@ -0,0 +1,255 @@ +/* $Id$ + * errPrintfVX.c + * Author: Marty Kraimer and Jeff Hill + * Date: 6-1-90 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * Modification Log: errPrintfVX.c + * ----------------- + * .01 02-16-95 mrk Extracted from errSymLib.c + *************************************************************************** + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#ifndef LOCAL +#define LOCAL static +#endif /* LOCAL */ + +static int mprintf (char *pFormat, ...); +static int vmprintf (char *pFormat, va_list pvar); + +extern FILE *iocLogFile; + +LOCAL SEM_ID clientWaitForTask; +LOCAL SEM_ID clientWaitForCompletion; +LOCAL SEM_ID serverWaitForWork; + +LOCAL void epicsPrintTask(void); +LOCAL void errPrintfPVT(void); + +typedef enum{cmdErrPrintf,cmdEpicsPrint} cmdType; + +LOCAL struct { + cmdType cmd; + int taskid; + long status; + char *pFileName; + int lineno; + char *pformat; + va_list pvar; + int oldtaskid; +}pvtData; + +void errInit(void) +{ + pvtData.oldtaskid = 0; + if((clientWaitForTask=semBCreate(SEM_Q_FIFO,SEM_EMPTY))==NULL) + logMsg("semBcreate failed in errInit",0,0,0,0,0,0); + if((clientWaitForCompletion=semBCreate(SEM_Q_FIFO,SEM_EMPTY))==NULL) + logMsg("semBcreate failed in errInit",0,0,0,0,0,0); + if((serverWaitForWork=semBCreate(SEM_Q_FIFO,SEM_EMPTY))==NULL) + logMsg("semBcreate failed in errInit",0,0,0,0,0,0); + taskSpawn(EPICSPRINT_NAME,EPICSPRINT_PRI,EPICSPRINT_OPT, + EPICSPRINT_STACK,(FUNCPTR)epicsPrintTask, + 0,0,0,0,0,0,0,0,0,0); + if ((errSymBld()) != 0) { + logMsg("errSymBld failed to initialize\n",0,0,0,0,0,0); + } +} + +LOCAL void epicsPrintTask(void) +{ + semGive(clientWaitForTask); + while(TRUE) { + if(semTake(serverWaitForWork,WAIT_FOREVER)!=OK) + logMsg("epicsPrint: semTake returned error\n",0,0,0,0,0,0); + switch(pvtData.cmd) { + case (cmdErrPrintf) : + errPrintfPVT(); + break; + case (cmdEpicsPrint) : + vmprintf(pvtData.pformat,pvtData.pvar); + break; + } + semGive(clientWaitForCompletion); + } +} + + +void errPrintf(long status, char *pFileName, int lineno, char *pformat, ...) +{ + va_list pvar; + + if(INT_CONTEXT()) { + int logMsgArgs[6]; + int i; + + va_start (pvar, pformat); + for (i=0; i0) { + int rtnval; + unsigned short modnum,errnum; + char name[256]; + + rtnval = errSymFind(status,name); + modnum = status >> 16; + errnum = status & 0xffff; + if(rtnval) { + mprintf("Error status (module %hu, number %hu) not in symbol table\n", + modnum, errnum); + } else { + mprintf("%s ",name); + } + } + vmprintf(pformat,pvar); + mprintf("\n"); + return; +} + +void epicsPrintf(char *pformat, ...) +{ + va_list pvar; + + va_start(pvar, pformat); + epicsVprintf(pformat,pvar); +} + +void epicsVprintf(char *pformat, va_list pvar) +{ + + if(INT_CONTEXT()) { + int logMsgArgs[6]; + int i; + + for (i=0; i= -1){ - rtnval = 0; - } - else { - rtnval = status; - } - if(status>0) { - rtnval = errSymFind(status,name); - modnum = status >> 16; - errnum = status & 0xffff; - if(rtnval) { - sprintf(name, - "Error status (module %hu, number %hu) not in symbol table", - modnum, errnum); - } - } - if(pFormatString){ - namelen = strlen(name); - formatlen = strlen(pFormatString); - strcat(name," "); - if(sizeof(name)-namelen-1 > formatlen){ - strcat(name, pFormatString); - } - else if(sizeof(name)-namelen-1 > sizeof(ctxToLarge)){ - strcat(name, ctxToLarge); - } - else{ - mprintf(ctxToLarge); - } - } - - vmprintf(name, pvar); - - return rtnval; -} - /**************************************************************** * ERRSYMBOLADD * adds symbols to the master errnumlist as compiled from errSymTbl.c diff --git a/src/libCom/error/errSymLib.c b/src/libCom/error/errSymLib.c index 4f0edd11f..fa0886419 100644 --- a/src/libCom/error/errSymLib.c +++ b/src/libCom/error/errSymLib.c @@ -116,11 +116,6 @@ extern ERRSYMTAB_ID errSymTbl; /*Declare storage for errVerbose( defined in errMdef.h)*/ int errVerbose=0; -#ifdef __STDC__ -int verrPrintStatus(long status, char *pFormatString, va_list pvar); -#else -int verrPrintStatus(); -#endif /**************************************************************** @@ -197,161 +192,6 @@ unsigned short errnum; return((unsigned short)(((modnum - 500) * 20) + errnum) % NHASH); } -/**************************************************************** - * ERRMESSAGE - now a macro to call errPrintf - * ERRPRINTF - print an error symbol message - ***************************************************************/ -#ifdef __STDC__ -void errPrintf(long status, char *pFileName, int lineno, char *pformat, ...) -#else -void errPrintf(va_alist) -va_dcl -#endif -{ - va_list pvar; - static char *pReformat; - static int reformatSize; - static char pAdd[] = {'\n', '\0'}; -#ifndef __STDC__ - long status; - char *pformat; - char *pFileName; - int lineno; -#endif - -#ifdef __STDC__ - va_start(pvar, pformat); -#else - va_start(pvar); - status = va_arg(pvar, long); - pFileName = va_arg(pvar, char *); - lineno = va_arg(pvar, int); - pformat = va_arg(pvar, char *); -#endif - - if(pFileName && errVerbose){ - mprintf("filename=\"%s\" line number=%d\n", pFileName, lineno); - } - - if (pformat != NULL) { - int size; - - size = strlen(pformat)+NELEMENTS(pAdd); - - if(reformatSize < size){ - /* - * use a reasonable size string - */ - size = max(0xff, size); - if(pReformat){ - free(pReformat); - } - - pReformat = (char *) malloc(size); - if(pReformat){ - reformatSize = size; - } - else{ - mprintf ("%s: calloc error\n", __FILE__); - return; - } - } - strcpy(pReformat, pformat); - strcat(pReformat, pAdd); - - } - - verrPrintStatus(status, pReformat, pvar); - - return; -} - -/**************************************************************** - * ERRPRINTSTATUS - ***************************************************************/ -#ifdef __STDC__ -int errPrintStatus(long status, char *pFormat, ...) -#else -int errPrintStatus(va_alist) -va_dcl -#endif -{ - va_list pvar; -#ifndef __STDC__ - long status; - char *pFormat; -#endif - -#ifdef __STDC__ - va_start(pvar, pFormat); -#else - va_start(pvar); - status = va_arg(pvar, long); - pFormat = va_arg(pvar, char *); -#endif - - return verrPrintStatus(status, pFormat, pvar); -} - -/**************************************************************** - * VERRPRINTSTATUS - ***************************************************************/ -#ifdef __STDC__ -int verrPrintStatus(long status, char *pFormatString, va_list pvar) -#else -int verrPrintStatus(status, pFormatString, pvar) -long status; -char *pFormatString; -va_list pvar; -#endif -{ - static char ctxToLarge[] = "** Context String Overflow **"; - char name[256]; - int rtnval; - int namelen; - int formatlen; - unsigned short modnum; - unsigned short errnum; - - - name[0] = '\0'; - if(status==0) status = MYERRNO; - if(status >= -1){ - rtnval = 0; - } - else { - rtnval = status; - } - if(status>0) { - rtnval = errSymFind(status,name); - modnum = status >> 16; - errnum = status & 0xffff; - if(rtnval) { - sprintf(name, - "Error status (module %hu, number %hu) not in symbol table", - modnum, errnum); - } - } - if(pFormatString){ - namelen = strlen(name); - formatlen = strlen(pFormatString); - strcat(name," "); - if(sizeof(name)-namelen-1 > formatlen){ - strcat(name, pFormatString); - } - else if(sizeof(name)-namelen-1 > sizeof(ctxToLarge)){ - strcat(name, ctxToLarge); - } - else{ - mprintf(ctxToLarge); - } - } - - vmprintf(name, pvar); - - return rtnval; -} - /**************************************************************** * ERRSYMBOLADD * adds symbols to the master errnumlist as compiled from errSymTbl.c