Changeset 567
- Timestamp:
- May 3, 2004, 4:25:41 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/archive/pslib/src/Utils/error.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/src/Utils/error.c
r490 r567 19 19 #include "psErrorCodes.c" 20 20 21 static char *errorStringList[PS_ERR_N_ERR_CLASSES]; // error strings indexed by errorCode 21 static int nerrorString = 0; // number of known error messages 22 static char **errorStringList = NULL; // error strings indexed by errorCode 22 23 23 24 /************************************************************************************************************/ … … 139 140 140 141 /************************************************************************************************************/ 141 142 static void 143 build_errorStringList(void) 144 { 145 for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) { 146 errorStringList[i] = NULL; 147 } 148 149 errorStringList[PS_ERR_NONE] = "No error"; 150 for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) { 151 if (errorStrings[i].descrip == NULL) { 152 break; 153 } 154 155 errorStringList[errorStrings[i].code] = errorStrings[i].descrip; 142 /* 143 * Register a set of psErrorDescription 144 */ 145 void p_psErrorRegister(const psErrorDescription *errors, // errors to register 146 int nerror) // number of errors 147 { 148 if (nerror <= 0) { // no new errors 149 return; 150 } 151 152 int codeMax = errors[nerror - 1].code; // largest new error code 153 154 if (codeMax > nerrorString) { 155 errorStringList = psRealloc(errorStringList, (codeMax + 1)*sizeof(char *)); 156 157 for (int i = nerrorString; i <= codeMax; i++) { 158 errorStringList[i] = NULL; 159 } 160 nerrorString = codeMax + 1; 161 } 162 163 for (int i = 0; i < nerror; i++) { 164 if (errorStringList[errors[i].code] != NULL && // that value is already registered differently 165 strcmp(errorStringList[errors[i].code], errors[i].descrip) != 0) { 166 psLogMsg("utils.error", PS_LOG_WARN, 167 "Attempt to register error code %d as \"%s\" that is already registered as \"%s\"", 168 errors[i].code, errors[i].descrip, errorStringList[errors[i].code]); 169 } 170 171 errorStringList[errors[i].code] = errors[i].descrip; 156 172 } 157 173 } … … 163 179 const char *psErrorCodeString(psErrorCode code) 164 180 { 165 if (errorStringList[PS_ERR_UNKNOWN] == NULL) { // need to build the errorStringList 166 build_errorStringList(); 167 } 168 169 return (code < PS_ERR_BASE ? strerror(code) : errorStringList[code]); 181 if (errorStringList == NULL) { // need to build the errorStringList 182 psErrorRegister(); 183 } 184 185 if (code < PS_ERR_BASE) { 186 return strerror(code); 187 } else if (code >= nerrorString) { 188 static char buff[30]; 189 sprintf(buff, "(Unknown code %d)", code); 190 return buff; 191 } else { 192 return errorStringList[code]; 193 } 170 194 } 171 195 … … 197 221 va_list ap) // arguments for format 198 222 { 199 if (errorStringList [PS_ERR_UNKNOWN] == NULL) {// need to build the errorStringList200 build_errorStringList();223 if (errorStringList == NULL) { // need to build the errorStringList 224 psErrorRegister(); 201 225 } 202 226
Note:
See TracChangeset
for help on using the changeset viewer.
