summaryrefslogtreecommitdiffstats
path: root/src/io
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2013-03-13 21:22:43 +0000
committer~suv <suv-sf@users.sourceforge.net>2013-03-13 21:22:43 +0000
commit5fdab345ed60a124a25aa0efecd36b4307b72681 (patch)
tree9da8eae3a08679edbbb5994b6b2681a2c81b97f1 /src/io
parentPrevent crashing on windows systems due to locale issues (diff)
parentcppcheck (diff)
downloadinkscape-5fdab345ed60a124a25aa0efecd36b4307b72681.tar.gz
inkscape-5fdab345ed60a124a25aa0efecd36b4307b72681.zip
merge from trunk (r12201)
(bzr r11668.1.57)
Diffstat (limited to 'src/io')
-rw-r--r--src/io/CMakeLists.txt3
-rw-r--r--src/io/Makefile_insert2
-rw-r--r--src/io/bufferstream.cpp157
-rw-r--r--src/io/bufferstream.h109
-rw-r--r--src/io/gzipstream.cpp87
-rw-r--r--src/io/inkjar.cpp2
6 files changed, 314 insertions, 46 deletions
diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt
index c5606779e..34502d3db 100644
--- a/src/io/CMakeLists.txt
+++ b/src/io/CMakeLists.txt
@@ -1,6 +1,7 @@
set(io_SRC
base64stream.cpp
+ bufferstream.cpp
ftos.cpp
gzipstream.cpp
inkjar.cpp
@@ -12,10 +13,10 @@ set(io_SRC
uristream.cpp
xsltstream.cpp
-
# -------
# Headers
base64stream.h
+ bufferstream.h
ftos.h
gzipstream.h
inkjar.h
diff --git a/src/io/Makefile_insert b/src/io/Makefile_insert
index bb47b46b8..935c0cc07 100644
--- a/src/io/Makefile_insert
+++ b/src/io/Makefile_insert
@@ -3,6 +3,8 @@
ink_common_sources += \
io/base64stream.h \
io/base64stream.cpp \
+ io/bufferstream.cpp \
+ io/bufferstream.h \
io/ftos.cpp \
io/ftos.h \
io/gzipstream.cpp \
diff --git a/src/io/bufferstream.cpp b/src/io/bufferstream.cpp
new file mode 100644
index 000000000..ba440254f
--- /dev/null
+++ b/src/io/bufferstream.cpp
@@ -0,0 +1,157 @@
+/*
+ * Phoebe DOM Implementation.
+ *
+ * This is a C++ approximation of the W3C DOM model, which follows
+ * fairly closely the specifications in the various .idl files, copies of
+ * which are provided for reference. Most important is this one:
+ *
+ * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2006 Bob Jamison
+ *
+ * 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
+ */
+
+/**
+ * This class provided buffered endpoints for input and output.
+ */
+
+#include "bufferstream.h"
+
+namespace Inkscape
+{
+namespace IO
+{
+
+//#########################################################################
+//# B U F F E R I N P U T S T R E A M
+//#########################################################################
+/**
+ *
+ */
+BufferInputStream::BufferInputStream(
+ const std::vector<unsigned char> &sourceBuffer)
+ : buffer(sourceBuffer)
+{
+ position = 0;
+ closed = false;
+}
+
+/**
+ *
+ */
+BufferInputStream::~BufferInputStream()
+{
+
+}
+
+/**
+ * Returns the number of bytes that can be read (or skipped over) from
+ * this input stream without blocking by the next caller of a method for
+ * this input stream.
+ */
+int BufferInputStream::available()
+{
+ if (closed)
+ return -1;
+ return buffer.size() - position;
+}
+
+
+/**
+ * Closes this input stream and releases any system resources
+ * associated with the stream.
+ */
+void BufferInputStream::close()
+{
+ closed = true;
+}
+
+/**
+ * Reads the next byte of data from the input stream. -1 if EOF
+ */
+int BufferInputStream::get()
+{
+ if (closed)
+ return -1;
+ if (position >= (int)buffer.size())
+ return -1;
+ int ch = (int) buffer[position++];
+ return ch;
+}
+
+
+
+
+//#########################################################################
+//# B U F F E R O U T P U T S T R E A M
+//#########################################################################
+
+/**
+ *
+ */
+BufferOutputStream::BufferOutputStream()
+{
+ closed = false;
+}
+
+/**
+ *
+ */
+BufferOutputStream::~BufferOutputStream()
+{
+}
+
+/**
+ * Closes this output stream and releases any system resources
+ * associated with this stream.
+ */
+void BufferOutputStream::close()
+{
+ closed = true;
+}
+
+/**
+ * Flushes this output stream and forces any buffered output
+ * bytes to be written out.
+ */
+void BufferOutputStream::flush()
+{
+ //nothing to do
+}
+
+/**
+ * Writes the specified byte to this output stream.
+ */
+int BufferOutputStream::put(gunichar ch)
+{
+ if (closed)
+ return -1;
+ buffer.push_back(ch);
+ return 1;
+}
+
+
+
+
+} //namespace IO
+} //namespace Inkscape
+
+//#########################################################################
+//# E N D O F F I L E
+//#########################################################################
diff --git a/src/io/bufferstream.h b/src/io/bufferstream.h
new file mode 100644
index 000000000..af5580efb
--- /dev/null
+++ b/src/io/bufferstream.h
@@ -0,0 +1,109 @@
+#ifndef SEEN_BUFFERSTREAM_H
+#define SEEN_BUFFERSTREAM_H
+/**
+ * @file
+ * Phoebe DOM Implementation.
+ *
+ * This is a C++ approximation of the W3C DOM model, which follows
+ * fairly closely the specifications in the various .idl files, copies of
+ * which are provided for reference. Most important is this one:
+ *
+ * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
+ */
+/*
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2006 Bob Jamison
+ *
+ * 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 <vector>
+#include "inkscapestream.h"
+
+
+namespace Inkscape
+{
+namespace IO
+{
+
+//#########################################################################
+//# S T R I N G I N P U T S T R E A M
+//#########################################################################
+
+/**
+ * This class is for reading character from a DOMString
+ *
+ */
+class BufferInputStream : public InputStream
+{
+
+public:
+
+ BufferInputStream(const std::vector<unsigned char> &sourceBuffer);
+ virtual ~BufferInputStream();
+ virtual int available();
+ virtual void close();
+ virtual int get();
+
+private:
+ const std::vector<unsigned char> &buffer;
+ long position;
+ bool closed;
+
+}; // class BufferInputStream
+
+
+
+
+//#########################################################################
+//# B U F F E R O U T P U T S T R E A M
+//#########################################################################
+
+/**
+ * This class is for sending a stream to a character buffer
+ *
+ */
+class BufferOutputStream : public OutputStream
+{
+
+public:
+
+ BufferOutputStream();
+ virtual ~BufferOutputStream();
+ virtual void close();
+ virtual void flush();
+ virtual int put(gunichar ch);
+ virtual std::vector<unsigned char> &getBuffer()
+ { return buffer; }
+
+ virtual void clear()
+ { buffer.clear(); }
+
+private:
+ std::vector<unsigned char> buffer;
+ bool closed;
+
+}; // class BufferOutputStream
+
+
+
+} //namespace IO
+} //namespace Inkscape
+
+
+
+#endif // SEEN_BUFFERSTREAM_H
diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp
index 8db7155db..380c42411 100644
--- a/src/io/gzipstream.cpp
+++ b/src/io/gzipstream.cpp
@@ -71,11 +71,11 @@ GzipInputStream::~GzipInputStream()
{
close();
if ( srcBuf ) {
- free(srcBuf);
+ delete[] srcBuf;
srcBuf = NULL;
}
if ( outputBuf ) {
- free(outputBuf);
+ delete[] outputBuf;
outputBuf = NULL;
}
}
@@ -108,11 +108,11 @@ void GzipInputStream::close()
}
if ( srcBuf ) {
- free(srcBuf);
+ delete[] srcBuf;
srcBuf = NULL;
}
if ( outputBuf ) {
- free(outputBuf);
+ delete[] outputBuf;
outputBuf = NULL;
}
closed = true;
@@ -161,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();
@@ -171,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
@@ -187,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;
@@ -272,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 ) {
@@ -359,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;
}
@@ -380,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;
}
@@ -403,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");
@@ -421,11 +423,8 @@ void GzipOutputStream::flush()
destination.flush();
inputBuf.clear();
- free(srcbuf);
- free(destbuf);
-
- //printf("done\n");
-
+ delete[] srcbuf;
+ delete[] destbuf;
}
diff --git a/src/io/inkjar.cpp b/src/io/inkjar.cpp
index 20b164b99..4af140737 100644
--- a/src/io/inkjar.cpp
+++ b/src/io/inkjar.cpp
@@ -311,7 +311,7 @@ guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc,
in_a -= nbytes;
#ifdef DEBUG
- std::printf("%d bytes written\n", out_a);
+ std::printf("%u bytes written\n", out_a);
#endif
}
lseek(fd, eflen, SEEK_CUR);