applied Justin Fletcher patch for --output or -o daniel

* xmllint.c: applied Justin Fletcher patch for --output or -o
daniel
diff --git a/ChangeLog b/ChangeLog
index 3d72797..0b86bf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Dec 18 12:13:33 CET 2001 Daniel Veillard <daniel@veillard.com>
+
+	* xmllint.c: applied Justin Fletcher patch for --output or -o
+
 Tue Dec 18 08:52:32 CET 2001 Daniel Veillard <daniel@veillard.com>
 
 	* win32/libxml2/libxml2.def.src: close #67019
diff --git a/xmllint.c b/xmllint.c
index f35187a..1d80b62 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -120,6 +120,8 @@
 static int catalogs = 0;
 static int nocatalogs = 0;
 #endif
+static const char *output = NULL;
+
 
 /*
  * Internal timing routines to remove the necessity to have unix-specific
@@ -809,26 +811,47 @@
 		}
 	    } else
 #endif /* HAVE_SYS_MMAN_H */
-	    if (compress)
-		xmlSaveFile("-", doc);
+	    if (compress) {
+		xmlSaveFile(output ? output : "-", doc);
+	    }
 	    else if (encoding != NULL) {
 	        if ( format ) {
-	            xmlSaveFormatFileEnc("-", doc, encoding, 1);
-		}  
+		    xmlSaveFormatFileEnc(output ? output : "-", doc, encoding, 1);
+		}
 		else {
-		    xmlSaveFileEnc("-", doc, encoding);
+		    xmlSaveFileEnc(output ? output : "-", doc, encoding);
 		}
 	    }
-	    else if (format)
-		xmlSaveFormatFile("-", doc, 1);
-	    else
-		xmlDocDump(stdout, doc);
+	    else if (format) {
+		xmlSaveFormatFile(output ? output : "-", doc, 1);
+	    }
+	    else {
+		FILE *out;
+		if (output == NULL)
+		    out = stdout;
+		else {
+		    out = fopen(output,"wb");
+		}
+		xmlDocDump(out, doc);
+
+		if (output)
+		    fclose(out);
+	    }
 	    if ((timing) && (!repeat)) {
 		endTimer("Saving");
 	    }
 #ifdef LIBXML_DEBUG_ENABLED
 	} else {
-	    xmlDebugDumpDocument(stdout, doc);
+	    FILE *out;
+	    if (output == NULL)
+	        out = stdout;
+	    else {
+		out = fopen(output,"wb");
+	    }
+	    xmlDebugDumpDocument(out, doc);
+
+	    if (output)
+		fclose(out);
 	}
 #endif
     }
@@ -929,9 +952,12 @@
     printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
     printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
     printf("\t--timing : print some timings\n");
+    printf("\t--output file or -o file: save to a given file\n");
     printf("\t--repeat : repeat 100 times, for timing or profiling\n");
     printf("\t--insert : ad-hoc test for valid insertions\n");
+#ifdef HAVE_ZLIB_H
     printf("\t--compress : turn on gzip compression of output\n");
+#endif
 #ifdef LIBXML_DOCB_ENABLED
     printf("\t--sgml : use the DocBook SGML parser\n");
 #endif
@@ -1001,6 +1027,12 @@
 	else if ((!strcmp(argv[i], "-noout")) ||
 	         (!strcmp(argv[i], "--noout")))
 	    noout++;
+	else if ((!strcmp(argv[i], "-o")) ||
+	         (!strcmp(argv[i], "-output")) ||
+	         (!strcmp(argv[i], "--output"))) {
+	    i++;
+	    output = argv[i++];
+	}
 	else if ((!strcmp(argv[i], "-htmlout")) ||
 	         (!strcmp(argv[i], "--htmlout")))
 	    htmlout++;
@@ -1070,11 +1102,13 @@
 	         (!strcmp(argv[i], "--xinclude")))
 	    xinclude++;
 #endif
+#ifdef HAVE_ZLIB_H
 	else if ((!strcmp(argv[i], "-compress")) ||
 	         (!strcmp(argv[i], "--compress"))) {
 	    compress++;
 	    xmlSetCompressMode(9);
         }
+#endif
 	else if ((!strcmp(argv[i], "-nowarning")) ||
 	         (!strcmp(argv[i], "--nowarning"))) {
 	    xmlGetWarningsDefaultValue = 0;
@@ -1165,6 +1199,11 @@
 	         (!strcmp(argv[i], "--encode"))) {
 	    i++;
 	    continue;
+        } else if ((!strcmp(argv[i], "-o")) ||
+                   (!strcmp(argv[i], "-output")) ||
+                   (!strcmp(argv[i], "--output"))) {
+            i++;
+	    continue;
         }
 	if ((!strcmp(argv[i], "-dtdvalid")) ||
 	         (!strcmp(argv[i], "--dtdvalid"))) {