IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 456


Ignore:
Timestamp:
Apr 19, 2004, 11:24:19 AM (22 years ago)
Author:
rhl
Message:

Added psErrorCodeString()

Location:
trunk/archive/pslib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/pslib/include/psError.h

    r382 r456  
    3434void psErrorClear(void);                ///< Clear the error stack
    3535
     36const char *psErrorCodeString(psErrorCode code);        ///< return the string associated with the error code
    3637void psErrorStackPrint(FILE *fd, const char *fmt, ...); ///< print the errorstack to this file descriptor
    3738void psVErrorStackPrint(FILE *fd,       //< write to this file descriptor
  • trunk/archive/pslib/src/Utils/error.c

    r386 r456  
    139139
    140140/************************************************************************************************************/
     141
     142static void
     143build_errorStringList(void)
     144{
     145    for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) {
     146        errorStringList[i] = NULL;
     147    }
     148   
     149    for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) {
     150        if (errorStrings[i].descrip == NULL) {
     151            break;
     152        }
     153       
     154        errorStringList[errorStrings[i].code] = errorStrings[i].descrip;
     155    }
     156}
     157
     158/************************************************************************************************************/
     159/*
     160 * Return the string associated with an error code
     161 */
     162const char *psErrorCodeString(psErrorCode code)
     163{
     164    if (errorStringList[PS_ERR_UNKNOWN] == NULL) { // need to build the errorStringList
     165        build_errorStringList();
     166    }
     167
     168    return (code < PS_ERR_BASE ? strerror(code) : errorStringList[code]);
     169}
     170
     171/************************************************************************************************************/
    141172/*
    142173 * Print the header then error stack to the provided file descriptor
     
    165196                        va_list ap)     // arguments for format
    166197{
    167     static int first = 1;
    168    
    169     if (first) {                        // need to build the errorStringList
    170         first = 0;
    171 
    172         for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) {
    173             errorStringList[i] = NULL;
    174         }
    175 
    176         for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) {
    177             if (errorStrings[i].descrip == NULL) {
    178                 break;
    179             }
    180            
    181             errorStringList[errorStrings[i].code] = errorStrings[i].descrip;
    182         }
     198    if (errorStringList[PS_ERR_UNKNOWN] == NULL) { // need to build the errorStringList
     199        build_errorStringList();
    183200    }
    184201
     
    208225        int code = stack[i]->error.code;
    209226        fprintf(fd, "%*s%-*s %-30s %s\n",
    210                 i, "", 30 - i, stack[i]->error.name,
    211                 (code < PS_ERR_BASE ? strerror(code) : errorStringList[code]), stack[i]->error.msg);
    212     }
    213 }
     227                i, "", 30 - i, stack[i]->error.name, psErrorCodeString(code), stack[i]->error.msg);
     228    }
     229}
Note: See TracChangeset for help on using the changeset viewer.