Index: /trunk/archive/pslib/src/Utils/error.c
===================================================================
--- /trunk/archive/pslib/src/Utils/error.c	(revision 566)
+++ /trunk/archive/pslib/src/Utils/error.c	(revision 567)
@@ -19,5 +19,6 @@
 #include "psErrorCodes.c"
 
-static char *errorStringList[PS_ERR_N_ERR_CLASSES]; // error strings indexed by errorCode
+static int nerrorString = 0;		// number of known error messages
+static char **errorStringList = NULL;	// error strings indexed by errorCode
 
 /************************************************************************************************************/
@@ -139,19 +140,34 @@
 
 /************************************************************************************************************/
-
-static void
-build_errorStringList(void)
-{
-    for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) {
-	errorStringList[i] = NULL;
-    }
-
-    errorStringList[PS_ERR_NONE] = "No error";
-    for (int i = 0; i < PS_ERR_N_ERR_CLASSES; i++) {
-	if (errorStrings[i].descrip == NULL) {
-	    break;
-	}
-	
-	errorStringList[errorStrings[i].code] = errorStrings[i].descrip;
+/*
+ * Register a set of psErrorDescription
+ */
+void p_psErrorRegister(const psErrorDescription *errors,       // errors to register
+		       int nerror)			       // number of errors
+{
+    if (nerror <= 0) {			// no new errors
+	return;
+    }
+
+    int codeMax = errors[nerror - 1].code; // largest new error code
+
+    if (codeMax > nerrorString) {
+	errorStringList = psRealloc(errorStringList, (codeMax + 1)*sizeof(char *));
+
+	for (int i = nerrorString; i <= codeMax; i++) {
+	    errorStringList[i] = NULL;
+	}
+	nerrorString = codeMax + 1;
+    }
+
+    for (int i = 0; i < nerror; i++) {
+	if (errorStringList[errors[i].code] != NULL && // that value is already registered differently
+	    strcmp(errorStringList[errors[i].code], errors[i].descrip) != 0) {
+	    psLogMsg("utils.error", PS_LOG_WARN,
+		     "Attempt to register error code %d as \"%s\" that is already registered as \"%s\"",
+		     errors[i].code, errors[i].descrip, errorStringList[errors[i].code]);
+	}
+
+	errorStringList[errors[i].code] = errors[i].descrip;
     }
 }
@@ -163,9 +179,17 @@
 const char *psErrorCodeString(psErrorCode code)
 {
-    if (errorStringList[PS_ERR_UNKNOWN] == NULL) { // need to build the errorStringList
-	build_errorStringList();
-    }
-
-    return (code < PS_ERR_BASE ? strerror(code) : errorStringList[code]);
+    if (errorStringList == NULL) {	// need to build the errorStringList
+	psErrorRegister();
+    }
+
+    if (code < PS_ERR_BASE) {
+	return strerror(code);
+    } else if (code >= nerrorString) {
+	static char buff[30];
+	sprintf(buff, "(Unknown code %d)", code);
+	return buff;
+    } else {
+	return errorStringList[code];
+    }
 }
 
@@ -197,6 +221,6 @@
 			va_list ap)	// arguments for format
 {
-    if (errorStringList[PS_ERR_UNKNOWN] == NULL) { // need to build the errorStringList
-	build_errorStringList();
+    if (errorStringList == NULL) {	// need to build the errorStringList
+	psErrorRegister();
     }
 
