Added compression on saving, Daniel.
diff --git a/ChangeLog b/ChangeLog
index 9557f5c..0d9292d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Sep 22 20:47:38 EDT 1998
+
+ * tree.c, tree.h: added saving with compression and added interfaces
+ to control the compression level (xmlGetCompressMode,
+ xmlSetCompressMode) and a new save to filename function (xmlSaveFile).
+
Mon Sep 21 20:11:13 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* parser.c: corrected a loop for files of size 0
diff --git a/include/libxml/parser.h b/include/libxml/parser.h
index a25e70a..46c5a19 100644
--- a/include/libxml/parser.h
+++ b/include/libxml/parser.h
@@ -122,8 +122,8 @@
* Global variables: just the SAX interface tables we are looking for full
* reentrancy of the code !
*/
-xmlSAXLocator xmlDefaultSAXLocator;
-xmlSAXHandler xmlDefaultSAXHandler;
+extern xmlSAXLocator xmlDefaultSAXLocator;
+extern xmlSAXHandler xmlDefaultSAXHandler;
/*
* Interfaces
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index 7a48a9b..0b27014 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -166,11 +166,15 @@
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
-extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
-extern void xmlDocDump(FILE *f, xmlDocPtr doc);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);
+extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
+extern void xmlDocDump(FILE *f, xmlDocPtr doc);
+int xmlSaveFile(const char *filename, xmlDocPtr cur);
+
+extern int xmlGetCompressMode(void);
+extern void xmlSetCompressMode(int mode);
#ifdef __cplusplus
}
diff --git a/parser.h b/parser.h
index a25e70a..46c5a19 100644
--- a/parser.h
+++ b/parser.h
@@ -122,8 +122,8 @@
* Global variables: just the SAX interface tables we are looking for full
* reentrancy of the code !
*/
-xmlSAXLocator xmlDefaultSAXLocator;
-xmlSAXHandler xmlDefaultSAXHandler;
+extern xmlSAXLocator xmlDefaultSAXLocator;
+extern xmlSAXHandler xmlDefaultSAXHandler;
/*
* Interfaces
diff --git a/tree.c b/tree.c
index 59d8454..c7eba5a 100644
--- a/tree.c
+++ b/tree.c
@@ -8,11 +8,16 @@
* TODO Cleanup the Dump mechanism.
*/
+#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h> /* for memset() only ! */
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#endif
+
#include "tree.h"
#include "entities.h"
@@ -1150,6 +1155,21 @@
}
/*
+ * Get the compression mode
+ */
+
+static int xmlCompressMode = 0;
+
+int xmlGetCompressMode(void) {
+ return(xmlCompressMode);
+}
+void xmlSetCompressMode(int mode) {
+ if (mode < 0) xmlCompressMode = 0;
+ if (mode > 9) xmlCompressMode = 9;
+ else xmlCompressMode = mode;
+}
+
+/*
* Dump an XML document to the given FD
*/
@@ -1164,6 +1184,49 @@
fwrite(buffer, sizeof(CHAR), buffer_index, f);
}
+/*
+ * Dump an XML document to a file.
+ */
+
+int xmlSaveFile(const char *filename, xmlDocPtr cur) {
+#ifdef HAVE_ZLIB_H
+ gzFile zoutput = NULL;
+ char mode[15];
+#endif
+ FILE *output;
+ int ret;
+
+#ifdef HAVE_ZLIB_H
+ if ((xmlCompressMode > 0) && (xmlCompressMode <= 9)) {
+ sprintf(mode, "w%d", xmlCompressMode);
+ zoutput = gzopen(filename, mode);
+ }
+ if (zoutput == NULL) {
+#endif
+ output = fopen(filename, "w");
+ if (output == NULL) return(-1);
+#ifdef HAVE_ZLIB_H
+ }
+#endif
+
+ /*
+ * save the content to a temp buffer.
+ */
+ buffer_index = 0;
+ xmlDocContentDump(cur);
+
+#ifdef HAVE_ZLIB_H
+ if (zoutput != NULL) {
+ ret = gzwrite(zoutput, buffer, sizeof(CHAR) * buffer_index);
+ gzclose(zoutput);
+ return(ret);
+ }
+#endif
+ ret = fwrite(buffer, sizeof(CHAR), buffer_index, output);
+ fclose(output);
+ return(ret * sizeof(CHAR));
+}
+
/************************************************************************
* *
* Debug *
diff --git a/tree.h b/tree.h
index 7a48a9b..0b27014 100644
--- a/tree.h
+++ b/tree.h
@@ -166,11 +166,15 @@
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
-extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
-extern void xmlDocDump(FILE *f, xmlDocPtr doc);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);
+extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
+extern void xmlDocDump(FILE *f, xmlDocPtr doc);
+int xmlSaveFile(const char *filename, xmlDocPtr cur);
+
+extern int xmlGetCompressMode(void);
+extern void xmlSetCompressMode(int mode);
#ifdef __cplusplus
}