Corrected an ambigious symbol-space for local attribute declarations.

* xmlschemas.c: Corrected an ambigious symbol-space for
  local attribute declarations. IFDEFed more IDC code to
  surpress compiler warnings.


* xmlschemas.c: tiny enhancement for content model error reports
  (#157190, #143948). Removed abbreviations: CT, ST and WC
  (#157190, reported by Frans  Englich).
* result/schemas/all* result/schemas/any3_0_0.err
  result/schemas/choice*
  result/schemas/cos-st-restricts-1-2-err_0_0.err
  result/schemas/derivation-ok-extension-err_0_0.err
  result/schemas/derivation-ok-extension_0_0.err
  result/schemas/derivation-ok-restriction-2-1-1_0_0.err
  result/schemas/derivation-ok-restriction-4-1-err_0_0.err
  result/schemas/deter0_0_0.err result/schemas/extension1_0_2.err
  result/schemas/facet-unionST-err1_0_0.err
  result/schemas/hexbinary_0_1.err
  result/schemas/list* result/schemas/restriction-attr1_0_0.err
  result/schemas/vdv-first4_0_1.err result/schemas/vdv-first4_0_2.err:
  Adapted output.
  xmlSchemaTypeFixup; this ensures facets of inherited types to be
  checked prior to facets of derived types - which caused a seg
  fault otherwise (bug #158216, reported by Frans Englich).
diff --git a/xmlschemas.c b/xmlschemas.c
index da1f0df..c0d4904 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -2536,6 +2536,7 @@
     xmlFree(type);
 }
 
+#ifdef IDC_ENABLED
 static void
 xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto)
 {
@@ -2563,7 +2564,7 @@
  *
  * Deallocates an identity-constraint definition.
  */
-void
+static void
 xmlSchemaFreeIDC(xmlSchemaIDCPtr idc)
 {
     xmlSchemaIDCSelectPtr cur, prev;
@@ -2593,6 +2594,7 @@
     }
     xmlFree(idc);
 }
+#endif /* IDC_ENABLED */
 
 /**
  * xmlSchemaFreeTypeList:
@@ -2921,6 +2923,7 @@
                     (xmlHashScannerFull) xmlSchemaElementDump, output);
 }
 
+#ifdef IDC_ENABLED
 /**
  * xmlSchemaDebugDumpIDCTable: 
  * @vctxt: the WXS validation context
@@ -2964,13 +2967,13 @@
 		    if (res == 0)
 			fprintf(output, "\"%s\" ", value);
 		    else
-			fprintf(output, "CANON-VALUE-FAILED ", value);
+			fprintf(output, "CANON-VALUE-FAILED ");
 		    if (value != NULL) {
 			xmlFree(value);
 			value = NULL;
 		    }
 		} else if (key != NULL)
-		    fprintf(output, "(no val), ", key->compValue);
+		    fprintf(output, "(no val), ");
 		else
 		    fprintf(output, "(key missing), ");
 	    }
@@ -2979,6 +2982,7 @@
 	bind = bind->next;
     } while (bind != NULL);
 }
+#endif /* IDC_ENABLED */
 #endif /* LIBXML_OUTPUT_ENABLED */
 
 /************************************************************************
@@ -3510,7 +3514,7 @@
 static xmlSchemaAttributePtr
 xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
                       const xmlChar * name, const xmlChar * namespace,
-		      xmlNodePtr node)
+		      xmlNodePtr node, int topLevel)
 {
     xmlSchemaAttributePtr ret = NULL;
     int val;
@@ -3540,12 +3544,45 @@
     val = xmlHashAddEntry3(schema->attrDecl, name,
                            namespace, ctxt->container, ret);
     if (val != 0) {
-	xmlSchemaPCustomErr(ctxt,
-	    XML_SCHEMAP_REDEFINED_ATTR,
-	    NULL, NULL, node,
-	    "A global attribute declaration with the name '%s' does already exist", name);
-        xmlFree(ret);
-        return (NULL);
+	if (topLevel) {
+	    xmlSchemaPCustomErr(ctxt,
+		XML_SCHEMAP_REDEFINED_ATTR,
+		NULL, NULL, node,
+		"A global attribute declaration with the name '%s' does "
+		"already exist", name);
+	    xmlFree(ret);	    
+	    return (NULL);
+	} else {
+	    char buf[20];
+	    xmlChar *str;
+	    /*
+	    * Using the ctxt->container for xmlHashAddEntry3 is ambigious
+	    * in the scenario:
+	    * 1. multiple top-level complex types have different target
+	    *    namespaces but have the SAME NAME; this can happen if
+	    *	 schemata are  imported
+	    * 2. those complex types contain attributes with an equal name
+	    * 3. those attributes are in no namespace 
+	    * We will compute a new context string.
+	    */
+	    snprintf(buf, 19, "%d", ctxt->counter++ + 1);
+	    str = xmlStrdup(BAD_CAST ctxt->container);
+	    str = xmlStrcat(str, BAD_CAST buf);
+	    val = xmlHashAddEntry3(schema->attrDecl, name,
+		namespace, xmlDictLookup(ctxt->dict, str, -1), ret);
+	    FREE_AND_NULL(str)
+	    if (val != 0) {
+		xmlSchemaPCustomErr(ctxt,
+		    XML_SCHEMAP_INTERNAL,
+		    NULL, NULL, node,
+		    "Internal error: xmlSchemaAddElement, "
+		    "a dublicate element declaration with the name '%s' "
+		    "could not be added to the hash.", name);
+		xmlFree(ret);
+		return (NULL);
+	    }
+	    
+	}
     }
     if (ctxt->assemble != NULL)
 	xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); 
@@ -3657,7 +3694,7 @@
 	} else {
 	    char buf[30]; 
 
-	    snprintf(buf, 29, "#eCont %d", ctxt->counter++ + 1);
+	    snprintf(buf, 29, "#eCont%d", ctxt->counter++ + 1);
 	    val = xmlHashAddEntry3(schema->elemDecl, name, (xmlChar *) buf,
 		namespace, ret);
 	    if (val != 0) {
@@ -5017,7 +5054,7 @@
     if ((minOccurs == 0) && (maxOccurs == 0))
 	return (NULL);
 
-    snprintf((char *) name, 30, "any %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#any%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -5241,9 +5278,9 @@
 	    &refPrefix, &ref) != 0) {
 	    return (NULL);
 	}	
-        snprintf(buf, 49, "#aRef %d", ctxt->counter++ + 1);
+        snprintf(buf, 49, "#aRef%d", ctxt->counter++ + 1);
         name = (const xmlChar *) buf;	
-	ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL, node);
+	ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL, node, 0);
 	if (ret == NULL) {
 	    if (repName != NULL)
 		xmlFree(repName);
@@ -5342,8 +5379,8 @@
 		}
 	    } else if (schema->flags & XML_SCHEMAS_QUALIF_ATTR)
 		ns = schema->targetNamespace;		
-	}				
-	ret = xmlSchemaAddAttribute(ctxt, schema, name, ns, node);
+	}	
+        ret = xmlSchemaAddAttribute(ctxt, schema, name, ns, node, topLevel);
 	if (ret == NULL) {
 	    if (repName != NULL)
 		xmlFree(repName);
@@ -5572,7 +5609,7 @@
 	xmlSchemaPValAttrNodeQName(ctxt, schema,
 	    NULL, NULL, attr, &refNs, &refPrefix, &ref);
 	 
-        snprintf(buf, 49, "#aGrRef %d", ctxt->counter++ + 1);
+        snprintf(buf, 49, "#agRef%d", ctxt->counter++ + 1);
 	name = (const xmlChar *) buf;
 	if (name == NULL) {
 	    xmlSchemaPErrMemory(ctxt, "creating internal name for an "
@@ -5763,6 +5800,7 @@
     return (ret);
 }
 
+#ifdef IDC_ENABLED
 static int
 xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, 
 			     xmlSchemaPtr schema,
@@ -6126,6 +6164,7 @@
 
     return (item);
 }
+#endif
 
 /**
  * xmlSchemaParseElement:
@@ -6204,7 +6243,7 @@
 	    (xmlChar **) &xmlSchemaElemDesElemRef, 
 	    NULL, attr, &refNs, &refPrefix, &ref);			
 	 
-        snprintf(buf, 49, "#eRef %d", ctxt->counter++ + 1);
+        snprintf(buf, 49, "#eRef%d", ctxt->counter++ + 1);
 	ret = xmlSchemaAddElement(ctxt, schema, (const xmlChar *) buf, NULL, node, 0);
 	if (ret == NULL) {
 	    if (repName != NULL)
@@ -6511,6 +6550,8 @@
 	    else
 		(xmlSchemaIDCPtr) ret->idcs = curIDC;
 	    lastIDC = curIDC;
+#else
+	    TODO
 #endif
 	    child = child->next;
 	}
@@ -6560,7 +6601,7 @@
     if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
         return (NULL);
 
-    snprintf((char *) name, 30, "#union %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#union%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -6647,7 +6688,7 @@
     if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
         return (NULL);
 
-    snprintf((char *) name, 30, "#list %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#list%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -6756,7 +6797,7 @@
 	/*
 	* Parse as local simple type definition.
 	*/
-        snprintf(buf, 39, "#ST %d", ctxt->counter++ + 1);
+        snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1);
 	type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node);
 	if (type == NULL)
 	    return (NULL);
@@ -6924,7 +6965,7 @@
         }
 	if (refNs == NULL)
 	    refNs = schema->targetNamespace;
-        snprintf(buf, 49, "#GrRef %d", ctxt->counter++ + 1);
+        snprintf(buf, 49, "#grRef%d", ctxt->counter++ + 1);
         name = (const xmlChar *) buf;
     }
     type = xmlSchemaAddGroup(ctxt, schema, name, ns, node);
@@ -6996,7 +7037,7 @@
         return (NULL);
 
 
-    snprintf((char *) name, 30, "all%d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#all%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -8048,7 +8089,7 @@
         return (NULL);
 
 
-    snprintf((char *) name, 30, "choice %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#ch%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -8158,7 +8199,7 @@
         return (NULL);
 
     oldcontainer = ctxt->container;
-    snprintf((char *) name, 30, "#seq %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#seq%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -8267,7 +8308,7 @@
 
     oldcontainer = ctxt->container;
 
-    snprintf((char *) name, 30, "#restr %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#restr%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -8489,7 +8530,7 @@
 
     oldcontainer = ctxt->container;
 
-    snprintf((char *) name, 30, "extension %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#ext%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);    
     if (type == NULL)
         return (NULL);
@@ -8567,7 +8608,7 @@
     if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
         return (NULL);
 
-    snprintf((char *) name, 30, "simpleContent %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#SC%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);    
     if (type == NULL)
         return (NULL);
@@ -8626,7 +8667,7 @@
     if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
         return (NULL);
 
-    snprintf((char *) name, 30, "#CC %d", ctxt->counter++ + 1);
+    snprintf((char *) name, 30, "#CC%d", ctxt->counter++ + 1);
     type = xmlSchemaAddType(ctxt, schema, name, NULL, node);
     if (type == NULL)
         return (NULL);
@@ -8737,7 +8778,7 @@
 	/*
 	* Parse as local complex type definition.
 	*/
-        snprintf(buf, 39, "#CT %d", ctxt->counter++ + 1);
+        snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1);
 	type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node);
 	if (type == NULL)
 	    return (NULL);
@@ -13526,6 +13567,10 @@
 		if (item->subtypes != NULL)
 		    xmlSchemaTypeFixup(item->subtypes, ctxt, NULL);
                 break;
+	    case XML_SCHEMA_TYPE_IDC_UNIQUE:
+	    case XML_SCHEMA_TYPE_IDC_KEY:
+	    case XML_SCHEMA_TYPE_IDC_KEYREF:
+		break;
         }
     }
 #ifdef DEBUG_TYPE
@@ -14386,7 +14431,7 @@
 static void
 xmlSchemaResolveIDCKeyRef(xmlSchemaIDCPtr idc,
 			  xmlSchemaParserCtxtPtr ctxt, 
-			  const xmlChar * name)
+			  const xmlChar * name ATTRIBUTE_UNUSED)
 {  
     if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF)
         return;