Clean up errPrintf stuff
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <dbDefs.h>
|
||||
#include <errMdef.h>
|
||||
#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");
|
||||
}
|
||||
@@ -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 <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <vxWorks.h>
|
||||
#include <taskLib.h>
|
||||
#include <intLib.h>
|
||||
#include <types.h>
|
||||
#include <symLib.h>
|
||||
#include <semLib.h>
|
||||
#include <error.h>
|
||||
#include <logLib.h>
|
||||
|
||||
#include <ellLib.h>
|
||||
#include <dbDefs.h>
|
||||
#include <task_params.h>
|
||||
#include <errMdef.h>
|
||||
#include <epicsPrint.h>
|
||||
#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; i<NELEMENTS(logMsgArgs); i++) {
|
||||
logMsgArgs[i] = va_arg(pvar, int);
|
||||
}
|
||||
logMsg (pformat,logMsgArgs[0],logMsgArgs[1],
|
||||
logMsgArgs[2],logMsgArgs[3],logMsgArgs[4],
|
||||
logMsgArgs[5]);
|
||||
va_end (pvar);
|
||||
return;
|
||||
}
|
||||
va_start (pvar, pformat);
|
||||
if(semTake(clientWaitForTask,WAIT_FOREVER)!=OK) {
|
||||
logMsg("epicsPrint: semTake returned error\n",0,0,0,0,0,0);
|
||||
taskSuspend(taskIdSelf());
|
||||
}
|
||||
pvtData.cmd = cmdErrPrintf;
|
||||
pvtData.taskid = taskIdSelf();
|
||||
pvtData.status = status;
|
||||
pvtData.pFileName = pFileName;
|
||||
pvtData.lineno = lineno;
|
||||
pvtData.pformat = pformat;
|
||||
pvtData.pvar = pvar;
|
||||
semGive(serverWaitForWork);
|
||||
if(semTake(clientWaitForCompletion,WAIT_FOREVER)!=OK) {
|
||||
logMsg("epicsPrint: semTake returned error\n",0,0,0,0,0,0);
|
||||
taskSuspend(taskIdSelf());
|
||||
}
|
||||
semGive(clientWaitForTask);
|
||||
}
|
||||
|
||||
LOCAL void errPrintfPVT(void)
|
||||
{
|
||||
long status = pvtData.status;
|
||||
char *pFileName = pvtData.pFileName;
|
||||
int lineno = pvtData.lineno;
|
||||
char *pformat = pvtData.pformat;
|
||||
va_list pvar = pvtData.pvar;
|
||||
|
||||
|
||||
if(pvtData.taskid != pvtData.oldtaskid) {
|
||||
mprintf("task: 0X%x %s\n",pvtData.taskid,taskName(pvtData.taskid));
|
||||
pvtData.oldtaskid = pvtData.taskid;
|
||||
}
|
||||
if(pFileName && errVerbose){
|
||||
mprintf("filename=\"%s\" line number=%d\n", pFileName, lineno);
|
||||
}
|
||||
if(status==0) status = MYERRNO;
|
||||
if(status>0) {
|
||||
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<NELEMENTS(logMsgArgs); i++) {
|
||||
logMsgArgs[i] = va_arg(pvar, int);
|
||||
}
|
||||
logMsg (pformat,logMsgArgs[0],logMsgArgs[1],
|
||||
logMsgArgs[2],logMsgArgs[3],logMsgArgs[4],
|
||||
logMsgArgs[5]);
|
||||
va_end (pvar);
|
||||
return;
|
||||
}
|
||||
if(semTake(clientWaitForTask,WAIT_FOREVER)!=OK) {
|
||||
logMsg("epicsPrint: semTake returned error\n",0,0,0,0,0,0);
|
||||
taskSuspend(taskIdSelf());
|
||||
}
|
||||
pvtData.cmd = cmdEpicsPrint;
|
||||
pvtData.pformat = pformat;
|
||||
pvtData.pvar = pvar;
|
||||
semGive(serverWaitForWork);
|
||||
if(semTake(clientWaitForCompletion,WAIT_FOREVER)!=OK) {
|
||||
logMsg("epicsPrint: semTake returned error\n",0,0,0,0,0,0);
|
||||
taskSuspend(taskIdSelf());
|
||||
}
|
||||
semGive(clientWaitForTask);
|
||||
}
|
||||
|
||||
LOCAL int mprintf (char *pFormat, ...)
|
||||
{
|
||||
va_list pvar;
|
||||
|
||||
va_start (pvar, pFormat);
|
||||
|
||||
return vmprintf (pFormat, pvar);
|
||||
}
|
||||
|
||||
|
||||
LOCAL int vmprintf (char *pFormat, va_list pvar)
|
||||
{
|
||||
int status;
|
||||
FILE ***pppFile;
|
||||
|
||||
|
||||
vfprintf(stdout,pFormat,pvar);
|
||||
fflush(stdout);
|
||||
vfprintf(iocLogFile,pFormat,pvar);
|
||||
fflush(iocLogFile);
|
||||
va_end(pvar);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user