diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
| commit | a168040d5a452544328a1e6ad35aaac351f94d44 (patch) | |
| tree | fae1ba829f543a473da281bd5fa6e4deabbf6912 /src/io/gzipstream.cpp | |
| parent | Removed function pointers from SPObject and subclasses. (diff) | |
| parent | Dutch translation update (diff) | |
| download | inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip | |
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/io/gzipstream.cpp')
| -rw-r--r-- | src/io/gzipstream.cpp | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index cbe29a41e..380c42411 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -8,13 +8,27 @@ * Authors: * Bob Jamison <rjamison@titan.com> * - * Copyright (C) 2004 Inkscape.org + * Copyright (C) 2004 * - * Released under GNU GPL, read the file 'COPYING' for more information + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "gzipstream.h" #include <cstdio> +#include <cstdlib> #include <cstring> #include <string> @@ -57,11 +71,11 @@ GzipInputStream::~GzipInputStream() { close(); if ( srcBuf ) { - free(srcBuf); + delete[] srcBuf; srcBuf = NULL; } if ( outputBuf ) { - free(outputBuf); + delete[] outputBuf; outputBuf = NULL; } } @@ -94,11 +108,11 @@ void GzipInputStream::close() } if ( srcBuf ) { - free(srcBuf); + delete[] srcBuf; srcBuf = NULL; } if ( outputBuf ) { - free(outputBuf); + delete[] outputBuf; outputBuf = NULL; } closed = true; @@ -147,7 +161,7 @@ bool GzipInputStream::load() int ch = source.get(); if (ch<0) break; - inputBuf.push_back((Byte)(ch & 0xff)); + inputBuf.push_back(static_cast<Byte>(ch & 0xff)); } long inputBufLen = inputBuf.size(); @@ -157,15 +171,15 @@ bool GzipInputStream::load() } srcLen = inputBuf.size(); - srcBuf = (Bytef *)malloc(srcLen * sizeof(Byte)); + srcBuf = new Byte [srcLen]; if (!srcBuf) { return false; } - outputBuf = (unsigned char *)malloc(OUT_SIZE); + outputBuf = new unsigned char [OUT_SIZE]; if ( !outputBuf ) { - free(srcBuf); - srcBuf = 0; + delete[] srcBuf; + srcBuf = NULL; return false; } outputBufLen = 0; // Not filled in yet @@ -173,33 +187,35 @@ bool GzipInputStream::load() std::vector<unsigned char>::iterator iter; Bytef *p = srcBuf; for (iter=inputBuf.begin() ; iter != inputBuf.end() ; ++iter) + { *p++ = *iter; + } int headerLen = 10; //Magic - int val = (int)srcBuf[0]; - //printf("val:%x\n", val); - val = (int)srcBuf[1]; - //printf("val:%x\n", val); + //int val = (int)srcBuf[0]; + ////printf("val:%x\n", val); + //val = (int)srcBuf[1]; + ////printf("val:%x\n", val); - //Method - val = (int)srcBuf[2]; - //printf("val:%x\n", val); + ////Method + //val = (int)srcBuf[2]; + ////printf("val:%x\n", val); //flags - int flags = (int)srcBuf[3]; + int flags = static_cast<int>(srcBuf[3]); - //time - val = (int)srcBuf[4]; - val = (int)srcBuf[5]; - val = (int)srcBuf[6]; - val = (int)srcBuf[7]; + ////time + //val = (int)srcBuf[4]; + //val = (int)srcBuf[5]; + //val = (int)srcBuf[6]; + //val = (int)srcBuf[7]; - //xflags - val = (int)srcBuf[8]; - //OS - val = (int)srcBuf[9]; + ////xflags + //val = (int)srcBuf[8]; + ////OS + //val = (int)srcBuf[9]; // if ( flags & FEXTRA ) { // headerLen += 2; @@ -258,19 +274,17 @@ bool GzipInputStream::load() int GzipInputStream::fetchMore() { - int zerr = Z_OK; - // TODO assumes we aren't called till the buffer is empty d_stream.next_out = outputBuf; d_stream.avail_out = OUT_SIZE; outputBufLen = 0; outputBufPos = 0; - zerr = inflate( &d_stream, Z_SYNC_FLUSH ); + int zerr = inflate( &d_stream, Z_SYNC_FLUSH ); if ( zerr == Z_OK || zerr == Z_STREAM_END ) { outputBufLen = OUT_SIZE - d_stream.avail_out; if ( outputBufLen ) { - crc = crc32(crc, (const Bytef *)outputBuf, outputBufLen); + crc = crc32(crc, const_cast<const Bytef *>(outputBuf), outputBufLen); } //printf("crc:%lx\n", crc); // } else if ( zerr != Z_STREAM_END ) { @@ -345,14 +359,14 @@ void GzipOutputStream::close() uLong outlong = crc; for (int n = 0; n < 4; n++) { - destination.put((int)(outlong & 0xff)); + destination.put(static_cast<gunichar>(outlong & 0xff)); outlong >>= 8; } //# send the file length outlong = totalIn & 0xffffffffL; for (int n = 0; n < 4; n++) { - destination.put((int)(outlong & 0xff)); + destination.put(static_cast<gunichar>(outlong & 0xff)); outlong >>= 8; } @@ -366,21 +380,23 @@ void GzipOutputStream::close() */ void GzipOutputStream::flush() { - if (closed || inputBuf.size()<1) + if (closed || inputBuf.empty()) + { return; - + } + uLong srclen = inputBuf.size(); - Bytef *srcbuf = (Bytef *)malloc(srclen * sizeof(Byte)); + Bytef *srcbuf = new Bytef [srclen]; if (!srcbuf) { return; } uLong destlen = srclen; - Bytef *destbuf = (Bytef *)malloc((destlen + (srclen/100) + 13) * sizeof(Byte)); + Bytef *destbuf = new Bytef [(destlen + (srclen/100) + 13)]; if (!destbuf) { - free(srcbuf); + delete[] srcbuf; return; } @@ -389,9 +405,9 @@ void GzipOutputStream::flush() for (iter=inputBuf.begin() ; iter != inputBuf.end() ; ++iter) *p++ = *iter; - crc = crc32(crc, (const Bytef *)srcbuf, srclen); + crc = crc32(crc, const_cast<const Bytef *>(srcbuf), srclen); - int zerr = compress(destbuf, (uLongf *)&destlen, srcbuf, srclen); + int zerr = compress(destbuf, static_cast<uLongf *>(&destlen), srcbuf, srclen); if (zerr != Z_OK) { printf("Some kind of problem\n"); @@ -407,11 +423,8 @@ void GzipOutputStream::flush() destination.flush(); inputBuf.clear(); - free(srcbuf); - free(destbuf); - - //printf("done\n"); - + delete[] srcbuf; + delete[] destbuf; } @@ -419,19 +432,19 @@ void GzipOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void GzipOutputStream::put(int ch) +int GzipOutputStream::put(gunichar ch) { if (closed) { //probably throw an exception here - return; + return -1; } //Add char to buffer inputBuf.push_back(ch); totalIn++; - + return 1; } |
