Implemented detection of compressed files, setting doc->compressed

* xmlIO.c include/libxml/xmlIO.h parser.c: Implemented detection
  of compressed files, setting doc->compressed appropriately
  (bug #120503).
diff --git a/ChangeLog b/ChangeLog
index 3a23da9..20c0dd1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Sep  7 19:58:33 PTD 2003 William Brack <wbrack@mmm.com.hk>
+
+	* xmlIO.c include/libxml/xmlIO.h parser.c: Implemented detection
+	  of compressed files, setting doc->compressed appropriately
+	  (bug #120503).
+
 Sun Sep  7 22:53:06 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
 	* parser.c: try to cope with the fact that apps may still
diff --git a/include/libxml/xmlIO.h b/include/libxml/xmlIO.h
index 419f812..9d182a6 100644
--- a/include/libxml/xmlIO.h
+++ b/include/libxml/xmlIO.h
@@ -129,6 +129,7 @@
     
     xmlBufferPtr buffer;    /* Local buffer encoded in UTF-8 */
     xmlBufferPtr raw;       /* if encoder != NULL buffer for raw input */
+    int	compressed;	    /* -1=unknown, 0=not compressed, 1=compressed */
 };
 
 
diff --git a/parser.c b/parser.c
index b5ae4a8..830a29a 100644
--- a/parser.c
+++ b/parser.c
@@ -2923,7 +2923,7 @@
 	    SHRINK;
 	    GROW;
 	    in = ctxt->input->cur;
-	} while ((*in >= 0x20) && (*in <= 0x7F) || (*in == 0x09));
+	} while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09));
 	nbchar = 0;
     }
     ctxt->input->line = line;
@@ -11345,7 +11345,13 @@
 
     xmlParseDocument(ctxt);
 
-    if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
+    if ((ctxt->wellFormed) || recovery) {
+        ret = ctxt->myDoc;
+	if (ctxt->input->buf->compressed > 0)
+	    ret->compression = 9;
+	else
+	    ret->compression = ctxt->input->buf->compressed;
+    }
     else {
        ret = NULL;
        xmlFreeDoc(ctxt->myDoc);
diff --git a/xmlIO.c b/xmlIO.c
index d100948..df7d975 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -1588,6 +1588,7 @@
     ret->readcallback = NULL;
     ret->closecallback = NULL;
     ret->context = NULL;
+    ret->compressed = -1;
 
     return(ret);
 }
@@ -1699,13 +1700,6 @@
 }
 
 /**
- * xmlParserInputBufferCreateFname:
- * @URI:  a C string containing the URI or filename
- * @enc:  the charset encoding if known
- *
- * Returns the new parser input or NULL
- */
-/**
  * xmlParserInputBufferCreateFilename:
  * @URI:  a C string containing the URI or filename
  * @enc:  the charset encoding if known
@@ -1729,9 +1723,6 @@
 
     if (URI == NULL) return(NULL);
 
-#ifdef LIBXML_CATALOG_ENABLED
-#endif
-
     /*
      * Try to find one of the input accept method accepting that scheme
      * Go in reverse to give precedence to user defined handlers.
@@ -1758,6 +1749,21 @@
 	ret->context = context;
 	ret->readcallback = xmlInputCallbackTable[i].readcallback;
 	ret->closecallback = xmlInputCallbackTable[i].closecallback;
+#ifdef HAVE_ZLIB_H
+	if (xmlInputCallbackTable[i].opencallback == xmlGzfileOpen) {
+	    if (((z_stream *)context)->avail_in > 4) {
+	        char *cptr, buff4[4];
+		cptr = ((z_stream *)context)->next_in;
+		if (gzread(context, buff4, 4) == 4) {
+		    if (strncmp(buff4, cptr, 4) == 0)
+		        ret->compressed = 0;
+		    else
+		        ret->compressed = 1;
+		    gzrewind(context);
+		}
+	    }
+	}
+#endif
     }
     return(ret);
 }