mirror of
				https://gitlab.gnome.org/GNOME/libxml2.git
				synced 2025-10-30 10:45:36 +03:00 
			
		
		
		
	Added compression on saving, Daniel.
This commit is contained in:
		| @@ -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> | Mon Sep 21 20:11:13 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org> | ||||||
|  |  | ||||||
| 	* parser.c: corrected a loop for files of size 0 | 	* parser.c: corrected a loop for files of size 0 | ||||||
|   | |||||||
| @@ -122,8 +122,8 @@ typedef struct xmlSAXHandler { | |||||||
|  * Global variables: just the SAX interface tables we are looking for full |  * Global variables: just the SAX interface tables we are looking for full | ||||||
|  *      reentrancy of the code ! |  *      reentrancy of the code ! | ||||||
|  */ |  */ | ||||||
| xmlSAXLocator xmlDefaultSAXLocator; | extern xmlSAXLocator xmlDefaultSAXLocator; | ||||||
| xmlSAXHandler xmlDefaultSAXHandler; | extern xmlSAXHandler xmlDefaultSAXHandler; | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Interfaces |  * Interfaces | ||||||
|   | |||||||
| @@ -166,11 +166,15 @@ extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns); | |||||||
| extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, | extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, | ||||||
|                               const CHAR *name, CHAR *content); |                               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 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 | #ifdef __cplusplus | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								parser.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								parser.h
									
									
									
									
									
								
							| @@ -122,8 +122,8 @@ typedef struct xmlSAXHandler { | |||||||
|  * Global variables: just the SAX interface tables we are looking for full |  * Global variables: just the SAX interface tables we are looking for full | ||||||
|  *      reentrancy of the code ! |  *      reentrancy of the code ! | ||||||
|  */ |  */ | ||||||
| xmlSAXLocator xmlDefaultSAXLocator; | extern xmlSAXLocator xmlDefaultSAXLocator; | ||||||
| xmlSAXHandler xmlDefaultSAXHandler; | extern xmlSAXHandler xmlDefaultSAXHandler; | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Interfaces |  * Interfaces | ||||||
|   | |||||||
							
								
								
									
										63
									
								
								tree.c
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								tree.c
									
									
									
									
									
								
							| @@ -8,11 +8,16 @@ | |||||||
|  * TODO Cleanup the Dump mechanism. |  * TODO Cleanup the Dump mechanism. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | #include "config.h" | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| #include <malloc.h> | #include <malloc.h> | ||||||
| #include <string.h> /* for memset() only ! */ | #include <string.h> /* for memset() only ! */ | ||||||
|  |  | ||||||
|  | #ifdef HAVE_ZLIB_H | ||||||
|  | #include <zlib.h> | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #include "tree.h" | #include "tree.h" | ||||||
| #include "entities.h" | #include "entities.h" | ||||||
|  |  | ||||||
| @@ -1149,6 +1154,21 @@ void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) { | |||||||
|     *size = buffer_index; |     *size = buffer_index; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * 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 |  * Dump an XML document to the given FD | ||||||
|  */ |  */ | ||||||
| @@ -1164,6 +1184,49 @@ void xmlDocDump(FILE *f, xmlDocPtr cur) { | |||||||
|     fwrite(buffer, sizeof(CHAR), buffer_index, f); |     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					* |  *				Debug					* | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								tree.h
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								tree.h
									
									
									
									
									
								
							| @@ -166,11 +166,15 @@ extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns); | |||||||
| extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, | extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, | ||||||
|                               const CHAR *name, CHAR *content); |                               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 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 | #ifdef __cplusplus | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user