aboutsummaryrefslogtreecommitdiff
path: root/dep/src
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:35:07 -0700
committermaximius <none@none>2009-10-17 15:35:07 -0700
commit26b5e033ffde3d161382fc9addbfa99738379641 (patch)
treea344f369ca32945f787a02dee35c3dbe342bed7e /dep/src
parentf21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff)
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
Diffstat (limited to 'dep/src')
-rw-r--r--dep/src/g3dlite/AABox.cpp58
-rw-r--r--dep/src/g3dlite/Box.cpp83
-rw-r--r--dep/src/g3dlite/Crypto.cpp17
-rw-r--r--dep/src/g3dlite/Matrix3.cpp295
-rw-r--r--dep/src/g3dlite/Plane.cpp23
-rw-r--r--dep/src/g3dlite/System.cpp135
-rw-r--r--dep/src/g3dlite/Triangle.cpp28
-rw-r--r--dep/src/g3dlite/Vector3.cpp75
-rw-r--r--dep/src/g3dlite/Vector4.cpp22
-rw-r--r--dep/src/g3dlite/format.cpp46
-rw-r--r--dep/src/sockets/Base64.cpp23
-rw-r--r--dep/src/sockets/Exception.cpp9
-rw-r--r--dep/src/sockets/Ipv4Address.cpp27
-rw-r--r--dep/src/sockets/Ipv6Address.cpp30
-rw-r--r--dep/src/sockets/Lock.cpp11
-rw-r--r--dep/src/sockets/Mutex.cpp12
-rw-r--r--dep/src/sockets/Parse.cpp36
-rw-r--r--dep/src/sockets/ResolvServer.cpp16
-rw-r--r--dep/src/sockets/ResolvSocket.cpp21
-rw-r--r--dep/src/sockets/Socket.cpp186
-rw-r--r--dep/src/sockets/SocketHandler.cpp59
-rw-r--r--dep/src/sockets/StdoutLog.cpp14
-rw-r--r--dep/src/sockets/StreamSocket.cpp26
-rw-r--r--dep/src/sockets/TcpSocket.cpp91
-rw-r--r--dep/src/sockets/Thread.cpp21
-rw-r--r--dep/src/sockets/UdpSocket.cpp59
-rw-r--r--dep/src/sockets/Utility.cpp50
-rw-r--r--dep/src/sockets/socket_include.cpp9
-rw-r--r--dep/src/zlib/adler32.c15
-rw-r--r--dep/src/zlib/compress.c11
-rw-r--r--dep/src/zlib/crc32.c56
-rw-r--r--dep/src/zlib/crc32.h1
-rw-r--r--dep/src/zlib/deflate.c186
-rw-r--r--dep/src/zlib/deflate.h59
-rw-r--r--dep/src/zlib/example.c98
-rw-r--r--dep/src/zlib/gzio.c124
-rw-r--r--dep/src/zlib/infback.c50
-rw-r--r--dep/src/zlib/inffast.c17
-rw-r--r--dep/src/zlib/inffast.h2
-rw-r--r--dep/src/zlib/inffixed.h3
-rw-r--r--dep/src/zlib/inflate.c81
-rw-r--r--dep/src/zlib/inflate.h7
-rw-r--r--dep/src/zlib/inftrees.c34
-rw-r--r--dep/src/zlib/inftrees.h6
-rw-r--r--dep/src/zlib/trees.c149
-rw-r--r--dep/src/zlib/trees.h7
-rw-r--r--dep/src/zlib/uncompr.c10
-rw-r--r--dep/src/zlib/zconf.h29
-rw-r--r--dep/src/zlib/zlib.h206
-rw-r--r--dep/src/zlib/zutil.c43
-rw-r--r--dep/src/zlib/zutil.h38
51 files changed, 2 insertions, 2712 deletions
diff --git a/dep/src/g3dlite/AABox.cpp b/dep/src/g3dlite/AABox.cpp
index f2f2b70535c..dd4f79394f7 100644
--- a/dep/src/g3dlite/AABox.cpp
+++ b/dep/src/g3dlite/AABox.cpp
@@ -1,61 +1,47 @@
/**
@file AABox.cpp
-
@maintainer Morgan McGuire, matrix@graphics3d.com
-
@created 2004-01-10
@edited 2006-01-11
*/
-
#include "G3D/platform.h"
# if defined(_MSC_VER) && (_MSC_VER <= 1200)
// VC6 std:: has signed/unsigned problems
# pragma warning (disable : 4018)
# endif
-
#include <assert.h>
#include "G3D/AABox.h"
#include "G3D/Box.h"
#include "G3D/Plane.h"
#include "G3D/Sphere.h"
-
namespace G3D {
-
Box AABox::toBox() const {
return Box(lo, hi);
}
-
-
void AABox::split(const Vector3::Axis& axis, float location, AABox& low, AABox& high) const {
// Low, medium, and high along the chosen axis
float L = G3D::min(location, lo[axis]);
float M = G3D::min(G3D::max(location, lo[axis]), hi[axis]);
float H = G3D::max(location, hi[axis]);
-
// Copy over this box.
high = low = *this;
-
// Now move the split points along the special axis
low.lo[axis] = L;
low.hi[axis] = M;
high.lo[axis] = M;
high.hi[axis] = H;
}
-
#if 0
Vector3 AABox::randomSurfacePoint() const {
Vector3 extent = hi - lo;
float aXY = extent.x * extent.y;
float aYZ = extent.y * extent.z;
float aZX = extent.z * extent.x;
-
float r = (float)random(0, aXY + aYZ + aZX);
-
// Choose evenly between positive and negative face planes
float d = ((float)random(0, 1) < 0.5f) ? 0.0f : 1.0f;
-
// The probability of choosing a given face is proportional to
// its area.
if (r < aXY) {
@@ -82,7 +68,6 @@ Vector3 AABox::randomSurfacePoint() const {
}
}
-
Vector3 AABox::randomInteriorPoint() const {
return Vector3(
(float)random(lo.x, hi.x),
@@ -91,60 +76,46 @@ Vector3 AABox::randomInteriorPoint() const {
}
#endif
-
bool AABox::intersects(const AABox& other) const {
// Must be overlap along all three axes.
// Try to find a separating axis.
-
for (int a = 0; a < 3; ++a) {
-
// |--------|
// |------|
-
if ((lo[a] > other.hi[a]) ||
(hi[a] < other.lo[a])) {
return false;
}
}
-
return true;
}
-
bool AABox::culledBy(
const Array<Plane>& plane,
int& cullingPlaneIndex,
const uint32 inMask,
uint32& outMask) const {
-
return culledBy(plane.getCArray(), plane.size(), cullingPlaneIndex, inMask, outMask);
}
-
bool AABox::culledBy(
const Array<Plane>& plane,
int& cullingPlaneIndex,
const uint32 inMask) const {
-
return culledBy(plane.getCArray(), plane.size(), cullingPlaneIndex, inMask);
}
-
int AABox::dummy = 0;
-
bool AABox::culledBy(
const class Plane* plane,
int numPlanes,
int& cullingPlane,
const uint32 _inMask,
uint32& childMask) const {
-
uint32 inMask = _inMask;
assert(numPlanes < 31);
-
childMask = 0;
-
const bool finite =
(abs(lo.x) < G3D::inf()) &&
(abs(hi.x) < G3D::inf()) &&
@@ -152,19 +123,14 @@ bool AABox::culledBy(
(abs(hi.y) < G3D::inf()) &&
(abs(lo.z) < G3D::inf()) &&
(abs(hi.z) < G3D::inf());
-
// See if there is one plane for which all of the
// vertices are in the negative half space.
for (int p = 0; p < numPlanes; p++) {
-
// Only test planes that are not masked
if ((inMask & 1) != 0) {
-
Vector3 corner;
-
int numContained = 0;
int v = 0;
-
// We can early-out only if we have found one point on each
// side of the plane (i.e. if we are straddling). That
// occurs when (numContained < v) && (numContained > 0)
@@ -174,7 +140,6 @@ bool AABox::culledBy(
corner.x = (v & 1) ? hi.x : lo.x;
corner.y = (v & 2) ? hi.y : lo.y;
corner.z = (v & 4) ? hi.z : lo.z;
-
if (finite) { // this branch is highly predictable
if (plane[p].halfSpaceContainsFinite(corner)) {
++numContained;
@@ -185,44 +150,36 @@ bool AABox::culledBy(
}
}
}
-
if (numContained == 0) {
// Plane p culled the box
cullingPlane = p;
-
// The caller should not recurse into the children,
// since the parent is culled. If they do recurse,
// make them only test against this one plane, which
// will immediately cull the volume.
childMask = 1 << p;
return true;
-
} else if (numContained < v) {
// The bounding volume straddled the plane; we have
// to keep testing against this plane
childMask |= (1 << p);
}
}
-
// Move on to the next bit.
inMask = inMask >> 1;
}
-
// None of the planes could cull this box
cullingPlane = -1;
return false;
}
-
bool AABox::culledBy(
const class Plane* plane,
int numPlanes,
int& cullingPlane,
const uint32 _inMask) const {
-
uint32 inMask = _inMask;
assert(numPlanes < 31);
-
const bool finite =
(abs(lo.x) < G3D::inf()) &&
(abs(hi.x) < G3D::inf()) &&
@@ -230,58 +187,45 @@ bool AABox::culledBy(
(abs(hi.y) < G3D::inf()) &&
(abs(lo.z) < G3D::inf()) &&
(abs(hi.z) < G3D::inf());
-
// See if there is one plane for which all of the
// vertices are in the negative half space.
for (int p = 0; p < numPlanes; p++) {
-
// Only test planes that are not masked
if ((inMask & 1) != 0) {
-
bool culled = true;
Vector3 corner;
-
int v;
-
// Assume this plane culls all points. See if there is a point
// not culled by the plane... early out when at least one point
// is in the positive half space.
for (v = 0; (v < 8) && culled; ++v) {
-
// Unrolling these 3 if's into a switch decreases performance
// by about 2x
corner.x = (v & 1) ? hi.x : lo.x;
corner.y = (v & 2) ? hi.y : lo.y;
corner.z = (v & 4) ? hi.z : lo.z;
-
if (finite) { // this branch is highly predictable
culled = ! plane[p].halfSpaceContainsFinite(corner);
} else {
culled = ! plane[p].halfSpaceContains(corner);
}
}
-
if (culled) {
// Plane p culled the box
cullingPlane = p;
-
return true;
}
}
-
// Move on to the next bit.
inMask = inMask >> 1;
}
-
// None of the planes could cull this box
cullingPlane = -1;
return false;
}
-
bool AABox::intersects(const class Sphere& sphere) const {
double d = 0;
-
//find the square of the distance
//from the sphere to the box
for (int i = 0; i < 3; ++i) {
@@ -291,10 +235,8 @@ bool AABox::intersects(const class Sphere& sphere) const {
d += square(sphere.center[i] - hi[i]);
}
}
-
return d <= square(sphere.radius);
}
-
} // namespace
diff --git a/dep/src/g3dlite/Box.cpp b/dep/src/g3dlite/Box.cpp
index fd3067048c0..76aea3293fa 100644
--- a/dep/src/g3dlite/Box.cpp
+++ b/dep/src/g3dlite/Box.cpp
@@ -1,21 +1,16 @@
/**
@file Box.cpp
Box class
-
@maintainer Morgan McGuire, matrix@graphics3d.com
-
@created 2001-06-02
@edited 2006-02-05
*/
-
#include "G3D/Box.h"
#include "G3D/debug.h"
#include "G3D/Plane.h"
#include "G3D/AABox.h"
#include "G3D/CoordinateFrame.h"
-
namespace G3D {
-
/**
Sets a field on four vertices. Used by the constructor.
*/
@@ -23,158 +18,119 @@ namespace G3D {
_corner[i0].field = _corner[i1].field = \
_corner[i2].field = _corner[i3].field = \
(extreme).field
-
Box::Box() {
}
-
Box::Box(const AABox& b) {
init(b.low(), b.high());
}
-
Box::Box(
const Vector3& min,
const Vector3& max) {
-
init(min.min(max), min.max(max));
-
}
-
void Box::init(
const Vector3& min,
const Vector3& max) {
-
setMany(0, 1, 2, 3, z, max);
setMany(4, 5, 6, 7, z, min);
-
setMany(1, 2, 5, 6, x, max);
setMany(0, 3, 4, 7, x, min);
-
setMany(3, 2, 6, 7, y, max);
setMany(0, 1, 5, 4, y, min);
-
_extent = max - min;
-
_axis[0] = Vector3::unitX();
_axis[1] = Vector3::unitY();
_axis[2] = Vector3::unitZ();
-
_volume = _extent.x * _extent.y * _extent.z;
- _area = 2 *
+ _area = 2 *
(_extent.x * _extent.y +
_extent.y * _extent.z +
_extent.z * _extent.x);
-
_center = (max + min) / 2;
}
-
float Box::volume() const {
return _volume;
}
-
float Box::surfaceArea() const {
return _area;
}
-
void Box::getLocalFrame(CoordinateFrame& frame) const {
-
frame.rotation = Matrix3(
_axis[0][0], _axis[1][0], _axis[2][0],
_axis[0][1], _axis[1][1], _axis[2][1],
_axis[0][2], _axis[1][2], _axis[2][2]);
-
frame.translation = _center;
}
-
CoordinateFrame Box::localFrame() const {
CoordinateFrame out;
getLocalFrame(out);
return out;
}
-
void Box::getFaceCorners(int f, Vector3& v0, Vector3& v1, Vector3& v2, Vector3& v3) const {
switch (f) {
case 0:
v0 = _corner[0]; v1 = _corner[1]; v2 = _corner[2]; v3 = _corner[3];
break;
-
case 1:
v0 = _corner[1]; v1 = _corner[5]; v2 = _corner[6]; v3 = _corner[2];
break;
-
case 2:
v0 = _corner[7]; v1 = _corner[6]; v2 = _corner[5]; v3 = _corner[4];
break;
-
case 3:
v0 = _corner[2]; v1 = _corner[6]; v2 = _corner[7]; v3 = _corner[3];
break;
-
case 4:
v0 = _corner[3]; v1 = _corner[7]; v2 = _corner[4]; v3 = _corner[0];
break;
-
case 5:
v0 = _corner[1]; v1 = _corner[0]; v2 = _corner[4]; v3 = _corner[5];
break;
-
default:
debugAssert((f >= 0) && (f < 6));
}
}
-
bool Box::culledBy(
const Array<Plane>& plane,
int& cullingPlaneIndex,
const uint32 inMask,
uint32& outMask) const {
-
return culledBy(plane.getCArray(), plane.size(), cullingPlaneIndex, inMask, outMask);
}
-
bool Box::culledBy(
const Array<Plane>& plane,
int& cullingPlaneIndex,
const uint32 inMask) const {
-
return culledBy(plane.getCArray(), plane.size(), cullingPlaneIndex, inMask);
}
-
int32 Box::dummy = 0;
-
bool Box::culledBy(
const class Plane* plane,
int numPlanes,
int& cullingPlane,
const uint32 _inMask,
uint32& childMask) const {
-
uint32 inMask = _inMask;
assert(numPlanes < 31);
-
childMask = 0;
-
// See if there is one plane for which all of the
// vertices are in the negative half space.
for (int p = 0; p < numPlanes; p++) {
-
// Only test planes that are not masked
if ((inMask & 1) != 0) {
-
Vector3 corner;
-
int numContained = 0;
int v = 0;
-
// We can early-out only if we have found one point on each
// side of the plane (i.e. if we are straddling). That
// occurs when (numContained < v) && (numContained > 0)
@@ -183,120 +139,93 @@ bool Box::culledBy(
++numContained;
}
}
-
if (numContained == 0) {
// Plane p culled the box
cullingPlane = p;
-
// The caller should not recurse into the children,
// since the parent is culled. If they do recurse,
// make them only test against this one plane, which
// will immediately cull the volume.
childMask = 1 << p;
return true;
-
} else if (numContained < v) {
// The bounding volume straddled the plane; we have
// to keep testing against this plane
childMask |= (1 << p);
}
}
-
// Move on to the next bit.
inMask = inMask >> 1;
}
-
// None of the planes could cull this box
cullingPlane = -1;
return false;
}
-
bool Box::culledBy(
const class Plane* plane,
int numPlanes,
int& cullingPlane,
const uint32 _inMask) const {
-
uint32 inMask = _inMask;
assert(numPlanes < 31);
-
// See if there is one plane for which all of the
// vertices are in the negative half space.
for (int p = 0; p < numPlanes; p++) {
-
// Only test planes that are not masked
if ((inMask & 1) != 0) {
-
bool culled = true;
-
int v;
-
// Assume this plane culls all points. See if there is a point
// not culled by the plane... early out when at least one point
// is in the positive half space.
for (v = 0; (v < 8) && culled; ++v) {
culled = ! plane[p].halfSpaceContains(getCorner(v));
}
-
if (culled) {
// Plane p culled the box
cullingPlane = p;
-
return true;
}
}
-
// Move on to the next bit.
inMask = inMask >> 1;
}
-
// None of the planes could cull this box
cullingPlane = -1;
return false;
}
-
bool Box::contains(
const Vector3& point) const {
-
// Form axes from three edges, transform the point into that
// space, and perform 3 interval tests
-
Vector3 u = _corner[4] - _corner[0];
Vector3 v = _corner[3] - _corner[0];
Vector3 w = _corner[1] - _corner[0];
-
Matrix3 M = Matrix3(u.x, v.x, w.x,
u.y, v.y, w.y,
u.z, v.z, w.z);
-
// M^-1 * (point - _corner[0]) = point in unit cube's object space
// compute the inverse of M
Vector3 osPoint = M.inverse() * (point - _corner[0]);
-
return
- (osPoint.x >= 0) &&
+ (osPoint.x >= 0) &&
(osPoint.y >= 0) &&
(osPoint.z >= 0) &&
(osPoint.x <= 1) &&
(osPoint.y <= 1) &&
(osPoint.z <= 1);
}
-
#undef setMany
-
#if 0
void Box::getRandomSurfacePoint(Vector3& P, Vector3& N) const {
float aXY = _extent.x * _extent.y;
float aYZ = _extent.y * _extent.z;
float aZX = _extent.z * _extent.x;
-
float r = (float)random(0, aXY + aYZ + aZX);
-
// Choose evenly between positive and negative face planes
float d = (random(0, 1) < 0.5f) ? -1.0f : 1.0f;
-
// The probability of choosing a given face is proportional to
// its area.
if (r < aXY) {
@@ -317,33 +246,25 @@ void Box::getRandomSurfacePoint(Vector3& P, Vector3& N) const {
}
}
-
Vector3 Box::randomInteriorPoint() const {
Vector3 sum = _center;
-
for (int a = 0; a < 3; ++a) {
sum += _axis[a] * (float)random(-0.5, 0.5) * _extent[a];
}
-
return sum;
}
#endif
-
void Box::getBounds(class AABox& aabb) const {
-
Vector3 lo = _corner[0];
Vector3 hi = lo;
-
for (int v = 1; v < 8; ++v) {
const Vector3& C = _corner[v];
lo = lo.min(C);
hi = hi.max(C);
}
-
aabb = AABox(lo, hi);
}
-
} // namespace
diff --git a/dep/src/g3dlite/Crypto.cpp b/dep/src/g3dlite/Crypto.cpp
index bff3a5a966c..ff8019ad29d 100644
--- a/dep/src/g3dlite/Crypto.cpp
+++ b/dep/src/g3dlite/Crypto.cpp
@@ -1,26 +1,19 @@
/**
@file Crypto.cpp
-
@author Morgan McGuire, matrix@graphics3d.com
-
@created 2006-03-28
@edited 2006-04-06
*/
-
#include "G3D/platform.h"
#include "G3D/Crypto.h"
#include "G3D/g3dmath.h"
-
namespace G3D {
-
int Crypto::smallPrime(int n) {
debugAssert(n < numSmallPrimes() && n >= 0);
-
// From:
// http://primes.utm.edu/lists/small/1000.txt
-
static const int table[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
@@ -53,15 +46,12 @@ int Crypto::smallPrime(int n) {
1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889,
1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987,
1993, 1997, 1999};
-
return table[n];
}
-
int Crypto::numSmallPrimes() {
return 303;
}
-
uint32 Crypto::crc32(const void* byte, size_t numBytes) {
static const uint32 crc32Table[256] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
@@ -80,7 +70,6 @@ uint32 Crypto::crc32(const void* byte, size_t numBytes) {
0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
-
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
@@ -97,7 +86,6 @@ uint32 Crypto::crc32(const void* byte, size_t numBytes) {
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
-
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
@@ -114,7 +102,6 @@ uint32 Crypto::crc32(const void* byte, size_t numBytes) {
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
-
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
@@ -132,16 +119,12 @@ uint32 Crypto::crc32(const void* byte, size_t numBytes) {
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
};
-
// By definition, initialize to all binary 1's
uint32 value = 0xFFFFFFFF;
-
for (size_t i = 0; i < numBytes; ++i) {
value = (value >> 8 ) ^ crc32Table[static_cast<const uint8*>(byte)[i] ^ (value & 0xFF)];
}
-
return value;
}
-
} // G3D
diff --git a/dep/src/g3dlite/Matrix3.cpp b/dep/src/g3dlite/Matrix3.cpp
index 630c1883c0b..717939c8809 100644
--- a/dep/src/g3dlite/Matrix3.cpp
+++ b/dep/src/g3dlite/Matrix3.cpp
@@ -1,14 +1,10 @@
/**
@file Matrix3.cpp
-
3x3 matrix class
-
@author Morgan McGuire, graphics3d.com
-
@created 2001-06-02
@edited 2006-04-06
*/
-
#include "G3D/platform.h"
#include "G3D/format.h"
#include <memory.h>
@@ -16,28 +12,21 @@
#include "G3D/Matrix3.h"
#include "G3D/g3dmath.h"
#include "G3D/Quat.h"
-
namespace G3D {
-
const float Matrix3::EPSILON = 1e-06f;
-
const Matrix3& Matrix3::zero() {
static Matrix3 m(0, 0, 0, 0, 0, 0, 0, 0, 0);
return m;
}
-
const Matrix3& Matrix3::identity() {
static Matrix3 m(1, 0, 0, 0, 1, 0, 0, 0, 1);
return m;
}
-
// Deprecated.
const Matrix3 Matrix3::ZERO(0, 0, 0, 0, 0, 0, 0, 0, 0);
const Matrix3 Matrix3::IDENTITY(1, 0, 0, 0, 1, 0, 0, 0, 1);
-
const float Matrix3::ms_fSvdEpsilon = 1e-04f;
const int Matrix3::ms_iSvdMaxIterations = 32;
-
bool Matrix3::fuzzyEq(const Matrix3& b) const {
for (int r = 0; r < 3; ++r) {
for (int c = 0; c < 3; ++c) {
@@ -49,12 +38,10 @@ bool Matrix3::fuzzyEq(const Matrix3& b) const {
return true;
}
-
bool Matrix3::isOrthonormal() const {
Vector3 X = getColumn(0);
Vector3 Y = getColumn(1);
Vector3 Z = getColumn(2);
-
return
(G3D::fuzzyEq(X.dot(Y), 0.0f) &&
G3D::fuzzyEq(Y.dot(Z), 0.0f) &&
@@ -63,7 +50,6 @@ bool Matrix3::isOrthonormal() const {
G3D::fuzzyEq(Y.squaredMagnitude(), 1.0f) &&
G3D::fuzzyEq(Z.squaredMagnitude(), 1.0f));
}
-
//----------------------------------------------------------------------------
Matrix3::Matrix3(const Quat& _q) {
// Implementation from Watt and Watt, pg 362
@@ -73,30 +59,23 @@ Matrix3::Matrix3(const Quat& _q) {
float xy = 2.0f * q.x * q.y;
float xz = 2.0f * q.x * q.z;
float xw = 2.0f * q.x * q.w;
-
float yy = 2.0f * q.y * q.y;
float yz = 2.0f * q.y * q.z;
float yw = 2.0f * q.y * q.w;
-
float zz = 2.0f * q.z * q.z;
float zw = 2.0f * q.z * q.w;
-
set(1.0f - yy - zz, xy - zw, xz + yw,
xy + zw, 1.0f - xx - zz, yz - xw,
xz - yw, yz + xw, 1.0f - xx - yy);
}
-
//----------------------------------------------------------------------------
-
Matrix3::Matrix3 (const float aafEntry[3][3]) {
memcpy(elt, aafEntry, 9*sizeof(float));
}
-
//----------------------------------------------------------------------------
Matrix3::Matrix3 (const Matrix3& rkMatrix) {
memcpy(elt, rkMatrix.elt, 9*sizeof(float));
}
-
//----------------------------------------------------------------------------
Matrix3::Matrix3(
float fEntry00, float fEntry01, float fEntry02,
@@ -106,12 +85,10 @@ Matrix3::Matrix3(
fEntry10, fEntry11, fEntry12,
fEntry20, fEntry21, fEntry22);
}
-
void Matrix3::set(
float fEntry00, float fEntry01, float fEntry02,
float fEntry10, float fEntry11, float fEntry12,
float fEntry20, float fEntry21, float fEntry22) {
-
elt[0][0] = fEntry00;
elt[0][1] = fEntry01;
elt[0][2] = fEntry02;
@@ -123,18 +100,15 @@ void Matrix3::set(
elt[2][2] = fEntry22;
}
-
//----------------------------------------------------------------------------
Vector3 Matrix3::getColumn (int iCol) const {
assert((0 <= iCol) && (iCol < 3));
return Vector3(elt[0][iCol], elt[1][iCol],
elt[2][iCol]);
}
-
Vector3 Matrix3::getRow (int iRow) const {
return Vector3(elt[iRow][0], elt[iRow][1], elt[iRow][2]);
}
-
void Matrix3::setColumn(int iCol, const Vector3 &vector) {
debugAssert((iCol >= 0) && (iCol < 3));
elt[0][iCol] = vector.x;
@@ -142,7 +116,6 @@ void Matrix3::setColumn(int iCol, const Vector3 &vector) {
elt[2][iCol] = vector.z;
}
-
void Matrix3::setRow(int iRow, const Vector3 &vector) {
debugAssert((iRow >= 0) && (iRow < 3));
elt[iRow][0] = vector.x;
@@ -150,7 +123,6 @@ void Matrix3::setRow(int iRow, const Vector3 &vector) {
elt[iRow][2] = vector.z;
}
-
//----------------------------------------------------------------------------
bool Matrix3::operator== (const Matrix3& rkMatrix) const {
for (int iRow = 0; iRow < 3; iRow++) {
@@ -159,47 +131,37 @@ bool Matrix3::operator== (const Matrix3& rkMatrix) const {
return false;
}
}
-
return true;
}
-
//----------------------------------------------------------------------------
bool Matrix3::operator!= (const Matrix3& rkMatrix) const {
return !operator==(rkMatrix);
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::operator+ (const Matrix3& rkMatrix) const {
Matrix3 kSum;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kSum.elt[iRow][iCol] = elt[iRow][iCol] +
rkMatrix.elt[iRow][iCol];
}
}
-
return kSum;
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::operator- (const Matrix3& rkMatrix) const {
Matrix3 kDiff;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kDiff.elt[iRow][iCol] = elt[iRow][iCol] -
rkMatrix.elt[iRow][iCol];
}
}
-
return kDiff;
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::operator* (const Matrix3& rkMatrix) const {
Matrix3 kProd;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kProd.elt[iRow][iCol] =
@@ -208,30 +170,24 @@ Matrix3 Matrix3::operator* (const Matrix3& rkMatrix) const {
elt[iRow][2] * rkMatrix.elt[2][iCol];
}
}
-
return kProd;
}
-
Matrix3& Matrix3::operator+= (const Matrix3& rkMatrix) {
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
elt[iRow][iCol] = elt[iRow][iCol] + rkMatrix.elt[iRow][iCol];
}
}
-
return *this;
}
-
Matrix3& Matrix3::operator-= (const Matrix3& rkMatrix) {
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
elt[iRow][iCol] = elt[iRow][iCol] - rkMatrix.elt[iRow][iCol];
}
}
-
return *this;
}
-
Matrix3& Matrix3::operator*= (const Matrix3& rkMatrix) {
Matrix3 mulMat;
for (int iRow = 0; iRow < 3; iRow++) {
@@ -242,76 +198,60 @@ Matrix3& Matrix3::operator*= (const Matrix3& rkMatrix) {
elt[iRow][2] * rkMatrix.elt[2][iCol];
}
}
-
*this = mulMat;
return *this;
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::operator- () const {
Matrix3 kNeg;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kNeg[iRow][iCol] = -elt[iRow][iCol];
}
}
-
return kNeg;
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::operator* (float fScalar) const {
Matrix3 kProd;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kProd[iRow][iCol] = fScalar * elt[iRow][iCol];
}
}
-
return kProd;
}
-
//----------------------------------------------------------------------------
Matrix3 operator* (double fScalar, const Matrix3& rkMatrix) {
Matrix3 kProd;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kProd[iRow][iCol] = fScalar * rkMatrix.elt[iRow][iCol];
}
}
-
return kProd;
}
-
Matrix3 operator* (float fScalar, const Matrix3& rkMatrix) {
return (double)fScalar * rkMatrix;
}
-
Matrix3 operator* (int fScalar, const Matrix3& rkMatrix) {
return (double)fScalar * rkMatrix;
}
//----------------------------------------------------------------------------
Matrix3 Matrix3::transpose () const {
Matrix3 kTranspose;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++) {
kTranspose[iRow][iCol] = elt[iCol][iRow];
}
}
-
return kTranspose;
}
-
//----------------------------------------------------------------------------
bool Matrix3::inverse (Matrix3& rkInverse, float fTolerance) const {
// Invert a 3x3 using cofactors. This is about 8 times faster than
// the Numerical Recipes code which uses Gaussian elimination.
-
rkInverse[0][0] = elt[1][1] * elt[2][2] -
elt[1][2] * elt[2][1];
rkInverse[0][1] = elt[0][2] * elt[2][1] -
@@ -330,32 +270,25 @@ bool Matrix3::inverse (Matrix3& rkInverse, float fTolerance) const {
elt[0][0] * elt[2][1];
rkInverse[2][2] = elt[0][0] * elt[1][1] -
elt[0][1] * elt[1][0];
-
float fDet =
elt[0][0] * rkInverse[0][0] +
elt[0][1] * rkInverse[1][0] +
elt[0][2] * rkInverse[2][0];
-
if ( G3D::abs(fDet) <= fTolerance )
return false;
-
float fInvDet = 1.0 / fDet;
-
for (int iRow = 0; iRow < 3; iRow++) {
for (int iCol = 0; iCol < 3; iCol++)
rkInverse[iRow][iCol] *= fInvDet;
}
-
return true;
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::inverse (float fTolerance) const {
Matrix3 kInverse = Matrix3::zero();
inverse(kInverse, fTolerance);
return kInverse;
}
-
//----------------------------------------------------------------------------
float Matrix3::determinant () const {
float fCofactor00 = elt[1][1] * elt[2][2] -
@@ -364,33 +297,27 @@ float Matrix3::determinant () const {
elt[1][0] * elt[2][2];
float fCofactor20 = elt[1][0] * elt[2][1] -
elt[1][1] * elt[2][0];
-
float fDet =
elt[0][0] * fCofactor00 +
elt[0][1] * fCofactor10 +
elt[0][2] * fCofactor20;
-
return fDet;
}
-
//----------------------------------------------------------------------------
void Matrix3::bidiagonalize (Matrix3& kA, Matrix3& kL,
Matrix3& kR) {
float afV[3], afW[3];
float fLength, fSign, fT1, fInvT1, fT2;
bool bIdentity;
-
// map first column to (*,0,0)
fLength = sqrt(kA[0][0] * kA[0][0] + kA[1][0] * kA[1][0] +
kA[2][0] * kA[2][0]);
-
if ( fLength > 0.0 ) {
fSign = (kA[0][0] > 0.0 ? 1.0 : -1.0);
fT1 = kA[0][0] + fSign * fLength;
fInvT1 = 1.0 / fT1;
afV[1] = kA[1][0] * fInvT1;
afV[2] = kA[2][0] * fInvT1;
-
fT2 = -2.0 / (1.0 + afV[1] * afV[1] + afV[2] * afV[2]);
afW[0] = fT2 * (kA[0][0] + kA[1][0] * afV[1] + kA[2][0] * afV[2]);
afW[1] = fT2 * (kA[0][1] + kA[1][1] * afV[1] + kA[2][1] * afV[2]);
@@ -402,7 +329,6 @@ void Matrix3::bidiagonalize (Matrix3& kA, Matrix3& kL,
kA[1][2] += afV[1] * afW[2];
kA[2][1] += afV[2] * afW[1];
kA[2][2] += afV[2] * afW[2];
-
kL[0][0] = 1.0 + fT2;
kL[0][1] = kL[1][0] = fT2 * afV[1];
kL[0][2] = kL[2][0] = fT2 * afV[2];
@@ -414,15 +340,12 @@ void Matrix3::bidiagonalize (Matrix3& kA, Matrix3& kL,
kL = Matrix3::identity();
bIdentity = true;
}
-
// map first row to (*,*,0)
fLength = sqrt(kA[0][1] * kA[0][1] + kA[0][2] * kA[0][2]);
-
if ( fLength > 0.0 ) {
fSign = (kA[0][1] > 0.0 ? 1.0 : -1.0);
fT1 = kA[0][1] + fSign * fLength;
afV[2] = kA[0][2] / fT1;
-
fT2 = -2.0 / (1.0 + afV[2] * afV[2]);
afW[0] = fT2 * (kA[0][1] + kA[0][2] * afV[2]);
afW[1] = fT2 * (kA[1][1] + kA[1][2] * afV[2]);
@@ -432,7 +355,6 @@ void Matrix3::bidiagonalize (Matrix3& kA, Matrix3& kL,
kA[1][2] += afW[1] * afV[2];
kA[2][1] += afW[2];
kA[2][2] += afW[2] * afV[2];
-
kR[0][0] = 1.0;
kR[0][1] = kR[1][0] = 0.0;
kR[0][2] = kR[2][0] = 0.0;
@@ -442,26 +364,21 @@ void Matrix3::bidiagonalize (Matrix3& kA, Matrix3& kL,
} else {
kR = Matrix3::identity();
}
-
// map second column to (*,*,0)
fLength = sqrt(kA[1][1] * kA[1][1] + kA[2][1] * kA[2][1]);
-
if ( fLength > 0.0 ) {
fSign = (kA[1][1] > 0.0 ? 1.0 : -1.0);
fT1 = kA[1][1] + fSign * fLength;
afV[2] = kA[2][1] / fT1;
-
fT2 = -2.0 / (1.0 + afV[2] * afV[2]);
afW[1] = fT2 * (kA[1][1] + kA[2][1] * afV[2]);
afW[2] = fT2 * (kA[1][2] + kA[2][2] * afV[2]);
kA[1][1] += afW[1];
kA[1][2] += afW[2];
kA[2][2] += afV[2] * afW[2];
-
float fA = 1.0 + fT2;
float fB = fT2 * afV[2];
float fC = 1.0 + fB * afV[2];
-
if ( bIdentity ) {
kL[0][0] = 1.0;
kL[0][1] = kL[1][0] = 0.0;
@@ -479,7 +396,6 @@ void Matrix3::bidiagonalize (Matrix3& kA, Matrix3& kL,
}
}
}
-
//----------------------------------------------------------------------------
void Matrix3::golubKahanStep (Matrix3& kA, Matrix3& kL,
Matrix3& kR) {
@@ -491,7 +407,6 @@ void Matrix3::golubKahanStep (Matrix3& kA, Matrix3& kL,
float fDiscr = sqrt(fDiff * fDiff + 4.0 * fT12 * fT12);
float fRoot1 = 0.5 * (fTrace + fDiscr);
float fRoot2 = 0.5 * (fTrace - fDiscr);
-
// adjust right
float fY = kA[0][0] - (G3D::abs(fRoot1 - fT22) <=
G3D::abs(fRoot2 - fT22) ? fRoot1 : fRoot2);
@@ -499,110 +414,69 @@ void Matrix3::golubKahanStep (Matrix3& kA, Matrix3& kL,
float fInvLength = 1.0 / sqrt(fY * fY + fZ * fZ);
float fSin = fZ * fInvLength;
float fCos = -fY * fInvLength;
-
float fTmp0 = kA[0][0];
float fTmp1 = kA[0][1];
kA[0][0] = fCos * fTmp0 - fSin * fTmp1;
kA[0][1] = fSin * fTmp0 + fCos * fTmp1;
kA[1][0] = -fSin * kA[1][1];
kA[1][1] *= fCos;
-
int iRow;
-
for (iRow = 0; iRow < 3; iRow++) {
fTmp0 = kR[0][iRow];
fTmp1 = kR[1][iRow];
kR[0][iRow] = fCos * fTmp0 - fSin * fTmp1;
kR[1][iRow] = fSin * fTmp0 + fCos * fTmp1;
}
-
// adjust left
fY = kA[0][0];
-
fZ = kA[1][0];
-
fInvLength = 1.0 / sqrt(fY * fY + fZ * fZ);
-
fSin = fZ * fInvLength;
-
fCos = -fY * fInvLength;
-
kA[0][0] = fCos * kA[0][0] - fSin * kA[1][0];
-
fTmp0 = kA[0][1];
-
fTmp1 = kA[1][1];
-
kA[0][1] = fCos * fTmp0 - fSin * fTmp1;
-
kA[1][1] = fSin * fTmp0 + fCos * fTmp1;
-
kA[0][2] = -fSin * kA[1][2];
-
kA[1][2] *= fCos;
-
int iCol;
-
for (iCol = 0; iCol < 3; iCol++) {
fTmp0 = kL[iCol][0];
fTmp1 = kL[iCol][1];
kL[iCol][0] = fCos * fTmp0 - fSin * fTmp1;
kL[iCol][1] = fSin * fTmp0 + fCos * fTmp1;
}
-
// adjust right
fY = kA[0][1];
-
fZ = kA[0][2];
-
fInvLength = 1.0 / sqrt(fY * fY + fZ * fZ);
-
fSin = fZ * fInvLength;
-
fCos = -fY * fInvLength;
-
kA[0][1] = fCos * kA[0][1] - fSin * kA[0][2];
-
fTmp0 = kA[1][1];
-
fTmp1 = kA[1][2];
-
kA[1][1] = fCos * fTmp0 - fSin * fTmp1;
-
kA[1][2] = fSin * fTmp0 + fCos * fTmp1;
-
kA[2][1] = -fSin * kA[2][2];
-
kA[2][2] *= fCos;
-
for (iRow = 0; iRow < 3; iRow++) {
fTmp0 = kR[1][iRow];
fTmp1 = kR[2][iRow];
kR[1][iRow] = fCos * fTmp0 - fSin * fTmp1;
kR[2][iRow] = fSin * fTmp0 + fCos * fTmp1;
}
-
// adjust left
fY = kA[1][1];
-
fZ = kA[2][1];
-
fInvLength = 1.0 / sqrt(fY * fY + fZ * fZ);
-
fSin = fZ * fInvLength;
-
fCos = -fY * fInvLength;
-
kA[1][1] = fCos * kA[1][1] - fSin * kA[2][1];
-
fTmp0 = kA[1][2];
-
fTmp1 = kA[2][2];
-
kA[1][2] = fCos * fTmp0 - fSin * fTmp1;
-
kA[2][2] = fSin * fTmp0 + fCos * fTmp1;
-
for (iCol = 0; iCol < 3; iCol++) {
fTmp0 = kL[iCol][1];
fTmp1 = kL[iCol][2];
@@ -610,25 +484,20 @@ void Matrix3::golubKahanStep (Matrix3& kA, Matrix3& kL,
kL[iCol][2] = fSin * fTmp0 + fCos * fTmp1;
}
}
-
//----------------------------------------------------------------------------
void Matrix3::singularValueDecomposition (Matrix3& kL, Vector3& kS,
Matrix3& kR) const {
int iRow, iCol;
-
Matrix3 kA = *this;
bidiagonalize(kA, kL, kR);
-
for (int i = 0; i < ms_iSvdMaxIterations; i++) {
float fTmp, fTmp0, fTmp1;
float fSin0, fCos0, fTan0;
float fSin1, fCos1, fTan1;
-
bool bTest1 = (G3D::abs(kA[0][1]) <=
ms_fSvdEpsilon * (G3D::abs(kA[0][0]) + G3D::abs(kA[1][1])));
bool bTest2 = (G3D::abs(kA[1][2]) <=
ms_fSvdEpsilon * (G3D::abs(kA[1][1]) + G3D::abs(kA[2][2])));
-
if ( bTest1 ) {
if ( bTest2 ) {
kS[0] = kA[0][0];
@@ -642,25 +511,21 @@ void Matrix3::singularValueDecomposition (Matrix3& kL, Vector3& kS,
fTan0 = 0.5 * (fTmp + sqrt(fTmp * fTmp + 4.0));
fCos0 = 1.0 / sqrt(1.0 + fTan0 * fTan0);
fSin0 = fTan0 * fCos0;
-
for (iCol = 0; iCol < 3; iCol++) {
fTmp0 = kL[iCol][1];
fTmp1 = kL[iCol][2];
kL[iCol][1] = fCos0 * fTmp0 - fSin0 * fTmp1;
kL[iCol][2] = fSin0 * fTmp0 + fCos0 * fTmp1;
}
-
fTan1 = (kA[1][2] - kA[2][2] * fTan0) / kA[1][1];
fCos1 = 1.0 / sqrt(1.0 + fTan1 * fTan1);
fSin1 = -fTan1 * fCos1;
-
for (iRow = 0; iRow < 3; iRow++) {
fTmp0 = kR[1][iRow];
fTmp1 = kR[2][iRow];
kR[1][iRow] = fCos1 * fTmp0 - fSin1 * fTmp1;
kR[2][iRow] = fSin1 * fTmp0 + fCos1 * fTmp1;
}
-
kS[0] = kA[0][0];
kS[1] = fCos0 * fCos1 * kA[1][1] -
fSin1 * (fCos0 * kA[1][2] - fSin0 * kA[2][2]);
@@ -676,25 +541,21 @@ void Matrix3::singularValueDecomposition (Matrix3& kL, Vector3& kS,
fTan0 = 0.5 * ( -fTmp + sqrt(fTmp * fTmp + 4.0));
fCos0 = 1.0 / sqrt(1.0 + fTan0 * fTan0);
fSin0 = fTan0 * fCos0;
-
for (iCol = 0; iCol < 3; iCol++) {
fTmp0 = kL[iCol][0];
fTmp1 = kL[iCol][1];
kL[iCol][0] = fCos0 * fTmp0 - fSin0 * fTmp1;
kL[iCol][1] = fSin0 * fTmp0 + fCos0 * fTmp1;
}
-
fTan1 = (kA[0][1] - kA[1][1] * fTan0) / kA[0][0];
fCos1 = 1.0 / sqrt(1.0 + fTan1 * fTan1);
fSin1 = -fTan1 * fCos1;
-
for (iRow = 0; iRow < 3; iRow++) {
fTmp0 = kR[0][iRow];
fTmp1 = kR[1][iRow];
kR[0][iRow] = fCos1 * fTmp0 - fSin1 * fTmp1;
kR[1][iRow] = fSin1 * fTmp0 + fCos1 * fTmp1;
}
-
kS[0] = fCos0 * fCos1 * kA[0][0] -
fSin1 * (fCos0 * kA[0][1] - fSin0 * kA[1][1]);
kS[1] = fSin0 * fSin1 * kA[0][0] +
@@ -706,41 +567,34 @@ void Matrix3::singularValueDecomposition (Matrix3& kL, Vector3& kS,
}
}
}
-
// positize diagonal
for (iRow = 0; iRow < 3; iRow++) {
if ( kS[iRow] < 0.0 ) {
kS[iRow] = -kS[iRow];
-
for (iCol = 0; iCol < 3; iCol++)
kR[iRow][iCol] = -kR[iRow][iCol];
}
}
}
-
//----------------------------------------------------------------------------
void Matrix3::singularValueComposition (const Matrix3& kL,
const Vector3& kS, const Matrix3& kR) {
int iRow, iCol;
Matrix3 kTmp;
-
// product S*R
for (iRow = 0; iRow < 3; iRow++) {
for (iCol = 0; iCol < 3; iCol++)
kTmp[iRow][iCol] = kS[iRow] * kR[iRow][iCol];
}
-
// product L*S*R
for (iRow = 0; iRow < 3; iRow++) {
for (iCol = 0; iCol < 3; iCol++) {
elt[iRow][iCol] = 0.0;
-
for (int iMid = 0; iMid < 3; iMid++)
elt[iRow][iCol] += kL[iRow][iMid] * kTmp[iMid][iCol];
}
}
}
-
//----------------------------------------------------------------------------
void Matrix3::orthonormalize () {
// Algorithm uses Gram-Schmidt orthogonalization. If 'this' matrix is
@@ -752,58 +606,46 @@ void Matrix3::orthonormalize () {
//
// where |V| indicates length of vector V and A*B indicates dot
// product of vectors A and B.
-
// compute q0
float fInvLength = 1.0 / sqrt(elt[0][0] * elt[0][0]
+ elt[1][0] * elt[1][0] +
elt[2][0] * elt[2][0]);
-
elt[0][0] *= fInvLength;
elt[1][0] *= fInvLength;
elt[2][0] *= fInvLength;
-
// compute q1
float fDot0 =
elt[0][0] * elt[0][1] +
elt[1][0] * elt[1][1] +
elt[2][0] * elt[2][1];
-
elt[0][1] -= fDot0 * elt[0][0];
elt[1][1] -= fDot0 * elt[1][0];
elt[2][1] -= fDot0 * elt[2][0];
-
fInvLength = 1.0 / sqrt(elt[0][1] * elt[0][1] +
elt[1][1] * elt[1][1] +
elt[2][1] * elt[2][1]);
-
elt[0][1] *= fInvLength;
elt[1][1] *= fInvLength;
elt[2][1] *= fInvLength;
-
// compute q2
float fDot1 =
elt[0][1] * elt[0][2] +
elt[1][1] * elt[1][2] +
elt[2][1] * elt[2][2];
-
fDot0 =
elt[0][0] * elt[0][2] +
elt[1][0] * elt[1][2] +
elt[2][0] * elt[2][2];
-
elt[0][2] -= fDot0 * elt[0][0] + fDot1 * elt[0][1];
elt[1][2] -= fDot0 * elt[1][0] + fDot1 * elt[1][1];
elt[2][2] -= fDot0 * elt[2][0] + fDot1 * elt[2][1];
-
fInvLength = 1.0 / sqrt(elt[0][2] * elt[0][2] +
elt[1][2] * elt[1][2] +
elt[2][2] * elt[2][2]);
-
elt[0][2] *= fInvLength;
elt[1][2] *= fInvLength;
elt[2][2] *= fInvLength;
}
-
//----------------------------------------------------------------------------
void Matrix3::qDUDecomposition (Matrix3& kQ,
Vector3& kD, Vector3& kU) const {
@@ -826,14 +668,11 @@ void Matrix3::qDUDecomposition (Matrix3& kQ,
//
// so D = diag(r00,r11,r22) and U has entries u01 = r01/r00,
// u02 = r02/r00, and u12 = r12/r11.
-
// Q = rotation
// D = scaling
// U = shear
-
// D stores the three diagonal entries r00, r11, r22
// U stores the entries U[0] = u01, U[1] = u02, U[2] = u12
-
// build orthogonal matrix Q
float fInvLength = 1.0 / sqrt(elt[0][0] * elt[0][0]
+ elt[1][0] * elt[1][0] +
@@ -841,7 +680,6 @@ void Matrix3::qDUDecomposition (Matrix3& kQ,
kQ[0][0] = elt[0][0] * fInvLength;
kQ[1][0] = elt[1][0] * fInvLength;
kQ[2][0] = elt[2][0] * fInvLength;
-
float fDot = kQ[0][0] * elt[0][1] + kQ[1][0] * elt[1][1] +
kQ[2][0] * elt[2][1];
kQ[0][1] = elt[0][1] - fDot * kQ[0][0];
@@ -852,7 +690,6 @@ void Matrix3::qDUDecomposition (Matrix3& kQ,
kQ[0][1] *= fInvLength;
kQ[1][1] *= fInvLength;
kQ[2][1] *= fInvLength;
-
fDot = kQ[0][0] * elt[0][2] + kQ[1][0] * elt[1][2] +
kQ[2][0] * elt[2][2];
kQ[0][2] = elt[0][2] - fDot * kQ[0][0];
@@ -868,134 +705,96 @@ void Matrix3::qDUDecomposition (Matrix3& kQ,
kQ[0][2] *= fInvLength;
kQ[1][2] *= fInvLength;
kQ[2][2] *= fInvLength;
-
// guarantee that orthogonal matrix has determinant 1 (no reflections)
float fDet = kQ[0][0] * kQ[1][1] * kQ[2][2] + kQ[0][1] * kQ[1][2] * kQ[2][0] +
kQ[0][2] * kQ[1][0] * kQ[2][1] - kQ[0][2] * kQ[1][1] * kQ[2][0] -
kQ[0][1] * kQ[1][0] * kQ[2][2] - kQ[0][0] * kQ[1][2] * kQ[2][1];
-
if ( fDet < 0.0 ) {
for (int iRow = 0; iRow < 3; iRow++)
for (int iCol = 0; iCol < 3; iCol++)
kQ[iRow][iCol] = -kQ[iRow][iCol];
}
-
// build "right" matrix R
Matrix3 kR;
-
kR[0][0] = kQ[0][0] * elt[0][0] + kQ[1][0] * elt[1][0] +
kQ[2][0] * elt[2][0];
-
kR[0][1] = kQ[0][0] * elt[0][1] + kQ[1][0] * elt[1][1] +
kQ[2][0] * elt[2][1];
-
kR[1][1] = kQ[0][1] * elt[0][1] + kQ[1][1] * elt[1][1] +
kQ[2][1] * elt[2][1];
-
kR[0][2] = kQ[0][0] * elt[0][2] + kQ[1][0] * elt[1][2] +
kQ[2][0] * elt[2][2];
-
kR[1][2] = kQ[0][1] * elt[0][2] + kQ[1][1] * elt[1][2] +
kQ[2][1] * elt[2][2];
-
kR[2][2] = kQ[0][2] * elt[0][2] + kQ[1][2] * elt[1][2] +
kQ[2][2] * elt[2][2];
-
// the scaling component
kD[0] = kR[0][0];
-
kD[1] = kR[1][1];
-
kD[2] = kR[2][2];
-
// the shear component
float fInvD0 = 1.0 / kD[0];
-
kU[0] = kR[0][1] * fInvD0;
-
kU[1] = kR[0][2] * fInvD0;
-
kU[2] = kR[1][2] / kD[1];
}
-
//----------------------------------------------------------------------------
float Matrix3::maxCubicRoot (float afCoeff[3]) {
// Spectral norm is for A^T*A, so characteristic polynomial
// P(x) = c[0]+c[1]*x+c[2]*x^2+x^3 has three positive float roots.
// This yields the assertions c[0] < 0 and c[2]*c[2] >= 3*c[1].
-
// quick out for uniform scale (triple root)
const float fOneThird = 1.0f / 3.0f;
const float fEpsilon = 1e-06f;
float fDiscr = afCoeff[2] * afCoeff[2] - 3.0f * afCoeff[1];
-
if ( fDiscr <= fEpsilon )
return -fOneThird*afCoeff[2];
-
// Compute an upper bound on roots of P(x). This assumes that A^T*A
// has been scaled by its largest entry.
float fX = 1.0f;
-
float fPoly = afCoeff[0] + fX * (afCoeff[1] + fX * (afCoeff[2] + fX));
-
if ( fPoly < 0.0f ) {
// uses a matrix norm to find an upper bound on maximum root
fX = G3D::abs(afCoeff[0]);
float fTmp = 1.0 + G3D::abs(afCoeff[1]);
-
if ( fTmp > fX )
fX = fTmp;
-
fTmp = 1.0 + G3D::abs(afCoeff[2]);
-
if ( fTmp > fX )
fX = fTmp;
}
-
// Newton's method to find root
float fTwoC2 = 2.0f * afCoeff[2];
-
for (int i = 0; i < 16; i++) {
fPoly = afCoeff[0] + fX * (afCoeff[1] + fX * (afCoeff[2] + fX));
-
if ( G3D::abs(fPoly) <= fEpsilon )
return fX;
-
float fDeriv = afCoeff[1] + fX * (fTwoC2 + 3.0f * fX);
-
fX -= fPoly / fDeriv;
}
-
return fX;
}
-
//----------------------------------------------------------------------------
float Matrix3::spectralNorm () const {
Matrix3 kP;
int iRow, iCol;
float fPmax = 0.0;
-
for (iRow = 0; iRow < 3; iRow++) {
for (iCol = 0; iCol < 3; iCol++) {
kP[iRow][iCol] = 0.0;
-
for (int iMid = 0; iMid < 3; iMid++) {
kP[iRow][iCol] +=
elt[iMid][iRow] * elt[iMid][iCol];
}
-
if ( kP[iRow][iCol] > fPmax )
fPmax = kP[iRow][iCol];
}
}
-
float fInvPmax = 1.0 / fPmax;
-
for (iRow = 0; iRow < 3; iRow++) {
for (iCol = 0; iCol < 3; iCol++)
kP[iRow][iCol] *= fInvPmax;
}
-
float afCoeff[3];
afCoeff[0] = -(kP[0][0] * (kP[1][1] * kP[2][2] - kP[1][2] * kP[2][1]) +
kP[0][1] * (kP[2][0] * kP[1][2] - kP[1][0] * kP[2][2]) +
@@ -1004,12 +803,10 @@ float Matrix3::spectralNorm () const {
kP[0][0] * kP[2][2] - kP[0][2] * kP[2][0] +
kP[1][1] * kP[2][2] - kP[1][2] * kP[2][1];
afCoeff[2] = -(kP[0][0] + kP[1][1] + kP[2][2]);
-
float fRoot = maxCubicRoot(afCoeff);
float fNorm = sqrt(fPmax * fRoot);
return fNorm;
}
-
//----------------------------------------------------------------------------
void Matrix3::toAxisAngle (Vector3& rkAxis, float& rfRadians) const {
// Let (x,y,z) be the unit-length axis and let A be an angle of rotation.
@@ -1033,11 +830,9 @@ void Matrix3::toAxisAngle (Vector3& rkAxis, float& rfRadians) const {
// P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and
// z^2-1. We can solve these for axis (x,y,z). Because the angle is pi,
// it does not matter which sign you choose on the square roots.
-
float fTrace = elt[0][0] + elt[1][1] + elt[2][2];
float fCos = 0.5 * (fTrace - 1.0);
rfRadians = G3D::aCos(fCos); // in [0,PI]
-
if ( rfRadians > 0.0 ) {
if ( rfRadians < G3D_PI ) {
rkAxis.x = elt[2][1] - elt[1][2];
@@ -1047,7 +842,6 @@ void Matrix3::toAxisAngle (Vector3& rkAxis, float& rfRadians) const {
} else {
// angle is PI
float fHalfInverse;
-
if ( elt[0][0] >= elt[1][1] ) {
// r00 >= r11
if ( elt[0][0] >= elt[2][2] ) {
@@ -1092,11 +886,9 @@ void Matrix3::toAxisAngle (Vector3& rkAxis, float& rfRadians) const {
rkAxis.z = 0.0;
}
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromAxisAngle (const Vector3& rkAxis, float fRadians) {
Matrix3 m;
-
float fCos = cos(fRadians);
float fSin = sin(fRadians);
float fOneMinusCos = 1.0 - fCos;
@@ -1109,7 +901,6 @@ Matrix3 Matrix3::fromAxisAngle (const Vector3& rkAxis, float fRadians) {
float fXSin = rkAxis.x * fSin;
float fYSin = rkAxis.y * fSin;
float fZSin = rkAxis.z * fSin;
-
m.elt[0][0] = fX2 * fOneMinusCos + fCos;
m.elt[0][1] = fXYM - fZSin;
m.elt[0][2] = fXZM + fYSin;
@@ -1119,17 +910,14 @@ Matrix3 Matrix3::fromAxisAngle (const Vector3& rkAxis, float fRadians) {
m.elt[2][0] = fXZM - fYSin;
m.elt[2][1] = fYZM + fXSin;
m.elt[2][2] = fZ2 * fOneMinusCos + fCos;
-
return m;
}
-
//----------------------------------------------------------------------------
bool Matrix3::toEulerAnglesXYZ (float& rfXAngle, float& rfYAngle,
float& rfZAngle) const {
// rot = cy*cz -cy*sz sy
// cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx
// -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
-
if ( elt[0][2] < 1.0f ) {
if ( elt[0][2] > -1.0f ) {
rfXAngle = G3D::aTan2( -elt[1][2], elt[2][2]);
@@ -1151,14 +939,12 @@ bool Matrix3::toEulerAnglesXYZ (float& rfXAngle, float& rfYAngle,
return false;
}
}
-
//----------------------------------------------------------------------------
bool Matrix3::toEulerAnglesXZY (float& rfXAngle, float& rfZAngle,
float& rfYAngle) const {
// rot = cy*cz -sz cz*sy
// sx*sy+cx*cy*sz cx*cz -cy*sx+cx*sy*sz
// -cx*sy+cy*sx*sz cz*sx cx*cy+sx*sy*sz
-
if ( elt[0][1] < 1.0f ) {
if ( elt[0][1] > -1.0f ) {
rfXAngle = G3D::aTan2(elt[2][1], elt[1][1]);
@@ -1180,14 +966,12 @@ bool Matrix3::toEulerAnglesXZY (float& rfXAngle, float& rfZAngle,
return false;
}
}
-
//----------------------------------------------------------------------------
bool Matrix3::toEulerAnglesYXZ (float& rfYAngle, float& rfXAngle,
float& rfZAngle) const {
// rot = cy*cz+sx*sy*sz cz*sx*sy-cy*sz cx*sy
// cx*sz cx*cz -sx
// -cz*sy+cy*sx*sz cy*cz*sx+sy*sz cx*cy
-
if ( elt[1][2] < 1.0 ) {
if ( elt[1][2] > -1.0 ) {
rfYAngle = G3D::aTan2(elt[0][2], elt[2][2]);
@@ -1209,14 +993,12 @@ bool Matrix3::toEulerAnglesYXZ (float& rfYAngle, float& rfXAngle,
return false;
}
}
-
//----------------------------------------------------------------------------
bool Matrix3::toEulerAnglesYZX (float& rfYAngle, float& rfZAngle,
float& rfXAngle) const {
// rot = cy*cz sx*sy-cx*cy*sz cx*sy+cy*sx*sz
// sz cx*cz -cz*sx
// -cz*sy cy*sx+cx*sy*sz cx*cy-sx*sy*sz
-
if ( elt[1][0] < 1.0 ) {
if ( elt[1][0] > -1.0 ) {
rfYAngle = G3D::aTan2( -elt[2][0], elt[0][0]);
@@ -1238,14 +1020,12 @@ bool Matrix3::toEulerAnglesYZX (float& rfYAngle, float& rfZAngle,
return false;
}
}
-
//----------------------------------------------------------------------------
bool Matrix3::toEulerAnglesZXY (float& rfZAngle, float& rfXAngle,
float& rfYAngle) const {
// rot = cy*cz-sx*sy*sz -cx*sz cz*sy+cy*sx*sz
// cz*sx*sy+cy*sz cx*cz -cy*cz*sx+sy*sz
// -cx*sy sx cx*cy
-
if ( elt[2][1] < 1.0 ) {
if ( elt[2][1] > -1.0 ) {
rfZAngle = G3D::aTan2( -elt[0][1], elt[1][1]);
@@ -1267,14 +1047,12 @@ bool Matrix3::toEulerAnglesZXY (float& rfZAngle, float& rfXAngle,
return false;
}
}
-
//----------------------------------------------------------------------------
bool Matrix3::toEulerAnglesZYX (float& rfZAngle, float& rfYAngle,
float& rfXAngle) const {
// rot = cy*cz cz*sx*sy-cx*sz cx*cz*sy+sx*sz
// cy*sz cx*cz+sx*sy*sz -cz*sx+cx*sy*sz
// -sy cy*sx cx*cy
-
if ( elt[2][0] < 1.0 ) {
if ( elt[2][0] > -1.0 ) {
rfZAngle = atan2f(elt[1][0], elt[0][0]);
@@ -1296,134 +1074,100 @@ bool Matrix3::toEulerAnglesZYX (float& rfZAngle, float& rfYAngle,
return false;
}
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromEulerAnglesXYZ (float fYAngle, float fPAngle,
float fRAngle) {
float fCos, fSin;
-
fCos = cosf(fYAngle);
fSin = sinf(fYAngle);
Matrix3 kXMat(1.0f, 0.0f, 0.0f, 0.0f, fCos, -fSin, 0.0, fSin, fCos);
-
fCos = cosf(fPAngle);
fSin = sinf(fPAngle);
Matrix3 kYMat(fCos, 0.0f, fSin, 0.0f, 1.0f, 0.0f, -fSin, 0.0f, fCos);
-
fCos = cosf(fRAngle);
fSin = sinf(fRAngle);
Matrix3 kZMat(fCos, -fSin, 0.0f, fSin, fCos, 0.0f, 0.0f, 0.0f, 1.0f);
-
return kXMat * (kYMat * kZMat);
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromEulerAnglesXZY (float fYAngle, float fPAngle,
float fRAngle) {
-
float fCos, fSin;
-
fCos = cosf(fYAngle);
fSin = sinf(fYAngle);
Matrix3 kXMat(1.0, 0.0, 0.0, 0.0, fCos, -fSin, 0.0, fSin, fCos);
-
fCos = cosf(fPAngle);
fSin = sinf(fPAngle);
Matrix3 kZMat(fCos, -fSin, 0.0, fSin, fCos, 0.0, 0.0, 0.0, 1.0);
-
fCos = cosf(fRAngle);
fSin = sinf(fRAngle);
Matrix3 kYMat(fCos, 0.0, fSin, 0.0, 1.0, 0.0, -fSin, 0.0, fCos);
-
return kXMat * (kZMat * kYMat);
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromEulerAnglesYXZ(
float fYAngle,
float fPAngle,
float fRAngle) {
-
float fCos, fSin;
-
fCos = cos(fYAngle);
fSin = sin(fYAngle);
Matrix3 kYMat(fCos, 0.0f, fSin, 0.0f, 1.0f, 0.0f, -fSin, 0.0f, fCos);
-
fCos = cos(fPAngle);
fSin = sin(fPAngle);
Matrix3 kXMat(1.0f, 0.0f, 0.0f, 0.0f, fCos, -fSin, 0.0f, fSin, fCos);
-
fCos = cos(fRAngle);
fSin = sin(fRAngle);
Matrix3 kZMat(fCos, -fSin, 0.0f, fSin, fCos, 0.0f, 0.0f, 0.0f, 1.0f);
-
return kYMat * (kXMat * kZMat);
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromEulerAnglesYZX(
float fYAngle,
float fPAngle,
float fRAngle) {
-
float fCos, fSin;
-
fCos = cos(fYAngle);
fSin = sin(fYAngle);
Matrix3 kYMat(fCos, 0.0f, fSin, 0.0f, 1.0f, 0.0f, -fSin, 0.0f, fCos);
-
fCos = cos(fPAngle);
fSin = sin(fPAngle);
Matrix3 kZMat(fCos, -fSin, 0.0f, fSin, fCos, 0.0f, 0.0f, 0.0f, 1.0f);
-
fCos = cos(fRAngle);
fSin = sin(fRAngle);
Matrix3 kXMat(1.0f, 0.0f, 0.0f, 0.0f, fCos, -fSin, 0.0f, fSin, fCos);
-
return kYMat * (kZMat * kXMat);
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromEulerAnglesZXY (float fYAngle, float fPAngle,
float fRAngle) {
float fCos, fSin;
-
fCos = cos(fYAngle);
fSin = sin(fYAngle);
Matrix3 kZMat(fCos, -fSin, 0.0, fSin, fCos, 0.0, 0.0, 0.0, 1.0);
-
fCos = cos(fPAngle);
fSin = sin(fPAngle);
Matrix3 kXMat(1.0, 0.0, 0.0, 0.0, fCos, -fSin, 0.0, fSin, fCos);
-
fCos = cos(fRAngle);
fSin = sin(fRAngle);
Matrix3 kYMat(fCos, 0.0, fSin, 0.0, 1.0, 0.0, -fSin, 0.0, fCos);
-
return kZMat * (kXMat * kYMat);
}
-
//----------------------------------------------------------------------------
Matrix3 Matrix3::fromEulerAnglesZYX (float fYAngle, float fPAngle,
float fRAngle) {
float fCos, fSin;
-
fCos = cos(fYAngle);
fSin = sin(fYAngle);
Matrix3 kZMat(fCos, -fSin, 0.0, fSin, fCos, 0.0, 0.0, 0.0, 1.0);
-
fCos = cos(fPAngle);
fSin = sin(fPAngle);
Matrix3 kYMat(fCos, 0.0, fSin, 0.0, 1.0, 0.0, -fSin, 0.0, fCos);
-
fCos = cos(fRAngle);
fSin = sin(fRAngle);
Matrix3 kXMat(1.0, 0.0, 0.0, 0.0, fCos, -fSin, 0.0, fSin, fCos);
-
return kZMat * (kYMat * kXMat);
}
-
//----------------------------------------------------------------------------
void Matrix3::tridiagonal (float afDiag[3], float afSubDiag[3]) {
// Householder reduction T = Q^t M Q
@@ -1433,17 +1177,14 @@ void Matrix3::tridiagonal (float afDiag[3], float afSubDiag[3]) {
// mat, orthogonal matrix Q
// diag, diagonal entries of T
// subd, subdiagonal entries of T (T is symmetric)
-
float fA = elt[0][0];
float fB = elt[0][1];
float fC = elt[0][2];
float fD = elt[1][1];
float fE = elt[1][2];
float fF = elt[2][2];
-
afDiag[0] = fA;
afSubDiag[2] = 0.0;
-
if ( G3D::abs(fC) >= EPSILON ) {
float fLength = sqrt(fB * fB + fC * fC);
float fInvLength = 1.0 / fLength;
@@ -1479,49 +1220,35 @@ void Matrix3::tridiagonal (float afDiag[3], float afSubDiag[3]) {
elt[2][2] = 1.0;
}
}
-
//----------------------------------------------------------------------------
bool Matrix3::qLAlgorithm (float afDiag[3], float afSubDiag[3]) {
// QL iteration with implicit shifting to reduce matrix from tridiagonal
// to diagonal
-
for (int i0 = 0; i0 < 3; i0++) {
const int iMaxIter = 32;
int iIter;
-
for (iIter = 0; iIter < iMaxIter; iIter++) {
int i1;
-
for (i1 = i0; i1 <= 1; i1++) {
float fSum = G3D::abs(afDiag[i1]) +
G3D::abs(afDiag[i1 + 1]);
-
if ( G3D::abs(afSubDiag[i1]) + fSum == fSum )
break;
}
-
if ( i1 == i0 )
break;
-
float fTmp0 = (afDiag[i0 + 1] - afDiag[i0]) / (2.0 * afSubDiag[i0]);
-
float fTmp1 = sqrt(fTmp0 * fTmp0 + 1.0);
-
if ( fTmp0 < 0.0 )
fTmp0 = afDiag[i1] - afDiag[i0] + afSubDiag[i0] / (fTmp0 - fTmp1);
else
fTmp0 = afDiag[i1] - afDiag[i0] + afSubDiag[i0] / (fTmp0 + fTmp1);
-
float fSin = 1.0;
-
float fCos = 1.0;
-
float fTmp2 = 0.0;
-
for (int i2 = i1 - 1; i2 >= i0; i2--) {
float fTmp3 = fSin * afSubDiag[i2];
float fTmp4 = fCos * afSubDiag[i2];
-
if (G3D::abs(fTmp3) >= G3D::abs(fTmp0)) {
fCos = fTmp0 / fTmp3;
fTmp1 = sqrt(fCos * fCos + 1.0);
@@ -1535,13 +1262,11 @@ bool Matrix3::qLAlgorithm (float afDiag[3], float afSubDiag[3]) {
fCos = 1.0 / fTmp1;
fSin *= fCos;
}
-
fTmp0 = afDiag[i2 + 1] - fTmp2;
fTmp1 = (afDiag[i2] - fTmp0) * fSin + 2.0 * fTmp4 * fCos;
fTmp2 = fSin * fTmp1;
afDiag[i2 + 1] = fTmp0 + fTmp2;
fTmp0 = fCos * fTmp1 - fTmp4;
-
for (int iRow = 0; iRow < 3; iRow++) {
fTmp3 = elt[iRow][i2 + 1];
elt[iRow][i2 + 1] = fSin * elt[iRow][i2] +
@@ -1550,21 +1275,17 @@ bool Matrix3::qLAlgorithm (float afDiag[3], float afSubDiag[3]) {
fSin * fTmp3;
}
}
-
afDiag[i0] -= fTmp2;
afSubDiag[i0] = fTmp0;
afSubDiag[i1] = 0.0;
}
-
if ( iIter == iMaxIter ) {
// should not get here under normal circumstances
return false;
}
}
-
return true;
}
-
//----------------------------------------------------------------------------
void Matrix3::eigenSolveSymmetric (float afEigenvalue[3],
Vector3 akEigenvector[3]) const {
@@ -1572,25 +1293,20 @@ void Matrix3::eigenSolveSymmetric (float afEigenvalue[3],
float afSubDiag[3];
kMatrix.tridiagonal(afEigenvalue, afSubDiag);
kMatrix.qLAlgorithm(afEigenvalue, afSubDiag);
-
for (int i = 0; i < 3; i++) {
akEigenvector[i][0] = kMatrix[0][i];
akEigenvector[i][1] = kMatrix[1][i];
akEigenvector[i][2] = kMatrix[2][i];
}
-
// make eigenvectors form a right--handed system
Vector3 kCross = akEigenvector[1].cross(akEigenvector[2]);
-
float fDet = akEigenvector[0].dot(kCross);
-
if ( fDet < 0.0 ) {
akEigenvector[2][0] = - akEigenvector[2][0];
akEigenvector[2][1] = - akEigenvector[2][1];
akEigenvector[2][2] = - akEigenvector[2][2];
}
}
-
//----------------------------------------------------------------------------
void Matrix3::tensorProduct (const Vector3& rkU, const Vector3& rkV,
Matrix3& rkProduct) {
@@ -1600,9 +1316,7 @@ void Matrix3::tensorProduct (const Vector3& rkU, const Vector3& rkV,
}
}
}
-
//----------------------------------------------------------------------------
-
// Runs in 52 cycles on AMD, 76 cycles on Intel Centrino
//
// The loop unrolling is necessary for performance.
@@ -1625,10 +1339,8 @@ void Matrix3::_mul(const Matrix3& A, const Matrix3& B, Matrix3& out) {
ARowPtr[0] * B.elt[0][2] +
ARowPtr[1] * B.elt[1][2] +
ARowPtr[2] * B.elt[2][2];
-
ARowPtr = A.elt[1];
outRowPtr = out.elt[1];
-
outRowPtr[0] =
ARowPtr[0] * B.elt[0][0] +
ARowPtr[1] * B.elt[1][0] +
@@ -1641,10 +1353,8 @@ void Matrix3::_mul(const Matrix3& A, const Matrix3& B, Matrix3& out) {
ARowPtr[0] * B.elt[0][2] +
ARowPtr[1] * B.elt[1][2] +
ARowPtr[2] * B.elt[2][2];
-
ARowPtr = A.elt[2];
outRowPtr = out.elt[2];
-
outRowPtr[0] =
ARowPtr[0] * B.elt[0][0] +
ARowPtr[1] * B.elt[1][0] +
@@ -1658,7 +1368,6 @@ void Matrix3::_mul(const Matrix3& A, const Matrix3& B, Matrix3& out) {
ARowPtr[1] * B.elt[1][2] +
ARowPtr[2] * B.elt[2][2];
}
-
//----------------------------------------------------------------------------
void Matrix3::_transpose(const Matrix3& A, Matrix3& out) {
out[0][0] = A.elt[0][0];
@@ -1671,7 +1380,6 @@ void Matrix3::_transpose(const Matrix3& A, Matrix3& out) {
out[2][1] = A.elt[1][2];
out[2][2] = A.elt[2][2];
}
-
//-----------------------------------------------------------------------------
std::string Matrix3::toString() const {
return G3D::format("[%g, %g, %g; %g, %g, %g; %g, %g, %g]",
@@ -1680,8 +1388,5 @@ std::string Matrix3::toString() const {
elt[2][0], elt[2][1], elt[2][2]);
}
-
-
} // namespace
-
diff --git a/dep/src/g3dlite/Plane.cpp b/dep/src/g3dlite/Plane.cpp
index 10ee7ff0f0c..86ca12c934b 100644
--- a/dep/src/g3dlite/Plane.cpp
+++ b/dep/src/g3dlite/Plane.cpp
@@ -1,32 +1,24 @@
/**
@file Plane.cpp
-
@maintainer Morgan McGuire, matrix@graphics3d.com
-
@created 2003-02-06
@edited 2006-01-29
*/
-
#include "G3D/platform.h"
#include "G3D/format.h"
#include "G3D/Plane.h"
#include "G3D/stringutils.h"
-
namespace G3D {
-
Plane::Plane(
Vector4 point0,
Vector4 point1,
Vector4 point2) {
-
debugAssertM(
point0.w != 0 ||
point1.w != 0 ||
point2.w != 0,
"At least one point must be finite.");
-
// Rotate the points around so that the finite points come first.
-
while ((point0.w == 0) &&
((point1.w == 0) || (point2.w != 0))) {
Vector4 temp = point0;
@@ -34,10 +26,8 @@ Plane::Plane(
point1 = point2;
point2 = temp;
}
-
Vector3 dir1;
Vector3 dir2;
-
if (point1.w == 0) {
// 1 finite, 2 infinite points; the plane must contain
// the direction of the two direcitons
@@ -55,31 +45,25 @@ Plane::Plane(
dir1 = point1.xyz() - point0.xyz();
dir2 = point2.xyz();
}
-
_normal = dir1.cross(dir2).direction();
_distance = _normal.dot(point0.xyz());
}
-
Plane::Plane(
const Vector3& point0,
const Vector3& point1,
const Vector3& point2) {
-
_normal = (point1 - point0).cross(point2 - point0).direction();
_distance = _normal.dot(point0);
}
-
Plane::Plane(
const Vector3& __normal,
const Vector3& point) {
-
_normal = __normal.direction();
_distance = _normal.dot(point);
}
-
Plane Plane::fromEquation(float a, float b, float c, float d) {
Vector3 n(a, b, c);
float magnitude = n.magnitude();
@@ -88,25 +72,21 @@ Plane Plane::fromEquation(float a, float b, float c, float d) {
return Plane(n, -d);
}
-
void Plane::flip() {
_normal = -_normal;
_distance = -_distance;
}
-
void Plane::getEquation(Vector3& n, float& d) const {
double _d;
getEquation(n, _d);
d = (float)_d;
}
-
void Plane::getEquation(Vector3& n, double& d) const {
n = _normal;
d = -_distance;
}
-
void Plane::getEquation(float& a, float& b, float& c, float& d) const {
double _a, _b, _c, _d;
getEquation(_a, _b, _c, _d);
@@ -115,7 +95,6 @@ void Plane::getEquation(float& a, float& b, float& c, float& d) const {
c = (float)_c;
d = (float)_d;
}
-
void Plane::getEquation(double& a, double& b, double& c, double& d) const {
a = _normal.x;
b = _normal.y;
@@ -123,10 +102,8 @@ void Plane::getEquation(double& a, double& b, double& c, double& d) const {
d = -_distance;
}
-
std::string Plane::toString() const {
return format("Plane(%g, %g, %g, %g)", _normal.x, _normal.y, _normal.z, _distance);
}
-
}
diff --git a/dep/src/g3dlite/System.cpp b/dep/src/g3dlite/System.cpp
index 88fd39b52ca..c81eaa3a919 100644
--- a/dep/src/g3dlite/System.cpp
+++ b/dep/src/g3dlite/System.cpp
@@ -1,40 +1,29 @@
/**
@file System.cpp
-
@maintainer Morgan McGuire, matrix@graphics3d.com
-
Note: every routine must call init() first.
-
There are two kinds of detection used in this file. At compile
time, the _MSC_VER #define is used to determine whether x86 assembly
can be used at all. At runtime, processor detection is used to
determine if we can safely call the routines that use that assembly.
-
@cite Rob Wyatt http://www.gamasutra.com/features/wyatts_world/19990709/processor_detection_01.htm
@cite Benjamin Jurke http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-ProcessorDetectionClass&forum=cotd&id=-1
@cite Michael Herf http://www.stereopsis.com/memcpy.html
-
@created 2003-01-25
@edited 2006-05-17
*/
-
#include "G3D/platform.h"
#include "G3D/System.h"
#include "G3D/debug.h"
#include "G3D/format.h"
-
#if defined(__OpenBSD__)
#include <stdint.h>
#endif
-
#ifdef G3D_WIN32
-
#include <conio.h>
#include <sys/timeb.h>
#include "G3D/RegistryUtil.h"
-
#elif defined(G3D_LINUX)
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -46,11 +35,8 @@
#include <sys/ioctl.h>
#include <sys/time.h>
#include <pthread.h>
-
// #include <assert.h>
-
#elif defined(G3D_OSX)
-
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
@@ -62,33 +48,24 @@
#include <unistd.h>
#include <pthread.h>
#include <mach-o/arch.h>
-
#include <sstream>
#include <CoreServices/CoreServices.h>
#endif
-
#if defined(SSE)
#include <xmmintrin.h>
#endif
-
namespace G3D {
-
static char versionCstr[1024];
System::OutOfMemoryCallback System::outOfMemoryCallback = NULL;
-
void System::init() {
// Cannot use most G3D data structures or utility functions in here because
// they are not initialized.
-
static bool initialized = false;
-
if (initialized) {
return;
}
-
initialized = true;
-
if ((G3D_VER % 100) != 0) {
sprintf(versionCstr, "G3D %d.%02d beta %d",
G3D_VER / 10000,
@@ -99,36 +76,26 @@ void System::init() {
G3D_VER / 10000,
(G3D_VER / 100) % 100);
}
-
}
-
-
void System::memcpy(void* dst, const void* src, size_t numBytes) {
::memcpy(dst, src, numBytes);
}
-
void System::memset(void* dst, uint8 value, size_t numBytes) {
::memset(dst, value, numBytes);
}
-
-
-
////////////////////////////////////////////////////////////////
class BufferPool {
public:
-
/** Only store buffers up to these sizes (in bytes) in each pool->
Different pools have different management strategies.
-
A large block is preallocated for tiny buffers; they are used with
tremendous frequency. Other buffers are allocated as demanded.
*/
enum {tinyBufferSize = 128, smallBufferSize = 1024, medBufferSize = 4096};
-
/**
Most buffers we're allowed to store.
64000 * 128 = 8 MB (preallocated)
@@ -136,40 +103,31 @@ public:
1024 * 4096 = 4 MB (allocated on demand)
*/
enum {maxTinyBuffers = 64000, maxSmallBuffers = 1024, maxMedBuffers = 1024};
-
private:
-
class MemBlock {
public:
void* ptr;
size_t bytes;
-
inline MemBlock() : ptr(NULL), bytes(0) {}
inline MemBlock(void* p, size_t b) : ptr(p), bytes(b) {}
};
-
MemBlock smallPool[maxSmallBuffers];
int smallPoolSize;
-
MemBlock medPool[maxMedBuffers];
int medPoolSize;
-
/** The tiny pool is a single block of storage into which all tiny
objects are allocated. This provides better locality for
small objects and avoids the search time, since all tiny
blocks are exactly the same size. */
void* tinyPool[maxTinyBuffers];
int tinyPoolSize;
-
/** Pointer to the data in the tiny pool */
void* tinyHeap;
-
# ifdef G3D_WIN32
CRITICAL_SECTION mutex;
# else
pthread_mutex_t mutex;
# endif
-
/** Provide synchronization between threads */
void lock() {
# ifdef G3D_WIN32
@@ -178,7 +136,6 @@ private:
pthread_mutex_lock(&mutex);
# endif
}
-
void unlock() {
# ifdef G3D_WIN32
LeaveCriticalSection(&mutex);
@@ -186,7 +143,6 @@ private:
pthread_mutex_unlock(&mutex);
# endif
}
-
/**
Malloc out of the tiny heap.
*/
@@ -195,33 +151,25 @@ private:
// and create a constant size block.
(void)bytes;
debugAssert(tinyBufferSize >= bytes);
-
void* ptr = NULL;
-
if (tinyPoolSize > 0) {
--tinyPoolSize;
// Return the last one
ptr = tinyPool[tinyPoolSize];
}
-
return ptr;
}
-
/** Returns true if this is a pointer into the tiny heap. */
bool inTinyHeap(void* ptr) {
return (ptr >= tinyHeap) &&
(ptr < (uint8*)tinyHeap + maxTinyBuffers * tinyBufferSize);
}
-
void tinyFree(void* ptr) {
debugAssert(tinyPoolSize < maxTinyBuffers);
-
// Put the pointer back into the free list
tinyPool[tinyPoolSize] = ptr;
++tinyPoolSize;
-
}
-
void flushPool(MemBlock* pool, int& poolSize) {
for (int i = 0; i < poolSize; ++i) {
::free(pool->ptr);
@@ -231,43 +179,32 @@ private:
poolSize = 0;
}
-
/** Allocate out of a specific pool-> Return NULL if no suitable
memory was found.
-
*/
void* malloc(MemBlock* pool, int& poolSize, size_t bytes) {
-
// OPT: find the smallest block that satisfies the request.
-
// See if there's something we can use in the buffer pool->
// Search backwards since usually we'll re-use the last one.
for (int i = (int)poolSize - 1; i >= 0; --i) {
if (pool[i].bytes >= bytes) {
// We found a suitable entry in the pool->
-
// No need to offset the pointer; it is already offset
void* ptr = pool[i].ptr;
-
// Remove this element from the pool
--poolSize;
pool[i] = pool[poolSize];
-
return ptr;
}
}
-
return NULL;
}
-
public:
-
/** Count of memory allocations that have occurred. */
int totalMallocs;
int mallocsFromTinyPool;
int mallocsFromSmallPool;
int mallocsFromMedPool;
-
/** Amount of memory currently allocated (according to the application).
This does not count the memory still remaining in the buffer pool,
but does count extra memory required for rounding off to the size
@@ -275,24 +212,17 @@ public:
Primarily useful for detecting leaks.*/
// TODO: make me an atomic int!
int bytesAllocated;
-
BufferPool() {
totalMallocs = 0;
-
mallocsFromTinyPool = 0;
mallocsFromSmallPool = 0;
mallocsFromMedPool = 0;
-
bytesAllocated = true;
-
tinyPoolSize = 0;
tinyHeap = NULL;
-
smallPoolSize = 0;
-
medPoolSize = 0;
-
// Initialize the tiny heap as a bunch of pointers into one
// pre-allocated buffer.
tinyHeap = ::malloc(maxTinyBuffers * tinyBufferSize);
@@ -300,7 +230,6 @@ public:
tinyPool[i] = (uint8*)tinyHeap + (tinyBufferSize * i);
}
tinyPoolSize = maxTinyBuffers;
-
# ifdef G3D_WIN32
InitializeCriticalSection(&mutex);
# else
@@ -308,7 +237,6 @@ public:
# endif
}
-
~BufferPool() {
::free(tinyHeap);
# ifdef G3D_WIN32
@@ -318,35 +246,29 @@ public:
# endif
}
-
void* realloc(void* ptr, size_t bytes) {
if (ptr == NULL) {
return malloc(bytes);
}
-
if (inTinyHeap(ptr)) {
if (bytes <= tinyBufferSize) {
// The old pointer actually had enough space.
return ptr;
} else {
// Free the old pointer and malloc
-
void* newPtr = malloc(bytes);
System::memcpy(newPtr, ptr, tinyBufferSize);
tinyFree(ptr);
return newPtr;
-
}
} else {
// In one of our heaps.
-
// See how big the block really was
size_t realSize = ((uint32*)ptr)[-1];
if (bytes <= realSize) {
// The old block was big enough.
return ptr;
}
-
// Need to reallocate
void* newPtr = malloc(bytes);
System::memcpy(newPtr, ptr, realSize);
@@ -355,58 +277,43 @@ public:
}
}
-
void* malloc(size_t bytes) {
lock();
++totalMallocs;
-
if (bytes <= tinyBufferSize) {
-
void* ptr = tinyMalloc(bytes);
-
if (ptr) {
++mallocsFromTinyPool;
unlock();
return ptr;
}
-
}
-
// Failure to allocate a tiny buffer is allowed to flow
// through to a small buffer
if (bytes <= smallBufferSize) {
-
void* ptr = malloc(smallPool, smallPoolSize, bytes);
-
if (ptr) {
++mallocsFromSmallPool;
unlock();
return ptr;
}
-
} else if (bytes <= medBufferSize) {
// Note that a small allocation failure does *not* fall
// through into a medium allocation because that would
// waste the medium buffer's resources.
-
void* ptr = malloc(medPool, medPoolSize, bytes);
-
if (ptr) {
++mallocsFromMedPool;
unlock();
return ptr;
}
}
-
bytesAllocated += 4 + (int) bytes;
unlock();
-
// Heap allocate
-
// Allocate 4 extra bytes for our size header (unfortunate,
// since malloc already added its own header).
void* ptr = ::malloc(bytes + 4);
-
if (ptr == NULL) {
// Flush memory pools to try and recover space
flushPool(smallPool, smallPoolSize);
@@ -414,7 +321,6 @@ public:
ptr = ::malloc(bytes + 4);
}
-
if (ptr == NULL) {
if ((System::outOfMemoryCallback != NULL) &&
(System::outOfMemoryCallback(bytes + 4, true) == true)) {
@@ -422,7 +328,6 @@ public:
ptr = ::malloc(bytes + 4);
}
}
-
if (ptr == NULL) {
if (System::outOfMemoryCallback != NULL) {
// Notify the application
@@ -430,30 +335,23 @@ public:
}
return NULL;
}
-
*(uint32*)ptr = (uint32)bytes;
-
return (uint8*)ptr + 4;
}
-
void free(void* ptr) {
if (ptr == NULL) {
// Free does nothing on null pointers
return;
}
-
debugAssert(isValidPointer(ptr));
-
if (inTinyHeap(ptr)) {
lock();
tinyFree(ptr);
unlock();
return;
}
-
uint32 bytes = ((uint32*)ptr)[-1];
-
lock();
if (bytes <= smallBufferSize) {
if (smallPoolSize < maxSmallBuffers) {
@@ -472,19 +370,15 @@ public:
}
bytesAllocated -= bytes + 4;
unlock();
-
// Free; the buffer pools are full or this is too big to store.
::free((uint8*)ptr - 4);
}
-
std::string performance() const {
if (totalMallocs > 0) {
int pooled = mallocsFromTinyPool +
mallocsFromSmallPool +
mallocsFromMedPool;
-
int total = totalMallocs;
-
return format("malloc performance: %5.1f%% <= %db, %5.1f%% <= %db, "
"%5.1f%% <= %db, %5.1f%% > %db",
100.0 * mallocsFromTinyPool / total,
@@ -499,18 +393,15 @@ public:
return "No System::malloc calls made yet.";
}
}
-
std::string status() const {
return format("preallocated shared buffers: %5d/%d x %db",
maxTinyBuffers - tinyPoolSize, maxTinyBuffers, tinyBufferSize);
}
};
-
// Dynamically allocated because we need to ensure that
// the buffer pool is still around when the last global variable
// is deallocated.
static BufferPool* bufferpool = NULL;
-
std::string System::mallocPerformance() {
#ifndef NO_BUFFERPOOL
return bufferpool->performance();
@@ -518,7 +409,6 @@ std::string System::mallocPerformance() {
return "NO_BUFFERPOOL";
#endif
}
-
std::string System::mallocStatus() {
#ifndef NO_BUFFERPOOL
return bufferpool->status();
@@ -527,7 +417,6 @@ std::string System::mallocStatus() {
#endif
}
-
void System::resetMallocPerformanceCounters() {
#ifndef NO_BUFFERPOOL
bufferpool->totalMallocs = 0;
@@ -537,7 +426,6 @@ void System::resetMallocPerformanceCounters() {
#endif
}
-
#ifndef NO_BUFFERPOOL
inline void initMem() {
// Putting the test here ensures that the system is always
@@ -550,7 +438,6 @@ inline void initMem() {
}
#endif
-
void* System::malloc(size_t bytes) {
#ifndef NO_BUFFERPOOL
initMem();
@@ -559,7 +446,6 @@ void* System::malloc(size_t bytes) {
return ::malloc(bytes);
#endif
}
-
void* System::calloc(size_t n, size_t x) {
#ifndef NO_BUFFERPOOL
void* b = System::malloc(n * x);
@@ -570,7 +456,6 @@ void* System::calloc(size_t n, size_t x) {
#endif
}
-
void* System::realloc(void* block, size_t bytes) {
#ifndef NO_BUFFERPOOL
initMem();
@@ -580,7 +465,6 @@ void* System::realloc(void* block, size_t bytes) {
#endif
}
-
void System::free(void* p) {
#ifndef NO_BUFFERPOOL
bufferpool->free(p);
@@ -589,39 +473,30 @@ void System::free(void* p) {
#endif
}
-
void* System::alignedMalloc(size_t bytes, size_t alignment) {
alwaysAssertM(isPow2(alignment), "alignment must be a power of 2");
-
// We must align to at least a word boundary.
alignment = iMax((int)alignment, sizeof(void *));
-
// Pad the allocation size with the alignment size and the
// size of the redirect pointer.
size_t totalBytes = bytes + alignment + sizeof(intptr_t);
-
void* truePtr = System::malloc(totalBytes);
-
if (!truePtr) {
// malloc returned NULL
return NULL;
}
-
debugAssert(isValidHeapPointer(truePtr));
#ifdef G3D_WIN32
// The blocks we return will not be valid Win32 debug heap
// pointers because they are offset
// debugAssert(_CrtIsValidPointer(truePtr, totalBytes, TRUE) );
#endif
-
// The return pointer will be the next aligned location (we must at least
// leave space for the redirect pointer, however).
char* alignedPtr = ((char*)truePtr)+ sizeof(intptr_t);
-
#if 0
// 2^n - 1 has the form 1111... in binary.
uint32 bitMask = (alignment - 1);
-
// Advance forward until we reach an aligned location.
while ((((intptr_t)alignedPtr) & bitMask) != 0) {
alignedPtr += sizeof(void*);
@@ -630,42 +505,32 @@ void* System::alignedMalloc(size_t bytes, size_t alignment) {
alignedPtr += alignment - (((intptr_t)alignedPtr) & (alignment - 1));
// assert((alignedPtr - truePtr) + bytes <= totalBytes);
#endif
-
debugAssert((alignedPtr - truePtr) + bytes <= totalBytes);
-
// Immediately before the aligned location, write the true array location
// so that we can free it correctly.
intptr_t* redirectPtr = (intptr_t*)(alignedPtr - sizeof(intptr_t));
redirectPtr[0] = (intptr_t)truePtr;
-
debugAssert(isValidHeapPointer(truePtr));
-
#ifdef G3D_WIN32
debugAssert( _CrtIsValidPointer(alignedPtr, bytes, TRUE) );
#endif
return (void*)alignedPtr;
}
-
void System::alignedFree(void* _ptr) {
if (_ptr == NULL) {
return;
}
-
char* alignedPtr = (char*)_ptr;
-
// Back up one word from the pointer the user passed in.
// We now have a pointer to a pointer to the true start
// of the memory block.
intptr_t* redirectPtr = (intptr_t*)(alignedPtr - sizeof(intptr_t));
-
// Dereference that pointer so that ptr = true start
void* truePtr = (void*)(redirectPtr[0]);
-
debugAssert(isValidHeapPointer(truePtr));
System::free(truePtr);
}
-
} // namespace
diff --git a/dep/src/g3dlite/Triangle.cpp b/dep/src/g3dlite/Triangle.cpp
index bb5b8f94635..06c586aa5bc 100644
--- a/dep/src/g3dlite/Triangle.cpp
+++ b/dep/src/g3dlite/Triangle.cpp
@@ -1,113 +1,85 @@
/**
@file Triangle.cpp
-
@maintainer Morgan McGuire, graphics3d.com
-
@created 2001-04-06
@edited 2006-01-20
-
Copyright 2000-2006, Morgan McGuire.
All rights reserved.
*/
-
#include "G3D/platform.h"
#include "G3D/Triangle.h"
#include "G3D/Plane.h"
#include "G3D/AABox.h"
-
namespace G3D {
-
void Triangle::init(const Vector3& v0, const Vector3& v1, const Vector3& v2) {
-
_plane = Plane(v0, v1, v2);
_vertex[0] = v0;
_vertex[1] = v1;
_vertex[2] = v2;
-
static int next[] = {1,2,0};
-
for (int i = 0; i < 3; ++i) {
const Vector3 e = _vertex[next[i]] - _vertex[i];
edgeMagnitude[i] = e.magnitude();
-
if (edgeMagnitude[i] == 0) {
edgeDirection[i] = Vector3::zero();
} else {
edgeDirection[i] = e / (float)edgeMagnitude[i];
}
}
-
edge01 = _vertex[1] - _vertex[0];
edge02 = _vertex[2] - _vertex[0];
-
_primaryAxis = _plane.normal().primaryAxis();
_area = (float)edgeDirection[0].cross(edgeDirection[2]).magnitude() * (edgeMagnitude[0] * edgeMagnitude[2]);
-
}
-
Triangle::Triangle() {
init(Vector3::zero(), Vector3::zero(), Vector3::zero());
}
-
Triangle::Triangle(const Vector3& v0, const Vector3& v1, const Vector3& v2) {
init(v0, v1, v2);
}
-
Triangle::~Triangle() {
}
-
double Triangle::area() const {
return _area;
}
-
const Vector3& Triangle::normal() const {
return _plane.normal();
}
-
const Plane& Triangle::plane() const {
return _plane;
}
-
Vector3 Triangle::center() const {
return (_vertex[0] + _vertex[1] + _vertex[2]) / 3.0;
}
-
Vector3 Triangle::randomPoint() const {
// Choose a random point in the parallelogram
-
float s = uniformRandom();
float t = uniformRandom();
-
if (t > 1.0f - s) {
// Outside the triangle; reflect about the
// diagonal of the parallelogram
t = 1.0f - t;
s = 1.0f - s;
}
-
return edge01 * s + edge02 * t + _vertex[0];
}
-
void Triangle::getBounds(AABox& out) const {
Vector3 lo = _vertex[0];
Vector3 hi = lo;
-
for (int i = 1; i < 3; ++i) {
lo = lo.min(_vertex[i]);
hi = hi.max(_vertex[i]);
}
-
out = AABox(lo, hi);
}
-
} // G3D
diff --git a/dep/src/g3dlite/Vector3.cpp b/dep/src/g3dlite/Vector3.cpp
index 09c3003888b..3346037e868 100644
--- a/dep/src/g3dlite/Vector3.cpp
+++ b/dep/src/g3dlite/Vector3.cpp
@@ -1,16 +1,11 @@
/**
@file Vector3.cpp
-
3D vector class
-
@maintainer Morgan McGuire, matrix@graphics3d.com
-
@cite Portions based on Dave Eberly's Magic Software Library at http://www.magic-software.com
-
@created 2001-06-02
@edited 2006-01-30
*/
-
#include <limits>
#include <stdlib.h>
#include "G3D/Vector3.h"
@@ -20,11 +15,8 @@
#include "G3D/Vector3int16.h"
#include "G3D/Matrix3.h"
#include "G3D/Vector2.h"
-
namespace G3D {
-
Vector3 Vector3::dummy;
-
// Deprecated.
const Vector3 Vector3::ZERO(0, 0, 0);
const Vector3 Vector3::ZERO3(0, 0, 0);
@@ -33,18 +25,13 @@ const Vector3 Vector3::UNIT_Y(0, 1, 0);
const Vector3 Vector3::UNIT_Z(0, 0, 1);
const Vector3 Vector3::INF3((float)G3D::inf(), (float)G3D::inf(), (float)G3D::inf());
const Vector3 Vector3::NAN3((float)G3D::nan(), (float)G3D::nan(), (float)G3D::nan());
-
Vector3::Vector3(const class Vector2& v, float _z) : x(v.x), y(v.y), z(_z) {
}
-
Vector3::Axis Vector3::primaryAxis() const {
-
Axis a = X_AXIS;
-
double nx = abs(x);
double ny = abs(y);
double nz = abs(z);
-
if (nx > ny) {
if (nx > nz) {
a = X_AXIS;
@@ -58,56 +45,43 @@ Vector3::Axis Vector3::primaryAxis() const {
a = Z_AXIS;
}
}
-
return a;
}
-
unsigned int Vector3::hashCode() const {
unsigned int xhash = (*(int*)(void*)(&x));
unsigned int yhash = (*(int*)(void*)(&y));
unsigned int zhash = (*(int*)(void*)(&z));
-
return xhash + (yhash * 37) + (zhash * 101);
}
-
std::ostream& operator<<(std::ostream& os, const Vector3& v) {
return os << v.toString();
}
-
//----------------------------------------------------------------------------
-
double frand() {
return rand() / (double) RAND_MAX;
}
-
Vector3::Vector3(const class Vector3int16& v) {
x = v.x;
y = v.y;
z = v.z;
}
-
Vector3 Vector3::random() {
Vector3 result;
-
do {
result = Vector3(uniformRandom(-1.0, 1.0),
uniformRandom(-1.0, 1.0),
uniformRandom(-1.0, 1.0));
} while (result.squaredMagnitude() >= 1.0f);
-
result.unitize();
-
return result;
}
-
//----------------------------------------------------------------------------
Vector3 Vector3::operator/ (float fScalar) const {
Vector3 kQuot;
-
if ( fScalar != 0.0 ) {
float fInvScalar = 1.0f / fScalar;
kQuot.x = fInvScalar * x;
@@ -118,7 +92,6 @@ Vector3 Vector3::operator/ (float fScalar) const {
return Vector3::inf();
}
}
-
//----------------------------------------------------------------------------
Vector3& Vector3::operator/= (float fScalar) {
if (fScalar != 0.0) {
@@ -131,14 +104,11 @@ Vector3& Vector3::operator/= (float fScalar) {
y = (float)G3D::inf();
z = (float)G3D::inf();
}
-
return *this;
}
-
//----------------------------------------------------------------------------
float Vector3::unitize (float fTolerance) {
float fMagnitude = magnitude();
-
if (fMagnitude > fTolerance) {
float fInvMagnitude = 1.0f / fMagnitude;
x *= fInvMagnitude;
@@ -147,53 +117,38 @@ float Vector3::unitize (float fTolerance) {
} else {
fMagnitude = 0.0f;
}
-
return fMagnitude;
}
-
//----------------------------------------------------------------------------
-
Vector3 Vector3::reflectAbout(const Vector3& normal) const {
-
Vector3 out;
-
Vector3 N = normal.direction();
-
// 2 * normal.dot(this) * normal - this
return N * 2 * this->dot(N) - *this;
}
-
//----------------------------------------------------------------------------
#if 0
Vector3 Vector3::cosRandom(const Vector3& normal) {
double e1 = G3D::random(0, 1);
double e2 = G3D::random(0, 1);
-
// Angle from normal
double theta = acos(sqrt(e1));
-
// Angle about normal
double phi = 2 * G3D_PI * e2;
-
// Make a coordinate system
Vector3 U = normal.direction();
Vector3 V = Vector3::unitX();
-
if (abs(U.dot(V)) > .9) {
V = Vector3::unitY();
}
-
Vector3 W = U.cross(V).direction();
V = W.cross(U);
-
// Convert to rectangular form
return cos(theta) * U + sin(theta) * (cos(phi) * V + sin(phi) * W);
}
//----------------------------------------------------------------------------
-
Vector3 Vector3::hemiRandom(const Vector3& normal) {
Vector3 V = Vector3::random();
-
if (V.dot(normal) < 0) {
return -V;
} else {
@@ -202,40 +157,30 @@ Vector3 Vector3::hemiRandom(const Vector3& normal) {
}
#endif
//----------------------------------------------------------------------------
-
Vector3 Vector3::reflectionDirection(const Vector3& normal) const {
return -reflectAbout(normal).direction();
}
-
//----------------------------------------------------------------------------
-
Vector3 Vector3::refractionDirection(
const Vector3& normal,
float iInside,
float iOutside) const {
-
// From pg. 24 of Henrik Wann Jensen. Realistic Image Synthesis
// Using Photon Mapping. AK Peters. ISBN: 1568811470. July 2001.
-
// Invert the directions from Wann Jensen's formulation
// and normalize the vectors.
const Vector3 W = -direction();
Vector3 N = normal.direction();
-
float h1 = iOutside;
float h2 = iInside;
-
if (normal.dot(*this) > 0.0f) {
h1 = iInside;
h2 = iOutside;
N = -N;
}
-
const float hRatio = h1 / h2;
const float WdotN = W.dot(N);
-
float det = 1.0f - (float)square(hRatio) * (1.0f - (float)square(WdotN));
-
if (det < 0) {
// Total internal reflection
return Vector3::zero();
@@ -243,7 +188,6 @@ Vector3 Vector3::refractionDirection(
return -hRatio * (W - WdotN * N) - N * sqrt(det);
}
}
-
//----------------------------------------------------------------------------
void Vector3::orthonormalize (Vector3 akVector[3]) {
// If the input vectors are v0, v1, and v2, then the Gram-Schmidt
@@ -255,28 +199,23 @@ void Vector3::orthonormalize (Vector3 akVector[3]) {
//
// where |A| indicates length of vector A and A*B indicates dot
// product of vectors A and B.
-
// compute u0
akVector[0].unitize();
-
// compute u1
float fDot0 = akVector[0].dot(akVector[1]);
akVector[1] -= akVector[0] * fDot0;
akVector[1].unitize();
-
// compute u2
float fDot1 = akVector[1].dot(akVector[2]);
fDot0 = akVector[0].dot(akVector[2]);
akVector[2] -= akVector[0] * fDot0 + akVector[1] * fDot1;
akVector[2].unitize();
}
-
//----------------------------------------------------------------------------
void Vector3::generateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
Vector3& rkW, bool bUnitLengthW) {
if ( !bUnitLengthW )
rkW.unitize();
-
if ( G3D::abs(rkW.x) >= G3D::abs(rkW.y)
&& G3D::abs(rkW.x) >= G3D::abs(rkW.z) ) {
rkU.x = -rkW.y;
@@ -287,30 +226,23 @@ void Vector3::generateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
rkU.y = + rkW.z;
rkU.z = -rkW.y;
}
-
rkU.unitize();
rkV = rkW.cross(rkU);
}
-
//----------------------------------------------------------------------------
-
std::string Vector3::toString() const {
return G3D::format("(%g, %g, %g)", x, y, z);
}
-
//----------------------------------------------------------------------------
-
Matrix3 Vector3::cross() const {
return Matrix3( 0, -z, y,
z, 0, -x,
-y, x, 0);
}
-
//----------------------------------------------------------------------------
// 2-char swizzles
-
Vector2 Vector3::xx() const { return Vector2 (x, x); }
Vector2 Vector3::yx() const { return Vector2 (y, x); }
Vector2 Vector3::zx() const { return Vector2 (z, x); }
@@ -320,9 +252,7 @@ Vector2 Vector3::zy() const { return Vector2 (z, y); }
Vector2 Vector3::xz() const { return Vector2 (x, z); }
Vector2 Vector3::yz() const { return Vector2 (y, z); }
Vector2 Vector3::zz() const { return Vector2 (z, z); }
-
// 3-char swizzles
-
Vector3 Vector3::xxx() const { return Vector3 (x, x, x); }
Vector3 Vector3::yxx() const { return Vector3 (y, x, x); }
Vector3 Vector3::zxx() const { return Vector3 (z, x, x); }
@@ -350,9 +280,7 @@ Vector3 Vector3::zyz() const { return Vector3 (z, y, z); }
Vector3 Vector3::xzz() const { return Vector3 (x, z, z); }
Vector3 Vector3::yzz() const { return Vector3 (y, z, z); }
Vector3 Vector3::zzz() const { return Vector3 (z, z, z); }
-
// 4-char swizzles
-
Vector4 Vector3::xxxx() const { return Vector4 (x, x, x, x); }
Vector4 Vector3::yxxx() const { return Vector4 (y, x, x, x); }
Vector4 Vector3::zxxx() const { return Vector4 (z, x, x, x); }
@@ -437,8 +365,5 @@ Vector4 Vector3::zzzz() const { return Vector4 (z, z, z, z); }
-
-
-
} // namespace
diff --git a/dep/src/g3dlite/Vector4.cpp b/dep/src/g3dlite/Vector4.cpp
index 91f916d1040..fbab13ea0ae 100644
--- a/dep/src/g3dlite/Vector4.cpp
+++ b/dep/src/g3dlite/Vector4.cpp
@@ -1,12 +1,9 @@
/**
@file Vector4.cpp
-
@maintainer Morgan McGuire, matrix@graphics3d.com
-
@created 2001-07-09
@edited 2003-09-29
*/
-
#include <stdlib.h>
#include <limits>
#include "G3D/Vector4.h"
@@ -14,18 +11,14 @@
#include "G3D/g3dmath.h"
#include "G3D/format.h"
#include "G3D/stringutils.h"
-
namespace G3D {
-
unsigned int Vector4::hashCode() const {
unsigned int xhash = (*(int*)(void*)(&x));
unsigned int yhash = (*(int*)(void*)(&y));
unsigned int zhash = (*(int*)(void*)(&z));
unsigned int whash = (*(int*)(void*)(&w));
-
return xhash + (yhash * 37) + (zhash * 101) + (whash * 241);
}
-
#if 0
Vector4::Vector4(const class Color4& c) {
x = c.r;
@@ -35,7 +28,6 @@ Vector4::Vector4(const class Color4& c) {
}
#endif
-
Vector4::Vector4(const Vector2& v1, const Vector2& v2) {
x = v1.x;
y = v1.y;
@@ -43,19 +35,15 @@ Vector4::Vector4(const Vector2& v1, const Vector2& v2) {
w = v2.y;
}
-
Vector4::Vector4(const Vector2& v1, float fz, float fw) {
x = v1.x;
y = v1.y;
z = fz;
w = fw;
}
-
//----------------------------------------------------------------------------
-
Vector4 Vector4::operator/ (float fScalar) const {
Vector4 kQuot;
-
if ( fScalar != 0.0 ) {
float fInvScalar = 1.0f / fScalar;
kQuot.x = fInvScalar * x;
@@ -67,7 +55,6 @@ Vector4 Vector4::operator/ (float fScalar) const {
return Vector4::inf();
}
}
-
//----------------------------------------------------------------------------
Vector4& Vector4::operator/= (float fScalar) {
if (fScalar != 0.0f) {
@@ -79,18 +66,14 @@ Vector4& Vector4::operator/= (float fScalar) {
} else {
*this = Vector4::inf();
}
-
return *this;
}
-
//----------------------------------------------------------------------------
-
std::string Vector4::toString() const {
return G3D::format("(%g, %g, %g, %g)", x, y, z, w);
}
// 2-char swizzles
-
Vector2 Vector4::xx() const { return Vector2 (x, x); }
Vector2 Vector4::yx() const { return Vector2 (y, x); }
Vector2 Vector4::zx() const { return Vector2 (z, x); }
@@ -107,9 +90,7 @@ Vector2 Vector4::xw() const { return Vector2 (x, w); }
Vector2 Vector4::yw() const { return Vector2 (y, w); }
Vector2 Vector4::zw() const { return Vector2 (z, w); }
Vector2 Vector4::ww() const { return Vector2 (w, w); }
-
// 3-char swizzles
-
Vector3 Vector4::xxx() const { return Vector3 (x, x, x); }
Vector3 Vector4::yxx() const { return Vector3 (y, x, x); }
Vector3 Vector4::zxx() const { return Vector3 (z, x, x); }
@@ -174,9 +155,7 @@ Vector3 Vector4::xww() const { return Vector3 (x, w, w); }
Vector3 Vector4::yww() const { return Vector3 (y, w, w); }
Vector3 Vector4::zww() const { return Vector3 (z, w, w); }
Vector3 Vector4::www() const { return Vector3 (w, w, w); }
-
// 4-char swizzles
-
Vector4 Vector4::xxxx() const { return Vector4 (x, x, x, x); }
Vector4 Vector4::yxxx() const { return Vector4 (y, x, x, x); }
Vector4 Vector4::zxxx() const { return Vector4 (z, x, x, x); }
@@ -434,6 +413,5 @@ Vector4 Vector4::ywww() const { return Vector4 (y, w, w, w); }
Vector4 Vector4::zwww() const { return Vector4 (z, w, w, w); }
Vector4 Vector4::wwww() const { return Vector4 (w, w, w, w); }
-
}; // namespace
diff --git a/dep/src/g3dlite/format.cpp b/dep/src/g3dlite/format.cpp
index 13f01e26e6b..276bf4dcee1 100644
--- a/dep/src/g3dlite/format.cpp
+++ b/dep/src/g3dlite/format.cpp
@@ -1,16 +1,12 @@
/**
@file format.cpp
-
@author Morgan McGuire, graphics3d.com
-
@created 2000-09-09
@edited 2006-04-30
*/
-
#include "G3D/format.h"
#include "G3D/platform.h"
#include "G3D/System.h"
-
#ifdef G3D_WIN32
#include <math.h>
#define vsnprintf _vsnprintf
@@ -19,27 +15,21 @@
#include <stdarg.h>
#define NEWLINE "\n"
#endif
-
#ifdef _MSC_VER
// disable: "C++ exception handler used"
# pragma warning (push)
# pragma warning (disable : 4530)
#endif // _MSC_VER
-
// If your platform does not have vsnprintf, you can find a
// implementation at http://www.ijs.si/software/snprintf/
-
namespace G3D {
-
std::string format(const char* fmt,...) {
va_list argList;
va_start(argList,fmt);
std::string result = vformat(fmt, argList);
va_end(argList);
-
return result;
}
-
#if defined(G3D_WIN32) && (_MSC_VER >= 1300)
// Both MSVC6 and 7 seem to use the non-standard vsnprintf
// so we are using vscprintf to determine buffer size, however
@@ -47,22 +37,16 @@ std::string format(const char* fmt,...) {
std::string vformat(const char *fmt, va_list argPtr) {
// We draw the line at a 1MB string.
const int maxSize = 1000000;
-
// If the string is less than 161 characters,
// allocate it on the stack because this saves
// the malloc/free time.
const int bufSize = 161;
char stackBuffer[bufSize];
-
int actualSize = _vscprintf(fmt, argPtr) + 1;
-
if (actualSize > bufSize) {
-
// Now use the heap.
char* heapBuffer = NULL;
-
if (actualSize < maxSize) {
-
heapBuffer = (char*)System::malloc(maxSize + 1);
vsnprintf(heapBuffer, maxSize, fmt, argPtr);
heapBuffer[maxSize] = '\0';
@@ -70,59 +54,43 @@ std::string vformat(const char *fmt, va_list argPtr) {
heapBuffer = (char*)System::malloc(actualSize);
vsprintf(heapBuffer, fmt, argPtr);
}
-
std::string formattedString(heapBuffer);
System::free(heapBuffer);
return formattedString;
} else {
-
vsprintf(stackBuffer, fmt, argPtr);
return std::string(stackBuffer);
}
}
-
#elif defined(G3D_WIN32) && (_MSC_VER < 1300)
-
std::string vformat(const char *fmt, va_list argPtr) {
// We draw the line at a 1MB string.
const int maxSize = 1000000;
-
// If the string is less than 161 characters,
// allocate it on the stack because this saves
// the malloc/free time.
const int bufSize = 161;
char stackBuffer[bufSize];
-
int actualWritten = vsnprintf(stackBuffer, bufSize, fmt, argPtr);
-
// Not a big enough buffer, bufSize characters written
if (actualWritten == -1) {
-
int heapSize = 512;
double powSize = 1.0;
char* heapBuffer = (char*)System::malloc(heapSize);
-
while ((vsnprintf(heapBuffer, heapSize, fmt, argPtr) == -1) &&
(heapSize < maxSize)) {
-
heapSize = iCeil(heapSize * ::pow((double)2.0, powSize++));
heapBuffer = (char*)System::realloc(heapBuffer, heapSize);
}
-
heapBuffer[heapSize-1] = '\0';
-
std::string heapString(heapBuffer);
System::free(heapBuffer);
-
return heapString;
} else {
-
return std::string(stackBuffer);
}
}
-
#else
-
// glibc 2.1 has been updated to the C99 standard
std::string vformat(const char* fmt, va_list argPtr) {
// If the string is less than 161 characters,
@@ -132,41 +100,27 @@ std::string vformat(const char* fmt, va_list argPtr) {
// console (plus the null terminator).
const int bufSize = 161;
char stackBuffer[bufSize];
-
int numChars = vsnprintf(stackBuffer, bufSize, fmt, argPtr);
-
if (numChars >= bufSize) {
// We didn't allocate a big enough string.
char* heapBuffer = (char*)System::malloc((numChars + 1) * sizeof(char));
-
assert(heapBuffer);
int numChars2 = vsnprintf(heapBuffer, numChars + 1, fmt, argPtr);
assert(numChars2 == numChars);
-
std::string result(heapBuffer);
-
System::free(heapBuffer);
-
return result;
-
} else {
-
return std::string(stackBuffer);
-
}
}
-
#endif
-
} // namespace
-
#ifdef G3D_WIN32
# undef vsnprintf
#endif
-
#ifdef _MSC_VER
# pragma warning (pop)
#endif
-
#undef NEWLINE
diff --git a/dep/src/sockets/Base64.cpp b/dep/src/sockets/Base64.cpp
index cb66b93af6f..a6a6992798c 100644
--- a/dep/src/sockets/Base64.cpp
+++ b/dep/src/sockets/Base64.cpp
@@ -4,42 +4,34 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Base64.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
const char *Base64::bstr =
"ABCDEFGHIJKLMNOPQ"
"RSTUVWXYZabcdefgh"
"ijklmnopqrstuvwxy"
"z0123456789+/";
-
const char Base64::rstr[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -50,19 +42,16 @@ const char Base64::rstr[] = {
0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0};
-
Base64::Base64()
{
}
-
void Base64::encode(FILE *fil, std::string& output, bool add_crlf)
{
size_t remain;
size_t i = 0;
size_t o = 0;
char input[4];
-
output = "";
remain = fread(input,1,3,fil);
while (remain > 0)
@@ -94,18 +83,15 @@ void Base64::encode(FILE *fil, std::string& output, bool add_crlf)
}
}
-
void Base64::encode(const std::string& str_in, std::string& str_out, bool add_crlf)
{
encode(str_in.c_str(), str_in.size(), str_out, add_crlf);
}
-
void Base64::encode(const char* input,size_t l,std::string& output, bool add_crlf)
{
size_t i = 0;
size_t o = 0;
-
output = "";
while (i < l)
{
@@ -136,12 +122,10 @@ void Base64::encode(const char* input,size_t l,std::string& output, bool add_crl
}
}
-
void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool add_crlf)
{
size_t i = 0;
size_t o = 0;
-
output = "";
while (i < l)
{
@@ -172,12 +156,10 @@ void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool
}
}
-
void Base64::decode(const std::string& input,std::string& output)
{
size_t i = 0;
size_t l = input.size();
-
output = "";
while (i < l)
{
@@ -205,13 +187,11 @@ void Base64::decode(const std::string& input,std::string& output)
}
}
-
void Base64::decode(const std::string& input, unsigned char *output, size_t& sz)
{
size_t i = 0;
size_t l = input.size();
size_t j = 0;
-
while (i < l)
{
while (i < l && (input[i] == 13 || input[i] == 10))
@@ -251,7 +231,6 @@ void Base64::decode(const std::string& input, unsigned char *output, size_t& sz)
sz = j;
}
-
size_t Base64::decode_length(const std::string& str64)
{
if (str64.empty() || str64.size() % 4)
@@ -264,10 +243,8 @@ size_t Base64::decode_length(const std::string& str64)
return l;
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/Exception.cpp b/dep/src/sockets/Exception.cpp
index 33a7b4a133c..9c8a7fe3b58 100644
--- a/dep/src/sockets/Exception.cpp
+++ b/dep/src/sockets/Exception.cpp
@@ -5,17 +5,14 @@
**/
/*
Copyright (C) 2007 Anders Hedstrom
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -24,26 +21,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma warning(disable:4786)
#endif
#include "Exception.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
-
Exception::Exception(const std::string& description) : m_description(description)
{
}
-
const std::string Exception::ToString() const
{
return m_description;
}
-
#ifdef SOCKETS_NAMESPACE
} // namespace SOCKETS_NAMESPACE {
#endif
-
diff --git a/dep/src/sockets/Ipv4Address.cpp b/dep/src/sockets/Ipv4Address.cpp
index b89cc2a449b..edd56ece048 100644
--- a/dep/src/sockets/Ipv4Address.cpp
+++ b/dep/src/sockets/Ipv4Address.cpp
@@ -5,17 +5,14 @@
**/
/*
Copyright (C) 2007 Anders Hedstrom
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -27,13 +24,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <netdb.h>
#endif
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
-
Ipv4Address::Ipv4Address(port_t port) : m_valid(true)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -41,7 +35,6 @@ Ipv4Address::Ipv4Address(port_t port) : m_valid(true)
m_addr.sin_port = htons( port );
}
-
Ipv4Address::Ipv4Address(ipaddr_t a,port_t port) : m_valid(true)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -50,7 +43,6 @@ Ipv4Address::Ipv4Address(ipaddr_t a,port_t port) : m_valid(true)
memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr));
}
-
Ipv4Address::Ipv4Address(struct in_addr& a,port_t port) : m_valid(true)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -59,7 +51,6 @@ Ipv4Address::Ipv4Address(struct in_addr& a,port_t port) : m_valid(true)
m_addr.sin_addr = a;
}
-
Ipv4Address::Ipv4Address(const std::string& host,port_t port) : m_valid(false)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -75,43 +66,36 @@ Ipv4Address::Ipv4Address(const std::string& host,port_t port) : m_valid(false)
}
}
-
Ipv4Address::Ipv4Address(struct sockaddr_in& sa)
{
m_addr = sa;
m_valid = sa.sin_family == AF_INET;
}
-
Ipv4Address::~Ipv4Address()
{
}
-
Ipv4Address::operator struct sockaddr *()
{
return (struct sockaddr *)&m_addr;
}
-
Ipv4Address::operator socklen_t()
{
return sizeof(struct sockaddr_in);
}
-
void Ipv4Address::SetPort(port_t port)
{
m_addr.sin_port = htons( port );
}
-
port_t Ipv4Address::GetPort()
{
return ntohs( m_addr.sin_port );
}
-
bool Ipv4Address::Resolve(const std::string& hostname,struct in_addr& a)
{
struct sockaddr_in sa;
@@ -129,7 +113,6 @@ bool Ipv4Address::Resolve(const std::string& hostname,struct in_addr& a)
return true;
}
-
bool Ipv4Address::Reverse(struct in_addr& a,std::string& name)
{
struct sockaddr_in sa;
@@ -139,7 +122,6 @@ bool Ipv4Address::Reverse(struct in_addr& a,std::string& name)
return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name);
}
-
std::string Ipv4Address::Convert(bool include_port)
{
if (include_port)
@@ -147,7 +129,6 @@ std::string Ipv4Address::Convert(bool include_port)
return Convert(m_addr.sin_addr);
}
-
std::string Ipv4Address::Convert(struct in_addr& a)
{
struct sockaddr_in sa;
@@ -159,25 +140,21 @@ std::string Ipv4Address::Convert(struct in_addr& a)
return name;
}
-
void Ipv4Address::SetAddress(struct sockaddr *sa)
{
memcpy(&m_addr, sa, sizeof(struct sockaddr_in));
}
-
int Ipv4Address::GetFamily()
{
return m_addr.sin_family;
}
-
bool Ipv4Address::IsValid()
{
return m_valid;
}
-
bool Ipv4Address::operator==(SocketAddress& a)
{
if (a.GetFamily() != GetFamily())
@@ -193,13 +170,11 @@ bool Ipv4Address::operator==(SocketAddress& a)
return true;
}
-
std::auto_ptr<SocketAddress> Ipv4Address::GetCopy()
{
return std::auto_ptr<SocketAddress>(new Ipv4Address(m_addr));
}
-
std::string Ipv4Address::Reverse()
{
std::string tmp;
@@ -207,9 +182,7 @@ std::string Ipv4Address::Reverse()
return tmp;
}
-
#ifdef SOCKETS_NAMESPACE
} // namespace SOCKETS_NAMESPACE {
#endif
-
diff --git a/dep/src/sockets/Ipv6Address.cpp b/dep/src/sockets/Ipv6Address.cpp
index 6c92de24871..3e6d4b09805 100644
--- a/dep/src/sockets/Ipv6Address.cpp
+++ b/dep/src/sockets/Ipv6Address.cpp
@@ -5,36 +5,30 @@
**/
/*
Copyright (C) 2007 Anders Hedstrom
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Ipv6Address.h"
#ifdef ENABLE_IPV6
-
#include "Utility.h"
#include "Parse.h"
#ifndef _WIN32
#include <netdb.h>
#endif
#ifdef IPPROTO_IPV6
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
Ipv6Address::Ipv6Address(port_t port) : m_valid(true)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -42,7 +36,6 @@ Ipv6Address::Ipv6Address(port_t port) : m_valid(true)
m_addr.sin6_port = htons( port );
}
-
Ipv6Address::Ipv6Address(struct in6_addr& a,port_t port) : m_valid(true)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -51,7 +44,6 @@ Ipv6Address::Ipv6Address(struct in6_addr& a,port_t port) : m_valid(true)
m_addr.sin6_addr = a;
}
-
Ipv6Address::Ipv6Address(const std::string& host,port_t port) : m_valid(false)
{
memset(&m_addr, 0, sizeof(m_addr));
@@ -67,43 +59,36 @@ Ipv6Address::Ipv6Address(const std::string& host,port_t port) : m_valid(false)
}
}
-
Ipv6Address::Ipv6Address(struct sockaddr_in6& sa)
{
m_addr = sa;
m_valid = sa.sin6_family == AF_INET6;
}
-
Ipv6Address::~Ipv6Address()
{
}
-
Ipv6Address::operator struct sockaddr *()
{
return (struct sockaddr *)&m_addr;
}
-
Ipv6Address::operator socklen_t()
{
return sizeof(struct sockaddr_in6);
}
-
void Ipv6Address::SetPort(port_t port)
{
m_addr.sin6_port = htons( port );
}
-
port_t Ipv6Address::GetPort()
{
return ntohs( m_addr.sin6_port );
}
-
bool Ipv6Address::Resolve(const std::string& hostname,struct in6_addr& a)
{
struct sockaddr_in6 sa;
@@ -121,7 +106,6 @@ bool Ipv6Address::Resolve(const std::string& hostname,struct in6_addr& a)
return true;
}
-
bool Ipv6Address::Reverse(struct in6_addr& a,std::string& name)
{
struct sockaddr_in6 sa;
@@ -131,7 +115,6 @@ bool Ipv6Address::Reverse(struct in6_addr& a,std::string& name)
return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name);
}
-
std::string Ipv6Address::Convert(bool include_port)
{
if (include_port)
@@ -139,7 +122,6 @@ std::string Ipv6Address::Convert(bool include_port)
return Convert(m_addr.sin6_addr);
}
-
std::string Ipv6Address::Convert(struct in6_addr& a,bool mixed)
{
char slask[100]; // l2ip temporary
@@ -187,51 +169,43 @@ std::string Ipv6Address::Convert(struct in6_addr& a,bool mixed)
return slask;
}
-
void Ipv6Address::SetAddress(struct sockaddr *sa)
{
memcpy(&m_addr, sa, sizeof(struct sockaddr_in6));
}
-
int Ipv6Address::GetFamily()
{
return m_addr.sin6_family;
}
-
void Ipv6Address::SetFlowinfo(uint32_t x)
{
m_addr.sin6_flowinfo = x;
}
-
uint32_t Ipv6Address::GetFlowinfo()
{
return m_addr.sin6_flowinfo;
}
-
#ifndef _WIN32
void Ipv6Address::SetScopeId(uint32_t x)
{
m_addr.sin6_scope_id = x;
}
-
uint32_t Ipv6Address::GetScopeId()
{
return m_addr.sin6_scope_id;
}
#endif
-
bool Ipv6Address::IsValid()
{
return m_valid;
}
-
bool Ipv6Address::operator==(SocketAddress& a)
{
if (a.GetFamily() != GetFamily())
@@ -247,13 +221,11 @@ bool Ipv6Address::operator==(SocketAddress& a)
return true;
}
-
std::auto_ptr<SocketAddress> Ipv6Address::GetCopy()
{
return std::auto_ptr<SocketAddress>(new Ipv6Address(m_addr));
}
-
std::string Ipv6Address::Reverse()
{
std::string tmp;
@@ -261,11 +233,9 @@ std::string Ipv6Address::Reverse()
return tmp;
}
-
#ifdef SOCKETS_NAMESPACE
} // namespace SOCKETS_NAMESPACE {
#endif
#endif // IPPROTO_IPV6
#endif // ENABLE_IPV6
-
diff --git a/dep/src/sockets/Lock.cpp b/dep/src/sockets/Lock.cpp
index 597ca30afc6..1abda3bebeb 100644
--- a/dep/src/sockets/Lock.cpp
+++ b/dep/src/sockets/Lock.cpp
@@ -4,53 +4,42 @@
**/
/*
Copyright (C) 2005,2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Mutex.h"
#include "Lock.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
Lock::Lock(Mutex& m) : m_mutex(m)
{
m_mutex.Lock();
}
-
Lock::~Lock()
{
m_mutex.Unlock();
}
-
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/Mutex.cpp b/dep/src/sockets/Mutex.cpp
index 3bfe64d04c7..4f6ec98b5e1 100644
--- a/dep/src/sockets/Mutex.cpp
+++ b/dep/src/sockets/Mutex.cpp
@@ -4,36 +4,29 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Mutex.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
Mutex::Mutex()
{
#ifdef _WIN32
@@ -43,7 +36,6 @@ Mutex::Mutex()
#endif
}
-
Mutex::~Mutex()
{
#ifdef _WIN32
@@ -53,7 +45,6 @@ Mutex::~Mutex()
#endif
}
-
void Mutex::Lock()
{
#ifdef _WIN32
@@ -64,7 +55,6 @@ void Mutex::Lock()
#endif
}
-
void Mutex::Unlock()
{
#ifdef _WIN32
@@ -74,9 +64,7 @@ void Mutex::Unlock()
#endif
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/Parse.cpp b/dep/src/sockets/Parse.cpp
index ccbd553b0e6..b0d51e187c8 100644
--- a/dep/src/sockets/Parse.cpp
+++ b/dep/src/sockets/Parse.cpp
@@ -2,45 +2,35 @@
**
** Written: 1999-Feb-10 grymse@alhem.net
**/
-
/*
Copyright (C) 1999-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <string.h>
-
#include "Parse.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
/* implementation of class Parse */
-
Parse::Parse()
:pa_the_str("")
,pa_splits("")
@@ -53,7 +43,6 @@ Parse::Parse()
,pa_quote(false)
{
}
-
Parse::Parse(const std::string&s)
:pa_the_str(s)
,pa_splits("")
@@ -66,7 +55,6 @@ Parse::Parse(const std::string&s)
,pa_quote(false)
{
}
-
Parse::Parse(const std::string&s,const std::string&sp)
:pa_the_str(s)
,pa_splits(sp)
@@ -79,7 +67,6 @@ Parse::Parse(const std::string&s,const std::string&sp)
,pa_quote(false)
{
}
-
Parse::Parse(const std::string&s,const std::string&sp,short /*nospace*/)
:pa_the_str(s)
,pa_splits(sp)
@@ -93,13 +80,10 @@ Parse::Parse(const std::string&s,const std::string&sp,short /*nospace*/)
{
}
-
Parse::~Parse()
{
}
-
#define C ((pa_the_ptr<pa_the_str.size()) ? pa_the_str[pa_the_ptr] : 0)
-
short Parse::issplit(const char c)
{
for (size_t i = 0; i < pa_splits.size(); i++)
@@ -107,11 +91,9 @@ short Parse::issplit(const char c)
return 1;
return 0;
}
-
void Parse::getsplit()
{
size_t x;
-
if (C == '=')
{
x = pa_the_ptr++;
@@ -127,14 +109,12 @@ void Parse::getsplit()
pa_the_ptr++;
pa_ord = (x < pa_the_str.size()) ? pa_the_str.substr(x,pa_the_ptr - x) : "";
}
-
std::string Parse::getword()
{
size_t x;
int disabled = 0;
int quote = 0;
int rem = 0;
-
if (pa_nospace)
{
while (C && issplit(C))
@@ -210,18 +190,15 @@ std::string Parse::getword()
}
return pa_ord;
}
-
void Parse::getword(std::string&s)
{
s = Parse::getword();
}
-
void Parse::getsplit(std::string&s)
{
Parse::getsplit();
s = pa_ord;
}
-
void Parse::getword(std::string&s,std::string&fill,int l)
{
Parse::getword();
@@ -230,7 +207,6 @@ void Parse::getword(std::string&s,std::string&fill,int l)
s += fill;
s += pa_ord;
}
-
std::string Parse::getrest()
{
std::string s;
@@ -239,29 +215,24 @@ std::string Parse::getrest()
s = (pa_the_ptr < pa_the_str.size()) ? pa_the_str.substr(pa_the_ptr) : "";
return s;
}
-
void Parse::getrest(std::string&s)
{
while (C && (C == ' ' || C == 9 || issplit(C)))
pa_the_ptr++;
s = (pa_the_ptr < pa_the_str.size()) ? pa_the_str.substr(pa_the_ptr) : "";
}
-
long Parse::getvalue()
{
Parse::getword();
return atol(pa_ord.c_str());
}
-
void Parse::setbreak(const char c)
{
pa_breakchar = c;
}
-
int Parse::getwordlen()
{
size_t x,y = pa_the_ptr,len;
-
if (C == pa_breakchar && pa_breakchar)
{
x = pa_the_ptr++;
@@ -279,23 +250,19 @@ int Parse::getwordlen()
pa_the_ptr = y;
return (int)len;
}
-
int Parse::getrestlen()
{
size_t y = pa_the_ptr;
size_t len;
-
while (C && (C == ' ' || C == 9 || issplit(C)))
pa_the_ptr++;
len = strlen(pa_the_str.c_str() + pa_the_ptr);
pa_the_ptr = y;
return (int)len;
}
-
void Parse::getline()
{
size_t x;
-
x = pa_the_ptr;
while (C && C != 13 && C != 10)
pa_the_ptr++;
@@ -305,13 +272,11 @@ void Parse::getline()
if (C == 10)
pa_the_ptr++;
}
-
void Parse::getline(std::string&s)
{
getline();
s = pa_ord;
}
-
/* end of implementation of class Parse */
/***************************************************/
#ifdef SOCKETS_NAMESPACE
@@ -319,4 +284,3 @@ void Parse::getline(std::string&s)
#endif
-
diff --git a/dep/src/sockets/ResolvServer.cpp b/dep/src/sockets/ResolvServer.cpp
index 492d6705080..07a27c6fc06 100644
--- a/dep/src/sockets/ResolvServer.cpp
+++ b/dep/src/sockets/ResolvServer.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -36,12 +31,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ListenSocket.h"
#include "ResolvSocket.h"
#include "SocketHandler.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
ResolvServer::ResolvServer(port_t port)
:Thread()
,m_quit(false)
@@ -50,24 +43,20 @@ ResolvServer::ResolvServer(port_t port)
{
}
-
ResolvServer::~ResolvServer()
{
}
-
void ResolvServer::Run()
{
// StdoutLog log;
SocketHandler h;
ListenSocket<ResolvSocket> l(h);
-
if (l.Bind("127.0.0.1", m_port))
{
return;
}
h.Add(&l);
-
m_ready = true;
while (!m_quit && IsRunning() )
{
@@ -76,23 +65,18 @@ void ResolvServer::Run()
SetRunning(false);
}
-
void ResolvServer::Quit()
{
m_quit = true;
}
-
bool ResolvServer::Ready()
{
return m_ready;
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
#endif // ENABLE_RESOLVER
-
diff --git a/dep/src/sockets/ResolvSocket.cpp b/dep/src/sockets/ResolvSocket.cpp
index 236e93f9704..f97be03cd06 100644
--- a/dep/src/sockets/ResolvSocket.cpp
+++ b/dep/src/sockets/ResolvSocket.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -42,24 +37,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ISocketHandler.h"
#include "Lock.h"
#include "Mutex.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
//#ifdef _DEBUG
//#define DEB(x) x
//#else
#define DEB(x)
//#endif
-
// static
ResolvSocket::cache_t ResolvSocket::m_cache;
ResolvSocket::timeout_t ResolvSocket::m_cache_to;
Mutex ResolvSocket::m_cache_mutex;
-
ResolvSocket::ResolvSocket(ISocketHandler& h)
:TcpSocket(h)
,m_bServer(false)
@@ -72,7 +63,6 @@ ResolvSocket::ResolvSocket(ISocketHandler& h)
SetLineProtocol();
}
-
ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, const std::string& host, port_t port, bool ipv6)
:TcpSocket(h)
,m_bServer(false)
@@ -87,7 +77,6 @@ ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, const std::string&
SetLineProtocol();
}
-
ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, ipaddr_t a)
:TcpSocket(h)
,m_bServer(false)
@@ -102,7 +91,6 @@ ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, ipaddr_t a)
SetLineProtocol();
}
-
#ifdef ENABLE_IPV6
ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, in6_addr& a)
:TcpSocket(h)
@@ -117,12 +105,10 @@ ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, in6_addr& a)
}
#endif
-
ResolvSocket::~ResolvSocket()
{
}
-
void ResolvSocket::OnLine(const std::string& line)
{
Parse pa(line, ":");
@@ -184,7 +170,6 @@ DEB(fprintf(stderr, " *** Returning cache for [%s][%s] = '%s'\n", m_query.c_str(
std::string key = pa.getword();
std::string value = pa.getrest();
DEB( fprintf(stderr, " *** ResolvSocket response; %s: %s\n", key.c_str(), value.c_str());)
-
if (key == "Cached")
{
m_cached = true;
@@ -268,7 +253,6 @@ DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(),
#endif
}
-
void ResolvSocket::OnDetached()
{
DEB( fprintf(stderr, " *** ResolvSocket::OnDetached(); query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
@@ -370,7 +354,6 @@ DEB( fprintf(stderr, " *** ResolvSocket::OnDetached(); query=%s, data=%s\n",
SetCloseAndDelete();
}
-
void ResolvSocket::OnConnect()
{
if (!m_resolv_host.empty())
@@ -405,7 +388,6 @@ void ResolvSocket::OnConnect()
Send( msg );
}
-
void ResolvSocket::OnDelete()
{
if (m_parent)
@@ -427,11 +409,8 @@ DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(),
}
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
#endif // ENABLE_RESOLVER
-
diff --git a/dep/src/sockets/Socket.cpp b/dep/src/sockets/Socket.cpp
index bf1a73abf6e..a0544c37db5 100644
--- a/dep/src/sockets/Socket.cpp
+++ b/dep/src/sockets/Socket.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -39,34 +34,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#include <ctype.h>
#include <fcntl.h>
-
#include "ISocketHandler.h"
#include "Utility.h"
-
#include "SocketAddress.h"
#include "SocketHandler.h"
#ifdef ENABLE_EXCEPTIONS
#include "Exception.h"
#endif
#include "Ipv4Address.h"
-
//#ifdef _DEBUG
//#define DEB(x) x; fflush(stderr);
//#else
#define DEB(x)
//#endif
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
// statics
#ifdef _WIN32
WSAInitializer Socket::m_winsock_init;
#endif
-
Socket::Socket(ISocketHandler& h)
//:m_flags(0)
:m_handler(h)
@@ -111,7 +100,6 @@ Socket::Socket(ISocketHandler& h)
{
}
-
Socket::~Socket()
{
Handler().Remove(this);
@@ -125,22 +113,18 @@ Socket::~Socket()
}
}
-
void Socket::Init()
{
}
-
void Socket::OnRead()
{
}
-
void Socket::OnWrite()
{
}
-
void Socket::OnException()
{
// %! exception doesn't always mean something bad happened, this code should be reworked
@@ -150,22 +134,18 @@ void Socket::OnException()
SetCloseAndDelete();
}
-
void Socket::OnDelete()
{
}
-
void Socket::OnConnect()
{
}
-
void Socket::OnAccept()
{
}
-
int Socket::Close()
{
if (m_socket == INVALID_SOCKET) // this could happen
@@ -191,12 +171,10 @@ int Socket::Close()
return n;
}
-
SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol)
{
struct protoent *p = NULL;
SOCKET s;
-
#ifdef ENABLE_POOL
m_socket_type = type;
m_socket_protocol = protocol;
@@ -215,7 +193,6 @@ SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol)
}
}
int protno = p ? p -> p_proto : 0;
-
s = socket(af, type, protno);
if (s == INVALID_SOCKET)
{
@@ -232,31 +209,26 @@ SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol)
return s;
}
-
void Socket::Attach(SOCKET s)
{
m_socket = s;
}
-
SOCKET Socket::GetSocket()
{
return m_socket;
}
-
void Socket::SetDeleteByHandler(bool x)
{
m_bDel = x;
}
-
bool Socket::DeleteByHandler()
{
return m_bDel;
}
-
void Socket::SetCloseAndDelete(bool x)
{
if (x != m_bClose)
@@ -270,25 +242,21 @@ void Socket::SetCloseAndDelete(bool x)
}
}
-
bool Socket::CloseAndDelete()
{
return m_bClose;
}
-
void Socket::SetRemoteAddress(SocketAddress& ad) //struct sockaddr* sa, socklen_t l)
{
m_remote_address = ad.GetCopy();
}
-
std::auto_ptr<SocketAddress> Socket::GetRemoteSocketAddress()
{
return m_remote_address -> GetCopy();
}
-
ISocketHandler& Socket::Handler() const
{
#ifdef ENABLE_DETACH
@@ -298,13 +266,11 @@ ISocketHandler& Socket::Handler() const
return m_handler;
}
-
ISocketHandler& Socket::MasterHandler() const
{
return m_handler;
}
-
ipaddr_t Socket::GetRemoteIP4()
{
ipaddr_t l = 0;
@@ -323,7 +289,6 @@ ipaddr_t Socket::GetRemoteIP4()
return l;
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
struct in6_addr Socket::GetRemoteIP6()
@@ -347,7 +312,6 @@ struct in6_addr Socket::GetRemoteIP6()
#endif
#endif
-
port_t Socket::GetRemotePort()
{
if (!m_remote_address.get())
@@ -357,7 +321,6 @@ port_t Socket::GetRemotePort()
return m_remote_address -> GetPort();
}
-
std::string Socket::GetRemoteAddress()
{
if (!m_remote_address.get())
@@ -367,7 +330,6 @@ std::string Socket::GetRemoteAddress()
return m_remote_address -> Convert(false);
}
-
std::string Socket::GetRemoteHostname()
{
if (!m_remote_address.get())
@@ -377,7 +339,6 @@ std::string Socket::GetRemoteHostname()
return m_remote_address -> Reverse();
}
-
bool Socket::SetNonblocking(bool bNb)
{
#ifdef _WIN32
@@ -410,7 +371,6 @@ bool Socket::SetNonblocking(bool bNb)
#endif
}
-
bool Socket::SetNonblocking(bool bNb, SOCKET s)
{
#ifdef _WIN32
@@ -443,13 +403,11 @@ bool Socket::SetNonblocking(bool bNb, SOCKET s)
#endif
}
-
void Socket::Set(bool bRead, bool bWrite, bool bException)
{
Handler().Set(m_socket, bRead, bWrite, bException);
}
-
bool Socket::Ready()
{
if (m_socket != INVALID_SOCKET && !CloseAndDelete())
@@ -457,138 +415,115 @@ bool Socket::Ready()
return false;
}
-
void Socket::OnLine(const std::string& )
{
}
-
void Socket::OnConnectFailed()
{
}
-
Socket *Socket::GetParent()
{
return m_parent;
}
-
void Socket::SetParent(Socket *x)
{
m_parent = x;
}
-
port_t Socket::GetPort()
{
Handler().LogError(this, "GetPort", 0, "GetPort only implemented for ListenSocket", LOG_LEVEL_WARNING);
return 0;
}
-
bool Socket::OnConnectRetry()
{
return true;
}
-
#ifdef ENABLE_RECONNECT
void Socket::OnReconnect()
{
}
#endif
-
time_t Socket::Uptime()
{
return time(NULL) - m_tCreate;
}
-
#ifdef ENABLE_IPV6
void Socket::SetIpv6(bool x)
{
m_ipv6 = x;
}
-
bool Socket::IsIpv6()
{
return m_ipv6;
}
#endif
-
void Socket::DisableRead(bool x)
{
m_b_disable_read = x;
}
-
bool Socket::IsDisableRead()
{
return m_b_disable_read;
}
-
void Socket::SendBuf(const char *,size_t,int)
{
}
-
void Socket::Send(const std::string&,int)
{
}
-
void Socket::SetConnected(bool x)
{
m_connected = x;
}
-
bool Socket::IsConnected()
{
return m_connected;
}
-
void Socket::OnDisconnect()
{
}
-
void Socket::SetLost()
{
m_bLost = true;
}
-
bool Socket::Lost()
{
return m_bLost;
}
-
void Socket::SetErasedByHandler(bool x)
{
m_b_erased_by_handler = x;
}
-
bool Socket::ErasedByHandler()
{
return m_b_erased_by_handler;
}
-
time_t Socket::TimeSinceClose()
{
return time(NULL) - m_tClose;
}
-
void Socket::SetClientRemoteAddress(SocketAddress& ad)
{
if (!ad.IsValid())
@@ -598,7 +533,6 @@ void Socket::SetClientRemoteAddress(SocketAddress& ad)
m_client_remote_address = ad.GetCopy();
}
-
std::auto_ptr<SocketAddress> Socket::GetClientRemoteAddress()
{
if (!m_client_remote_address.get())
@@ -608,83 +542,69 @@ std::auto_ptr<SocketAddress> Socket::GetClientRemoteAddress()
return m_client_remote_address -> GetCopy();
}
-
uint64_t Socket::GetBytesSent(bool)
{
return 0;
}
-
uint64_t Socket::GetBytesReceived(bool)
{
return 0;
}
-
#ifdef HAVE_OPENSSL
void Socket::OnSSLConnect()
{
}
-
void Socket::OnSSLAccept()
{
}
-
bool Socket::SSLNegotiate()
{
return false;
}
-
bool Socket::IsSSL()
{
return m_b_enable_ssl;
}
-
void Socket::EnableSSL(bool x)
{
m_b_enable_ssl = x;
}
-
bool Socket::IsSSLNegotiate()
{
return m_b_ssl;
}
-
void Socket::SetSSLNegotiate(bool x)
{
m_b_ssl = x;
}
-
bool Socket::IsSSLServer()
{
return m_b_ssl_server;
}
-
void Socket::SetSSLServer(bool x)
{
m_b_ssl_server = x;
}
-
void Socket::OnSSLConnectFailed()
{
}
-
void Socket::OnSSLAcceptFailed()
{
}
#endif // HAVE_OPENSSL
-
#ifdef ENABLE_POOL
void Socket::CopyConnection(Socket *sock)
{
@@ -694,132 +614,110 @@ void Socket::CopyConnection(Socket *sock)
#endif
SetSocketType( sock -> GetSocketType() );
SetSocketProtocol( sock -> GetSocketProtocol() );
-
SetClientRemoteAddress( *sock -> GetClientRemoteAddress() );
SetRemoteAddress( *sock -> GetRemoteSocketAddress() );
}
-
void Socket::SetIsClient()
{
m_bClient = true;
}
-
void Socket::SetSocketType(int x)
{
m_socket_type = x;
}
-
int Socket::GetSocketType()
{
return m_socket_type;
}
-
void Socket::SetSocketProtocol(const std::string& x)
{
m_socket_protocol = x;
}
-
const std::string& Socket::GetSocketProtocol()
{
return m_socket_protocol;
}
-
void Socket::SetRetain()
{
if (m_bClient) m_bRetain = true;
}
-
bool Socket::Retain()
{
return m_bRetain;
}
-
#endif // ENABLE_POOL
-
#ifdef ENABLE_SOCKS4
void Socket::OnSocks4Connect()
{
Handler().LogError(this, "OnSocks4Connect", 0, "Use with TcpSocket only");
}
-
void Socket::OnSocks4ConnectFailed()
{
Handler().LogError(this, "OnSocks4ConnectFailed", 0, "Use with TcpSocket only");
}
-
bool Socket::OnSocks4Read()
{
Handler().LogError(this, "OnSocks4Read", 0, "Use with TcpSocket only");
return true;
}
-
void Socket::SetSocks4Host(const std::string& host)
{
Utility::u2ip(host, m_socks4_host);
}
-
bool Socket::Socks4()
{
return m_bSocks4;
}
-
void Socket::SetSocks4(bool x)
{
m_bSocks4 = x;
}
-
void Socket::SetSocks4Host(ipaddr_t a)
{
m_socks4_host = a;
}
-
void Socket::SetSocks4Port(port_t p)
{
m_socks4_port = p;
}
-
void Socket::SetSocks4Userid(const std::string& x)
{
m_socks4_userid = x;
}
-
ipaddr_t Socket::GetSocks4Host()
{
return m_socks4_host;
}
-
port_t Socket::GetSocks4Port()
{
return m_socks4_port;
}
-
const std::string& Socket::GetSocks4Userid()
{
return m_socks4_userid;
}
#endif // ENABLE_SOCKS4
-
#ifdef ENABLE_DETACH
bool Socket::Detach()
{
@@ -833,7 +731,6 @@ bool Socket::Detach()
return true;
}
-
void Socket::DetachSocket()
{
SetDetached();
@@ -841,43 +738,36 @@ void Socket::DetachSocket()
m_pThread -> SetRelease(true);
}
-
void Socket::OnDetached()
{
}
-
void Socket::SetDetach(bool x)
{
Handler().AddList(m_socket, LIST_DETACH, x);
m_detach = x;
}
-
bool Socket::IsDetach()
{
return m_detach;
}
-
void Socket::SetDetached(bool x)
{
m_detached = x;
}
-
const bool Socket::IsDetached() const
{
return m_detached;
}
-
void Socket::SetSlaveHandler(ISocketHandler *p)
{
m_slave_handler = p;
}
-
Socket::SocketThread::SocketThread(Socket *p)
:Thread(false)
,m_socket(p)
@@ -885,7 +775,6 @@ Socket::SocketThread::SocketThread(Socket *p)
// Creator will release
}
-
Socket::SocketThread::~SocketThread()
{
if (IsRunning())
@@ -900,7 +789,6 @@ Socket::SocketThread::~SocketThread()
}
}
-
void Socket::SocketThread::Run()
{
SocketHandler h;
@@ -919,14 +807,12 @@ void Socket::SocketThread::Run()
}
#endif // ENABLE_DETACH
-
#ifdef ENABLE_RESOLVER
int Socket::Resolve(const std::string& host,port_t port)
{
return Handler().Resolve(this, host, port);
}
-
#ifdef ENABLE_IPV6
int Socket::Resolve6(const std::string& host,port_t port)
{
@@ -934,13 +820,11 @@ int Socket::Resolve6(const std::string& host,port_t port)
}
#endif
-
int Socket::Resolve(ipaddr_t a)
{
return Handler().Resolve(this, a);
}
-
#ifdef ENABLE_IPV6
int Socket::Resolve(in6_addr& a)
{
@@ -948,33 +832,27 @@ int Socket::Resolve(in6_addr& a)
}
#endif
-
void Socket::OnResolved(int,ipaddr_t,port_t)
{
}
-
#ifdef ENABLE_IPV6
void Socket::OnResolved(int,in6_addr&,port_t)
{
}
#endif
-
void Socket::OnReverseResolved(int,const std::string&)
{
}
-
void Socket::OnResolveFailed(int)
{
}
#endif // ENABLE_RESOLVER
-
/* IP options */
-
bool Socket::SetIpOptions(const void *p, socklen_t len)
{
#ifdef IP_OPTIONS
@@ -990,7 +868,6 @@ bool Socket::SetIpOptions(const void *p, socklen_t len)
#endif
}
-
#ifdef IP_PKTINFO
bool Socket::SetIpPktinfo(bool x)
{
@@ -1004,7 +881,6 @@ bool Socket::SetIpPktinfo(bool x)
}
#endif
-
#ifdef IP_RECVTOS
bool Socket::SetIpRecvTOS(bool x)
{
@@ -1018,7 +894,6 @@ bool Socket::SetIpRecvTOS(bool x)
}
#endif
-
#ifdef IP_RECVTTL
bool Socket::SetIpRecvTTL(bool x)
{
@@ -1032,7 +907,6 @@ bool Socket::SetIpRecvTTL(bool x)
}
#endif
-
#ifdef IP_RECVOPTS
bool Socket::SetIpRecvopts(bool x)
{
@@ -1046,7 +920,6 @@ bool Socket::SetIpRecvopts(bool x)
}
#endif
-
#ifdef IP_RETOPTS
bool Socket::SetIpRetopts(bool x)
{
@@ -1060,7 +933,6 @@ bool Socket::SetIpRetopts(bool x)
}
#endif
-
bool Socket::SetIpTOS(unsigned char tos)
{
#ifdef IP_TOS
@@ -1076,7 +948,6 @@ bool Socket::SetIpTOS(unsigned char tos)
#endif
}
-
unsigned char Socket::IpTOS()
{
unsigned char tos = 0;
@@ -1092,7 +963,6 @@ unsigned char Socket::IpTOS()
return tos;
}
-
bool Socket::SetIpTTL(int ttl)
{
#ifdef IP_TTL
@@ -1108,7 +978,6 @@ bool Socket::SetIpTTL(int ttl)
#endif
}
-
int Socket::IpTTL()
{
int ttl = 0;
@@ -1124,7 +993,6 @@ int Socket::IpTTL()
return ttl;
}
-
bool Socket::SetIpHdrincl(bool x)
{
#ifdef IP_HDRINCL
@@ -1141,7 +1009,6 @@ bool Socket::SetIpHdrincl(bool x)
#endif
}
-
#ifdef IP_RECVERR
bool Socket::SetIpRecverr(bool x)
{
@@ -1155,7 +1022,6 @@ bool Socket::SetIpRecverr(bool x)
}
#endif
-
#ifdef IP_MTU_DISCOVER
bool Socket::SetIpMtudiscover(bool x)
{
@@ -1169,7 +1035,6 @@ bool Socket::SetIpMtudiscover(bool x)
}
#endif
-
#ifdef IP_MTU
int Socket::IpMtu()
{
@@ -1183,7 +1048,6 @@ int Socket::IpMtu()
}
#endif
-
#ifdef IP_ROUTER_ALERT
bool Socket::SetIpRouterAlert(bool x)
{
@@ -1197,7 +1061,6 @@ bool Socket::SetIpRouterAlert(bool x)
}
#endif
-
bool Socket::SetIpMulticastTTL(int ttl)
{
#ifdef IP_MULTICAST_TTL
@@ -1213,7 +1076,6 @@ bool Socket::SetIpMulticastTTL(int ttl)
#endif
}
-
int Socket::IpMulticastTTL()
{
int ttl = 0;
@@ -1229,7 +1091,6 @@ int Socket::IpMulticastTTL()
return ttl;
}
-
bool Socket::SetMulticastLoop(bool x)
{
#ifdef IP_MULTICAST_LOOP
@@ -1246,7 +1107,6 @@ bool Socket::SetMulticastLoop(bool x)
#endif
}
-
#ifdef LINUX
bool Socket::IpAddMembership(struct ip_mreqn& ref)
{
@@ -1264,7 +1124,6 @@ bool Socket::IpAddMembership(struct ip_mreqn& ref)
}
#endif
-
bool Socket::IpAddMembership(struct ip_mreq& ref)
{
#ifdef IP_ADD_MEMBERSHIP
@@ -1280,7 +1139,6 @@ bool Socket::IpAddMembership(struct ip_mreq& ref)
#endif
}
-
#ifdef LINUX
bool Socket::IpDropMembership(struct ip_mreqn& ref)
{
@@ -1298,7 +1156,6 @@ bool Socket::IpDropMembership(struct ip_mreqn& ref)
}
#endif
-
bool Socket::IpDropMembership(struct ip_mreq& ref)
{
#ifdef IP_DROP_MEMBERSHIP
@@ -1314,10 +1171,8 @@ bool Socket::IpDropMembership(struct ip_mreq& ref)
#endif
}
-
/* SOCKET options */
-
bool Socket::SetSoReuseaddr(bool x)
{
#ifdef SO_REUSEADDR
@@ -1334,7 +1189,6 @@ bool Socket::SetSoReuseaddr(bool x)
#endif
}
-
bool Socket::SetSoKeepalive(bool x)
{
#ifdef SO_KEEPALIVE
@@ -1351,7 +1205,6 @@ bool Socket::SetSoKeepalive(bool x)
#endif
}
-
#ifdef SO_NOSIGPIPE
bool Socket::SetSoNosigpipe(bool x)
{
@@ -1365,7 +1218,6 @@ bool Socket::SetSoNosigpipe(bool x)
}
#endif
-
bool Socket::SoAcceptconn()
{
int value = 0;
@@ -1381,7 +1233,6 @@ bool Socket::SoAcceptconn()
return value ? true : false;
}
-
#ifdef SO_BSDCOMPAT
bool Socket::SetSoBsdcompat(bool x)
{
@@ -1395,7 +1246,6 @@ bool Socket::SetSoBsdcompat(bool x)
}
#endif
-
#ifdef SO_BINDTODEVICE
bool Socket::SetSoBindtodevice(const std::string& intf)
{
@@ -1408,7 +1258,6 @@ bool Socket::SetSoBindtodevice(const std::string& intf)
}
#endif
-
bool Socket::SetSoBroadcast(bool x)
{
#ifdef SO_BROADCAST
@@ -1425,7 +1274,6 @@ bool Socket::SetSoBroadcast(bool x)
#endif
}
-
bool Socket::SetSoDebug(bool x)
{
#ifdef SO_DEBUG
@@ -1442,7 +1290,6 @@ bool Socket::SetSoDebug(bool x)
#endif
}
-
int Socket::SoError()
{
int value = 0;
@@ -1458,7 +1305,6 @@ int Socket::SoError()
return value;
}
-
bool Socket::SetSoDontroute(bool x)
{
#ifdef SO_DONTROUTE
@@ -1475,7 +1321,6 @@ bool Socket::SetSoDontroute(bool x)
#endif
}
-
bool Socket::SetSoLinger(int onoff, int linger)
{
#ifdef SO_LINGER
@@ -1494,7 +1339,6 @@ bool Socket::SetSoLinger(int onoff, int linger)
#endif
}
-
bool Socket::SetSoOobinline(bool x)
{
#ifdef SO_OOBINLINE
@@ -1511,7 +1355,6 @@ bool Socket::SetSoOobinline(bool x)
#endif
}
-
#ifdef SO_PASSCRED
bool Socket::SetSoPasscred(bool x)
{
@@ -1525,7 +1368,6 @@ bool Socket::SetSoPasscred(bool x)
}
#endif
-
#ifdef SO_PEERCRED
bool Socket::SoPeercred(struct ucred& ucr)
{
@@ -1538,7 +1380,6 @@ bool Socket::SoPeercred(struct ucred& ucr)
}
#endif
-
#ifdef SO_PRIORITY
bool Socket::SetSoPriority(int x)
{
@@ -1551,7 +1392,6 @@ bool Socket::SetSoPriority(int x)
}
#endif
-
bool Socket::SetSoRcvlowat(int x)
{
#ifdef SO_RCVLOWAT
@@ -1567,7 +1407,6 @@ bool Socket::SetSoRcvlowat(int x)
#endif
}
-
bool Socket::SetSoSndlowat(int x)
{
#ifdef SO_SNDLOWAT
@@ -1583,7 +1422,6 @@ bool Socket::SetSoSndlowat(int x)
#endif
}
-
bool Socket::SetSoRcvtimeo(struct timeval& tv)
{
#ifdef SO_RCVTIMEO
@@ -1599,7 +1437,6 @@ bool Socket::SetSoRcvtimeo(struct timeval& tv)
#endif
}
-
bool Socket::SetSoSndtimeo(struct timeval& tv)
{
#ifdef SO_SNDTIMEO
@@ -1615,7 +1452,6 @@ bool Socket::SetSoSndtimeo(struct timeval& tv)
#endif
}
-
bool Socket::SetSoRcvbuf(int x)
{
#ifdef SO_RCVBUF
@@ -1631,7 +1467,6 @@ bool Socket::SetSoRcvbuf(int x)
#endif
}
-
int Socket::SoRcvbuf()
{
int value = 0;
@@ -1647,7 +1482,6 @@ int Socket::SoRcvbuf()
return value;
}
-
#ifdef SO_RCVBUFFORCE
bool Socket::SetSoRcvbufforce(int x)
{
@@ -1660,7 +1494,6 @@ bool Socket::SetSoRcvbufforce(int x)
}
#endif
-
bool Socket::SetSoSndbuf(int x)
{
#ifdef SO_SNDBUF
@@ -1676,7 +1509,6 @@ bool Socket::SetSoSndbuf(int x)
#endif
}
-
int Socket::SoSndbuf()
{
int value = 0;
@@ -1692,7 +1524,6 @@ int Socket::SoSndbuf()
return value;
}
-
#ifdef SO_SNDBUFFORCE
bool Socket::SetSoSndbufforce(int x)
{
@@ -1705,7 +1536,6 @@ bool Socket::SetSoSndbufforce(int x)
}
#endif
-
#ifdef SO_TIMESTAMP
bool Socket::SetSoTimestamp(bool x)
{
@@ -1719,7 +1549,6 @@ bool Socket::SetSoTimestamp(bool x)
}
#endif
-
int Socket::SoType()
{
int value = 0;
@@ -1735,31 +1564,26 @@ int Socket::SoType()
return value;
}
-
#ifdef ENABLE_TRIGGERS
void Socket::Subscribe(int id)
{
Handler().Subscribe(id, this);
}
-
void Socket::Unsubscribe(int id)
{
Handler().Unsubscribe(id, this);
}
-
void Socket::OnTrigger(int, const TriggerData&)
{
}
-
void Socket::OnCancelled(int)
{
}
#endif
-
void Socket::SetTimeout(time_t secs)
{
if (!secs)
@@ -1772,17 +1596,14 @@ void Socket::SetTimeout(time_t secs)
m_timeout_limit = secs;
}
-
void Socket::OnTimeout()
{
}
-
void Socket::OnConnectTimeout()
{
}
-
bool Socket::Timeout(time_t tnow)
{
if (tnow - m_timeout_start > m_timeout_limit)
@@ -1790,7 +1611,6 @@ bool Socket::Timeout(time_t tnow)
return false;
}
-
/** Returns local port number for bound socket file descriptor. */
port_t Socket::GetSockPort()
{
@@ -1813,7 +1633,6 @@ port_t Socket::GetSockPort()
return ntohs(sa.sin_port);
}
-
/** Returns local ipv4 address for bound socket file descriptor. */
ipaddr_t Socket::GetSockIP4()
{
@@ -1834,7 +1653,6 @@ ipaddr_t Socket::GetSockIP4()
return a;
}
-
/** Returns local ipv4 address as text for bound socket file descriptor. */
std::string Socket::GetSockAddress()
{
@@ -1854,7 +1672,6 @@ std::string Socket::GetSockAddress()
return addr.Convert();
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
/** Returns local ipv6 address for bound socket file descriptor. */
@@ -1873,7 +1690,6 @@ struct in6_addr Socket::GetSockIP6()
return a;
}
-
/** Returns local ipv6 address as text for bound socket file descriptor. */
std::string Socket::GetSockAddress6()
{
@@ -1891,9 +1707,7 @@ std::string Socket::GetSockAddress6()
#endif
#endif
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/SocketHandler.cpp b/dep/src/sockets/SocketHandler.cpp
index 84d110cfe72..ff6d4b36d64 100644
--- a/dep/src/sockets/SocketHandler.cpp
+++ b/dep/src/sockets/SocketHandler.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -36,7 +31,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdio.h>
#include <errno.h>
#include <cstdio>
-
#include "SocketHandler.h"
#include "UdpSocket.h"
#include "ResolvSocket.h"
@@ -45,19 +39,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Mutex.h"
#include "Utility.h"
#include "SocketAddress.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
//#ifdef _DEBUG
//#define DEB(x) x; fflush(stderr);
//#else
#define DEB(x)
//#endif
-
SocketHandler::SocketHandler(StdLog *p)
:m_stdlog(p)
,m_mutex(m_mutex)
@@ -90,7 +81,6 @@ SocketHandler::SocketHandler(StdLog *p)
FD_ZERO(&m_efds);
}
-
SocketHandler::SocketHandler(Mutex& mutex,StdLog *p)
:m_stdlog(p)
,m_mutex(mutex)
@@ -124,7 +114,6 @@ SocketHandler::SocketHandler(Mutex& mutex,StdLog *p)
FD_ZERO(&m_efds);
}
-
SocketHandler::~SocketHandler()
{
#ifdef ENABLE_RESOLVER
@@ -147,7 +136,6 @@ DEB( fprintf(stderr, " fd closed %d\n", p -> GetSocket());)
// p -> OnDelete(); // hey, I turn this back on. what's the worst that could happen??!!
// MinionSocket breaks, calling MinderHandler methods in OnDelete -
// MinderHandler is already gone when that happens...
-
// only delete socket when controlled
// ie master sockethandler can delete non-detached sockets
// and a slave sockethandler can only delete a detach socket
@@ -182,33 +170,28 @@ DEB( fprintf(stderr, "/Emptying sockets list in SocketHandler destructor,
}
}
-
Mutex& SocketHandler::GetMutex() const
{
return m_mutex;
}
-
#ifdef ENABLE_DETACH
void SocketHandler::SetSlave(bool x)
{
m_slave = x;
}
-
bool SocketHandler::IsSlave()
{
return m_slave;
}
#endif
-
void SocketHandler::RegStdLog(StdLog *log)
{
m_stdlog = log;
}
-
void SocketHandler::LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t)
{
if (m_stdlog)
@@ -217,7 +200,6 @@ void SocketHandler::LogError(Socket *p,const std::string& user_text,int err,cons
}
}
-
void SocketHandler::Add(Socket *p)
{
if (p -> GetSocket() == INVALID_SOCKET)
@@ -238,7 +220,6 @@ void SocketHandler::Add(Socket *p)
m_add[p -> GetSocket()] = p;
}
-
void SocketHandler::Get(SOCKET s,bool& r,bool& w,bool& e)
{
if (s >= 0)
@@ -249,7 +230,6 @@ void SocketHandler::Get(SOCKET s,bool& r,bool& w,bool& e)
}
}
-
void SocketHandler::Set(SOCKET s,bool bRead,bool bWrite,bool bException)
{
DEB( fprintf(stderr, "Set(%d, %s, %s, %s)\n", s, bRead ? "true" : "false", bWrite ? "true" : "false", bException ? "true" : "false");)
@@ -291,7 +271,6 @@ DEB( fprintf(stderr, "Set(%d, %s, %s, %s)\n", s, bRead ? "true" : "false", bW
}
}
-
int SocketHandler::Select(long sec,long usec)
{
struct timeval tv;
@@ -300,7 +279,6 @@ int SocketHandler::Select(long sec,long usec)
return Select(&tv);
}
-
int SocketHandler::Select()
{
if (!m_fds_callonconnect.empty() ||
@@ -317,7 +295,6 @@ int SocketHandler::Select()
return Select(NULL);
}
-
int SocketHandler::Select(struct timeval *tsel)
{
size_t ignore = 0;
@@ -528,7 +505,6 @@ DEB( fprintf(stderr, "m_maxsock: %d\n", m_maxsock);
} // m_fds loop
m_preverror = -1;
} // if (n > 0)
-
// check CallOnConnect - EVENT
if (!m_fds_callonconnect.empty())
{
@@ -826,7 +802,6 @@ DEB( fprintf(stderr, "Close() before OnDelete\n");)
}
}
}
-
// check erased sockets
bool check_max_fd = false;
while (!m_fds_erase.empty())
@@ -965,7 +940,6 @@ DEB( fprintf(stderr, "Close() before OnDelete\n");)
return n;
}
-
#ifdef ENABLE_RESOLVER
bool SocketHandler::Resolving(Socket *p0)
{
@@ -974,7 +948,6 @@ bool SocketHandler::Resolving(Socket *p0)
}
#endif
-
bool SocketHandler::Valid(Socket *p0)
{
for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
@@ -986,13 +959,11 @@ bool SocketHandler::Valid(Socket *p0)
return false;
}
-
bool SocketHandler::OkToAccept(Socket *)
{
return true;
}
-
size_t SocketHandler::GetCount()
{
/*
@@ -1003,33 +974,28 @@ printf(" m_delete : %d\n", m_delete.size());
return m_sockets.size() + m_add.size() + m_delete.size();
}
-
#ifdef ENABLE_SOCKS4
void SocketHandler::SetSocks4Host(ipaddr_t a)
{
m_socks4_host = a;
}
-
void SocketHandler::SetSocks4Host(const std::string& host)
{
Utility::u2ip(host, m_socks4_host);
}
-
void SocketHandler::SetSocks4Port(port_t port)
{
m_socks4_port = port;
}
-
void SocketHandler::SetSocks4Userid(const std::string& id)
{
m_socks4_userid = id;
}
#endif
-
#ifdef ENABLE_RESOLVER
int SocketHandler::Resolve(Socket *p,const std::string& host,port_t port)
{
@@ -1049,7 +1015,6 @@ DEB( fprintf(stderr, " *** Resolve '%s:%d' id#%d m_resolve_q size: %d p: %p
return resolv -> GetId();
}
-
#ifdef ENABLE_IPV6
int SocketHandler::Resolve6(Socket *p,const std::string& host,port_t port)
{
@@ -1069,7 +1034,6 @@ int SocketHandler::Resolve6(Socket *p,const std::string& host,port_t port)
}
#endif
-
int SocketHandler::Resolve(Socket *p,ipaddr_t a)
{
// check cache
@@ -1087,7 +1051,6 @@ int SocketHandler::Resolve(Socket *p,ipaddr_t a)
return resolv -> GetId();
}
-
#ifdef ENABLE_IPV6
int SocketHandler::Resolve(Socket *p,in6_addr& a)
{
@@ -1107,7 +1070,6 @@ int SocketHandler::Resolve(Socket *p,in6_addr& a)
}
#endif
-
void SocketHandler::EnableResolver(port_t port)
{
if (!m_resolver)
@@ -1117,60 +1079,51 @@ void SocketHandler::EnableResolver(port_t port)
}
}
-
bool SocketHandler::ResolverReady()
{
return m_resolver ? m_resolver -> Ready() : false;
}
#endif // ENABLE_RESOLVER
-
#ifdef ENABLE_SOCKS4
void SocketHandler::SetSocks4TryDirect(bool x)
{
m_bTryDirect = x;
}
-
ipaddr_t SocketHandler::GetSocks4Host()
{
return m_socks4_host;
}
-
port_t SocketHandler::GetSocks4Port()
{
return m_socks4_port;
}
-
const std::string& SocketHandler::GetSocks4Userid()
{
return m_socks4_userid;
}
-
bool SocketHandler::Socks4TryDirect()
{
return m_bTryDirect;
}
#endif
-
#ifdef ENABLE_RESOLVER
bool SocketHandler::ResolverEnabled()
{
return m_resolver ? true : false;
}
-
port_t SocketHandler::GetResolverPort()
{
return m_resolver_port;
}
#endif // ENABLE_RESOLVER
-
#ifdef ENABLE_POOL
ISocketHandler::PoolSocket *SocketHandler::FindConnection(int type,const std::string& protocol,SocketAddress& ad)
{
@@ -1193,20 +1146,17 @@ ISocketHandler::PoolSocket *SocketHandler::FindConnection(int type,const std::st
return NULL;
}
-
void SocketHandler::EnablePool(bool x)
{
m_b_enable_pool = x;
}
-
bool SocketHandler::PoolEnabled()
{
return m_b_enable_pool;
}
#endif
-
void SocketHandler::Remove(Socket *p)
{
#ifdef ENABLE_RESOLVER
@@ -1247,7 +1197,6 @@ void SocketHandler::Remove(Socket *p)
}
}
-
void SocketHandler::CheckSanity()
{
CheckList(m_fds, "active sockets"); // active sockets
@@ -1261,7 +1210,6 @@ void SocketHandler::CheckSanity()
CheckList(m_fds_close, "checklist close and delete");
}
-
void SocketHandler::CheckList(socket_v& ref,const std::string& listname)
{
for (socket_v::iterator it = ref.begin(); it != ref.end(); it++)
@@ -1288,7 +1236,6 @@ void SocketHandler::CheckList(socket_v& ref,const std::string& listname)
}
}
-
void SocketHandler::AddList(SOCKET s,list_t which_one,bool add)
{
if (s == INVALID_SOCKET)
@@ -1345,7 +1292,6 @@ DEB( fprintf(stderr, "AddList; %5d: %s: %s\n", s, (which_one == LIST_CALLONC
//DEB( fprintf(stderr, "/AddList\n");)
}
-
#ifdef ENABLE_TRIGGERS
int SocketHandler::TriggerID(Socket *src)
{
@@ -1354,7 +1300,6 @@ int SocketHandler::TriggerID(Socket *src)
return id;
}
-
bool SocketHandler::Subscribe(int id, Socket *dst)
{
if (m_trigger_src.find(id) != m_trigger_src.end())
@@ -1372,7 +1317,6 @@ bool SocketHandler::Subscribe(int id, Socket *dst)
return false;
}
-
bool SocketHandler::Unsubscribe(int id, Socket *dst)
{
if (m_trigger_src.find(id) != m_trigger_src.end())
@@ -1390,7 +1334,6 @@ bool SocketHandler::Unsubscribe(int id, Socket *dst)
return false;
}
-
void SocketHandler::Trigger(int id, Socket::TriggerData& data, bool erase)
{
if (m_trigger_src.find(id) != m_trigger_src.end())
@@ -1417,9 +1360,7 @@ void SocketHandler::Trigger(int id, Socket::TriggerData& data, bool erase)
}
#endif // ENABLE_TRIGGERS
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/StdoutLog.cpp b/dep/src/sockets/StdoutLog.cpp
index 998613f0fb2..44743c729f7 100644
--- a/dep/src/sockets/StdoutLog.cpp
+++ b/dep/src/sockets/StdoutLog.cpp
@@ -4,48 +4,37 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
-
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
-
#include <cstdio>
-
#include "ISocketHandler.h"
#include "Socket.h"
#include "StdoutLog.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
-
void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int err,const std::string& sys_err,loglevel_t lvl)
{
time_t t = time(NULL);
@@ -56,7 +45,6 @@ void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int
localtime_r(&t, &tp);
#endif
std::string level;
-
switch (lvl)
{
case LOG_LEVEL_WARNING:
@@ -93,10 +81,8 @@ void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int
}
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/StreamSocket.cpp b/dep/src/sockets/StreamSocket.cpp
index c8a3c32e496..84bcf7bdca1 100644
--- a/dep/src/sockets/StreamSocket.cpp
+++ b/dep/src/sockets/StreamSocket.cpp
@@ -1,12 +1,10 @@
#include "StreamSocket.h"
#include "ISocketHandler.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
StreamSocket::StreamSocket(ISocketHandler& h) : Socket(h)
,m_bConnecting(false)
,m_connect_timeout(5)
@@ -20,12 +18,10 @@ StreamSocket::StreamSocket(ISocketHandler& h) : Socket(h)
{
}
-
StreamSocket::~StreamSocket()
{
}
-
void StreamSocket::SetConnecting(bool x)
{
if (x != m_bConnecting)
@@ -42,13 +38,11 @@ void StreamSocket::SetConnecting(bool x)
}
}
-
bool StreamSocket::Connecting()
{
return m_bConnecting;
}
-
bool StreamSocket::Ready()
{
if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
@@ -56,115 +50,95 @@ bool StreamSocket::Ready()
return false;
}
-
void StreamSocket::SetConnectTimeout(int x)
{
m_connect_timeout = x;
}
-
int StreamSocket::GetConnectTimeout()
{
return m_connect_timeout;
}
-
void StreamSocket::SetFlushBeforeClose(bool x)
{
m_flush_before_close = x;
}
-
bool StreamSocket::GetFlushBeforeClose()
{
return m_flush_before_close;
}
-
int StreamSocket::GetConnectionRetry()
{
return m_connection_retry;
}
-
void StreamSocket::SetConnectionRetry(int x)
{
m_connection_retry = x;
}
-
int StreamSocket::GetConnectionRetries()
{
return m_retries;
}
-
void StreamSocket::IncreaseConnectionRetries()
{
m_retries++;
}
-
void StreamSocket::ResetConnectionRetries()
{
m_retries = 0;
}
-
void StreamSocket::SetCallOnConnect(bool x)
{
Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x);
m_call_on_connect = x;
}
-
bool StreamSocket::CallOnConnect()
{
return m_call_on_connect;
}
-
void StreamSocket::SetRetryClientConnect(bool x)
{
Handler().AddList(GetSocket(), LIST_RETRY, x);
m_b_retry_connect = x;
}
-
bool StreamSocket::RetryClientConnect()
{
return m_b_retry_connect;
}
-
void StreamSocket::SetLineProtocol(bool x)
{
m_line_protocol = x;
}
-
bool StreamSocket::LineProtocol()
{
return m_line_protocol;
}
-
void StreamSocket::SetShutdown(int x)
{
m_shutdown = x;
}
-
int StreamSocket::GetShutdown()
{
return m_shutdown;
}
-
-
#ifdef SOCKETS_NAMESPACE
} // namespace SOCKETS_NAMESPACE {
#endif
-
diff --git a/dep/src/sockets/TcpSocket.cpp b/dep/src/sockets/TcpSocket.cpp
index c4efa05d5bf..902f631a6af 100644
--- a/dep/src/sockets/TcpSocket.cpp
+++ b/dep/src/sockets/TcpSocket.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -46,32 +41,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#include <map>
#include <cstdio>
-
#include "TcpSocket.h"
#include "Utility.h"
#include "Ipv4Address.h"
#include "Ipv6Address.h"
#include "Mutex.h"
#include "IFile.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
//#ifdef _DEBUG
//#define DEB(x) x
//#else
#define DEB(x)
//#endif
-
// statics
#ifdef HAVE_OPENSSL
SSLInitializer TcpSocket::m_ssl_init;
#endif
-
// thanks, q
#ifdef _MSC_VER
#pragma warning(disable:4355)
@@ -109,7 +99,6 @@ TcpSocket::TcpSocket(ISocketHandler& h) : StreamSocket(h)
#pragma warning(default:4355)
#endif
-
#ifdef _MSC_VER
#pragma warning(disable:4355)
#endif
@@ -146,7 +135,6 @@ TcpSocket::TcpSocket(ISocketHandler& h,size_t isize,size_t osize) : StreamSocket
#pragma warning(default:4355)
#endif
-
TcpSocket::~TcpSocket()
{
#ifdef SOCKETS_DYNAMIC_TEMP
@@ -168,7 +156,6 @@ TcpSocket::~TcpSocket()
#endif
}
-
bool TcpSocket::Open(ipaddr_t ip,port_t port,bool skip_socks)
{
Ipv4Address ad(ip, port);
@@ -176,7 +163,6 @@ bool TcpSocket::Open(ipaddr_t ip,port_t port,bool skip_socks)
return Open(ad, local, skip_socks);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
bool TcpSocket::Open(in6_addr ip,port_t port,bool skip_socks)
@@ -187,14 +173,12 @@ bool TcpSocket::Open(in6_addr ip,port_t port,bool skip_socks)
#endif
#endif
-
bool TcpSocket::Open(SocketAddress& ad,bool skip_socks)
{
Ipv4Address bind_ad("0.0.0.0", 0);
return Open(ad, bind_ad, skip_socks);
}
-
bool TcpSocket::Open(SocketAddress& ad,SocketAddress& bind_ad,bool skip_socks)
{
if (!ad.IsValid())
@@ -222,7 +206,6 @@ bool TcpSocket::Open(SocketAddress& ad,SocketAddress& bind_ad,bool skip_socks)
{
CopyConnection( pools );
delete pools;
-
SetIsClient();
SetCallOnConnect(); // ISocketHandler must call OnConnect
Handler().LogError(this, "SetCallOnConnect", 0, "Found pooled connection", LOG_LEVEL_INFO);
@@ -314,13 +297,11 @@ bool TcpSocket::Open(SocketAddress& ad,SocketAddress& bind_ad,bool skip_socks)
Attach(s);
SetCallOnConnect(); // ISocketHandler must call OnConnect
}
-
// 'true' means connected or connecting(not yet connected)
// 'false' means something failed
return true; //!Connecting();
}
-
bool TcpSocket::Open(const std::string &host,port_t port)
{
#ifdef ENABLE_IPV6
@@ -369,7 +350,6 @@ bool TcpSocket::Open(const std::string &host,port_t port)
#endif
}
-
#ifdef ENABLE_RESOLVER
void TcpSocket::OnResolved(int id,ipaddr_t a,port_t port)
{
@@ -401,7 +381,6 @@ DEB( fprintf(stderr, "TcpSocket::OnResolved id %d addr %x port %d\n", id, a,
}
}
-
#ifdef ENABLE_IPV6
void TcpSocket::OnResolved(int id,in6_addr& a,port_t port)
{
@@ -429,7 +408,6 @@ void TcpSocket::OnResolved(int id,in6_addr& a,port_t port)
#endif
#endif
-
void TcpSocket::OnRead()
{
int n = 0;
@@ -542,7 +520,6 @@ DEB( fprintf(stderr, "SSL read problem, errcode = %d\n",n);)
OnRead( buf, n );
}
-
void TcpSocket::OnRead( char *buf, size_t n )
{
// unbuffered
@@ -620,18 +597,15 @@ void TcpSocket::OnRead( char *buf, size_t n )
#endif
}
-
void TcpSocket::OnWriteComplete()
{
}
-
void TcpSocket::OnWrite()
{
if (Connecting())
{
int err = SoError();
-
// don't reset connecting flag on error here, we want the OnConnectFailed timeout later on
if (!err) // ok
{
@@ -642,7 +616,6 @@ void TcpSocket::OnWrite()
}
Handler().LogError(this, "tcp: connect failed", err, StrError(err), LOG_LEVEL_FATAL);
Set(false, false); // no more monitoring because connection failed
-
// failed
#ifdef ENABLE_SOCKS4
if (Socks4())
@@ -670,7 +643,6 @@ void TcpSocket::OnWrite()
// try send next block in buffer
// if full block is sent, repeat
// if all blocks are sent, reset m_wfds
-
bool repeat = false;
size_t sz = m_transfer_limit ? GetOutputLength() : 0;
do
@@ -699,12 +671,10 @@ void TcpSocket::OnWrite()
}
}
} while (repeat);
-
if (m_transfer_limit && sz > m_transfer_limit && GetOutputLength() < m_transfer_limit)
{
OnTransferLimit();
}
-
// check output buffer set, set/reset m_wfds accordingly
{
bool br;
@@ -718,7 +688,6 @@ void TcpSocket::OnWrite()
}
}
-
int TcpSocket::TryWrite(const char *buf, size_t len)
{
int n = 0;
@@ -787,7 +756,6 @@ DEB( int errnr = SSL_get_error(m_ssl, n);
return n;
}
-
void TcpSocket::Buffer(const char *buf, size_t len)
{
size_t ptr = 0;
@@ -819,13 +787,11 @@ void TcpSocket::Buffer(const char *buf, size_t len)
}
}
-
void TcpSocket::Send(const std::string &str,int i)
{
SendBuf(str.c_str(),str.size(),i);
}
-
void TcpSocket::SendBuf(const char *buf,size_t len,int)
{
if (!Ready() && !Connecting())
@@ -862,7 +828,6 @@ void TcpSocket::SendBuf(const char *buf,size_t len,int)
// else
// try_send
// if any data is unsent, buffer it and set m_wfds
-
// check output buffer set, set/reset m_wfds accordingly
{
bool br;
@@ -876,12 +841,10 @@ void TcpSocket::SendBuf(const char *buf,size_t len,int)
}
}
-
void TcpSocket::OnLine(const std::string& )
{
}
-
#ifdef _MSC_VER
#pragma warning(disable:4355)
#endif
@@ -894,7 +857,6 @@ TcpSocket::TcpSocket(const TcpSocket& s)
#pragma warning(default:4355)
#endif
-
#ifdef ENABLE_SOCKS4
void TcpSocket::OnSocks4Connect()
{
@@ -929,7 +891,6 @@ void TcpSocket::OnSocks4Connect()
m_socks4_state = 0;
}
-
void TcpSocket::OnSocks4ConnectFailed()
{
Handler().LogError(this,"OnSocks4ConnectFailed",0,"connection to socks4 server failed, trying direct connection",LOG_LEVEL_WARNING);
@@ -945,7 +906,6 @@ void TcpSocket::OnSocks4ConnectFailed()
}
}
-
bool TcpSocket::OnSocks4Read()
{
switch (m_socks4_state)
@@ -974,7 +934,6 @@ bool TcpSocket::OnSocks4Read()
{
ibuf.Read( (char *)&m_socks4_dstip, 4);
SetSocks4(false);
-
switch (m_socks4_cd)
{
case 90:
@@ -1005,7 +964,6 @@ bool TcpSocket::OnSocks4Read()
}
#endif
-
void TcpSocket::Sendf(const char *format, ...)
{
va_list ap;
@@ -1020,7 +978,6 @@ void TcpSocket::Sendf(const char *format, ...)
Send( slask );
}
-
#ifdef HAVE_OPENSSL
void TcpSocket::OnSSLConnect()
{
@@ -1064,7 +1021,6 @@ DEB( fprintf(stderr, " m_sbio is NULL\n");)
}
}
-
void TcpSocket::OnSSLAccept()
{
SetNonblocking(true);
@@ -1103,7 +1059,6 @@ DEB( fprintf(stderr, " m_sbio is NULL\n");)
}
}
-
bool TcpSocket::SSLNegotiate()
{
if (!IsSSLServer()) // client
@@ -1200,20 +1155,17 @@ DEB( fprintf(stderr, "SSL_accept() failed - closing socket, retur
return false;
}
-
void TcpSocket::InitSSLClient()
{
InitializeContext("", SSLv23_method());
}
-
void TcpSocket::InitSSLServer()
{
Handler().LogError(this, "InitSSLServer", 0, "You MUST implement your own InitSSLServer method", LOG_LEVEL_FATAL);
SetCloseAndDelete();
}
-
void TcpSocket::InitializeContext(const std::string& context, SSL_METHOD *meth_in)
{
/* Create our context*/
@@ -1230,7 +1182,6 @@ void TcpSocket::InitializeContext(const std::string& context, SSL_METHOD *meth_i
}
}
-
void TcpSocket::InitializeContext(const std::string& context,const std::string& keyfile,const std::string& password,SSL_METHOD *meth_in)
{
/* Create our context*/
@@ -1250,13 +1201,11 @@ void TcpSocket::InitializeContext(const std::string& context,const std::string&
{
m_ssl_ctx = server_contexts[context];
}
-
/* Load our keys and certificates*/
if (!(SSL_CTX_use_certificate_file(m_ssl_ctx, keyfile.c_str(), SSL_FILETYPE_PEM)))
{
Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read certificate file " + keyfile, LOG_LEVEL_FATAL);
}
-
m_password = password;
SSL_CTX_set_default_passwd_cb(m_ssl_ctx, SSL_password_cb);
SSL_CTX_set_default_passwd_cb_userdata(m_ssl_ctx, this);
@@ -1266,7 +1215,6 @@ void TcpSocket::InitializeContext(const std::string& context,const std::string&
}
}
-
void TcpSocket::InitializeContext(const std::string& context,const std::string& certfile,const std::string& keyfile,const std::string& password,SSL_METHOD *meth_in)
{
/* Create our context*/
@@ -1286,13 +1234,11 @@ void TcpSocket::InitializeContext(const std::string& context,const std::string&
{
m_ssl_ctx = server_contexts[context];
}
-
/* Load our keys and certificates*/
if (!(SSL_CTX_use_certificate_file(m_ssl_ctx, certfile.c_str(), SSL_FILETYPE_PEM)))
{
Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read certificate file " + keyfile, LOG_LEVEL_FATAL);
}
-
m_password = password;
SSL_CTX_set_default_passwd_cb(m_ssl_ctx, SSL_password_cb);
SSL_CTX_set_default_passwd_cb_userdata(m_ssl_ctx, this);
@@ -1302,7 +1248,6 @@ void TcpSocket::InitializeContext(const std::string& context,const std::string&
}
}
-
int TcpSocket::SSL_password_cb(char *buf,int num,int rwflag,void *userdata)
{
Socket *p0 = static_cast<Socket *>(userdata);
@@ -1317,7 +1262,6 @@ int TcpSocket::SSL_password_cb(char *buf,int num,int rwflag,void *userdata)
}
#endif // HAVE_OPENSSL
-
int TcpSocket::Close()
{
if (GetSocket() == INVALID_SOCKET) // this could happen
@@ -1356,7 +1300,6 @@ int TcpSocket::Close()
return Socket::Close();
}
-
#ifdef HAVE_OPENSSL
SSL_CTX *TcpSocket::GetSslContext()
{
@@ -1364,7 +1307,6 @@ SSL_CTX *TcpSocket::GetSslContext()
Handler().LogError(this, "GetSslContext", 0, "SSL Context is NULL; check InitSSLServer/InitSSLClient", LOG_LEVEL_WARNING);
return m_ssl_ctx;
}
-
SSL *TcpSocket::GetSsl()
{
if (!m_ssl)
@@ -1373,7 +1315,6 @@ SSL *TcpSocket::GetSsl()
}
#endif
-
#ifdef ENABLE_RECONNECT
void TcpSocket::SetReconnect(bool x)
{
@@ -1381,24 +1322,20 @@ void TcpSocket::SetReconnect(bool x)
}
#endif
-
void TcpSocket::OnRawData(const char *buf_in,size_t len)
{
}
-
size_t TcpSocket::GetInputLength()
{
return ibuf.GetLength();
}
-
size_t TcpSocket::GetOutputLength()
{
return m_output_length;
}
-
uint64_t TcpSocket::GetBytesReceived(bool clear)
{
uint64_t z = m_bytes_received;
@@ -1407,7 +1344,6 @@ uint64_t TcpSocket::GetBytesReceived(bool clear)
return z;
}
-
uint64_t TcpSocket::GetBytesSent(bool clear)
{
uint64_t z = m_bytes_sent;
@@ -1416,27 +1352,23 @@ uint64_t TcpSocket::GetBytesSent(bool clear)
return z;
}
-
#ifdef ENABLE_RECONNECT
bool TcpSocket::Reconnect()
{
return m_b_reconnect;
}
-
void TcpSocket::SetIsReconnect(bool x)
{
m_b_is_reconnect = x;
}
-
bool TcpSocket::IsReconnect()
{
return m_b_is_reconnect;
}
#endif
-
#ifdef HAVE_OPENSSL
const std::string& TcpSocket::GetPassword()
{
@@ -1444,13 +1376,11 @@ const std::string& TcpSocket::GetPassword()
}
#endif
-
void TcpSocket::DisableInputBuffer(bool x)
{
m_b_input_buffer_disabled = x;
}
-
void TcpSocket::OnOptions(int family,int type,int protocol,SOCKET s)
{
DEB( fprintf(stderr, "Socket::OnOptions()\n");)
@@ -1461,14 +1391,12 @@ DEB( fprintf(stderr, "Socket::OnOptions()\n");)
SetSoKeepalive(true);
}
-
void TcpSocket::SetLineProtocol(bool x)
{
StreamSocket::SetLineProtocol(x);
DisableInputBuffer(x);
}
-
bool TcpSocket::SetTcpNodelay(bool x)
{
#ifdef TCP_NODELAY
@@ -1485,7 +1413,6 @@ bool TcpSocket::SetTcpNodelay(bool x)
#endif
}
-
TcpSocket::CircularBuffer::CircularBuffer(size_t size)
:buf(new char[2 * size])
,m_max(size)
@@ -1496,13 +1423,11 @@ TcpSocket::CircularBuffer::CircularBuffer(size_t size)
{
}
-
TcpSocket::CircularBuffer::~CircularBuffer()
{
delete[] buf;
}
-
bool TcpSocket::CircularBuffer::Write(const char *s,size_t l)
{
if (m_q + l > m_max)
@@ -1532,7 +1457,6 @@ bool TcpSocket::CircularBuffer::Write(const char *s,size_t l)
return true;
}
-
bool TcpSocket::CircularBuffer::Read(char *s,size_t l)
{
if (l > m_q)
@@ -1567,7 +1491,6 @@ bool TcpSocket::CircularBuffer::Read(char *s,size_t l)
}
return true;
}
-
bool TcpSocket::CircularBuffer::SoftRead(char *s, size_t l)
{
if (l > m_q)
@@ -1592,37 +1515,31 @@ bool TcpSocket::CircularBuffer::SoftRead(char *s, size_t l)
}
return true;
}
-
bool TcpSocket::CircularBuffer::Remove(size_t l)
{
return Read(NULL, l);
}
-
size_t TcpSocket::CircularBuffer::GetLength()
{
return m_q;
}
-
const char *TcpSocket::CircularBuffer::GetStart()
{
return buf + m_b;
}
-
size_t TcpSocket::CircularBuffer::GetL()
{
return (m_b + m_q > m_max) ? m_max - m_b : m_q;
}
-
size_t TcpSocket::CircularBuffer::Space()
{
return m_max - m_q;
}
-
unsigned long TcpSocket::CircularBuffer::ByteCounter(bool clear)
{
if (clear)
@@ -1634,7 +1551,6 @@ unsigned long TcpSocket::CircularBuffer::ByteCounter(bool clear)
return m_count;
}
-
std::string TcpSocket::CircularBuffer::ReadString(size_t l)
{
char *sz = new char[l + 1];
@@ -1649,7 +1565,6 @@ std::string TcpSocket::CircularBuffer::ReadString(size_t l)
return tmp;
}
-
void TcpSocket::OnConnectTimeout()
{
Handler().LogError(this, "connect", -1, "connect timeout", LOG_LEVEL_FATAL);
@@ -1687,7 +1602,6 @@ void TcpSocket::OnConnectTimeout()
SetConnecting(false);
}
-
#ifdef _WIN32
void TcpSocket::OnException()
{
@@ -1723,26 +1637,21 @@ void TcpSocket::OnException()
}
#endif // _WIN32
-
int TcpSocket::Protocol()
{
return IPPROTO_TCP;
}
-
void TcpSocket::SetTransferLimit(size_t sz)
{
m_transfer_limit = sz;
}
-
void TcpSocket::OnTransferLimit()
{
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/Thread.cpp b/dep/src/sockets/Thread.cpp
index a387a7e3824..713c02b3f52 100644
--- a/dep/src/sockets/Thread.cpp
+++ b/dep/src/sockets/Thread.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -34,15 +29,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
#include <unistd.h>
#endif
-
#include "Thread.h"
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
Thread::Thread(bool release)
:m_thread(0)
,m_running(true)
@@ -55,7 +47,6 @@ Thread::Thread(bool release)
m_thread = (HANDLE)_beginthreadex(NULL, 0, &StartThread, this, 0, &m_dwThreadId);
#else
pthread_attr_t attr;
-
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
if (pthread_create(&m_thread,&attr, StartThread,this) == -1)
@@ -68,7 +59,6 @@ Thread::Thread(bool release)
m_release = release;
}
-
Thread::~Thread()
{
m_b_destructor = true;
@@ -88,11 +78,9 @@ Thread::~Thread()
#endif
}
-
threadfunc_t STDPREFIX Thread::StartThread(threadparam_t zz)
{
Thread *p = (Thread *)zz;
-
while (p -> m_running && !p -> m_release)
{
#ifdef _WIN32
@@ -116,52 +104,43 @@ threadfunc_t STDPREFIX Thread::StartThread(threadparam_t zz)
return (threadfunc_t)NULL;
}
-
bool Thread::IsRunning()
{
return m_running;
}
-
void Thread::SetRunning(bool x)
{
m_running = x;
}
-
bool Thread::IsReleased()
{
return m_release;
}
-
void Thread::SetRelease(bool x)
{
m_release = x;
}
-
bool Thread::DeleteOnExit()
{
return m_b_delete_on_exit;
}
-
void Thread::SetDeleteOnExit(bool x)
{
m_b_delete_on_exit = x;
}
-
bool Thread::IsDestructor()
{
return m_b_destructor;
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/UdpSocket.cpp b/dep/src/sockets/UdpSocket.cpp
index f4c3d2f9657..f1abe54a1a8 100644
--- a/dep/src/sockets/UdpSocket.cpp
+++ b/dep/src/sockets/UdpSocket.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -35,7 +30,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
#include <errno.h>
#endif
-
#include "ISocketHandler.h"
#include "UdpSocket.h"
#include "Utility.h"
@@ -47,12 +41,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// include this to see strange sights
//#include <linux/in6.h>
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
UdpSocket::UdpSocket(ISocketHandler& h, int ibufsz, bool ipv6, int retries) : Socket(h)
, m_ibuf(new char[ibufsz])
, m_ibufsz(ibufsz)
@@ -69,14 +61,12 @@ UdpSocket::UdpSocket(ISocketHandler& h, int ibufsz, bool ipv6, int retries) : So
#endif
}
-
UdpSocket::~UdpSocket()
{
Close();
delete[] m_ibuf;
}
-
int UdpSocket::Bind(port_t &port, int range)
{
#ifdef ENABLE_IPV6
@@ -92,7 +82,6 @@ int UdpSocket::Bind(port_t &port, int range)
return Bind(ad, range);
}
-
int UdpSocket::Bind(const std::string& intf, port_t &port, int range)
{
#ifdef ENABLE_IPV6
@@ -118,14 +107,12 @@ int UdpSocket::Bind(const std::string& intf, port_t &port, int range)
return -1;
}
-
int UdpSocket::Bind(ipaddr_t a, port_t &port, int range)
{
Ipv4Address ad(a, port);
return Bind(ad, range);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
int UdpSocket::Bind(in6_addr a, port_t &port, int range)
@@ -136,7 +123,6 @@ int UdpSocket::Bind(in6_addr a, port_t &port, int range)
#endif
#endif
-
int UdpSocket::Bind(SocketAddress& ad, int range)
{
if (GetSocket() == INVALID_SOCKET)
@@ -169,7 +155,6 @@ int UdpSocket::Bind(SocketAddress& ad, int range)
return -1;
}
-
/** if you wish to use Send, first Open a connection */
bool UdpSocket::Open(ipaddr_t l, port_t port)
{
@@ -177,7 +162,6 @@ bool UdpSocket::Open(ipaddr_t l, port_t port)
return Open(ad);
}
-
bool UdpSocket::Open(const std::string& host, port_t port)
{
#ifdef ENABLE_IPV6
@@ -201,7 +185,6 @@ bool UdpSocket::Open(const std::string& host, port_t port)
return false;
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
bool UdpSocket::Open(struct in6_addr& a, port_t port)
@@ -212,7 +195,6 @@ bool UdpSocket::Open(struct in6_addr& a, port_t port)
#endif
#endif
-
bool UdpSocket::Open(SocketAddress& ad)
{
if (GetSocket() == INVALID_SOCKET)
@@ -234,7 +216,6 @@ bool UdpSocket::Open(SocketAddress& ad)
return false;
}
-
void UdpSocket::CreateConnection()
{
#ifdef ENABLE_IPV6
@@ -267,7 +248,6 @@ void UdpSocket::CreateConnection()
}
}
-
/** send to specified address */
void UdpSocket::SendToBuf(const std::string& h, port_t p, const char *data, int len, int flags)
{
@@ -291,7 +271,6 @@ void UdpSocket::SendToBuf(const std::string& h, port_t p, const char *data, int
}
}
-
/** send to specified address */
void UdpSocket::SendToBuf(ipaddr_t a, port_t p, const char *data, int len, int flags)
{
@@ -299,7 +278,6 @@ void UdpSocket::SendToBuf(ipaddr_t a, port_t p, const char *data, int len, int f
SendToBuf(ad, data, len, flags);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void UdpSocket::SendToBuf(in6_addr a, port_t p, const char *data, int len, int flags)
@@ -310,7 +288,6 @@ void UdpSocket::SendToBuf(in6_addr a, port_t p, const char *data, int len, int f
#endif
#endif
-
void UdpSocket::SendToBuf(SocketAddress& ad, const char *data, int len, int flags)
{
if (GetSocket() == INVALID_SOCKET)
@@ -327,19 +304,16 @@ void UdpSocket::SendToBuf(SocketAddress& ad, const char *data, int len, int flag
}
}
-
void UdpSocket::SendTo(const std::string& a, port_t p, const std::string& str, int flags)
{
SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
}
-
void UdpSocket::SendTo(ipaddr_t a, port_t p, const std::string& str, int flags)
{
SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void UdpSocket::SendTo(in6_addr a, port_t p, const std::string& str, int flags)
@@ -349,13 +323,11 @@ void UdpSocket::SendTo(in6_addr a, port_t p, const std::string& str, int flags)
#endif
#endif
-
void UdpSocket::SendTo(SocketAddress& ad, const std::string& str, int flags)
{
SendToBuf(ad, str.c_str(), (int)str.size(), flags);
}
-
/** send to connected address */
void UdpSocket::SendBuf(const char *data, size_t len, int flags)
{
@@ -370,13 +342,11 @@ void UdpSocket::SendBuf(const char *data, size_t len, int flags)
}
}
-
void UdpSocket::Send(const std::string& str, int flags)
{
SendBuf(str.c_str(), (int)str.size(), flags);
}
-
#if defined(LINUX) || defined(MACOSX)
int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts)
{
@@ -397,15 +367,12 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
} cmsg_un;
struct cmsghdr *cmsg;
struct timeval *tv;
-
vec[0].iov_base = ioBuf;
vec[0].iov_len = inBufSize;
-
memset(&msg, 0, sizeof(msg));
memset(from, 0, fromlen);
memset(ioBuf, 0, inBufSize);
memset(&cmsg_un, 0, sizeof(cmsg_un));
-
msg.msg_name = (caddr_t)from;
msg.msg_namelen = fromlen;
msg.msg_iov = vec;
@@ -413,14 +380,10 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
msg.msg_control = cmsg_un.data;
msg.msg_controllen = sizeof(cmsg_un.data);
msg.msg_flags = 0;
-
// Original version - for reference only
//int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
-
int n = recvmsg(GetSocket(), &msg, MSG_DONTWAIT);
-
// now ioBuf will contain the data, as if we used recvfrom
-
// Now get the time
if(n != -1 && msg.msg_controllen >= sizeof(struct cmsghdr) && !(msg.msg_flags & MSG_CTRUNC))
{
@@ -442,7 +405,6 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
}
#endif
-
void UdpSocket::OnRead()
{
#ifdef ENABLE_IPV6
@@ -555,12 +517,10 @@ void UdpSocket::OnRead()
}
}
-
void UdpSocket::SetBroadcast(bool b)
{
int one = 1;
int zero = 0;
-
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -581,12 +541,10 @@ void UdpSocket::SetBroadcast(bool b)
}
}
-
bool UdpSocket::IsBroadcast()
{
int is_broadcast = 0;
socklen_t size;
-
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -598,7 +556,6 @@ bool UdpSocket::IsBroadcast()
return is_broadcast != 0;
}
-
void UdpSocket::SetMulticastTTL(int ttl)
{
if (GetSocket() == INVALID_SOCKET)
@@ -611,12 +568,10 @@ void UdpSocket::SetMulticastTTL(int ttl)
}
}
-
int UdpSocket::GetMulticastTTL()
{
int ttl = 0;
socklen_t size = sizeof(int);
-
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -628,7 +583,6 @@ int UdpSocket::GetMulticastTTL()
return ttl;
}
-
void UdpSocket::SetMulticastLoop(bool x)
{
if (GetSocket() == INVALID_SOCKET)
@@ -655,7 +609,6 @@ void UdpSocket::SetMulticastLoop(bool x)
}
}
-
bool UdpSocket::IsMulticastLoop()
{
if (GetSocket() == INVALID_SOCKET)
@@ -685,7 +638,6 @@ bool UdpSocket::IsMulticastLoop()
return is_loop ? true : false;
}
-
void UdpSocket::AddMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
{
if (GetSocket() == INVALID_SOCKET)
@@ -726,7 +678,6 @@ void UdpSocket::AddMulticastMembership(const std::string& group, const std::stri
}
}
-
void UdpSocket::DropMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
{
if (GetSocket() == INVALID_SOCKET)
@@ -767,7 +718,6 @@ void UdpSocket::DropMulticastMembership(const std::string& group, const std::str
}
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void UdpSocket::SetMulticastHops(int hops)
@@ -787,7 +737,6 @@ void UdpSocket::SetMulticastHops(int hops)
}
}
-
int UdpSocket::GetMulticastHops()
{
if (GetSocket() == INVALID_SOCKET)
@@ -810,44 +759,36 @@ int UdpSocket::GetMulticastHops()
#endif // IPPROTO_IPV6
#endif
-
bool UdpSocket::IsBound()
{
return m_bind_ok;
}
-
void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len)
{
}
-
void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len, struct timeval *ts)
{
}
-
port_t UdpSocket::GetPort()
{
return m_port;
}
-
int UdpSocket::GetLastSizeWritten()
{
return m_last_size_written;
}
-
void UdpSocket::SetTimestamp(bool x)
{
m_b_read_ts = x;
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/Utility.cpp b/dep/src/sockets/Utility.cpp
index 6473f0a2564..70dbfc83595 100644
--- a/dep/src/sockets/Utility.cpp
+++ b/dep/src/sockets/Utility.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -40,12 +35,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <pthread.h>
#endif
#include <map>
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
// defines for the random number generator
#define TWIST_IA 397
#define TWIST_IB (TWIST_LEN - TWIST_IA)
@@ -55,7 +48,6 @@ namespace SOCKETS_NAMESPACE {
#define TWIST(b,i,j) ((b)[i] & UMASK) | ((b)[j] & LMASK)
#define MAGIC_TWIST(s) (((s) & 1) * MATRIX_A)
-
// statics
std::string Utility::m_host;
bool Utility::m_local_resolved = false;
@@ -68,7 +60,6 @@ std::string Utility::m_local_addr6;
#endif
#endif
-
std::string Utility::base64(const std::string& str_in)
{
std::string str;
@@ -77,7 +68,6 @@ std::string Utility::base64(const std::string& str_in)
return str;
}
-
std::string Utility::base64d(const std::string& str_in)
{
std::string str;
@@ -86,7 +76,6 @@ std::string Utility::base64d(const std::string& str_in)
return str;
}
-
std::string Utility::l2string(long l)
{
std::string str;
@@ -96,7 +85,6 @@ std::string Utility::l2string(long l)
return str;
}
-
std::string Utility::bigint2string(uint64_t l)
{
std::string str;
@@ -114,7 +102,6 @@ std::string Utility::bigint2string(uint64_t l)
return str;
}
-
uint64_t Utility::atoi64(const std::string& str)
{
uint64_t l = 0;
@@ -125,7 +112,6 @@ uint64_t Utility::atoi64(const std::string& str)
return l;
}
-
unsigned int Utility::hex2unsigned(const std::string& str)
{
unsigned int r = 0;
@@ -136,7 +122,6 @@ unsigned int Utility::hex2unsigned(const std::string& str)
return r;
}
-
/*
* Encode string per RFC1738 URL encoding rules
* tnx rstaveley
@@ -167,7 +152,6 @@ static char hex[] = "0123456789ABCDEF";
return dst;
} // rfc1738_encode
-
/*
* Decode string per RFC1738 URL encoding rules
* tnx rstaveley
@@ -198,7 +182,6 @@ std::string Utility::rfc1738_decode(const std::string& src)
return dst;
} // rfc1738_decode
-
bool Utility::isipv4(const std::string& str)
{
int dots = 0;
@@ -216,7 +199,6 @@ bool Utility::isipv4(const std::string& str)
return true;
}
-
bool Utility::isipv6(const std::string& str)
{
size_t qc = 0;
@@ -256,7 +238,6 @@ bool Utility::isipv6(const std::string& str)
return true;
}
-
bool Utility::u2ip(const std::string& str, ipaddr_t& l)
{
struct sockaddr_in sa;
@@ -265,7 +246,6 @@ bool Utility::u2ip(const std::string& str, ipaddr_t& l)
return r;
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
bool Utility::u2ip(const std::string& str, struct in6_addr& l)
@@ -278,7 +258,6 @@ bool Utility::u2ip(const std::string& str, struct in6_addr& l)
#endif
#endif
-
void Utility::l2ip(const ipaddr_t ip, std::string& str)
{
struct sockaddr_in sa;
@@ -288,7 +267,6 @@ void Utility::l2ip(const ipaddr_t ip, std::string& str)
Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST);
}
-
void Utility::l2ip(const in_addr& ip, std::string& str)
{
struct sockaddr_in sa;
@@ -298,7 +276,6 @@ void Utility::l2ip(const in_addr& ip, std::string& str)
Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void Utility::l2ip(const struct in6_addr& ip, std::string& str,bool mixed)
@@ -347,7 +324,6 @@ void Utility::l2ip(const struct in6_addr& ip, std::string& str,bool mixed)
str = slask;
}
-
int Utility::in6_addr_compare(in6_addr a,in6_addr b)
{
for (size_t i = 0; i < 16; i++)
@@ -362,11 +338,9 @@ int Utility::in6_addr_compare(in6_addr a,in6_addr b)
#endif
#endif
-
void Utility::ResolveLocal()
{
char h[256];
-
// get local hostname and translate into ip-address
*h = 0;
gethostname(h,255);
@@ -391,7 +365,6 @@ void Utility::ResolveLocal()
m_local_resolved = true;
}
-
const std::string& Utility::GetLocalHostname()
{
if (!m_local_resolved)
@@ -401,7 +374,6 @@ const std::string& Utility::GetLocalHostname()
return m_host;
}
-
ipaddr_t Utility::GetLocalIP()
{
if (!m_local_resolved)
@@ -411,7 +383,6 @@ ipaddr_t Utility::GetLocalIP()
return m_ip;
}
-
const std::string& Utility::GetLocalAddress()
{
if (!m_local_resolved)
@@ -421,7 +392,6 @@ const std::string& Utility::GetLocalAddress()
return m_addr;
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
const struct in6_addr& Utility::GetLocalIP6()
@@ -433,7 +403,6 @@ const struct in6_addr& Utility::GetLocalIP6()
return m_local_ip6;
}
-
const std::string& Utility::GetLocalAddress6()
{
if (!m_local_resolved)
@@ -445,7 +414,6 @@ const std::string& Utility::GetLocalAddress6()
#endif
#endif
-
void Utility::SetEnv(const std::string& var,const std::string& value)
{
#if (defined(SOLARIS8) || defined(SOLARIS))
@@ -469,7 +437,6 @@ void Utility::SetEnv(const std::string& var,const std::string& value)
#endif
}
-
std::string Utility::Sa2String(struct sockaddr *sa)
{
#ifdef ENABLE_IPV6
@@ -495,7 +462,6 @@ std::string Utility::Sa2String(struct sockaddr *sa)
return "";
}
-
void Utility::GetTime(struct timeval *p)
{
#ifdef _WIN32
@@ -511,7 +477,6 @@ void Utility::GetTime(struct timeval *p)
#endif
}
-
std::auto_ptr<SocketAddress> Utility::CreateAddress(struct sockaddr *sa,socklen_t sa_len)
{
switch (sa -> sa_family)
@@ -538,7 +503,6 @@ std::auto_ptr<SocketAddress> Utility::CreateAddress(struct sockaddr *sa,socklen_
return std::auto_ptr<SocketAddress>(NULL);
}
-
bool Utility::u2ip(const std::string& host, struct sockaddr_in& sa, int ai_flags)
{
memset(&sa, 0, sizeof(sa));
@@ -631,7 +595,6 @@ bool Utility::u2ip(const std::string& host, struct sockaddr_in& sa, int ai_flags
#endif // NO_GETADDRINFO
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
bool Utility::u2ip(const std::string& host, struct sockaddr_in6& sa, int ai_flags)
@@ -747,14 +710,12 @@ bool Utility::u2ip(const std::string& host, struct sockaddr_in6& sa, int ai_flag
#endif // IPPROTO_IPV6
#endif // ENABLE_IPV6
-
bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, int flags)
{
std::string service;
return Utility::reverse(sa, sa_len, hostname, service, flags);
}
-
bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, std::string& service, int flags)
{
hostname = "";
@@ -870,7 +831,6 @@ bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostna
#endif // NO_GETADDRINFO
}
-
bool Utility::u2service(const std::string& name, int& service, int ai_flags)
{
#ifdef NO_GETADDRINFO
@@ -903,7 +863,6 @@ bool Utility::u2service(const std::string& name, int& service, int ai_flags)
#endif // NO_GETADDRINFO
}
-
unsigned long Utility::ThreadID()
{
#ifdef _WIN32
@@ -913,7 +872,6 @@ unsigned long Utility::ThreadID()
#endif
}
-
std::string Utility::ToLower(const std::string& str)
{
std::string r;
@@ -927,7 +885,6 @@ std::string Utility::ToLower(const std::string& str)
return r;
}
-
std::string Utility::ToUpper(const std::string& str)
{
std::string r;
@@ -941,7 +898,6 @@ std::string Utility::ToUpper(const std::string& str)
return r;
}
-
std::string Utility::ToString(double d)
{
char tmp[100];
@@ -949,14 +905,12 @@ std::string Utility::ToString(double d)
return tmp;
}
-
unsigned long Utility::Rnd()
{
static Utility::Rng generator( (unsigned long)time(NULL) );
return generator.Get();
}
-
Utility::Rng::Rng(unsigned long seed) : m_value( 0 )
{
m_tmp[0]= seed & 0xffffffffUL;
@@ -966,7 +920,6 @@ Utility::Rng::Rng(unsigned long seed) : m_value( 0 )
}
}
-
unsigned long Utility::Rng::Get()
{
unsigned long val = m_tmp[m_value];
@@ -987,14 +940,11 @@ unsigned long Utility::Rng::Get()
}
unsigned long s = TWIST(m_tmp, TWIST_LEN - 1, 0);
m_tmp[TWIST_LEN - 1] = m_tmp[TWIST_IA - 1] ^ (s >> 1) ^ MAGIC_TWIST(s);
-
m_value = 0;
}
return val;
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-
diff --git a/dep/src/sockets/socket_include.cpp b/dep/src/sockets/socket_include.cpp
index 133ff745d91..171b5c39a23 100644
--- a/dep/src/sockets/socket_include.cpp
+++ b/dep/src/sockets/socket_include.cpp
@@ -4,31 +4,25 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program 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 General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
-
// only to be included in win32 projects
const char *StrError(int x)
{
@@ -78,7 +72,6 @@ static char tmp[100];
case 11002: return "Nonauthoritative host not found.";
case 11003: return "This is a nonrecoverable error.";
case 11004: return "Valid name, no data record of requested type.";
-
default:
break;
}
@@ -87,5 +80,3 @@ static char tmp[100];
}
-
-
diff --git a/dep/src/zlib/adler32.c b/dep/src/zlib/adler32.c
index 007ba26277c..483da9c58c0 100644
--- a/dep/src/zlib/adler32.c
+++ b/dep/src/zlib/adler32.c
@@ -2,22 +2,17 @@
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* @(#) $Id$ */
-
#define ZLIB_INTERNAL
#include "zlib.h"
-
#define BASE 65521UL /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
-
/* use NO_DIVIDE if your processor does not do division in hardware */
#ifdef NO_DIVIDE
# define MOD(a) \
@@ -52,7 +47,6 @@
# define MOD(a) a %= BASE
# define MOD4(a) a %= BASE
#endif
-
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
@@ -61,11 +55,9 @@ uLong ZEXPORT adler32(adler, buf, len)
{
unsigned long sum2;
unsigned n;
-
/* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;
-
/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
adler += buf[0];
@@ -76,11 +68,9 @@ uLong ZEXPORT adler32(adler, buf, len)
sum2 -= BASE;
return adler | (sum2 << 16);
}
-
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL)
return 1L;
-
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {
while (len--) {
@@ -92,7 +82,6 @@ uLong ZEXPORT adler32(adler, buf, len)
MOD4(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
-
/* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) {
len -= NMAX;
@@ -104,7 +93,6 @@ uLong ZEXPORT adler32(adler, buf, len)
MOD(adler);
MOD(sum2);
}
-
/* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */
while (len >= 16) {
@@ -119,11 +107,9 @@ uLong ZEXPORT adler32(adler, buf, len)
MOD(adler);
MOD(sum2);
}
-
/* return recombined sums */
return adler | (sum2 << 16);
}
-
/* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
uLong adler1;
@@ -133,7 +119,6 @@ uLong ZEXPORT adler32_combine(adler1, adler2, len2)
unsigned long sum1;
unsigned long sum2;
unsigned rem;
-
/* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE);
sum1 = adler1 & 0xffff;
diff --git a/dep/src/zlib/compress.c b/dep/src/zlib/compress.c
index df04f0148e6..488bfa6cda9 100644
--- a/dep/src/zlib/compress.c
+++ b/dep/src/zlib/compress.c
@@ -2,19 +2,15 @@
* Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* @(#) $Id$ */
-
#define ZLIB_INTERNAL
#include "zlib.h"
-
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
-
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
@@ -28,7 +24,6 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
{
z_stream stream;
int err;
-
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
@@ -38,25 +33,20 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
-
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
-
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
-
err = deflateEnd(&stream);
return err;
}
-
/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
@@ -67,7 +57,6 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}
-
/* ===========================================================================
If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated.
diff --git a/dep/src/zlib/crc32.c b/dep/src/zlib/crc32.c
index f658a9ef55e..8838c354a4e 100644
--- a/dep/src/zlib/crc32.c
+++ b/dep/src/zlib/crc32.c
@@ -8,9 +8,7 @@
* instead of four steps with four exclusive-ors. This results in about a
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
*/
-
/* @(#) $Id$ */
-
/*
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
protection on the static variables used to control the first-use generation
@@ -18,18 +16,14 @@
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
*/
-
#ifdef MAKECRCH
# include <stdio.h>
# ifndef DYNAMIC_CRC_TABLE
# define DYNAMIC_CRC_TABLE
# endif /* !DYNAMIC_CRC_TABLE */
#endif /* MAKECRCH */
-
#include "zutil.h" /* for STDC and FAR definitions */
-
#define local static
-
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
#ifndef NOBYFOUR
# ifdef STDC /* need ANSI C limits.h to determine sizes */
@@ -50,7 +44,6 @@
# endif
# endif /* STDC */
#endif /* !NOBYFOUR */
-
/* Definitions for doing the crc four data bytes at a time. */
#ifdef BYFOUR
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
@@ -63,14 +56,11 @@
#else
# define TBLS 1
#endif /* BYFOUR */
-
/* Local functions for crc concatenation */
local unsigned long gf2_matrix_times OF((unsigned long *mat,
unsigned long vec));
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
-
#ifdef DYNAMIC_CRC_TABLE
-
local volatile int crc_table_empty = 1;
local unsigned long FAR crc_table[TBLS][256];
local void make_crc_table OF((void));
@@ -80,7 +70,6 @@ local void make_crc_table OF((void));
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
-
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
@@ -88,7 +77,6 @@ local void make_crc_table OF((void));
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
-
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
@@ -96,7 +84,6 @@ local void make_crc_table OF((void));
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
-
The first table is simply the CRC of all possible eight bit values. This is
all the information needed to generate CRCs on data a byte at a time for all
combinations of CRC register values and incoming bytes. The remaining tables
@@ -111,18 +98,15 @@ local void make_crc_table()
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
-
/* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in
case the advice about DYNAMIC_CRC_TABLE is ignored) */
if (first) {
first = 0;
-
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly = 0UL;
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
poly |= 1UL << (31 - p[n]);
-
/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
c = (unsigned long)n;
@@ -130,7 +114,6 @@ local void make_crc_table()
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
}
-
#ifdef BYFOUR
/* generate crc for each value followed by one, two, and three zeros,
and then the byte reversal of those as well as the first table */
@@ -144,7 +127,6 @@ local void make_crc_table()
}
}
#endif /* BYFOUR */
-
crc_table_empty = 0;
}
else { /* not first */
@@ -152,12 +134,10 @@ local void make_crc_table()
while (crc_table_empty)
;
}
-
#ifdef MAKECRCH
/* write out CRC tables to crc32.h */
{
FILE *out;
-
out = fopen("crc32.h", "w");
if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
@@ -178,27 +158,23 @@ local void make_crc_table()
}
#endif /* MAKECRCH */
}
-
#ifdef MAKECRCH
local void write_table(out, table)
FILE *out;
const unsigned long FAR *table;
{
int n;
-
for (n = 0; n < 256; n++)
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
}
#endif /* MAKECRCH */
-
#else /* !DYNAMIC_CRC_TABLE */
/* ========================================================================
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
*/
#include "crc32.h"
#endif /* DYNAMIC_CRC_TABLE */
-
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
@@ -210,11 +186,9 @@ const unsigned long FAR * ZEXPORT get_crc_table()
#endif /* DYNAMIC_CRC_TABLE */
return (const unsigned long FAR *)crc_table;
}
-
/* ========================================================================= */
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
-
/* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc;
@@ -222,16 +196,13 @@ unsigned long ZEXPORT crc32(crc, buf, len)
unsigned len;
{
if (buf == Z_NULL) return 0UL;
-
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
-
#ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) {
u4 endian;
-
endian = 1;
if (*((unsigned char *)(&endian)))
return crc32_little(crc, buf, len);
@@ -249,15 +220,12 @@ unsigned long ZEXPORT crc32(crc, buf, len)
} while (--len);
return crc ^ 0xffffffffUL;
}
-
#ifdef BYFOUR
-
/* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
-
/* ========================================================================= */
local unsigned long crc32_little(crc, buf, len)
unsigned long crc;
@@ -266,14 +234,12 @@ local unsigned long crc32_little(crc, buf, len)
{
register u4 c;
register const u4 FAR *buf4;
-
c = (u4)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--;
}
-
buf4 = (const u4 FAR *)(const void FAR *)buf;
while (len >= 32) {
DOLIT32;
@@ -284,20 +250,17 @@ local unsigned long crc32_little(crc, buf, len)
len -= 4;
}
buf = (const unsigned char FAR *)buf4;
-
if (len) do {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
} while (--len);
c = ~c;
return (unsigned long)c;
}
-
/* ========================================================================= */
#define DOBIG4 c ^= *++buf4; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
-
/* ========================================================================= */
local unsigned long crc32_big(crc, buf, len)
unsigned long crc;
@@ -306,14 +269,12 @@ local unsigned long crc32_big(crc, buf, len)
{
register u4 c;
register const u4 FAR *buf4;
-
c = REV((u4)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--;
}
-
buf4 = (const u4 FAR *)(const void FAR *)buf;
buf4--;
while (len >= 32) {
@@ -326,25 +287,20 @@ local unsigned long crc32_big(crc, buf, len)
}
buf4++;
buf = (const unsigned char FAR *)buf4;
-
if (len) do {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len);
c = ~c;
return (unsigned long)(REV(c));
}
-
#endif /* BYFOUR */
-
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
-
/* ========================================================================= */
local unsigned long gf2_matrix_times(mat, vec)
unsigned long *mat;
unsigned long vec;
{
unsigned long sum;
-
sum = 0;
while (vec) {
if (vec & 1)
@@ -354,18 +310,15 @@ local unsigned long gf2_matrix_times(mat, vec)
}
return sum;
}
-
/* ========================================================================= */
local void gf2_matrix_square(square, mat)
unsigned long *square;
unsigned long *mat;
{
int n;
-
for (n = 0; n < GF2_DIM; n++)
square[n] = gf2_matrix_times(mat, mat[n]);
}
-
/* ========================================================================= */
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
uLong crc1;
@@ -376,11 +329,9 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
unsigned long row;
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
-
/* degenerate case */
if (len2 == 0)
return crc1;
-
/* put operator for one zero bit in odd */
odd[0] = 0xedb88320L; /* CRC-32 polynomial */
row = 1;
@@ -388,13 +339,10 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
odd[n] = row;
row <<= 1;
}
-
/* put operator for two zero bits in even */
gf2_matrix_square(even, odd);
-
/* put operator for four zero bits in odd */
gf2_matrix_square(odd, even);
-
/* apply len2 zeros to crc1 (first square will put the operator for one
zero byte, eight zero bits, in even) */
do {
@@ -403,20 +351,16 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
if (len2 & 1)
crc1 = gf2_matrix_times(even, crc1);
len2 >>= 1;
-
/* if no more bits set, then done */
if (len2 == 0)
break;
-
/* another iteration of the loop with odd and even swapped */
gf2_matrix_square(odd, even);
if (len2 & 1)
crc1 = gf2_matrix_times(odd, crc1);
len2 >>= 1;
-
/* if no more bits set, then done */
} while (len2 != 0);
-
/* return combined crc */
crc1 ^= crc2;
return crc1;
diff --git a/dep/src/zlib/crc32.h b/dep/src/zlib/crc32.h
index dfd1deaa522..05ffb21364b 100644
--- a/dep/src/zlib/crc32.h
+++ b/dep/src/zlib/crc32.h
@@ -1,7 +1,6 @@
/* crc32.h -- tables for rapid CRC calculation
* Generated automatically by crc32.c
*/
-
local const unsigned long FAR crc_table[TBLS][256] =
{
{
diff --git a/dep/src/zlib/deflate.c b/dep/src/zlib/deflate.c
index 29ce1f64a57..0651ae4cd8a 100644
--- a/dep/src/zlib/deflate.c
+++ b/dep/src/zlib/deflate.c
@@ -2,7 +2,6 @@
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/*
* ALGORITHM
*
@@ -46,11 +45,8 @@
* Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
*
*/
-
/* @(#) $Id$ */
-
#include "deflate.h"
-
const char deflate_copyright[] =
" deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
/*
@@ -59,7 +55,6 @@ const char deflate_copyright[] =
include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product.
*/
-
/* ===========================================================================
* Function prototypes.
*/
@@ -69,10 +64,8 @@ typedef enum {
finish_started, /* finish started, need only more output at next deflate */
finish_done /* finish done, accept no more input or output */
} block_state;
-
typedef block_state (*compress_func) OF((deflate_state *s, int flush));
/* Compression function. Returns the block state after the call. */
-
local void fill_window OF((deflate_state *s));
local block_state deflate_stored OF((deflate_state *s, int flush));
local block_state deflate_fast OF((deflate_state *s, int flush));
@@ -92,29 +85,23 @@ local uInt longest_match OF((deflate_state *s, IPos cur_match));
#endif
#endif
local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
-
#ifdef DEBUG
local void check_match OF((deflate_state *s, IPos start, IPos match,
int length));
#endif
-
/* ===========================================================================
* Local data
*/
-
#define NIL 0
/* Tail of hash chains */
-
#ifndef TOO_FAR
# define TOO_FAR 4096
#endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
-
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file.
* See deflate.c for comments about the MIN_MATCH+1.
*/
-
/* Values for max_lazy_match, good_match and max_chain_length, depending on
* the desired pack level (0..9). The values given below have been tuned to
* exclude worst case performance for pathological files. Better values may be
@@ -127,7 +114,6 @@ typedef struct config_s {
ush max_chain;
compress_func func;
} config;
-
#ifdef FASTEST
local const config configuration_table[2] = {
/* good lazy nice chain */
@@ -140,7 +126,6 @@ local const config configuration_table[10] = {
/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
/* 2 */ {4, 5, 16, 8, deflate_fast},
/* 3 */ {4, 6, 32, 32, deflate_fast},
-
/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
/* 5 */ {8, 16, 32, 32, deflate_slow},
/* 6 */ {8, 16, 128, 128, deflate_slow},
@@ -148,19 +133,15 @@ local const config configuration_table[10] = {
/* 8 */ {32, 128, 258, 1024, deflate_slow},
/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
#endif
-
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
* meaning.
*/
-
#define EQUAL 0
/* result of memcmp for equal strings */
-
#ifndef NO_DUMMY_DECL
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
#endif
-
/* ===========================================================================
* Update a hash value with the given input byte
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
@@ -169,7 +150,6 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
*/
#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
-
/* ===========================================================================
* Insert string str in the dictionary and set match_head to the previous head
* of the hash chain (the most recent string with same hash key). Return
@@ -191,7 +171,6 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
s->head[s->ins_h] = (Pos)(str))
#endif
-
/* ===========================================================================
* Initialize the hash table (avoiding 64K overflow for 16 bit systems).
* prev[] will be initialized on the fly.
@@ -199,7 +178,6 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
#define CLEAR_HASH(s) \
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
-
/* ========================================================================= */
int ZEXPORT deflateInit_(strm, level, version, stream_size)
z_streamp strm;
@@ -211,7 +189,6 @@ int ZEXPORT deflateInit_(strm, level, version, stream_size)
Z_DEFAULT_STRATEGY, version, stream_size);
/* To do: ignore strm->next_in if we use it as window */
}
-
/* ========================================================================= */
int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
version, stream_size)
@@ -227,31 +204,26 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
deflate_state *s;
int wrap = 1;
static const char my_version[] = ZLIB_VERSION;
-
ushf *overlay;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 24 bits.
*/
-
if (version == Z_NULL || version[0] != my_version[0] ||
stream_size != sizeof(z_stream)) {
return Z_VERSION_ERROR;
}
if (strm == Z_NULL) return Z_STREAM_ERROR;
-
strm->msg = Z_NULL;
if (strm->zalloc == (alloc_func)0) {
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
}
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
-
#ifdef FASTEST
if (level != 0) level = 1;
#else
if (level == Z_DEFAULT_COMPRESSION) level = 6;
#endif
-
if (windowBits < 0) { /* suppress zlib wrapper */
wrap = 0;
windowBits = -windowBits;
@@ -272,28 +244,22 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
if (s == Z_NULL) return Z_MEM_ERROR;
strm->state = (struct internal_state FAR *)s;
s->strm = strm;
-
s->wrap = wrap;
s->gzhead = Z_NULL;
s->w_bits = windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
-
s->hash_bits = memLevel + 7;
s->hash_size = 1 << s->hash_bits;
s->hash_mask = s->hash_size - 1;
s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
-
s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
-
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
-
overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
s->pending_buf = (uchf *) overlay;
s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
-
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) {
s->status = FINISH_STATE;
@@ -303,14 +269,11 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
}
s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
-
s->level = level;
s->strategy = strategy;
s->method = (Byte)method;
-
return deflateReset(strm);
}
-
/* ========================================================================= */
int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
z_streamp strm;
@@ -321,16 +284,13 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
uInt length = dictLength;
uInt n;
IPos hash_head = 0;
-
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
strm->state->wrap == 2 ||
(strm->state->wrap == 1 && strm->state->status != INIT_STATE))
return Z_STREAM_ERROR;
-
s = strm->state;
if (s->wrap)
strm->adler = adler32(strm->adler, dictionary, dictLength);
-
if (length < MIN_MATCH) return Z_OK;
if (length > MAX_DIST(s)) {
length = MAX_DIST(s);
@@ -339,7 +299,6 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
zmemcpy(s->window, dictionary, length);
s->strstart = length;
s->block_start = (long)length;
-
/* Insert all strings in the hash table (except for the last two bytes).
* s->lookahead stays null, so s->ins_h will be recomputed at the next
* call of fill_window.
@@ -352,26 +311,21 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
if (hash_head) hash_head = 0; /* to make compiler happy */
return Z_OK;
}
-
/* ========================================================================= */
int ZEXPORT deflateReset (strm)
z_streamp strm;
{
deflate_state *s;
-
if (strm == Z_NULL || strm->state == Z_NULL ||
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
return Z_STREAM_ERROR;
}
-
strm->total_in = strm->total_out = 0;
strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
strm->data_type = Z_UNKNOWN;
-
s = (deflate_state *)strm->state;
s->pending = 0;
s->pending_out = s->pending_buf;
-
if (s->wrap < 0) {
s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
}
@@ -382,13 +336,10 @@ int ZEXPORT deflateReset (strm)
#endif
adler32(0L, Z_NULL, 0);
s->last_flush = Z_NO_FLUSH;
-
_tr_init(s);
lm_init(s);
-
return Z_OK;
}
-
/* ========================================================================= */
int ZEXPORT deflateSetHeader (strm, head)
z_streamp strm;
@@ -399,7 +350,6 @@ int ZEXPORT deflateSetHeader (strm, head)
strm->state->gzhead = head;
return Z_OK;
}
-
/* ========================================================================= */
int ZEXPORT deflatePrime (strm, bits, value)
z_streamp strm;
@@ -411,7 +361,6 @@ int ZEXPORT deflatePrime (strm, bits, value)
strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
return Z_OK;
}
-
/* ========================================================================= */
int ZEXPORT deflateParams(strm, level, strategy)
z_streamp strm;
@@ -421,10 +370,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
deflate_state *s;
compress_func func;
int err = Z_OK;
-
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
s = strm->state;
-
#ifdef FASTEST
if (level != 0) level = 1;
#else
@@ -434,7 +381,6 @@ int ZEXPORT deflateParams(strm, level, strategy)
return Z_STREAM_ERROR;
}
func = configuration_table[s->level].func;
-
if (func != configuration_table[level].func && strm->total_in != 0) {
/* Flush the last buffer: */
err = deflate(strm, Z_PARTIAL_FLUSH);
@@ -449,7 +395,6 @@ int ZEXPORT deflateParams(strm, level, strategy)
s->strategy = strategy;
return err;
}
-
/* ========================================================================= */
int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
z_streamp strm;
@@ -459,7 +404,6 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
int max_chain;
{
deflate_state *s;
-
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
s = strm->state;
s->good_match = good_length;
@@ -468,7 +412,6 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
s->max_chain_length = max_chain;
return Z_OK;
}
-
/* =========================================================================
* For the default windowBits of 15 and memLevel of 8, this function returns
* a close to exact, as well as small, upper bound on the compressed size.
@@ -492,24 +435,19 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
{
deflate_state *s;
uLong destLen;
-
/* conservative upper bound */
destLen = sourceLen +
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
-
/* if can't get parameters, return conservative bound */
if (strm == Z_NULL || strm->state == Z_NULL)
return destLen;
-
/* if not default parameters, return conservative bound */
s = strm->state;
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
return destLen;
-
/* default settings: return tight bound for that case */
return compressBound(sourceLen);
}
-
/* =========================================================================
* Put a short in the pending buffer. The 16-bit value is put in MSB order.
* IN assertion: the stream state is correct and there is enough room in
@@ -522,7 +460,6 @@ local void putShortMSB (s, b)
put_byte(s, (Byte)(b >> 8));
put_byte(s, (Byte)(b & 0xff));
}
-
/* =========================================================================
* Flush as much pending output as possible. All deflate() output goes
* through this function so some applications may wish to modify it
@@ -533,10 +470,8 @@ local void flush_pending(strm)
z_streamp strm;
{
unsigned len = strm->state->pending;
-
if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return;
-
zmemcpy(strm->next_out, strm->state->pending_out, len);
strm->next_out += len;
strm->state->pending_out += len;
@@ -547,7 +482,6 @@ local void flush_pending(strm)
strm->state->pending_out = strm->state->pending_buf;
}
}
-
/* ========================================================================= */
int ZEXPORT deflate (strm, flush)
z_streamp strm;
@@ -555,24 +489,20 @@ int ZEXPORT deflate (strm, flush)
{
int old_flush; /* value of flush param for previous deflate call */
deflate_state *s;
-
if (strm == Z_NULL || strm->state == Z_NULL ||
flush > Z_FINISH || flush < 0) {
return Z_STREAM_ERROR;
}
s = strm->state;
-
if (strm->next_out == Z_NULL ||
(strm->next_in == Z_NULL && strm->avail_in != 0) ||
(s->status == FINISH_STATE && flush != Z_FINISH)) {
ERR_RETURN(strm, Z_STREAM_ERROR);
}
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
-
s->strm = strm; /* just in case */
old_flush = s->last_flush;
s->last_flush = flush;
-
/* Write the header */
if (s->status == INIT_STATE) {
#ifdef GZIP
@@ -624,7 +554,6 @@ int ZEXPORT deflate (strm, flush)
{
uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
uInt level_flags;
-
if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
level_flags = 0;
else if (s->level < 6)
@@ -636,10 +565,8 @@ int ZEXPORT deflate (strm, flush)
header |= (level_flags << 6);
if (s->strstart != 0) header |= PRESET_DICT;
header += 31 - (header % 31);
-
s->status = BUSY_STATE;
putShortMSB(s, header);
-
/* Save the adler32 of the preset dictionary: */
if (s->strstart != 0) {
putShortMSB(s, (uInt)(strm->adler >> 16));
@@ -652,7 +579,6 @@ int ZEXPORT deflate (strm, flush)
if (s->status == EXTRA_STATE) {
if (s->gzhead->extra != NULL) {
uInt beg = s->pending; /* start of bytes to update crc */
-
while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
if (s->pending == s->pending_buf_size) {
if (s->gzhead->hcrc && s->pending > beg)
@@ -681,7 +607,6 @@ int ZEXPORT deflate (strm, flush)
if (s->gzhead->name != NULL) {
uInt beg = s->pending; /* start of bytes to update crc */
int val;
-
do {
if (s->pending == s->pending_buf_size) {
if (s->gzhead->hcrc && s->pending > beg)
@@ -712,7 +637,6 @@ int ZEXPORT deflate (strm, flush)
if (s->gzhead->comment != NULL) {
uInt beg = s->pending; /* start of bytes to update crc */
int val;
-
do {
if (s->pending == s->pending_buf_size) {
if (s->gzhead->hcrc && s->pending > beg)
@@ -752,7 +676,6 @@ int ZEXPORT deflate (strm, flush)
s->status = BUSY_STATE;
}
#endif
-
/* Flush as much pending output as possible */
if (s->pending != 0) {
flush_pending(strm);
@@ -766,7 +689,6 @@ int ZEXPORT deflate (strm, flush)
s->last_flush = -1;
return Z_OK;
}
-
/* Make sure there is something to do and avoid duplicate consecutive
* flushes. For repeated and useless calls with Z_FINISH, we keep
* returning Z_STREAM_END instead of Z_BUF_ERROR.
@@ -775,20 +697,16 @@ int ZEXPORT deflate (strm, flush)
flush != Z_FINISH) {
ERR_RETURN(strm, Z_BUF_ERROR);
}
-
/* User must not provide more input after the first FINISH: */
if (s->status == FINISH_STATE && strm->avail_in != 0) {
ERR_RETURN(strm, Z_BUF_ERROR);
}
-
/* Start a new block or continue the current one.
*/
if (strm->avail_in != 0 || s->lookahead != 0 ||
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
block_state bstate;
-
bstate = (*(configuration_table[s->level].func))(s, flush);
-
if (bstate == finish_started || bstate == finish_done) {
s->status = FINISH_STATE;
}
@@ -825,10 +743,8 @@ int ZEXPORT deflate (strm, flush)
}
}
Assert(strm->avail_out > 0, "bug2");
-
if (flush != Z_FINISH) return Z_OK;
if (s->wrap <= 0) return Z_STREAM_END;
-
/* Write the trailer */
#ifdef GZIP
if (s->wrap == 2) {
@@ -854,15 +770,12 @@ int ZEXPORT deflate (strm, flush)
if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
return s->pending != 0 ? Z_OK : Z_STREAM_END;
}
-
/* ========================================================================= */
int ZEXPORT deflateEnd (strm)
z_streamp strm;
{
int status;
-
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-
status = strm->state->status;
if (status != INIT_STATE &&
status != EXTRA_STATE &&
@@ -873,19 +786,15 @@ int ZEXPORT deflateEnd (strm)
status != FINISH_STATE) {
return Z_STREAM_ERROR;
}
-
/* Deallocate in reverse order of allocations: */
TRY_FREE(strm, strm->state->pending_buf);
TRY_FREE(strm, strm->state->head);
TRY_FREE(strm, strm->state->prev);
TRY_FREE(strm, strm->state->window);
-
ZFREE(strm, strm->state);
strm->state = Z_NULL;
-
return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
}
-
/* =========================================================================
* Copy the source state to the destination state.
* To simplify the source, this is not supported for 16-bit MSDOS (which
@@ -902,27 +811,21 @@ int ZEXPORT deflateCopy (dest, source)
deflate_state *ss;
ushf *overlay;
-
if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
return Z_STREAM_ERROR;
}
-
ss = source->state;
-
zmemcpy(dest, source, sizeof(z_stream));
-
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
if (ds == Z_NULL) return Z_MEM_ERROR;
dest->state = (struct internal_state FAR *) ds;
zmemcpy(ds, ss, sizeof(deflate_state));
ds->strm = dest;
-
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
ds->pending_buf = (uchf *) overlay;
-
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
ds->pending_buf == Z_NULL) {
deflateEnd (dest);
@@ -933,19 +836,15 @@ int ZEXPORT deflateCopy (dest, source)
zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
-
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
-
ds->l_desc.dyn_tree = ds->dyn_ltree;
ds->d_desc.dyn_tree = ds->dyn_dtree;
ds->bl_desc.dyn_tree = ds->bl_tree;
-
return Z_OK;
#endif /* MAXSEG_64K */
}
-
/* ===========================================================================
* Read a new buffer from the current input stream, update the adler32
* and total number of bytes read. All deflate() input goes through
@@ -959,12 +858,9 @@ local int read_buf(strm, buf, size)
unsigned size;
{
unsigned len = strm->avail_in;
-
if (len > size) len = size;
if (len == 0) return 0;
-
strm->avail_in -= len;
-
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, strm->next_in, len);
}
@@ -976,10 +872,8 @@ local int read_buf(strm, buf, size)
zmemcpy(buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
-
return (int)len;
}
-
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
@@ -987,16 +881,13 @@ local void lm_init (s)
deflate_state *s;
{
s->window_size = (ulg)2L*s->w_size;
-
CLEAR_HASH(s);
-
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
-
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
@@ -1009,7 +900,6 @@ local void lm_init (s)
#endif
#endif
}
-
#ifndef FASTEST
/* ===========================================================================
* Set match_start to the longest match starting at the given string and
@@ -1041,7 +931,6 @@ local uInt longest_match(s, cur_match)
*/
Posf *prev = s->prev;
uInt wmask = s->w_mask;
-
#ifdef UNALIGNED_OK
/* Compare two bytes at a time. Note: this is not always beneficial.
* Try with and without -DUNALIGNED_OK to check.
@@ -1054,12 +943,10 @@ local uInt longest_match(s, cur_match)
register Byte scan_end1 = scan[best_len-1];
register Byte scan_end = scan[best_len];
#endif
-
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
* It is easy to get rid of this optimization if necessary.
*/
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
-
/* Do not waste too much time if we already have a good match: */
if (s->prev_length >= s->good_match) {
chain_length >>= 2;
@@ -1068,13 +955,10 @@ local uInt longest_match(s, cur_match)
* to make deflate deterministic.
*/
if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
-
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
-
do {
Assert(cur_match < s->strstart, "no future");
match = s->window + cur_match;
-
/* Skip to next match if the match length cannot increase
* or if the match length is less than 2. Note that the checks below
* for insufficient lookahead only occur occasionally for performance
@@ -1089,7 +973,6 @@ local uInt longest_match(s, cur_match)
*/
if (*(ushf*)(match+best_len-1) != scan_end ||
*(ushf*)match != scan_start) continue;
-
/* It is not necessary to compare scan[2] and match[2] since they are
* always equal when the other bytes match, given that the hash keys
* are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
@@ -1108,21 +991,16 @@ local uInt longest_match(s, cur_match)
*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
scan < strend);
/* The funny "do {}" generates better code on most compilers */
-
/* Here, scan <= window+strstart+257 */
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
if (*scan == *match) scan++;
-
len = (MAX_MATCH - 1) - (int)(strend-scan);
scan = strend - (MAX_MATCH-1);
-
#else /* UNALIGNED_OK */
-
if (match[best_len] != scan_end ||
match[best_len-1] != scan_end1 ||
*match != *scan ||
*++match != scan[1]) continue;
-
/* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they
@@ -1131,7 +1009,6 @@ local uInt longest_match(s, cur_match)
*/
scan += 2, match++;
Assert(*scan == *match, "match[2]?");
-
/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
@@ -1141,14 +1018,10 @@ local uInt longest_match(s, cur_match)
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
scan < strend);
-
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
len = MAX_MATCH - (int)(strend - scan);
scan = strend - MAX_MATCH;
-
#endif /* UNALIGNED_OK */
-
if (len > best_len) {
s->match_start = cur_match;
best_len = len;
@@ -1162,13 +1035,11 @@ local uInt longest_match(s, cur_match)
}
} while ((cur_match = prev[cur_match & wmask]) > limit
&& --chain_length != 0);
-
if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
return s->lookahead;
}
#endif /* ASMV */
#endif /* FASTEST */
-
/* ---------------------------------------------------------------------------
* Optimized version for level == 1 or strategy == Z_RLE only
*/
@@ -1180,22 +1051,16 @@ local uInt longest_match_fast(s, cur_match)
register Bytef *match; /* matched string */
register int len; /* length of current match */
register Bytef *strend = s->window + s->strstart + MAX_MATCH;
-
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
* It is easy to get rid of this optimization if necessary.
*/
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
-
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
-
Assert(cur_match < s->strstart, "no future");
-
match = s->window + cur_match;
-
/* Return failure if the match length is less than 2:
*/
if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
-
/* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they
@@ -1204,7 +1069,6 @@ local uInt longest_match_fast(s, cur_match)
*/
scan += 2, match += 2;
Assert(*scan == *match, "match[2]?");
-
/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
@@ -1214,17 +1078,12 @@ local uInt longest_match_fast(s, cur_match)
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
scan < strend);
-
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
len = MAX_MATCH - (int)(strend - scan);
-
if (len < MIN_MATCH) return MIN_MATCH - 1;
-
s->match_start = cur_match;
return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
}
-
#ifdef DEBUG
/* ===========================================================================
* Check that the match at match_start is indeed a match.
@@ -1252,7 +1111,6 @@ local void check_match(s, start, match, length)
#else
# define check_match(s, start, match, length)
#endif /* DEBUG */
-
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead.
@@ -1270,15 +1128,12 @@ local void fill_window(s)
register Posf *p;
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
-
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
-
/* Deal with !@#$% 64K limit: */
if (sizeof(int) <= 2) {
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
more = wsize;
-
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if
* strstart == 0 && lookahead == 1 (input done a byte at time)
@@ -1286,17 +1141,14 @@ local void fill_window(s)
more--;
}
}
-
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (s->strstart >= wsize+MAX_DIST(s)) {
-
zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
s->match_start -= wsize;
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
s->block_start -= (long) wsize;
-
/* Slide the hash table (could be avoided with 32 bit values
at the expense of memory usage). We slide even when level == 0
to keep the hash table consistent if we switch back to level > 0
@@ -1310,7 +1162,6 @@ local void fill_window(s)
m = *--p;
*p = (Pos)(m >= wsize ? m-wsize : NIL);
} while (--n);
-
n = wsize;
#ifndef FASTEST
p = &s->prev[n];
@@ -1325,7 +1176,6 @@ local void fill_window(s)
more += wsize;
}
if (s->strm->avail_in == 0) return;
-
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
@@ -1338,10 +1188,8 @@ local void fill_window(s)
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
-
n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
s->lookahead += n;
-
/* Initialize the hash value now that we have some input: */
if (s->lookahead >= MIN_MATCH) {
s->ins_h = s->window[s->strstart];
@@ -1353,10 +1201,8 @@ local void fill_window(s)
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
*/
-
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
}
-
/* ===========================================================================
* Flush the current block, with given end-of-file flag.
* IN assertion: strstart is set to the end of the current match.
@@ -1371,13 +1217,11 @@ local void fill_window(s)
flush_pending(s->strm); \
Tracev((stderr,"[FLUSH]")); \
}
-
/* Same but force premature exit if necessary. */
#define FLUSH_BLOCK(s, eof) { \
FLUSH_BLOCK_ONLY(s, eof); \
if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
}
-
/* ===========================================================================
* Copy without compression as much as possible from the input stream, return
* the current block state.
@@ -1396,29 +1240,22 @@ local block_state deflate_stored(s, flush)
*/
ulg max_block_size = 0xffff;
ulg max_start;
-
if (max_block_size > s->pending_buf_size - 5) {
max_block_size = s->pending_buf_size - 5;
}
-
/* Copy as much as possible from input to output: */
for (;;) {
/* Fill the window as much as possible: */
if (s->lookahead <= 1) {
-
Assert(s->strstart < s->w_size+MAX_DIST(s) ||
s->block_start >= (long)s->w_size, "slide too late");
-
fill_window(s);
if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
-
if (s->lookahead == 0) break; /* flush the current block */
}
Assert(s->block_start >= 0L, "block gone");
-
s->strstart += s->lookahead;
s->lookahead = 0;
-
/* Emit a stored block if pending_buf will be full: */
max_start = s->block_start + max_block_size;
if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
@@ -1437,7 +1274,6 @@ local block_state deflate_stored(s, flush)
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
}
-
/* ===========================================================================
* Compress as much as possible from the input stream, return the current
* block state.
@@ -1451,7 +1287,6 @@ local block_state deflate_fast(s, flush)
{
IPos hash_head = NIL; /* head of the hash chain */
int bflush; /* set if current block must be flushed */
-
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
@@ -1465,14 +1300,12 @@ local block_state deflate_fast(s, flush)
}
if (s->lookahead == 0) break; /* flush the current block */
}
-
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
if (s->lookahead >= MIN_MATCH) {
INSERT_STRING(s, s->strstart, hash_head);
}
-
/* Find the longest match, discarding those <= prev_length.
* At this point we have always match_length < MIN_MATCH
*/
@@ -1497,12 +1330,9 @@ local block_state deflate_fast(s, flush)
}
if (s->match_length >= MIN_MATCH) {
check_match(s, s->strstart, s->match_start, s->match_length);
-
_tr_tally_dist(s, s->strstart - s->match_start,
s->match_length - MIN_MATCH, bflush);
-
s->lookahead -= s->match_length;
-
/* Insert new strings in the hash table only if the match length
* is not too large. This saves time but degrades compression.
*/
@@ -1544,7 +1374,6 @@ local block_state deflate_fast(s, flush)
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
}
-
#ifndef FASTEST
/* ===========================================================================
* Same as above, but achieves better compression. We use a lazy
@@ -1557,7 +1386,6 @@ local block_state deflate_slow(s, flush)
{
IPos hash_head = NIL; /* head of hash chain */
int bflush; /* set if current block must be flushed */
-
/* Process the input block. */
for (;;) {
/* Make sure that we always have enough lookahead, except
@@ -1572,19 +1400,16 @@ local block_state deflate_slow(s, flush)
}
if (s->lookahead == 0) break; /* flush the current block */
}
-
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
if (s->lookahead >= MIN_MATCH) {
INSERT_STRING(s, s->strstart, hash_head);
}
-
/* Find the longest match, discarding those <= prev_length.
*/
s->prev_length = s->match_length, s->prev_match = s->match_start;
s->match_length = MIN_MATCH-1;
-
if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
s->strstart - hash_head <= MAX_DIST(s)) {
/* To simplify the code, we prevent matches with the string
@@ -1597,14 +1422,12 @@ local block_state deflate_slow(s, flush)
s->match_length = longest_match_fast (s, hash_head);
}
/* longest_match() or longest_match_fast() sets match_start */
-
if (s->match_length <= 5 && (s->strategy == Z_FILTERED
#if TOO_FAR <= 32767
|| (s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR)
#endif
)) {
-
/* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway.
*/
@@ -1617,12 +1440,9 @@ local block_state deflate_slow(s, flush)
if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
/* Do not insert strings in hash table beyond this. */
-
check_match(s, s->strstart-1, s->prev_match, s->prev_length);
-
_tr_tally_dist(s, s->strstart -1 - s->prev_match,
s->prev_length - MIN_MATCH, bflush);
-
/* Insert in hash table all strings up to the end of the match.
* strstart-1 and strstart are already inserted. If there is not
* enough lookahead, the last two strings are not inserted in
@@ -1638,9 +1458,7 @@ local block_state deflate_slow(s, flush)
s->match_available = 0;
s->match_length = MIN_MATCH-1;
s->strstart++;
-
if (bflush) FLUSH_BLOCK(s, 0);
-
} else if (s->match_available) {
/* If there was no match at the previous position, output a
* single literal. If there was a match but the current match
@@ -1673,7 +1491,6 @@ local block_state deflate_slow(s, flush)
return flush == Z_FINISH ? finish_done : block_done;
}
#endif /* FASTEST */
-
#if 0
/* ===========================================================================
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
@@ -1689,7 +1506,6 @@ local block_state deflate_rle(s, flush)
uInt max; /* maximum length of run */
uInt prev; /* byte at distance one to match */
Bytef *scan; /* scan for end of run */
-
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
@@ -1702,7 +1518,6 @@ local block_state deflate_rle(s, flush)
}
if (s->lookahead == 0) break; /* flush the current block */
}
-
/* See how many times the previous byte repeats */
run = 0;
if (s->strstart > 0) { /* if there is a previous byte, that is */
@@ -1714,7 +1529,6 @@ local block_state deflate_rle(s, flush)
break;
} while (++run < max);
}
-
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
if (run >= MIN_MATCH) {
check_match(s, s->strstart, s->strstart - 1, run);
diff --git a/dep/src/zlib/deflate.h b/dep/src/zlib/deflate.h
index d56e97db4cb..8f3d217b13f 100644
--- a/dep/src/zlib/deflate.h
+++ b/dep/src/zlib/deflate.h
@@ -2,19 +2,14 @@
* Copyright (C) 1995-2004 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
-
/* @(#) $Id$ */
-
#ifndef DEFLATE_H
#define DEFLATE_H
-
#include "zutil.h"
-
/* define NO_GZIP when compiling if you want to disable gzip header and
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip encoding
@@ -22,32 +17,23 @@
#ifndef NO_GZIP
# define GZIP
#endif
-
/* ===========================================================================
* Internal compression state.
*/
-
#define LENGTH_CODES 29
/* number of length codes, not counting the special END_BLOCK code */
-
#define LITERALS 256
/* number of literal bytes 0..255 */
-
#define L_CODES (LITERALS+1+LENGTH_CODES)
/* number of Literal or Length codes, including the END_BLOCK code */
-
#define D_CODES 30
/* number of distance codes */
-
#define BL_CODES 19
/* number of codes used to transfer the bit lengths */
-
#define HEAP_SIZE (2*L_CODES+1)
/* maximum heap size */
-
#define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */
-
#define INIT_STATE 42
#define EXTRA_STATE 69
#define NAME_STATE 73
@@ -57,7 +43,6 @@
#define FINISH_STATE 666
/* Stream status */
-
/* Data structure describing a single value and its code string. */
typedef struct ct_data_s {
union {
@@ -69,28 +54,22 @@ typedef struct ct_data_s {
ush len; /* length of bit string */
} dl;
} FAR ct_data;
-
#define Freq fc.freq
#define Code fc.code
#define Dad dl.dad
#define Len dl.len
-
typedef struct static_tree_desc_s static_tree_desc;
-
typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */
static_tree_desc *stat_desc; /* the corresponding static tree */
} FAR tree_desc;
-
typedef ush Pos;
typedef Pos FAR Posf;
typedef unsigned IPos;
-
/* A Pos is an index in the character window. We use short instead of int to
* save space in the various tables. IPos is used only for parameter passing.
*/
-
typedef struct internal_state {
z_streamp strm; /* pointer back to this zlib stream */
int status; /* as the name implies */
@@ -103,13 +82,10 @@ typedef struct internal_state {
uInt gzindex; /* where in extra, name, or comment */
Byte method; /* STORED (for zip only) or DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
-
/* used by deflate.c: */
-
uInt w_size; /* LZ77 window size (32K by default) */
uInt w_bits; /* log2(w_size) (8..16) */
uInt w_mask; /* w_size - 1 */
-
Bytef *window;
/* Sliding window. Input bytes are read into the second half of the window,
* and move to the first half later to keep a dictionary of at least wSize
@@ -119,55 +95,45 @@ typedef struct internal_state {
* the window size to 64K, which is quite useful on MSDOS.
* To do: use the user input buffer as sliding window.
*/
-
ulg window_size;
/* Actual size of window: 2*wSize, except when the user input buffer
* is directly used as sliding window.
*/
-
Posf *prev;
/* Link to older string with same hash index. To limit the size of this
* array to 64K, this link is maintained only for the last 32K strings.
* An index in this array is thus a window index modulo 32K.
*/
-
Posf *head; /* Heads of the hash chains or NIL. */
-
uInt ins_h; /* hash index of string to be inserted */
uInt hash_size; /* number of elements in hash table */
uInt hash_bits; /* log2(hash_size) */
uInt hash_mask; /* hash_size-1 */
-
uInt hash_shift;
/* Number of bits by which ins_h must be shifted at each input
* step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
* hash_shift * MIN_MATCH >= hash_bits
*/
-
long block_start;
/* Window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
-
uInt match_length; /* length of best match */
IPos prev_match; /* previous match */
int match_available; /* set if previous match exists */
uInt strstart; /* start of string to insert */
uInt match_start; /* start of matching string */
uInt lookahead; /* number of valid bytes ahead in window */
-
uInt prev_length;
/* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
*/
-
uInt max_chain_length;
/* To speed up deflation, hash chains are never searched beyond this
* length. A higher limit improves compression ratio but degrades the
* speed.
*/
-
uInt max_lazy_match;
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
@@ -178,41 +144,31 @@ typedef struct internal_state {
* greater than this length. This saves time but degrades compression.
* max_insert_length is used only for compression levels <= 3.
*/
-
int level; /* compression level (1..9) */
int strategy; /* favor or force Huffman coding*/
-
uInt good_match;
/* Use a faster search when the previous match is longer than this */
-
int nice_match; /* Stop searching when current match exceeds this */
-
/* used by trees.c: */
/* Didn't use ct_data typedef below to supress compiler warning */
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
-
struct tree_desc_s l_desc; /* desc. for literal tree */
struct tree_desc_s d_desc; /* desc. for distance tree */
struct tree_desc_s bl_desc; /* desc. for bit length tree */
-
ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
-
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
int heap_len; /* number of elements in the heap */
int heap_max; /* element of largest frequency */
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
* The same heap array is used to build all trees.
*/
-
uch depth[2*L_CODES+1];
/* Depth of each subtree used as tie breaker for trees of equal frequency
*/
-
uchf *l_buf; /* buffer for literals or lengths */
-
uInt lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for
* limiting lit_bufsize to 64K:
@@ -232,25 +188,20 @@ typedef struct internal_state {
* trees more frequently.
* - I can't count above 4
*/
-
uInt last_lit; /* running index in l_buf */
-
ushf *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
*/
-
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
-
#ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
-
ush bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least
* significant bits).
@@ -259,25 +210,20 @@ typedef struct internal_state {
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
*/
-
} FAR deflate_state;
-
/* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf.
*/
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
-
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file.
* See deflate.c for comments about the MIN_MATCH+1.
*/
-
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
/* In order to simplify the code, particularly on 16 bit machines, match
* distances are limited to MAX_DIST instead of WSIZE.
*/
-
/* in trees.c */
void _tr_init OF((deflate_state *s));
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
@@ -286,17 +232,14 @@ void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
void _tr_align OF((deflate_state *s));
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
int eof));
-
#define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
/* Mapping from a distance to a distance code. dist is the distance - 1 and
* must not have side effects. _dist_code[256] and _dist_code[257] are never
* used.
*/
-
#ifndef DEBUG
/* Inline versions of _tr_tally for speed: */
-
#if defined(GEN_TREES_H) || !defined(STDC)
extern uch _length_code[];
extern uch _dist_code[];
@@ -304,7 +247,6 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
extern const uch _length_code[];
extern const uch _dist_code[];
#endif
-
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->d_buf[s->last_lit] = 0; \
@@ -327,6 +269,5 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
# define _tr_tally_dist(s, distance, length, flush) \
flush = _tr_tally(s, distance, length)
#endif
-
#endif /* DEFLATE_H */
diff --git a/dep/src/zlib/example.c b/dep/src/zlib/example.c
index 6c8a0ee7633..7cf0a92a135 100644
--- a/dep/src/zlib/example.c
+++ b/dep/src/zlib/example.c
@@ -2,38 +2,30 @@
* Copyright (C) 1995-2004 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* @(#) $Id$ */
-
#include <stdio.h>
#include "zlib.h"
-
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
-
#if defined(VMS) || defined(RISCOS)
# define TESTFILE "foo-gz"
#else
# define TESTFILE "foo.gz"
#endif
-
#define CHECK_ERR(err, msg) { \
if (err != Z_OK) { \
fprintf(stderr, "%s error: %d\n", msg, err); \
exit(1); \
} \
}
-
const char hello[] = "hello, hello!";
/* "hello world" would be more standard, but the repeated "hello"
* stresses the compression code better, sorry...
*/
-
const char dictionary[] = "hello";
uLong dictId; /* Adler32 value of the dictionary */
-
void test_compress OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_gzio OF((const char *fname,
@@ -52,7 +44,6 @@ void test_dict_deflate OF((Byte *compr, uLong comprLen));
void test_dict_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
int main OF((int argc, char *argv[]));
-
/* ===========================================================================
* Test compress() and uncompress()
*/
@@ -62,15 +53,11 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
{
int err;
uLong len = (uLong)strlen(hello)+1;
-
err = compress(compr, &comprLen, (const Bytef*)hello, len);
CHECK_ERR(err, "compress");
-
strcpy((char*)uncompr, "garbage");
-
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
CHECK_ERR(err, "uncompress");
-
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad uncompress\n");
exit(1);
@@ -78,7 +65,6 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
printf("uncompress(): %s\n", (char *)uncompr);
}
}
-
/* ===========================================================================
* Test read/write of .gz files
*/
@@ -94,7 +80,6 @@ void test_gzio(fname, uncompr, uncomprLen)
int len = (int)strlen(hello)+1;
gzFile file;
z_off_t pos;
-
file = gzopen(fname, "wb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
@@ -111,14 +96,12 @@ void test_gzio(fname, uncompr, uncomprLen)
}
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
gzclose(file);
-
file = gzopen(fname, "rb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
strcpy((char*)uncompr, "garbage");
-
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
exit(1);
@@ -129,24 +112,20 @@ void test_gzio(fname, uncompr, uncomprLen)
} else {
printf("gzread(): %s\n", (char*)uncompr);
}
-
pos = gzseek(file, -8L, SEEK_CUR);
if (pos != 6 || gztell(file) != pos) {
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
(long)pos, (long)gztell(file));
exit(1);
}
-
if (gzgetc(file) != ' ') {
fprintf(stderr, "gzgetc error\n");
exit(1);
}
-
if (gzungetc(' ', file) != ' ') {
fprintf(stderr, "gzungetc error\n");
exit(1);
}
-
gzgets(file, (char*)uncompr, (int)uncomprLen);
if (strlen((char*)uncompr) != 7) { /* " hello!" */
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
@@ -158,11 +137,9 @@ void test_gzio(fname, uncompr, uncomprLen)
} else {
printf("gzgets() after gzseek: %s\n", (char*)uncompr);
}
-
gzclose(file);
#endif
}
-
/* ===========================================================================
* Test deflate() with small buffers
*/
@@ -173,17 +150,13 @@ void test_deflate(compr, comprLen)
z_stream c_stream; /* compression stream */
int err;
uLong len = (uLong)strlen(hello)+1;
-
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
-
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
-
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
-
while (c_stream.total_in != len && c_stream.total_out < comprLen) {
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
err = deflate(&c_stream, Z_NO_FLUSH);
@@ -196,11 +169,9 @@ void test_deflate(compr, comprLen)
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "deflate");
}
-
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
-
/* ===========================================================================
* Test inflate() with small buffers
*/
@@ -210,30 +181,23 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
{
int err;
z_stream d_stream; /* decompression stream */
-
strcpy((char*)uncompr, "garbage");
-
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
-
d_stream.next_in = compr;
d_stream.avail_in = 0;
d_stream.next_out = uncompr;
-
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
-
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "inflate");
}
-
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
-
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate\n");
exit(1);
@@ -241,7 +205,6 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
printf("inflate(): %s\n", (char *)uncompr);
}
}
-
/* ===========================================================================
* Test deflate() with large buffers and dynamic change of compression level
*/
@@ -251,17 +214,13 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
{
z_stream c_stream; /* compression stream */
int err;
-
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
-
err = deflateInit(&c_stream, Z_BEST_SPEED);
CHECK_ERR(err, "deflateInit");
-
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
-
/* At this point, uncompr is still mostly zeroes, so it should compress
* very well:
*/
@@ -273,21 +232,18 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
fprintf(stderr, "deflate not greedy\n");
exit(1);
}
-
/* Feed in already compressed data and switch to no compression: */
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
c_stream.next_in = compr;
c_stream.avail_in = (uInt)comprLen/2;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
-
/* Switch back to compressing mode: */
deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
-
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
@@ -296,7 +252,6 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
-
/* ===========================================================================
* Test inflate() with large buffers
*/
@@ -306,19 +261,14 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
{
int err;
z_stream d_stream; /* decompression stream */
-
strcpy((char*)uncompr, "garbage");
-
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
-
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
-
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
-
for (;;) {
d_stream.next_out = uncompr; /* discard the output */
d_stream.avail_out = (uInt)uncomprLen;
@@ -326,10 +276,8 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "large inflate");
}
-
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
-
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
exit(1);
@@ -337,7 +285,6 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
printf("large_inflate(): OK\n");
}
}
-
/* ===========================================================================
* Test deflate() with full flush
*/
@@ -348,34 +295,27 @@ void test_flush(compr, comprLen)
z_stream c_stream; /* compression stream */
int err;
uInt len = (uInt)strlen(hello)+1;
-
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
-
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
-
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
c_stream.avail_in = 3;
c_stream.avail_out = (uInt)*comprLen;
err = deflate(&c_stream, Z_FULL_FLUSH);
CHECK_ERR(err, "deflate");
-
compr[3]++; /* force an error in first compressed block */
c_stream.avail_in = len - 3;
-
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
-
*comprLen = c_stream.total_out;
}
-
/* ===========================================================================
* Test inflateSync()
*/
@@ -385,29 +325,21 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
{
int err;
z_stream d_stream; /* decompression stream */
-
strcpy((char*)uncompr, "garbage");
-
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
-
d_stream.next_in = compr;
d_stream.avail_in = 2; /* just read the zlib header */
-
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
-
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
-
inflate(&d_stream, Z_NO_FLUSH);
CHECK_ERR(err, "inflate");
-
d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
err = inflateSync(&d_stream); /* but skip the damaged part */
CHECK_ERR(err, "inflateSync");
-
err = inflate(&d_stream, Z_FINISH);
if (err != Z_DATA_ERROR) {
fprintf(stderr, "inflate should report DATA_ERROR\n");
@@ -416,10 +348,8 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
-
printf("after inflateSync(): hel%s\n", (char *)uncompr);
}
-
/* ===========================================================================
* Test deflate() with preset dictionary
*/
@@ -429,25 +359,19 @@ void test_dict_deflate(compr, comprLen)
{
z_stream c_stream; /* compression stream */
int err;
-
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
-
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
CHECK_ERR(err, "deflateInit");
-
err = deflateSetDictionary(&c_stream,
(const Bytef*)dictionary, sizeof(dictionary));
CHECK_ERR(err, "deflateSetDictionary");
-
dictId = c_stream.adler;
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
-
c_stream.next_in = (Bytef*)hello;
c_stream.avail_in = (uInt)strlen(hello)+1;
-
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
@@ -456,7 +380,6 @@ void test_dict_deflate(compr, comprLen)
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
-
/* ===========================================================================
* Test inflate() with a preset dictionary
*/
@@ -466,22 +389,16 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
{
int err;
z_stream d_stream; /* decompression stream */
-
strcpy((char*)uncompr, "garbage");
-
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
-
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
-
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
-
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
-
for (;;) {
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
@@ -495,10 +412,8 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
}
CHECK_ERR(err, "inflate with dict");
}
-
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
-
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate with dict\n");
exit(1);
@@ -506,11 +421,9 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
printf("inflate with dictionary: %s\n", (char *)uncompr);
}
}
-
/* ===========================================================================
* Usage: example [output.gz [input.gz]]
*/
-
int main(argc, argv)
int argc;
char *argv[];
@@ -519,18 +432,14 @@ int main(argc, argv)
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;
-
if (zlibVersion()[0] != myVersion[0]) {
fprintf(stderr, "incompatible zlib version\n");
exit(1);
-
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
fprintf(stderr, "warning: different zlib version\n");
}
-
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
-
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
/* compr and uncompr are cleared to avoid reading uninitialized
@@ -541,25 +450,18 @@ int main(argc, argv)
exit(1);
}
test_compress(compr, comprLen, uncompr, uncomprLen);
-
test_gzio((argc > 1 ? argv[1] : TESTFILE),
uncompr, uncomprLen);
-
test_deflate(compr, comprLen);
test_inflate(compr, comprLen, uncompr, uncomprLen);
-
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
-
test_flush(compr, &comprLen);
test_sync(compr, comprLen, uncompr, uncomprLen);
comprLen = uncomprLen;
-
test_dict_deflate(compr, comprLen);
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
-
free(compr);
free(uncompr);
-
return 0;
}
diff --git a/dep/src/zlib/gzio.c b/dep/src/zlib/gzio.c
index 7e90f4928fc..7143aabebe3 100644
--- a/dep/src/zlib/gzio.c
+++ b/dep/src/zlib/gzio.c
@@ -4,21 +4,15 @@
*
* Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
*/
-
/* @(#) $Id$ */
-
#include <stdio.h>
-
#include "zutil.h"
-
#ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS
#endif
-
#ifndef NO_DUMMY_DECL
struct internal_state {int dummy;}; /* for buggy compilers */
#endif
-
#ifndef Z_BUFSIZE
# ifdef MAXSEG_64K
# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
@@ -29,22 +23,17 @@ struct internal_state {int dummy;}; /* for buggy compilers */
#ifndef Z_PRINTF_BUFSIZE
# define Z_PRINTF_BUFSIZE 4096
#endif
-
#ifdef __MVS__
# pragma map (fdopen , "\174\174FDOPEN")
FILE *fdopen(int, const char *);
#endif
-
#ifndef STDC
extern voidp malloc OF((uInt size));
extern void free OF((voidpf ptr));
#endif
-
#define ALLOC(size) malloc(size)
#define TRYFREE(p) {if (p) free(p);}
-
static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
-
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
@@ -52,7 +41,6 @@ static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define RESERVED 0xE0 /* bits 5..7: reserved */
-
typedef struct gz_stream {
z_stream stream;
int z_err; /* error code for last stream operation */
@@ -72,7 +60,6 @@ typedef struct gz_stream {
int last; /* true if push-back is last character */
} gz_stream;
-
local gzFile gz_open OF((const char *path, const char *mode, int fd));
local int do_flush OF((gzFile file, int flush));
local int get_byte OF((gz_stream *s));
@@ -80,7 +67,6 @@ local void check_header OF((gz_stream *s));
local int destroy OF((gz_stream *s));
local void putLong OF((FILE *file, uLong x));
local uLong getLong OF((gz_stream *s));
-
/* ===========================================================================
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb"). The file is given either by file descriptor
@@ -102,12 +88,9 @@ local gzFile gz_open (path, mode, fd)
gz_stream *s;
char fmode[80]; /* copy of mode, without the compression level */
char *m = fmode;
-
if (!path || !mode) return Z_NULL;
-
s = (gz_stream *)ALLOC(sizeof(gz_stream));
if (!s) return Z_NULL;
-
s->stream.zalloc = (alloc_func)0;
s->stream.zfree = (free_func)0;
s->stream.opaque = (voidpf)0;
@@ -123,13 +106,11 @@ local gzFile gz_open (path, mode, fd)
s->crc = crc32(0L, Z_NULL, 0);
s->msg = NULL;
s->transparent = 0;
-
s->path = (char*)ALLOC(strlen(path)+1);
if (s->path == NULL) {
return destroy(s), (gzFile)Z_NULL;
}
strcpy(s->path, path); /* do this early for debugging */
-
s->mode = '\0';
do {
if (*p == 'r') s->mode = 'r';
@@ -147,7 +128,6 @@ local gzFile gz_open (path, mode, fd)
}
} while (*p++ && m != fmode + sizeof(fmode));
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
-
if (s->mode == 'w') {
#ifdef NO_GZCOMPRESS
err = Z_STREAM_ERROR;
@@ -155,7 +135,6 @@ local gzFile gz_open (path, mode, fd)
err = deflateInit2(&(s->stream), level,
Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
/* windowBits is passed < 0 to suppress zlib header */
-
s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
#endif
if (err != Z_OK || s->outbuf == Z_NULL) {
@@ -163,7 +142,6 @@ local gzFile gz_open (path, mode, fd)
}
} else {
s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
-
err = inflateInit2(&(s->stream), -MAX_WBITS);
/* windowBits is passed < 0 to tell that there is no zlib header.
* Note that in this case inflate *requires* an extra "dummy" byte
@@ -176,10 +154,8 @@ local gzFile gz_open (path, mode, fd)
}
}
s->stream.avail_out = Z_BUFSIZE;
-
errno = 0;
s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
-
if (s->file == NULL) {
return destroy(s), (gzFile)Z_NULL;
}
@@ -198,10 +174,8 @@ local gzFile gz_open (path, mode, fd)
check_header(s); /* skip the .gz header */
s->start = ftell(s->file) - s->stream.avail_in;
}
-
return (gzFile)s;
}
-
/* ===========================================================================
Opens a gzip (.gz) file for reading or writing.
*/
@@ -211,7 +185,6 @@ gzFile ZEXPORT gzopen (path, mode)
{
return gz_open (path, mode, -1);
}
-
/* ===========================================================================
Associate a gzFile with the file descriptor fd. fd is not dup'ed here
to mimic the behavio(u)r of fdopen.
@@ -221,13 +194,10 @@ gzFile ZEXPORT gzdopen (fd, mode)
const char *mode;
{
char name[46]; /* allow for up to 128-bit integers */
-
if (fd < 0) return (gzFile)Z_NULL;
sprintf(name, "<fd:%d>", fd); /* for debugging */
-
return gz_open (name, mode, fd);
}
-
/* ===========================================================================
* Update the compression level and strategy
*/
@@ -237,22 +207,17 @@ int ZEXPORT gzsetparams (file, level, strategy)
int strategy;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
-
/* Make room to allow flushing */
if (s->stream.avail_out == 0) {
-
s->stream.next_out = s->outbuf;
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
s->z_err = Z_ERRNO;
}
s->stream.avail_out = Z_BUFSIZE;
}
-
return deflateParams (&(s->stream), level, strategy);
}
-
/* ===========================================================================
Read a byte from a gz_stream; update next_in and avail_in. Return EOF
for end of file.
@@ -275,7 +240,6 @@ local int get_byte(s)
s->stream.avail_in--;
return *(s->stream.next_in)++;
}
-
/* ===========================================================================
Check the gzip header of a gz_stream opened for reading. Set the stream
mode to transparent if the gzip magic header is not present; set s->err
@@ -292,7 +256,6 @@ local void check_header(s)
int flags; /* flags byte */
uInt len;
int c;
-
/* Assure two bytes in the buffer so we can peek ahead -- handle case
where first byte of header is at the end of the buffer after the last
gzip segment */
@@ -309,7 +272,6 @@ local void check_header(s)
return;
}
}
-
/* Peek ahead to check the gzip magic header */
if (s->stream.next_in[0] != gz_magic[0] ||
s->stream.next_in[1] != gz_magic[1]) {
@@ -318,7 +280,6 @@ local void check_header(s)
}
s->stream.avail_in -= 2;
s->stream.next_in += 2;
-
/* Check the rest of the gzip header */
method = get_byte(s);
flags = get_byte(s);
@@ -326,10 +287,8 @@ local void check_header(s)
s->z_err = Z_DATA_ERROR;
return;
}
-
/* Discard time, xflags and OS code: */
for (len = 0; len < 6; len++) (void)get_byte(s);
-
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
len = (uInt)get_byte(s);
len += ((uInt)get_byte(s))<<8;
@@ -347,7 +306,6 @@ local void check_header(s)
}
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
}
-
/* ===========================================================================
* Cleanup then free the given gz_stream. Return a zlib error code.
Try freeing in the reverse order of allocations.
@@ -356,11 +314,8 @@ local int destroy (s)
gz_stream *s;
{
int err = Z_OK;
-
if (!s) return Z_STREAM_ERROR;
-
TRYFREE(s->msg);
-
if (s->stream.state != NULL) {
if (s->mode == 'w') {
#ifdef NO_GZCOMPRESS
@@ -379,14 +334,12 @@ local int destroy (s)
err = Z_ERRNO;
}
if (s->z_err < 0) err = s->z_err;
-
TRYFREE(s->inbuf);
TRYFREE(s->outbuf);
TRYFREE(s->path);
TRYFREE(s);
return err;
}
-
/* ===========================================================================
Reads the given number of uncompressed bytes from the compressed file.
gzread returns the number of bytes actually read (0 for end of file).
@@ -399,16 +352,12 @@ int ZEXPORT gzread (file, buf, len)
gz_stream *s = (gz_stream*)file;
Bytef *start = (Bytef*)buf; /* starting point for crc computation */
Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
-
if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
-
if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
if (s->z_err == Z_STREAM_END) return 0; /* EOF */
-
next_out = (Byte*)buf;
s->stream.next_out = (Bytef*)buf;
s->stream.avail_out = len;
-
if (s->stream.avail_out && s->back != EOF) {
*next_out++ = s->back;
s->stream.next_out++;
@@ -421,9 +370,7 @@ int ZEXPORT gzread (file, buf, len)
return 1;
}
}
-
while (s->stream.avail_out != 0) {
-
if (s->transparent) {
/* Copy first the lookahead bytes: */
uInt n = s->stream.avail_in;
@@ -447,7 +394,6 @@ int ZEXPORT gzread (file, buf, len)
return (int)len;
}
if (s->stream.avail_in == 0 && !s->z_eof) {
-
errno = 0;
s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
if (s->stream.avail_in == 0) {
@@ -464,12 +410,10 @@ int ZEXPORT gzread (file, buf, len)
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
s->in -= s->stream.avail_in;
s->out -= s->stream.avail_out;
-
if (s->z_err == Z_STREAM_END) {
/* Check CRC and original size */
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
start = s->stream.next_out;
-
if (getLong(s) != s->crc) {
s->z_err = Z_DATA_ERROR;
} else {
@@ -488,14 +432,12 @@ int ZEXPORT gzread (file, buf, len)
if (s->z_err != Z_OK || s->z_eof) break;
}
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
-
if (len == s->stream.avail_out &&
(s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO))
return -1;
return (int)(len - s->stream.avail_out);
}
-
/* ===========================================================================
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
@@ -504,11 +446,9 @@ int ZEXPORT gzgetc(file)
gzFile file;
{
unsigned char c;
-
return gzread(file, &c, 1) == 1 ? c : -1;
}
-
/* ===========================================================================
Push one byte back onto the stream.
*/
@@ -517,7 +457,6 @@ int ZEXPORT gzungetc(c, file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
s->back = c;
s->out--;
@@ -527,14 +466,12 @@ int ZEXPORT gzungetc(c, file)
return c;
}
-
/* ===========================================================================
Reads bytes from the compressed file until len-1 characters are
read, or a newline character is read and transferred to buf, or an
end-of-file condition is encountered. The string is then terminated
with a null character.
gzgets returns buf, or Z_NULL in case of error.
-
The current implementation is not optimized at all.
*/
char * ZEXPORT gzgets(file, buf, len)
@@ -544,13 +481,11 @@ char * ZEXPORT gzgets(file, buf, len)
{
char *b = buf;
if (buf == Z_NULL || len <= 0) return Z_NULL;
-
while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
*buf = '\0';
return b == buf && len > 0 ? Z_NULL : b;
}
-
#ifndef NO_GZCOMPRESS
/* ===========================================================================
Writes the given number of uncompressed bytes into the compressed file.
@@ -562,16 +497,11 @@ int ZEXPORT gzwrite (file, buf, len)
unsigned len;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
-
s->stream.next_in = (Bytef*)buf;
s->stream.avail_in = len;
-
while (s->stream.avail_in != 0) {
-
if (s->stream.avail_out == 0) {
-
s->stream.next_out = s->outbuf;
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
s->z_err = Z_ERRNO;
@@ -587,11 +517,9 @@ int ZEXPORT gzwrite (file, buf, len)
if (s->z_err != Z_OK) break;
}
s->crc = crc32(s->crc, (const Bytef *)buf, len);
-
return (int)(len - s->stream.avail_in);
}
-
/* ===========================================================================
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
@@ -599,13 +527,11 @@ int ZEXPORT gzwrite (file, buf, len)
*/
#ifdef STDC
#include <stdarg.h>
-
int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
{
char buf[Z_PRINTF_BUFSIZE];
va_list va;
int len;
-
buf[sizeof(buf) - 1] = 0;
va_start(va, format);
#ifdef NO_vsnprintf
@@ -633,7 +559,6 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
return gzwrite(file, buf, (unsigned)len);
}
#else /* not ANSI C */
-
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
gzFile file;
@@ -643,7 +568,6 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
{
char buf[Z_PRINTF_BUFSIZE];
int len;
-
buf[sizeof(buf) - 1] = 0;
#ifdef NO_snprintf
# ifdef HAS_sprintf_void
@@ -670,7 +594,6 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
return gzwrite(file, buf, len);
}
#endif
-
/* ===========================================================================
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
@@ -680,11 +603,9 @@ int ZEXPORT gzputc(file, c)
int c;
{
unsigned char cc = (unsigned char) c; /* required for big endian systems */
-
return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
}
-
/* ===========================================================================
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
@@ -697,7 +618,6 @@ int ZEXPORT gzputs(file, s)
return gzwrite(file, (char*)s, (unsigned)strlen(s));
}
-
/* ===========================================================================
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function.
@@ -709,14 +629,10 @@ local int do_flush (file, flush)
uInt len;
int done = 0;
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
-
s->stream.avail_in = 0; /* should be zero already anyway */
-
for (;;) {
len = Z_BUFSIZE - s->stream.avail_out;
-
if (len != 0) {
if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
s->z_err = Z_ERRNO;
@@ -729,33 +645,27 @@ local int do_flush (file, flush)
s->out += s->stream.avail_out;
s->z_err = deflate(&(s->stream), flush);
s->out -= s->stream.avail_out;
-
/* Ignore the second of two consecutive flushes: */
if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
-
/* deflate has finished flushing only when it hasn't used up
* all the available space in the output buffer:
*/
done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
-
if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
}
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
}
-
int ZEXPORT gzflush (file, flush)
gzFile file;
int flush;
{
gz_stream *s = (gz_stream*)file;
int err = do_flush (file, flush);
-
if (err) return err;
fflush(s->file);
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
}
#endif /* NO_GZCOMPRESS */
-
/* ===========================================================================
Sets the starting position for the next gzread or gzwrite on the given
compressed file. The offset represents a number of bytes in the
@@ -770,12 +680,10 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
int whence;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || whence == SEEK_END ||
s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
return -1L;
}
-
if (s->mode == 'w') {
#ifdef NO_GZCOMPRESS
return -1L;
@@ -784,7 +692,6 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
offset -= s->in;
}
if (offset < 0) return -1L;
-
/* At this point, offset is the number of zero bytes to write. */
if (s->inbuf == Z_NULL) {
s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
@@ -794,34 +701,28 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
while (offset > 0) {
uInt size = Z_BUFSIZE;
if (offset < Z_BUFSIZE) size = (uInt)offset;
-
size = gzwrite(file, s->inbuf, size);
if (size == 0) return -1L;
-
offset -= size;
}
return s->in;
#endif
}
/* Rest of function is for reading only */
-
/* compute absolute position */
if (whence == SEEK_CUR) {
offset += s->out;
}
if (offset < 0) return -1L;
-
if (s->transparent) {
/* map to fseek */
s->back = EOF;
s->stream.avail_in = 0;
s->stream.next_in = s->inbuf;
if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
-
s->in = s->out = offset;
return offset;
}
-
/* For a negative seek, rewind and use positive seek */
if (offset >= s->out) {
offset -= s->out;
@@ -829,7 +730,6 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
return -1L;
}
/* offset is now the number of bytes to skip. */
-
if (offset != 0 && s->outbuf == Z_NULL) {
s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
if (s->outbuf == Z_NULL) return -1L;
@@ -843,14 +743,12 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
while (offset > 0) {
int size = Z_BUFSIZE;
if (offset < Z_BUFSIZE) size = (int)offset;
-
size = gzread(file, s->outbuf, (uInt)size);
if (size <= 0) return -1L;
offset -= size;
}
return s->out;
}
-
/* ===========================================================================
Rewinds input file.
*/
@@ -858,9 +756,7 @@ int ZEXPORT gzrewind (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || s->mode != 'r') return -1;
-
s->z_err = Z_OK;
s->z_eof = 0;
s->back = EOF;
@@ -872,7 +768,6 @@ int ZEXPORT gzrewind (file)
s->out = 0;
return fseek(s->file, s->start, SEEK_SET);
}
-
/* ===========================================================================
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
@@ -883,7 +778,6 @@ z_off_t ZEXPORT gztell (file)
{
return gzseek(file, 0L, SEEK_CUR);
}
-
/* ===========================================================================
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
@@ -892,7 +786,6 @@ int ZEXPORT gzeof (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
-
/* With concatenated compressed files that can have embedded
* crc trailers, z_eof is no longer the only/best indicator of EOF
* on a gz_stream. Handle end-of-stream error explicitly here.
@@ -901,7 +794,6 @@ int ZEXPORT gzeof (file)
if (s->z_eof) return 1;
return s->z_err == Z_STREAM_END;
}
-
/* ===========================================================================
Returns 1 if reading and doing so transparently, otherwise zero.
*/
@@ -909,11 +801,9 @@ int ZEXPORT gzdirect (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL || s->mode != 'r') return 0;
return s->transparent;
}
-
/* ===========================================================================
Outputs a long in LSB order to the given file
*/
@@ -927,7 +817,6 @@ local void putLong (file, x)
x >>= 8;
}
}
-
/* ===========================================================================
Reads a long in LSB order from the given gz_stream. Sets z_err in case
of error.
@@ -937,7 +826,6 @@ local uLong getLong (s)
{
uLong x = (uLong)get_byte(s);
int c;
-
x += ((uLong)get_byte(s))<<8;
x += ((uLong)get_byte(s))<<16;
c = get_byte(s);
@@ -945,7 +833,6 @@ local uLong getLong (s)
x += ((uLong)c)<<24;
return x;
}
-
/* ===========================================================================
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state.
@@ -954,29 +841,24 @@ int ZEXPORT gzclose (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL) return Z_STREAM_ERROR;
-
if (s->mode == 'w') {
#ifdef NO_GZCOMPRESS
return Z_STREAM_ERROR;
#else
if (do_flush (file, Z_FINISH) != Z_OK)
return destroy((gz_stream*)file);
-
putLong (s->file, s->crc);
putLong (s->file, (uLong)(s->in & 0xffffffff));
#endif
}
return destroy((gz_stream*)file);
}
-
#ifdef STDC
# define zstrerror(errnum) strerror(errnum)
#else
# define zstrerror(errnum) ""
#endif
-
/* ===========================================================================
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
@@ -990,18 +872,14 @@ const char * ZEXPORT gzerror (file, errnum)
{
char *m;
gz_stream *s = (gz_stream*)file;
-
if (s == NULL) {
*errnum = Z_STREAM_ERROR;
return (const char*)ERR_MSG(Z_STREAM_ERROR);
}
*errnum = s->z_err;
if (*errnum == Z_OK) return (const char*)"";
-
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
-
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
-
TRYFREE(s->msg);
s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR);
@@ -1010,7 +888,6 @@ const char * ZEXPORT gzerror (file, errnum)
strcat(s->msg, m);
return (const char*)s->msg;
}
-
/* ===========================================================================
Clear the error and end-of-file flags, and do the same for the real file.
*/
@@ -1018,7 +895,6 @@ void ZEXPORT gzclearerr (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
-
if (s == NULL) return;
if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
s->z_eof = 0;
diff --git a/dep/src/zlib/infback.c b/dep/src/zlib/infback.c
index 455dbc9ee84..80f35cc59ac 100644
--- a/dep/src/zlib/infback.c
+++ b/dep/src/zlib/infback.c
@@ -2,26 +2,21 @@
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/*
This code is largely copied from inflate.c. Normally either infback.o or
inflate.o would be linked into an application--not both. The interface
with inffast.c is retained so that optimized assembler-coded versions of
inflate_fast() can be used with either inflate.c or infback.c.
*/
-
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
-
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
-
/*
strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions.
-
windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes.
*/
@@ -33,7 +28,6 @@ const char *version;
int stream_size;
{
struct inflate_state FAR *state;
-
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
@@ -59,7 +53,6 @@ int stream_size;
state->whave = 0;
return Z_OK;
}
-
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
@@ -77,12 +70,10 @@ struct inflate_state FAR *state;
static int virgin = 1;
static code *lenfix, *distfix;
static code fixed[544];
-
/* build fixed huffman tables if first call (may not be thread safe) */
if (virgin) {
unsigned sym, bits;
static code *next;
-
/* literal/length table */
sym = 0;
while (sym < 144) state->lens[sym++] = 8;
@@ -93,14 +84,12 @@ struct inflate_state FAR *state;
lenfix = next;
bits = 9;
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
/* distance table */
sym = 0;
while (sym < 32) state->lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
/* do this just once */
virgin = 0;
}
@@ -112,9 +101,7 @@ struct inflate_state FAR *state;
state->distcode = distfix;
state->distbits = 5;
}
-
/* Macros for inflateBack(): */
-
/* Load returned state from inflate_fast() */
#define LOAD() \
do { \
@@ -125,7 +112,6 @@ struct inflate_state FAR *state;
hold = state->hold; \
bits = state->bits; \
} while (0)
-
/* Set state from registers for inflate_fast() */
#define RESTORE() \
do { \
@@ -136,14 +122,12 @@ struct inflate_state FAR *state;
state->hold = hold; \
state->bits = bits; \
} while (0)
-
/* Clear the input bit accumulator */
#define INITBITS() \
do { \
hold = 0; \
bits = 0; \
} while (0)
-
/* Assure that some input is available. If input is requested, but denied,
then return a Z_BUF_ERROR from inflateBack(). */
#define PULL() \
@@ -157,7 +141,6 @@ struct inflate_state FAR *state;
} \
} \
} while (0)
-
/* Get a byte of input into the bit accumulator, or return from inflateBack()
with an error if there is no input available. */
#define PULLBYTE() \
@@ -167,7 +150,6 @@ struct inflate_state FAR *state;
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
-
/* Assure that there are at least n bits in the bit accumulator. If there is
not enough available input to do that, then return from inflateBack() with
an error. */
@@ -176,25 +158,21 @@ struct inflate_state FAR *state;
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)
-
/* Return the low n bits of the bit accumulator (n < 16) */
#define BITS(n) \
((unsigned)hold & ((1U << (n)) - 1))
-
/* Remove n bits from the bit accumulator */
#define DROPBITS(n) \
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
-
/* Remove zero to seven bits as needed to go to a byte boundary */
#define BYTEBITS() \
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
-
/* Assure that some output space is available, by writing out the window
if it's full. If the write fails, return from inflateBack() with a
Z_BUF_ERROR. */
@@ -210,12 +188,10 @@ struct inflate_state FAR *state;
} \
} \
} while (0)
-
/*
strm provides the memory allocation functions and window buffer on input,
and provides information on the unused input on return. For Z_DATA_ERROR
returns, strm will also provide an error message.
-
in() and out() are the call-back input and output functions. When
inflateBack() needs more input, it calls in(). When inflateBack() has
filled the window with output, or when it completes with data in the
@@ -223,12 +199,10 @@ struct inflate_state FAR *state;
change the provided input until in() is called again or inflateBack()
returns. The application must not change the window/output buffer until
inflateBack() returns.
-
in() and out() are called with a descriptor parameter provided in the
inflateBack() call. This parameter can be a structure that provides the
information required to do the read or write, as well as accumulated
information on the input and output such as totals and check values.
-
in() should return zero on failure. out() should return non-zero on
failure. If either in() or out() fails, than inflateBack() returns a
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
@@ -259,12 +233,10 @@ void FAR *out_desc;
int ret; /* return code */
static const unsigned short order[19] = /* permutation of code lengths */
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
/* Check that the strm exists and that the state was initialized */
if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
-
/* Reset the state */
strm->msg = Z_NULL;
state->mode = TYPE;
@@ -276,7 +248,6 @@ void FAR *out_desc;
bits = 0;
put = state->window;
left = state->wsize;
-
/* Inflate until end of block marked as last */
for (;;)
switch (state->mode) {
@@ -313,7 +284,6 @@ void FAR *out_desc;
}
DROPBITS(2);
break;
-
case STORED:
/* get and verify stored block length */
BYTEBITS(); /* go to byte boundary */
@@ -327,7 +297,6 @@ void FAR *out_desc;
Tracev((stderr, "inflate: stored length %u\n",
state->length));
INITBITS();
-
/* copy stored block from input to output */
while (state->length != 0) {
copy = state->length;
@@ -345,7 +314,6 @@ void FAR *out_desc;
Tracev((stderr, "inflate: stored end\n"));
state->mode = TYPE;
break;
-
case TABLE:
/* get dynamic table entries descriptor */
NEEDBITS(14);
@@ -363,7 +331,6 @@ void FAR *out_desc;
}
#endif
Tracev((stderr, "inflate: table sizes ok\n"));
-
/* get code length code lengths (not a typo) */
state->have = 0;
while (state->have < state->ncode) {
@@ -384,7 +351,6 @@ void FAR *out_desc;
break;
}
Tracev((stderr, "inflate: code lengths ok\n"));
-
/* get length and distance code code lengths */
state->have = 0;
while (state->have < state->nlen + state->ndist) {
@@ -434,10 +400,8 @@ void FAR *out_desc;
state->lens[state->have++] = (unsigned short)len;
}
}
-
/* handle error breaks in while */
if (state->mode == BAD) break;
-
/* build code tables */
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
@@ -460,7 +424,6 @@ void FAR *out_desc;
}
Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN;
-
case LEN:
/* use inflate_fast() if we have enough input and output */
if (have >= 6 && left >= 258) {
@@ -471,7 +434,6 @@ void FAR *out_desc;
LOAD();
break;
}
-
/* get a literal, length, or end-of-block code */
for (;;) {
this = state->lencode[BITS(state->lenbits)];
@@ -490,7 +452,6 @@ void FAR *out_desc;
}
DROPBITS(this.bits);
state->length = (unsigned)this.val;
-
/* process literal */
if (this.op == 0) {
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
@@ -502,21 +463,18 @@ void FAR *out_desc;
state->mode = LEN;
break;
}
-
/* process end of block */
if (this.op & 32) {
Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE;
break;
}
-
/* invalid code */
if (this.op & 64) {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
}
-
/* length code -- get extra bits, if any */
state->extra = (unsigned)(this.op) & 15;
if (state->extra != 0) {
@@ -525,7 +483,6 @@ void FAR *out_desc;
DROPBITS(state->extra);
}
Tracevv((stderr, "inflate: length %u\n", state->length));
-
/* get distance code */
for (;;) {
this = state->distcode[BITS(state->distbits)];
@@ -549,7 +506,6 @@ void FAR *out_desc;
break;
}
state->offset = (unsigned)this.val;
-
/* get distance extra bits, if any */
state->extra = (unsigned)(this.op) & 15;
if (state->extra != 0) {
@@ -564,7 +520,6 @@ void FAR *out_desc;
break;
}
Tracevv((stderr, "inflate: distance %u\n", state->offset));
-
/* copy match from window to output */
do {
ROOM();
@@ -585,7 +540,6 @@ void FAR *out_desc;
} while (--copy);
} while (state->length != 0);
break;
-
case DONE:
/* inflate stream terminated properly -- write leftover output */
ret = Z_STREAM_END;
@@ -594,23 +548,19 @@ void FAR *out_desc;
ret = Z_BUF_ERROR;
}
goto inf_leave;
-
case BAD:
ret = Z_DATA_ERROR;
goto inf_leave;
-
default: /* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR;
goto inf_leave;
}
-
/* Return unused input */
inf_leave:
strm->next_in = next;
strm->avail_in = have;
return ret;
}
-
int ZEXPORT inflateBackEnd(strm)
z_streamp strm;
{
diff --git a/dep/src/zlib/inffast.c b/dep/src/zlib/inffast.c
index bbee92ed1e6..25f57b424c0 100644
--- a/dep/src/zlib/inffast.c
+++ b/dep/src/zlib/inffast.c
@@ -2,14 +2,11 @@
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
-
#ifndef ASMINF
-
/* Allow machine dependent optimization for post-increment or pre-increment.
Based on testing to date,
Pre-increment preferred for:
@@ -28,7 +25,6 @@
# define OFF 1
# define PUP(a) *++(a)
#endif
-
/*
Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is
@@ -36,29 +32,22 @@
When large enough input and output buffers are supplied to inflate(), for
example, a 16K input buffer and a 64K output buffer, more than 95% of the
inflate execution time is spent in this routine.
-
Entry assumptions:
-
state->mode == LEN
strm->avail_in >= 6
strm->avail_out >= 258
start >= strm->avail_out
state->bits < 8
-
On return, state->mode is one of:
-
LEN -- ran out of enough output space or enough available input
TYPE -- reached end of block code, inflate() to interpret next block
BAD -- error in block data
-
Notes:
-
- The maximum input bits used by a length/distance pair is 15 bits for the
length code, 5 bits for the length extra, 15 bits for the distance code,
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
Therefore if strm->avail_in >= 6, then there is enough input to avoid
checking for available input while decoding.
-
- The maximum bytes that a single length/distance pair can output is 258
bytes, which is the maximum length that can be coded. inflate_fast()
requires strm->avail_out >= 258 for each loop to avoid checking for
@@ -93,7 +82,6 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
unsigned len; /* match length, unused bytes */
unsigned dist; /* match distance */
unsigned char FAR *from; /* where to copy match from */
-
/* copy state to local variables */
state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF;
@@ -114,7 +102,6 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
dcode = state->distcode;
lmask = (1U << state->lenbits) - 1;
dmask = (1U << state->distbits) - 1;
-
/* decode literals and length/distances until end-of-block or not enough
input data or output space */
do {
@@ -283,13 +270,11 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
break;
}
} while (in < last && out < end);
-
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3;
in -= len;
bits -= len << 3;
hold &= (1U << bits) - 1;
-
/* update state and return */
strm->next_in = in + OFF;
strm->next_out = out + OFF;
@@ -300,7 +285,6 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
state->bits = bits;
return;
}
-
/*
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- Using bit fields for code structure
@@ -314,5 +298,4 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
- Larger unrolled copy loops (three is about right)
- Moving len -= 3 statement into middle of loop
*/
-
#endif /* !ASMINF */
diff --git a/dep/src/zlib/inffast.h b/dep/src/zlib/inffast.h
index c66fae6da2c..2b59deac282 100644
--- a/dep/src/zlib/inffast.h
+++ b/dep/src/zlib/inffast.h
@@ -2,11 +2,9 @@
* Copyright (C) 1995-2003 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
-
void inflate_fast OF((z_streamp strm, unsigned start));
diff --git a/dep/src/zlib/inffixed.h b/dep/src/zlib/inffixed.h
index 3757019557f..16b7e6f4cda 100644
--- a/dep/src/zlib/inffixed.h
+++ b/dep/src/zlib/inffixed.h
@@ -1,12 +1,10 @@
/* inffixed.h -- table for decoding fixed codes
* Generated automatically by makefixed().
*/
-
/* WARNING: this file should *not* be used by applications. It
is part of the implementation of the compression library and
is subject to change. Applications should only use zlib.h.
*/
-
static const code lenfix[512] = {
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
@@ -83,7 +81,6 @@
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
{0,9,255}
};
-
static const code distfix[32] = {
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
diff --git a/dep/src/zlib/inflate.c b/dep/src/zlib/inflate.c
index 792fdee8e9c..733563d5e5a 100644
--- a/dep/src/zlib/inflate.c
+++ b/dep/src/zlib/inflate.c
@@ -2,7 +2,6 @@
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/*
* Change history:
*
@@ -79,18 +78,15 @@
*
* The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
*/
-
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
-
#ifdef MAKEFIXED
# ifndef BUILDFIXED
# define BUILDFIXED
# endif
#endif
-
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
local int updatewindow OF((z_streamp strm, unsigned out));
@@ -99,12 +95,10 @@ local int updatewindow OF((z_streamp strm, unsigned out));
#endif
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
unsigned len));
-
int ZEXPORT inflateReset(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
-
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
strm->total_in = strm->total_out = state->total = 0;
@@ -124,14 +118,12 @@ z_streamp strm;
Tracev((stderr, "inflate: reset\n"));
return Z_OK;
}
-
int ZEXPORT inflatePrime(strm, bits, value)
z_streamp strm;
int bits;
int value;
{
struct inflate_state FAR *state;
-
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
@@ -140,7 +132,6 @@ int value;
state->bits += bits;
return Z_OK;
}
-
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
z_streamp strm;
int windowBits;
@@ -148,7 +139,6 @@ const char *version;
int stream_size;
{
struct inflate_state FAR *state;
-
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
@@ -183,7 +173,6 @@ int stream_size;
state->window = Z_NULL;
return inflateReset(strm);
}
-
int ZEXPORT inflateInit_(strm, version, stream_size)
z_streamp strm;
const char *version;
@@ -191,7 +180,6 @@ int stream_size;
{
return inflateInit2_(strm, DEF_WBITS, version, stream_size);
}
-
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
@@ -209,12 +197,10 @@ struct inflate_state FAR *state;
static int virgin = 1;
static code *lenfix, *distfix;
static code fixed[544];
-
/* build fixed huffman tables if first call (may not be thread safe) */
if (virgin) {
unsigned sym, bits;
static code *next;
-
/* literal/length table */
sym = 0;
while (sym < 144) state->lens[sym++] = 8;
@@ -225,14 +211,12 @@ struct inflate_state FAR *state;
lenfix = next;
bits = 9;
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
/* distance table */
sym = 0;
while (sym < 32) state->lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
/* do this just once */
virgin = 0;
}
@@ -244,33 +228,26 @@ struct inflate_state FAR *state;
state->distcode = distfix;
state->distbits = 5;
}
-
#ifdef MAKEFIXED
#include <stdio.h>
-
/*
Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
those tables to stdout, which would be piped to inffixed.h. A small program
can simply call makefixed to do this:
-
void makefixed(void);
-
int main(void)
{
makefixed();
return 0;
}
-
Then that can be linked with zlib built with MAKEFIXED defined and run:
-
a.out > inffixed.h
*/
void makefixed()
{
unsigned low, size;
struct inflate_state state;
-
fixedtables(&state);
puts(" /* inffixed.h -- table for decoding fixed codes");
puts(" * Generated automatically by makefixed().");
@@ -305,7 +282,6 @@ void makefixed()
puts("\n };");
}
#endif /* MAKEFIXED */
-
/*
Update the window with the last wsize (normally 32K) bytes written before
returning. If window does not exist yet, create it. This is only called
@@ -313,7 +289,6 @@ void makefixed()
inflate call, but the end of the deflate stream has not been reached yet.
It is also called to create a window for dictionary data when a dictionary
is loaded.
-
Providing output buffers larger than 32K to inflate() should provide a speed
advantage, since only the last 32K of output is copied to the sliding window
upon return from inflate(), and since all distances after the first 32K of
@@ -326,9 +301,7 @@ unsigned out;
{
struct inflate_state FAR *state;
unsigned copy, dist;
-
state = (struct inflate_state FAR *)strm->state;
-
/* if it hasn't been done already, allocate space for the window */
if (state->window == Z_NULL) {
state->window = (unsigned char FAR *)
@@ -336,14 +309,12 @@ unsigned out;
sizeof(unsigned char));
if (state->window == Z_NULL) return 1;
}
-
/* if window not in use yet, initialize */
if (state->wsize == 0) {
state->wsize = 1U << state->wbits;
state->write = 0;
state->whave = 0;
}
-
/* copy state->wsize or less output bytes into the circular window */
copy = out - strm->avail_out;
if (copy >= state->wsize) {
@@ -369,9 +340,7 @@ unsigned out;
}
return 0;
}
-
/* Macros for inflate(): */
-
/* check function to use adler32() for zlib or crc32() for gzip */
#ifdef GUNZIP
# define UPDATE(check, buf, len) \
@@ -379,7 +348,6 @@ unsigned out;
#else
# define UPDATE(check, buf, len) adler32(check, buf, len)
#endif
-
/* check macros for header crc */
#ifdef GUNZIP
# define CRC2(check, word) \
@@ -388,7 +356,6 @@ unsigned out;
hbuf[1] = (unsigned char)((word) >> 8); \
check = crc32(check, hbuf, 2); \
} while (0)
-
# define CRC4(check, word) \
do { \
hbuf[0] = (unsigned char)(word); \
@@ -398,7 +365,6 @@ unsigned out;
check = crc32(check, hbuf, 4); \
} while (0)
#endif
-
/* Load registers with state in inflate() for speed */
#define LOAD() \
do { \
@@ -409,7 +375,6 @@ unsigned out;
hold = state->hold; \
bits = state->bits; \
} while (0)
-
/* Restore state from registers in inflate() */
#define RESTORE() \
do { \
@@ -420,14 +385,12 @@ unsigned out;
state->hold = hold; \
state->bits = bits; \
} while (0)
-
/* Clear the input bit accumulator */
#define INITBITS() \
do { \
hold = 0; \
bits = 0; \
} while (0)
-
/* Get a byte of input into the bit accumulator, or return from inflate()
if there is no input available. */
#define PULLBYTE() \
@@ -437,7 +400,6 @@ unsigned out;
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
-
/* Assure that there are at least n bits in the bit accumulator. If there is
not enough available input to do that, then return from inflate(). */
#define NEEDBITS(n) \
@@ -445,35 +407,29 @@ unsigned out;
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)
-
/* Return the low n bits of the bit accumulator (n < 16) */
#define BITS(n) \
((unsigned)hold & ((1U << (n)) - 1))
-
/* Remove n bits from the bit accumulator */
#define DROPBITS(n) \
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
-
/* Remove zero to seven bits as needed to go to a byte boundary */
#define BYTEBITS() \
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
-
/* Reverse the bytes in a 32-bit value */
#define REVERSE(q) \
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
-
/*
inflate() uses a state machine to process as much input data and generate as
much output data as possible before returning. The state machine is
structured roughly as follows:
-
for (;;) switch (state) {
...
case STATEn:
@@ -484,18 +440,15 @@ unsigned out;
break;
...
}
-
so when inflate() is called again, the same case is attempted again, and
if the appropriate resources are provided, the machine proceeds to the
next state. The NEEDBITS() macro is usually the way the state evaluates
whether it can proceed or should return. NEEDBITS() does the return if
the requested bits are not available. The typical use of the BITS macros
is:
-
NEEDBITS(n);
... do something with BITS(n) ...
DROPBITS(n);
-
where NEEDBITS(n) either returns from inflate() if there isn't enough
input left to load n bits into the accumulator, or it continues. BITS(n)
gives the low n bits in the accumulator. When done, DROPBITS(n) drops
@@ -503,18 +456,15 @@ unsigned out;
and sets the number of available bits to zero. BYTEBITS() discards just
enough bits to put the accumulator on a byte boundary. After BYTEBITS()
and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
-
NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
if there is no input available. The decoding of variable length codes uses
PULLBYTE() directly in order to pull just enough bytes to decode the next
code, and no more.
-
Some states loop until they get enough input, making sure that enough
state information is maintained to continue the loop where it left off
if NEEDBITS() returns in the loop. For example, want, need, and keep
would all have to actually be part of the saved state in case NEEDBITS()
returns:
-
case STATEw:
while (want < need) {
NEEDBITS(n);
@@ -523,14 +473,11 @@ unsigned out;
}
state = STATEx;
case STATEx:
-
As shown above, if the next state is also the next case, then the break
is omitted.
-
A state may also return if there is not enough output space available to
complete that state. Those states are copying stored data, writing a
literal byte, and copying a matching string.
-
When returning, a "goto inf_leave" is used to update the total counters,
update the check value, and determine whether any progress has been made
during that inflate() call in order to return the proper return code.
@@ -539,7 +486,6 @@ unsigned out;
output written. If a goto inf_leave occurs in the middle of decompression
and there is no window currently, goto inf_leave will create one and copy
output to the window for the next call of inflate().
-
In this implementation, the flush parameter of inflate() only affects the
return code (per zlib.h). inflate() always writes as much as possible to
strm->next_out, given the space available and the provided input--the effect
@@ -550,7 +496,6 @@ unsigned out;
when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
will return Z_BUF_ERROR if it has not reached the end of the stream.
*/
-
int ZEXPORT inflate(strm, flush)
z_streamp strm;
int flush;
@@ -573,11 +518,9 @@ int flush;
#endif
static const unsigned short order[19] = /* permutation of code lengths */
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
(strm->next_in == Z_NULL && strm->avail_in != 0))
return Z_STREAM_ERROR;
-
state = (struct inflate_state FAR *)strm->state;
if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
LOAD();
@@ -921,10 +864,8 @@ int flush;
state->lens[state->have++] = (unsigned short)len;
}
}
-
/* handle error breaks in while */
if (state->mode == BAD) break;
-
/* build code tables */
state->next = state->codes;
state->lencode = (code const FAR *)(state->next);
@@ -1123,7 +1064,6 @@ int flush;
default:
return Z_STREAM_ERROR;
}
-
/*
Return from inflate(), updating the total counts and the check value.
If there was no progress during the inflate() call, return a buffer
@@ -1151,7 +1091,6 @@ int flush;
ret = Z_BUF_ERROR;
return ret;
}
-
int ZEXPORT inflateEnd(strm)
z_streamp strm;
{
@@ -1165,7 +1104,6 @@ z_streamp strm;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
}
-
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
z_streamp strm;
const Bytef *dictionary;
@@ -1173,13 +1111,11 @@ uInt dictLength;
{
struct inflate_state FAR *state;
unsigned long id;
-
/* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
-
/* check for correct dictionary id */
if (state->mode == DICT) {
id = adler32(0L, Z_NULL, 0);
@@ -1187,7 +1123,6 @@ uInt dictLength;
if (id != state->check)
return Z_DATA_ERROR;
}
-
/* copy dictionary to window */
if (updatewindow(strm, strm->avail_out)) {
state->mode = MEM;
@@ -1207,24 +1142,20 @@ uInt dictLength;
Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
}
-
int ZEXPORT inflateGetHeader(strm, head)
z_streamp strm;
gz_headerp head;
{
struct inflate_state FAR *state;
-
/* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
-
/* save header structure */
state->head = head;
head->done = 0;
return Z_OK;
}
-
/*
Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
or when out of input. When called, *have is the number of pattern bytes
@@ -1243,7 +1174,6 @@ unsigned len;
{
unsigned got;
unsigned next;
-
got = *have;
next = 0;
while (next < len && got < 4) {
@@ -1258,7 +1188,6 @@ unsigned len;
*have = got;
return next;
}
-
int ZEXPORT inflateSync(strm)
z_streamp strm;
{
@@ -1266,12 +1195,10 @@ z_streamp strm;
unsigned long in, out; /* temporary to save total_in and total_out */
unsigned char buf[4]; /* to restore bit buffer to byte string */
struct inflate_state FAR *state;
-
/* check parameters */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
-
/* if first time, start search in bit buffer */
if (state->mode != SYNC) {
state->mode = SYNC;
@@ -1286,13 +1213,11 @@ z_streamp strm;
state->have = 0;
syncsearch(&(state->have), buf, len);
}
-
/* search available input */
len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
strm->avail_in -= len;
strm->next_in += len;
strm->total_in += len;
-
/* return no joy or set up to restart inflate() on a new block */
if (state->have != 4) return Z_DATA_ERROR;
in = strm->total_in; out = strm->total_out;
@@ -1301,7 +1226,6 @@ z_streamp strm;
state->mode = TYPE;
return Z_OK;
}
-
/*
Returns true if inflate is currently at the end of a block generated by
Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
@@ -1314,12 +1238,10 @@ int ZEXPORT inflateSyncPoint(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
-
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
return state->mode == STORED && state->bits == 0;
}
-
int ZEXPORT inflateCopy(dest, source)
z_streamp dest;
z_streamp source;
@@ -1328,13 +1250,11 @@ z_streamp source;
struct inflate_state FAR *copy;
unsigned char FAR *window;
unsigned wsize;
-
/* check input */
if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)source->state;
-
/* allocate space */
copy = (struct inflate_state FAR *)
ZALLOC(source, 1, sizeof(struct inflate_state));
@@ -1348,7 +1268,6 @@ z_streamp source;
return Z_MEM_ERROR;
}
}
-
/* copy state */
zmemcpy(dest, source, sizeof(z_stream));
zmemcpy(copy, state, sizeof(struct inflate_state));
diff --git a/dep/src/zlib/inflate.h b/dep/src/zlib/inflate.h
index 7c05e08fcba..8cc93dbcbf2 100644
--- a/dep/src/zlib/inflate.h
+++ b/dep/src/zlib/inflate.h
@@ -2,12 +2,10 @@
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
-
/* define NO_GZIP when compiling if you want to disable gzip header and
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip decoding
@@ -15,7 +13,6 @@
#ifndef NO_GZIP
# define GUNZIP
#endif
-
/* Possible inflate modes between inflate() calls */
typedef enum {
HEAD, /* i: waiting for magic header */
@@ -49,12 +46,9 @@ typedef enum {
MEM, /* got an inflate() memory error -- remain here until reset */
SYNC /* looking for synchronization bytes to restart inflate() */
} inflate_mode;
-
/*
State transitions between above modes -
-
(most modes can go to the BAD or MEM mode -- not shown for clarity)
-
Process header:
HEAD -> (gzip) or (zlib)
(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
@@ -72,7 +66,6 @@ typedef enum {
Process trailer:
CHECK -> LENGTH -> DONE
*/
-
/* state maintained between inflate() calls. Approximately 7K bytes. */
struct inflate_state {
inflate_mode mode; /* current inflate mode */
diff --git a/dep/src/zlib/inftrees.c b/dep/src/zlib/inftrees.c
index 8a9c13ff03d..821dabc5caa 100644
--- a/dep/src/zlib/inftrees.c
+++ b/dep/src/zlib/inftrees.c
@@ -2,12 +2,9 @@
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
#include "zutil.h"
#include "inftrees.h"
-
#define MAXBITS 15
-
const char inflate_copyright[] =
" inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
/*
@@ -16,7 +13,6 @@ const char inflate_copyright[] =
include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product.
*/
-
/*
Build a set of tables to decode the provided canonical Huffman code.
The code lengths are lens[0..codes-1]. The result starts at *table,
@@ -71,7 +67,6 @@ unsigned short FAR *work;
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
28, 28, 29, 29, 64, 64};
-
/*
Process a set of code lengths to create a canonical Huffman code. The
code lengths are lens[0..codes-1]. Each length corresponds to the
@@ -84,31 +79,26 @@ unsigned short FAR *work;
from their more natural integer increment ordering, and so when the
decoding tables are built in the large loop below, the integer codes
are incremented backwards.
-
This routine assumes, but does not check, that all of the entries in
lens[] are in the range 0..MAXBITS. The caller must assure this.
1..MAXBITS is interpreted as that code length. zero means that that
symbol does not occur in this code.
-
The codes are sorted by computing a count of codes for each length,
creating from that a table of starting indices for each length in the
sorted table, and then entering the symbols in order in the sorted
table. The sorted table is work[], with that space being provided by
the caller.
-
The length counts are used for other purposes as well, i.e. finding
the minimum and maximum length codes, determining if there are any
codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the
decoding tables.
*/
-
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
for (len = 0; len <= MAXBITS; len++)
count[len] = 0;
for (sym = 0; sym < codes; sym++)
count[lens[sym]]++;
-
/* bound code lengths, force root to be within code lengths */
root = *bits;
for (max = MAXBITS; max >= 1; max--)
@@ -126,7 +116,6 @@ unsigned short FAR *work;
for (min = 1; min <= MAXBITS; min++)
if (count[min] != 0) break;
if (root < min) root = min;
-
/* check for an over-subscribed or incomplete set of lengths */
left = 1;
for (len = 1; len <= MAXBITS; len++) {
@@ -136,16 +125,13 @@ unsigned short FAR *work;
}
if (left > 0 && (type == CODES || max != 1))
return -1; /* incomplete set */
-
/* generate offsets into symbol table for each length for sorting */
offs[1] = 0;
for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + count[len];
-
/* sort symbols by length, by symbol order within each length */
for (sym = 0; sym < codes; sym++)
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
-
/*
Create and fill in decoding tables. In this loop, the table being
filled is at next and has curr index bits. The code being used is huff
@@ -153,31 +139,26 @@ unsigned short FAR *work;
bits off of the bottom. For codes where len is less than drop + curr,
those top drop + curr - len bits are incremented through all values to
fill the table with replicated entries.
-
root is the number of index bits for the root table. When len exceeds
root, sub-tables are created pointed to by the root entry with an index
of the low root bits of huff. This is saved in low to check for when a
new sub-table should be started. drop is zero when the root table is
being filled, and drop is root when sub-tables are being filled.
-
When a new sub-table is needed, it is necessary to look ahead in the
code lengths to determine what size sub-table is needed. The length
counts are used for this, and so count[] is decremented as codes are
entered in the tables.
-
used keeps track of how many table entries have been allocated from the
provided *table space. It is checked when a LENS table is being made
against the space in *table, ENOUGH, minus the maximum space needed by
the worst case distance code, MAXD. This should never happen, but the
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
This assumes that when type == LENS, bits == 9.
-
sym increments through all symbols, and the loop terminates when
all codes of length max, i.e. all codes, have been processed. This
routine permits incomplete codes, so another loop after this one fills
in the rest of the decoding tables with invalid code markers.
*/
-
/* set up for code type */
switch (type) {
case CODES:
@@ -196,7 +177,6 @@ unsigned short FAR *work;
extra = dext;
end = -1;
}
-
/* initialize state for loop */
huff = 0; /* starting code */
sym = 0; /* starting code symbol */
@@ -207,11 +187,9 @@ unsigned short FAR *work;
low = (unsigned)(-1); /* trigger new sub-table when len > root */
used = 1U << root; /* use root table entries */
mask = used - 1; /* mask for comparing low */
-
/* check available table space */
if (type == LENS && used >= ENOUGH - MAXD)
return 1;
-
/* process all codes and make table entries */
for (;;) {
/* create table entry */
@@ -228,7 +206,6 @@ unsigned short FAR *work;
this.op = (unsigned char)(32 + 64); /* end of block */
this.val = 0;
}
-
/* replicate for those indices with low len bits equal to huff */
incr = 1U << (len - drop);
fill = 1U << curr;
@@ -237,7 +214,6 @@ unsigned short FAR *work;
fill -= incr;
next[(huff >> drop) + fill] = this;
} while (fill != 0);
-
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
@@ -248,23 +224,19 @@ unsigned short FAR *work;
}
else
huff = 0;
-
/* go to next symbol, update count, len */
sym++;
if (--(count[len]) == 0) {
if (len == max) break;
len = lens[work[sym]];
}
-
/* create new sub-table if needed */
if (len > root && (huff & mask) != low) {
/* if first time, transition to sub-tables */
if (drop == 0)
drop = root;
-
/* increment past last table */
next += min; /* here min is 1 << curr */
-
/* determine length of next table */
curr = len - drop;
left = (int)(1 << curr);
@@ -274,12 +246,10 @@ unsigned short FAR *work;
curr++;
left <<= 1;
}
-
/* check for enough space */
used += 1U << curr;
if (type == LENS && used >= ENOUGH - MAXD)
return 1;
-
/* point entry in root table to sub-table */
low = huff & mask;
(*table)[low].op = (unsigned char)curr;
@@ -287,7 +257,6 @@ unsigned short FAR *work;
(*table)[low].val = (unsigned short)(next - *table);
}
}
-
/*
Fill in rest of table for incomplete codes. This loop is similar to the
loop above in incrementing huff for table indices. It is assumed that
@@ -306,10 +275,8 @@ unsigned short FAR *work;
next = *table;
this.bits = (unsigned char)len;
}
-
/* put invalid code marker in table */
next[huff >> drop] = this;
-
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
@@ -321,7 +288,6 @@ unsigned short FAR *work;
else
huff = 0;
}
-
/* set return parameters */
*table += used;
*bits = root;
diff --git a/dep/src/zlib/inftrees.h b/dep/src/zlib/inftrees.h
index 977ee2f78f5..625b590241f 100644
--- a/dep/src/zlib/inftrees.h
+++ b/dep/src/zlib/inftrees.h
@@ -2,12 +2,10 @@
* Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
-
/* Structure for decoding tables. Each entry provides either the
information needed to do the operation requested by the code that
indexed that table entry, or it provides a pointer to another
@@ -26,7 +24,6 @@ typedef struct {
unsigned char bits; /* bits in this part of the code */
unsigned short val; /* offset in table or code value */
} code;
-
/* op values as set by inflate_table():
00000000 - literal
0000tttt - table link, tttt != 0 is the number of table index bits
@@ -34,7 +31,6 @@ typedef struct {
01100000 - end of block
01000000 - invalid code
*/
-
/* Maximum size of dynamic tree. The maximum found in a long but non-
exhaustive search was 1444 code structures (852 for length/literals
and 592 for distances, the latter actually the result of an
@@ -42,14 +38,12 @@ typedef struct {
below is more than safe. */
#define ENOUGH 2048
#define MAXD 592
-
/* Type of code to build for inftable() */
typedef enum {
CODES,
LENS,
DISTS
} codetype;
-
extern int inflate_table OF((codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work));
diff --git a/dep/src/zlib/trees.c b/dep/src/zlib/trees.c
index 395e4e16814..5e1908f51ff 100644
--- a/dep/src/zlib/trees.c
+++ b/dep/src/zlib/trees.c
@@ -2,7 +2,6 @@
* Copyright (C) 1995-2005 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/*
* ALGORITHM
*
@@ -28,96 +27,70 @@
* Algorithms, p290.
* Addison-Wesley, 1983. ISBN 0-201-06672-6.
*/
-
/* @(#) $Id$ */
-
/* #define GEN_TREES_H */
-
#include "deflate.h"
-
#ifdef DEBUG
# include <ctype.h>
#endif
-
/* ===========================================================================
* Constants
*/
-
#define MAX_BL_BITS 7
/* Bit length codes must not exceed MAX_BL_BITS bits */
-
#define END_BLOCK 256
/* end of block literal code */
-
#define REP_3_6 16
/* repeat previous bit length 3-6 times (2 bits of repeat count) */
-
#define REPZ_3_10 17
/* repeat a zero length 3-10 times (3 bits of repeat count) */
-
#define REPZ_11_138 18
/* repeat a zero length 11-138 times (7 bits of repeat count) */
-
local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
-
local const int extra_dbits[D_CODES] /* extra bits for each distance code */
= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
-
local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
-
local const uch bl_order[BL_CODES]
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
/* The lengths of the bit length codes are sent in order of decreasing
* probability, to avoid transmitting the lengths for unused bit length codes.
*/
-
#define Buf_size (8 * 2*sizeof(char))
/* Number of bits used within bi_buf. (bi_buf might be implemented on
* more than 16 bits on some systems.)
*/
-
/* ===========================================================================
* Local data. These are initialized only once.
*/
-
#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
-
#if defined(GEN_TREES_H) || !defined(STDC)
/* non ANSI compilers may not accept trees.h */
-
local ct_data static_ltree[L_CODES+2];
/* The static literal tree. Since the bit lengths are imposed, there is no
* need for the L_CODES extra codes used during heap construction. However
* The codes 286 and 287 are needed to build a canonical tree (see _tr_init
* below).
*/
-
local ct_data static_dtree[D_CODES];
/* The static distance tree. (Actually a trivial tree since all codes use
* 5 bits.)
*/
-
uch _dist_code[DIST_CODE_LEN];
/* Distance codes. The first 256 values correspond to the distances
* 3 .. 258, the last 256 values correspond to the top 8 bits of
* the 15 bit distances.
*/
-
uch _length_code[MAX_MATCH-MIN_MATCH+1];
/* length code for each normalized match length (0 == MIN_MATCH) */
-
local int base_length[LENGTH_CODES];
/* First normalized length for each code (0 = MIN_MATCH) */
-
local int base_dist[D_CODES];
/* First normalized distance for each code (0 = distance of 1) */
-
#else
# include "trees.h"
#endif /* GEN_TREES_H */
-
struct static_tree_desc_s {
const ct_data *static_tree; /* static tree or NULL */
const intf *extra_bits; /* extra bits for each code or NULL */
@@ -125,20 +98,15 @@ struct static_tree_desc_s {
int elems; /* max number of elements in the tree */
int max_length; /* max bit length for the codes */
};
-
local static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
-
local static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
-
local static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
-
/* ===========================================================================
* Local (static) routines in this file.
*/
-
local void tr_static_init OF((void));
local void init_block OF((deflate_state *s));
local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
@@ -158,21 +126,17 @@ local void bi_windup OF((deflate_state *s));
local void bi_flush OF((deflate_state *s));
local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
int header));
-
#ifdef GEN_TREES_H
local void gen_trees_header OF((void));
#endif
-
#ifndef DEBUG
# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
/* Send a code of the given tree. c and tree must not have side effects */
-
#else /* DEBUG */
# define send_code(s, c, tree) \
{ if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
send_bits(s, tree[c].Code, tree[c].Len); }
#endif
-
/* ===========================================================================
* Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf.
@@ -181,14 +145,12 @@ local void gen_trees_header OF((void));
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
-
/* ===========================================================================
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
#ifdef DEBUG
local void send_bits OF((deflate_state *s, int value, int length));
-
local void send_bits(s, value, length)
deflate_state *s;
int value; /* value to send */
@@ -197,7 +159,6 @@ local void send_bits(s, value, length)
Tracevv((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length;
-
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
* unused bits in value.
@@ -213,7 +174,6 @@ local void send_bits(s, value, length)
}
}
#else /* !DEBUG */
-
#define send_bits(s, value, length) \
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
@@ -229,9 +189,7 @@ local void send_bits(s, value, length)
}
#endif /* DEBUG */
-
/* the arguments must not have side effects */
-
/* ===========================================================================
* Initialize the various 'constant' tables.
*/
@@ -246,16 +204,13 @@ local void tr_static_init()
int dist; /* distance index */
ush bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
-
if (static_init_done) return;
-
/* For some embedded targets, global variables are not initialized: */
static_l_desc.static_tree = static_ltree;
static_l_desc.extra_bits = extra_lbits;
static_d_desc.static_tree = static_dtree;
static_d_desc.extra_bits = extra_dbits;
static_bl_desc.extra_bits = extra_blbits;
-
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
for (code = 0; code < LENGTH_CODES-1; code++) {
@@ -270,7 +225,6 @@ local void tr_static_init()
* overwrite length_code[255] to use the best encoding:
*/
_length_code[length-1] = (uch)code;
-
/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
dist = 0;
for (code = 0 ; code < 16; code++) {
@@ -288,7 +242,6 @@ local void tr_static_init()
}
}
Assert (dist == 256, "tr_static_init: 256+dist != 512");
-
/* Construct the codes of the static literal tree */
for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
n = 0;
@@ -301,20 +254,17 @@ local void tr_static_init()
* all ones)
*/
gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
-
/* The static distance tree is trivial: */
for (n = 0; n < D_CODES; n++) {
static_dtree[n].Len = 5;
static_dtree[n].Code = bi_reverse((unsigned)n, 5);
}
static_init_done = 1;
-
# ifdef GEN_TREES_H
gen_trees_header();
# endif
#endif /* defined(GEN_TREES_H) || !defined(STDC) */
}
-
/* ===========================================================================
* Genererate the file trees.h describing the static trees.
*/
@@ -322,60 +272,49 @@ local void tr_static_init()
# ifndef DEBUG
# include <stdio.h>
# endif
-
# define SEPARATOR(i, last, width) \
((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width)-1 ? ",\n" : ", "))
-
void gen_trees_header()
{
FILE *header = fopen("trees.h", "w");
int i;
-
Assert (header != NULL, "Can't open trees.h");
fprintf(header,
"/* header created automatically with -DGEN_TREES_H */\n\n");
-
fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
for (i = 0; i < L_CODES+2; i++) {
fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
}
-
fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) {
fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
}
-
fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
for (i = 0; i < DIST_CODE_LEN; i++) {
fprintf(header, "%2u%s", _dist_code[i],
SEPARATOR(i, DIST_CODE_LEN-1, 20));
}
-
fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
fprintf(header, "%2u%s", _length_code[i],
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
}
-
fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
for (i = 0; i < LENGTH_CODES; i++) {
fprintf(header, "%1u%s", base_length[i],
SEPARATOR(i, LENGTH_CODES-1, 20));
}
-
fprintf(header, "local const int base_dist[D_CODES] = {\n");
for (i = 0; i < D_CODES; i++) {
fprintf(header, "%5u%s", base_dist[i],
SEPARATOR(i, D_CODES-1, 10));
}
-
fclose(header);
}
#endif /* GEN_TREES_H */
-
/* ===========================================================================
* Initialize the tree data structures for a new zlib stream.
*/
@@ -383,16 +322,12 @@ void _tr_init(s)
deflate_state *s;
{
tr_static_init();
-
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
-
s->d_desc.dyn_tree = s->dyn_dtree;
s->d_desc.stat_desc = &static_d_desc;
-
s->bl_desc.dyn_tree = s->bl_tree;
s->bl_desc.stat_desc = &static_bl_desc;
-
s->bi_buf = 0;
s->bi_valid = 0;
s->last_eob_len = 8; /* enough lookahead for inflate */
@@ -400,11 +335,9 @@ void _tr_init(s)
s->compressed_len = 0L;
s->bits_sent = 0L;
#endif
-
/* Initialize the first block of the first file: */
init_block(s);
}
-
/* ===========================================================================
* Initialize a new block.
*/
@@ -412,21 +345,17 @@ local void init_block(s)
deflate_state *s;
{
int n; /* iterates over tree elements */
-
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
-
s->dyn_ltree[END_BLOCK].Freq = 1;
s->opt_len = s->static_len = 0L;
s->last_lit = s->matches = 0;
}
-
#define SMALLEST 1
/* Index within the heap array of least frequent node in the Huffman tree */
-
/* ===========================================================================
* Remove the smallest element from the heap and recreate the heap with
* one less element. Updates heap and heap_len.
@@ -437,7 +366,6 @@ local void init_block(s)
s->heap[SMALLEST] = s->heap[s->heap_len--]; \
pqdownheap(s, tree, SMALLEST); \
}
-
/* ===========================================================================
* Compares to subtrees, using the tree depth as tie breaker when
* the subtrees have equal frequency. This minimizes the worst case length.
@@ -445,7 +373,6 @@ local void init_block(s)
#define smaller(tree, n, m, depth) \
(tree[n].Freq < tree[m].Freq || \
(tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
-
/* ===========================================================================
* Restore the heap property by moving down the tree starting at node k,
* exchanging a node with the smallest of its two sons if necessary, stopping
@@ -467,16 +394,13 @@ local void pqdownheap(s, tree, k)
}
/* Exit if v is smaller than both sons */
if (smaller(tree, v, s->heap[j], s->depth)) break;
-
/* Exchange v with the smallest son */
s->heap[k] = s->heap[j]; k = j;
-
/* And continue down the tree, setting j to the left son of k */
j <<= 1;
}
s->heap[k] = v;
}
-
/* ===========================================================================
* Compute the optimal bit lengths for a tree and update the total bit length
* for the current block.
@@ -503,23 +427,18 @@ local void gen_bitlen(s, desc)
int xbits; /* extra bits */
ush f; /* frequency */
int overflow = 0; /* number of elements with bit length too large */
-
for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
-
/* In a first pass, compute the optimal bit lengths (which may
* overflow in the case of the bit length tree).
*/
tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
-
for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
n = s->heap[h];
bits = tree[tree[n].Dad].Len + 1;
if (bits > max_length) bits = max_length, overflow++;
tree[n].Len = (ush)bits;
/* We overwrite tree[n].Dad which is no longer needed */
-
if (n > max_code) continue; /* not a leaf node */
-
s->bl_count[bits]++;
xbits = 0;
if (n >= base) xbits = extra[n-base];
@@ -528,10 +447,8 @@ local void gen_bitlen(s, desc)
if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
}
if (overflow == 0) return;
-
Trace((stderr,"\nbit length overflow\n"));
/* This happens for example on obj2 and pic of the Calgary corpus */
-
/* Find the first bit length which could increase: */
do {
bits = max_length-1;
@@ -544,7 +461,6 @@ local void gen_bitlen(s, desc)
*/
overflow -= 2;
} while (overflow > 0);
-
/* Now recompute all bit lengths, scanning in increasing frequency.
* h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
* lengths instead of fixing only the wrong ones. This idea is taken
@@ -565,7 +481,6 @@ local void gen_bitlen(s, desc)
}
}
}
-
/* ===========================================================================
* Generate the codes for a given tree and bit counts (which need not be
* optimal).
@@ -583,7 +498,6 @@ local void gen_codes (tree, max_code, bl_count)
ush code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
-
/* The distribution counts are first used to generate the code values
* without bit reversal.
*/
@@ -596,18 +510,15 @@ local void gen_codes (tree, max_code, bl_count)
Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
"inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
-
for (n = 0; n <= max_code; n++) {
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = bi_reverse(next_code[len]++, len);
-
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
}
}
-
/* ===========================================================================
* Construct one Huffman tree and assigns the code bit strings and lengths.
* Update the total bit length for the current block.
@@ -626,13 +537,11 @@ local void build_tree(s, desc)
int n, m; /* iterate over heap elements */
int max_code = -1; /* largest code with non zero frequency */
int node; /* new node being created */
-
/* Construct the initial heap, with least frequent element in
* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
* heap[0] is not used.
*/
s->heap_len = 0, s->heap_max = HEAP_SIZE;
-
for (n = 0; n < elems; n++) {
if (tree[n].Freq != 0) {
s->heap[++(s->heap_len)] = max_code = n;
@@ -641,7 +550,6 @@ local void build_tree(s, desc)
tree[n].Len = 0;
}
}
-
/* The pkzip format requires that at least one distance code exists,
* and that at least one bit should be sent even if there is only one
* possible code. So to avoid special checks later on we force at least
@@ -655,12 +563,10 @@ local void build_tree(s, desc)
/* node is 0 or 1 so it does not have extra bits */
}
desc->max_code = max_code;
-
/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
* establish sub-heaps of increasing lengths:
*/
for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
-
/* Construct the Huffman tree by repeatedly combining the least two
* frequent nodes.
*/
@@ -668,10 +574,8 @@ local void build_tree(s, desc)
do {
pqremove(s, tree, n); /* n = node of least frequency */
m = s->heap[SMALLEST]; /* m = node of next least frequency */
-
s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
s->heap[--(s->heap_max)] = m;
-
/* Create a new node father of n and m */
tree[node].Freq = tree[n].Freq + tree[m].Freq;
s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
@@ -686,20 +590,15 @@ local void build_tree(s, desc)
/* and insert the new node in the heap */
s->heap[SMALLEST] = node++;
pqdownheap(s, tree, SMALLEST);
-
} while (s->heap_len >= 2);
-
s->heap[--(s->heap_max)] = s->heap[SMALLEST];
-
/* At this point, the fields freq and dad are set. We can now
* generate the bit lengths.
*/
gen_bitlen(s, (tree_desc *)desc);
-
/* The field len is now set, we can generate the bit codes */
gen_codes ((ct_data *)tree, max_code, s->bl_count);
}
-
/* ===========================================================================
* Scan a literal or distance tree to determine the frequencies of the codes
* in the bit length tree.
@@ -716,10 +615,8 @@ local void scan_tree (s, tree, max_code)
int count = 0; /* repeat count of the current code */
int max_count = 7; /* max repeat count */
int min_count = 4; /* min repeat count */
-
if (nextlen == 0) max_count = 138, min_count = 3;
tree[max_code+1].Len = (ush)0xffff; /* guard */
-
for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len;
if (++count < max_count && curlen == nextlen) {
@@ -744,7 +641,6 @@ local void scan_tree (s, tree, max_code)
}
}
}
-
/* ===========================================================================
* Send a literal or distance tree in compressed form, using the codes in
* bl_tree.
@@ -761,27 +657,22 @@ local void send_tree (s, tree, max_code)
int count = 0; /* repeat count of the current code */
int max_count = 7; /* max repeat count */
int min_count = 4; /* min repeat count */
-
/* tree[max_code+1].Len = -1; */ /* guard already set */
if (nextlen == 0) max_count = 138, min_count = 3;
-
for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len;
if (++count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
-
} else if (curlen != 0) {
if (curlen != prevlen) {
send_code(s, curlen, s->bl_tree); count--;
}
Assert(count >= 3 && count <= 6, " 3_6?");
send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
-
} else if (count <= 10) {
send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
-
} else {
send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
}
@@ -795,7 +686,6 @@ local void send_tree (s, tree, max_code)
}
}
}
-
/* ===========================================================================
* Construct the Huffman tree for the bit lengths and return the index in
* bl_order of the last bit length code to send.
@@ -804,17 +694,14 @@ local int build_bl_tree(s)
deflate_state *s;
{
int max_blindex; /* index of last bit length code of non zero freq */
-
/* Determine the bit length frequencies for literal and distance trees */
scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
-
/* Build the bit length tree: */
build_tree(s, (tree_desc *)(&(s->bl_desc)));
/* opt_len now includes the length of the tree representations, except
* the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
*/
-
/* Determine the number of bit length codes to send. The pkzip format
* requires that at least 4 bit length codes be sent. (appnote.txt says
* 3 but the actual value used is 4.)
@@ -826,10 +713,8 @@ local int build_bl_tree(s)
s->opt_len += 3*(max_blindex+1) + 5+5+4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
s->opt_len, s->static_len));
-
return max_blindex;
}
-
/* ===========================================================================
* Send the header for a block using dynamic Huffman trees: the counts, the
* lengths of the bit length codes, the literal tree and the distance tree.
@@ -840,7 +725,6 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
int lcodes, dcodes, blcodes; /* number of codes for each tree */
{
int rank; /* index in bl_order */
-
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
"too many codes");
@@ -853,14 +737,11 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
}
Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
-
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
-
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
}
-
/* ===========================================================================
* Send a stored block
*/
@@ -877,7 +758,6 @@ void _tr_stored_block(s, buf, stored_len, eof)
#endif
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
-
/* ===========================================================================
* Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer.
@@ -913,7 +793,6 @@ void _tr_align(s)
}
s->last_eob_len = 7;
}
-
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static
* trees or store, and output the encoded block to the zip file.
@@ -926,46 +805,36 @@ void _tr_flush_block(s, buf, stored_len, eof)
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex = 0; /* index of last bit length code of non zero freq */
-
/* Build the Huffman trees unless a stored block is forced */
if (s->level > 0) {
-
/* Check if the file is binary or text */
if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
set_data_type(s);
-
/* Construct the literal and distance trees */
build_tree(s, (tree_desc *)(&(s->l_desc)));
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
s->static_len));
-
build_tree(s, (tree_desc *)(&(s->d_desc)));
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
s->static_len));
/* At this point, opt_len and static_len are the total bit lengths of
* the compressed block data, excluding the tree representations.
*/
-
/* Build the bit length tree for the above two trees, and get the index
* in bl_order of the last bit length code to send.
*/
max_blindex = build_bl_tree(s);
-
/* Determine the best encoding. Compute the block lengths in bytes. */
opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3;
-
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->last_lit));
-
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
-
} else {
Assert(buf != (char*)0, "lost buf");
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
}
-
#ifdef FORCE_STORED
if (buf != (char*)0) { /* force stored block */
#else
@@ -979,7 +848,6 @@ void _tr_flush_block(s, buf, stored_len, eof)
* transform a block into a stored block.
*/
_tr_stored_block(s, buf, stored_len, eof);
-
#ifdef FORCE_STATIC
} else if (static_lenb >= 0) { /* force static trees */
#else
@@ -1004,7 +872,6 @@ void _tr_flush_block(s, buf, stored_len, eof)
* and uLong implemented on 32 bits.
*/
init_block(s);
-
if (eof) {
bi_windup(s);
#ifdef DEBUG
@@ -1014,7 +881,6 @@ void _tr_flush_block(s, buf, stored_len, eof)
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
s->compressed_len-7*eof));
}
-
/* ===========================================================================
* Save the match info and tally the frequency counts. Return true if
* the current block must be flushed.
@@ -1036,11 +902,9 @@ int _tr_tally (s, dist, lc)
Assert((ush)dist < (ush)MAX_DIST(s) &&
(ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
(ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
-
s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
s->dyn_dtree[d_code(dist)].Freq++;
}
-
#ifdef TRUNCATE_BLOCK
/* Try to guess if it is profitable to stop the current block here */
if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
@@ -1065,7 +929,6 @@ int _tr_tally (s, dist, lc)
* 64K-1 bytes.
*/
}
-
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
@@ -1079,7 +942,6 @@ local void compress_block(s, ltree, dtree)
unsigned lx = 0; /* running index in l_buf */
unsigned code; /* the code to send */
int extra; /* number of extra bits to send */
-
if (s->last_lit != 0) do {
dist = s->d_buf[lx];
lc = s->l_buf[lx++];
@@ -1098,7 +960,6 @@ local void compress_block(s, ltree, dtree)
dist--; /* dist is now the match distance - 1 */
code = d_code(dist);
Assert (code < D_CODES, "bad d_code");
-
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
@@ -1106,17 +967,13 @@ local void compress_block(s, ltree, dtree)
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
-
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
"pendingBuf overflow");
-
} while (lx < s->last_lit);
-
send_code(s, END_BLOCK, ltree);
s->last_eob_len = ltree[END_BLOCK].Len;
}
-
/* ===========================================================================
* Set the data type to BINARY or TEXT, using a crude approximation:
* set it to Z_TEXT if all symbols are either printable characters (33 to 255)
@@ -1127,7 +984,6 @@ local void set_data_type(s)
deflate_state *s;
{
int n;
-
for (n = 0; n < 9; n++)
if (s->dyn_ltree[n].Freq != 0)
break;
@@ -1137,7 +993,6 @@ local void set_data_type(s)
break;
s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
}
-
/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table)
@@ -1154,7 +1009,6 @@ local unsigned bi_reverse(code, len)
} while (--len > 0);
return res >> 1;
}
-
/* ===========================================================================
* Flush the bit buffer, keeping at most 7 bits in it.
*/
@@ -1171,7 +1025,6 @@ local void bi_flush(s)
s->bi_valid -= 8;
}
}
-
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/
@@ -1189,7 +1042,6 @@ local void bi_windup(s)
s->bits_sent = (s->bits_sent+7) & ~7;
#endif
}
-
/* ===========================================================================
* Copy a stored block, storing first the length and its
* one's complement if requested.
@@ -1202,7 +1054,6 @@ local void copy_block(s, buf, len, header)
{
bi_windup(s); /* align on byte boundary */
s->last_eob_len = 8; /* enough lookahead for inflate */
-
if (header) {
put_short(s, (ush)len);
put_short(s, (ush)~len);
diff --git a/dep/src/zlib/trees.h b/dep/src/zlib/trees.h
index ba8cd78357b..bcfecb67797 100644
--- a/dep/src/zlib/trees.h
+++ b/dep/src/zlib/trees.h
@@ -1,5 +1,4 @@
/* header created automatically with -DGEN_TREES_H */
-
local const ct_data static_ltree[L_CODES+2] = {
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
@@ -60,7 +59,6 @@ local const ct_data static_ltree[L_CODES+2] = {
{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
};
-
local const ct_data static_dtree[D_CODES] = {
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
@@ -69,7 +67,6 @@ local const ct_data static_dtree[D_CODES] = {
{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
};
-
const uch _dist_code[DIST_CODE_LEN] = {
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
@@ -98,7 +95,6 @@ const uch _dist_code[DIST_CODE_LEN] = {
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
};
-
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
@@ -114,16 +110,13 @@ const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
};
-
local const int base_length[LENGTH_CODES] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
64, 80, 96, 112, 128, 160, 192, 224, 0
};
-
local const int base_dist[D_CODES] = {
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
};
-
diff --git a/dep/src/zlib/uncompr.c b/dep/src/zlib/uncompr.c
index b59e3d0defb..5858b9f2279 100644
--- a/dep/src/zlib/uncompr.c
+++ b/dep/src/zlib/uncompr.c
@@ -2,12 +2,9 @@
* Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* @(#) $Id$ */
-
#define ZLIB_INTERNAL
#include "zlib.h"
-
/* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
@@ -18,7 +15,6 @@
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
-
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
@@ -31,22 +27,17 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
{
z_stream stream;
int err;
-
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
-
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
-
err = inflateInit(&stream);
if (err != Z_OK) return err;
-
err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
inflateEnd(&stream);
@@ -55,7 +46,6 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
return err;
}
*destLen = stream.total_out;
-
err = inflateEnd(&stream);
return err;
}
diff --git a/dep/src/zlib/zconf.h b/dep/src/zlib/zconf.h
index 719855a60d4..6c3086b96d7 100644
--- a/dep/src/zlib/zconf.h
+++ b/dep/src/zlib/zconf.h
@@ -2,12 +2,9 @@
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* @(#) $Id$ */
-
#ifndef ZCONF_H
#define ZCONF_H
-
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
@@ -42,7 +39,6 @@
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define zError z_zError
-
# define alloc_func z_alloc_func
# define free_func z_free_func
# define in_func z_in_func
@@ -58,7 +54,6 @@
# define voidpf z_voidpf
# define voidp z_voidp
#endif
-
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
@@ -80,7 +75,6 @@
# endif
# endif
#endif
-
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
@@ -91,7 +85,6 @@
#ifdef MSDOS
# define UNALIGNED_OK
#endif
-
#ifdef __STDC_VERSION__
# ifndef STDC
# define STDC
@@ -114,22 +107,18 @@
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# define STDC
#endif
-
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC
#endif
-
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
-
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
#endif
-
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
@@ -138,7 +127,6 @@
# define MAX_MEM_LEVEL 9
# endif
#endif
-
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
@@ -147,7 +135,6 @@
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
-
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
@@ -155,14 +142,11 @@
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
-
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
-
/* Type declarations */
-
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
@@ -170,7 +154,6 @@
# define OF(args) ()
# endif
#endif
-
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
@@ -197,7 +180,6 @@
# endif
# endif
#endif
-
#if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
@@ -230,7 +212,6 @@
# endif
# endif
#endif
-
#if defined (__BEOS__)
# ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL
@@ -242,7 +223,6 @@
# endif
# endif
#endif
-
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
@@ -252,17 +232,14 @@
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
-
#ifndef FAR
# define FAR
#endif
-
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
-
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
@@ -273,7 +250,6 @@ typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
-
#ifdef STDC
typedef void const *voidpc;
typedef void FAR *voidpf;
@@ -283,7 +259,6 @@ typedef uLong FAR uLongf;
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
-
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
@@ -300,18 +275,15 @@ typedef uLong FAR uLongf;
#ifndef z_off_t
# define z_off_t long
#endif
-
#if defined(__OS400__)
# define NO_vsnprintf
#endif
-
#if defined(__MVS__)
# define NO_vsnprintf
# ifdef FAR
# undef FAR
# endif
#endif
-
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
@@ -328,6 +300,5 @@ typedef uLong FAR uLongf;
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_copyright,"INCOPY")
#endif
-
#endif /* ZCONF_H */
diff --git a/dep/src/zlib/zlib.h b/dep/src/zlib/zlib.h
index 2ad74617098..718a0899472 100644
--- a/dep/src/zlib/zlib.h
+++ b/dep/src/zlib/zlib.h
@@ -1,16 +1,12 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.3, July 18th, 2005
-
Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
-
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
-
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
-
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
@@ -18,90 +14,68 @@
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
-
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
-
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
-
#ifndef ZLIB_H
#define ZLIB_H
-
#include "zconf.h"
-
#ifdef __cplusplus
extern "C" {
#endif
-
#define ZLIB_VERSION "1.2.3"
#define ZLIB_VERNUM 0x1230
-
/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms will be added later and will have the same
stream interface.
-
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
-
The compressed data format used by default by the in-memory functions is
the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
around a deflate stream, which is itself documented in RFC 1951.
-
The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio using the functions that start
with "gz". The gzip format is different from the zlib format. gzip is a
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
-
This library can optionally read and write gzip streams in memory as well.
-
The zlib format was designed to be compact and fast for use in memory
and on communications channels. The gzip format was designed for single-
file compression on file systems, has a larger header than zlib to maintain
directory information, and uses a different, slower check method than zlib.
-
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never
crash even in case of corrupted input.
*/
-
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
-
struct internal_state;
-
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
-
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
-
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
-
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
-
int data_type; /* best guess about the data type: binary or text */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
-
typedef z_stream FAR *z_streamp;
-
/*
gzip header information passed to and from zlib routines. See RFC 1952
for more details on the meanings of these fields.
@@ -122,25 +96,20 @@ typedef struct gz_header_s {
int done; /* true when done reading gzip header (not used
when writing a gzip file) */
} gz_header;
-
typedef gz_header FAR *gz_headerp;
-
/*
The application must update next_in and avail_in when avail_in has
dropped to zero. It must update next_out and avail_out when avail_out
has dropped to zero. The application must initialize zalloc, zfree and
opaque before calling the init function. All other fields are set by the
compression library and must not be updated by the application.
-
The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the
opaque value.
-
zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe.
-
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
@@ -149,16 +118,13 @@ typedef gz_header FAR *gz_headerp;
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
-
The fields total_in and total_out can be used for statistics or
progress reports. After compression, total_in holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step).
*/
-
/* constants */
-
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
#define Z_SYNC_FLUSH 2
@@ -166,7 +132,6 @@ typedef gz_header FAR *gz_headerp;
#define Z_FINISH 4
#define Z_BLOCK 5
/* Allowed flush values; see deflate() and inflate() below for details */
-
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
@@ -179,57 +144,45 @@ typedef gz_header FAR *gz_headerp;
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
-
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
-
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_RLE 3
#define Z_FIXED 4
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
-
#define Z_BINARY 0
#define Z_TEXT 1
#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2
/* Possible values of the data_type field (though see inflate()) */
-
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
-
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
-
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
-
/* basic functions */
-
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by deflateInit and inflateInit.
*/
-
/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
-
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
use default allocation functions.
-
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
compression (currently equivalent to level 6).
-
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
@@ -238,28 +191,23 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
perform any compression: this will be done by deflate().
*/
-
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some
output latency (reading input without producing any output) except when
forced to flush.
-
The detailed semantics are as follows. deflate performs one or both of the
following actions:
-
- Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
-
- Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
-
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating avail_in or avail_out accordingly; avail_out
@@ -268,31 +216,26 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
-
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
decide how much data to accumualte before producing output, in order to
maximize compression.
-
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular
avail_in is zero after the call if enough output space has been provided
before the call.) Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
-
If flush is set to Z_FULL_FLUSH, all output is flushed as with
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
restart from this point if previous compressed data has been damaged or if
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
compression.
-
If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero
avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
avail_out is greater than six to avoid repeated flush markers due to
avail_out == 0 on return.
-
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there
was enough output space; if deflate returns with Z_OK, this function must be
@@ -300,20 +243,16 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
-
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
the value returned by deflateBound (see below). If deflate does not return
Z_STREAM_END, then it must be called again as described above.
-
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
-
deflate() may update strm->data_type if it can make a good guess about
the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
-
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
@@ -324,13 +263,11 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
space to continue compressing.
*/
-
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
-
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case,
@@ -338,10 +275,8 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
deallocated).
*/
-
/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
-
Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
@@ -350,7 +285,6 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
accordingly; otherwise the allocation will be deferred to the first call of
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
use default allocation functions.
-
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller. msg is set to null if there is no error
@@ -359,27 +293,22 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
avail_in may be modified, but next_out and avail_out are unchanged.)
*/
-
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce
some output latency (reading input without producing any output) except when
forced to flush.
-
The detailed semantics are as follows. inflate performs one or both of the
following actions:
-
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing
will resume at this point for the next call of inflate().
-
- Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there
is no more input data or no more space in the output buffer (see below
about the flush parameter).
-
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
@@ -388,7 +317,6 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
-
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
@@ -397,7 +325,6 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
the header and before the first block. When doing a raw inflate, inflate()
will go ahead and process the first block, and will return when it gets to
the end of that block, or when it runs out of data.
-
The Z_BLOCK option assists in appending to or combining deflate streams.
Also to assist in this, on return inflate() will set strm->data_type to the
number of unused bits in the last byte taken from strm->next_in, plus 64
@@ -409,7 +336,6 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
number of unused bits may in general be greater than seven, except when
bit 7 of data_type is set, in which case the number of unused bits will be
less than eight.
-
inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step
(a single call of inflate), the parameter flush should be set to
@@ -420,13 +346,11 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
is never required, but can be used to inform inflate that a faster approach
may be used for the single inflate() call.
-
In this implementation, inflate() always flushes as much output as
possible to the output buffer, and always uses the faster approach on the
first call. So the only effect of the flush parameter in this implementation
is on the return value of inflate(), as noted below, or when it returns early
because Z_BLOCK is used.
-
If a preset dictionary is needed after this call (see inflateSetDictionary
below), inflate sets strm->adler to the adler32 checksum of the dictionary
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
@@ -435,14 +359,12 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
below. At the end of the stream, inflate() checks that its computed adler32
checksum is equal to that saved by the compressor and returns Z_STREAM_END
only if the checksum is correct.
-
inflate() will decompress and check either zlib-wrapped or gzip-wrapped
deflate data. The header type is detected automatically. Any information
contained in the gzip header is not retained, so applications that need that
information should instead use raw inflate, see inflateInit2() below, or
inflateBack() and perform their own processing of the gzip header and
trailer.
-
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
@@ -458,24 +380,19 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
of the data is desired.
*/
-
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
-
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated).
*/
-
/* Advanced functions */
-
/*
The following functions are needed only in some special applications.
*/
-
/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
@@ -483,37 +400,30 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int windowBits,
int memLevel,
int strategy));
-
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by
the caller.
-
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
-
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead.
-
windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
determines the window size. deflate() will then generate raw deflate data
with no zlib header or trailer, and will not compute an adler32 check value.
-
windowBits can also be greater than 15 for optional gzip encoding. Add
16 to windowBits to write a simple gzip header and trailer around the
compressed data instead of a zlib wrapper. The gzip header will have no
file name, no extra data, no comment, no modification time (set to zero),
no header crc, and the operating system will be set to 255 (unknown). If a
gzip stream is being written, strm->adler is a crc32 instead of an adler32.
-
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but
is slow and reduces compression ratio; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.
-
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
@@ -528,13 +438,11 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
compressed output even if it is not set appropriately. Z_FIXED prevents the
use of dynamic Huffman codes, allowing for a simpler decoder for special
applications.
-
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
method). msg is set to null if there is no error message. deflateInit2 does
not perform any compression: this will be done by deflate().
*/
-
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
@@ -544,14 +452,12 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
immediately after deflateInit, deflateInit2 or deflateReset, before any
call of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
-
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy; the data can then be compressed better than
with the default empty dictionary.
-
Depending on the size of the compression data structures selected by
deflateInit or deflateInit2, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size in
@@ -559,50 +465,42 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
put at the end of the dictionary, not at the front. In addition, the
current implementation of deflate will use at most the window size minus
262 bytes of the provided dictionary.
-
Upon return of this function, strm->adler is set to the adler32 value
of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.) If a raw deflate was requested, then the
adler32 value is not computed and strm->adler is not set.
-
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate().
*/
-
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.
-
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and
can consume lots of memory.
-
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
-
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
The stream will keep the same compression level and any other attributes
that may have been set by deflateInit2.
-
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
-
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
@@ -614,16 +512,13 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
strategy. If the compression level is changed, the input available so far
is compressed with the old level (and may be flushed); the new level will
take effect only at the next call of deflate().
-
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
-
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/
-
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
int good_length,
int max_lazy,
@@ -636,11 +531,9 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
fanatic optimizer trying to squeeze out the last compressed bit for their
specific input data. Read the deflate.c source code for the meaning of the
max_lazy, good_length, nice_length, and max_chain parameters.
-
deflateTune() can be called after deflateInit() or deflateInit2(), and
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
*/
-
ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
uLong sourceLen));
/*
@@ -649,7 +542,6 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
or deflateInit2(). This would be used to allocate an output buffer
for deflation in a single pass, and so would be called before deflate().
*/
-
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits,
int value));
@@ -661,11 +553,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
first deflate() call after a deflateInit2() or deflateReset(). bits must be
less than or equal to 16, and that many of the least significant bits of
value will be inserted in the output.
-
deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
-
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
gz_headerp head));
/*
@@ -681,23 +571,18 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
the current versions of the command-line version of gzip (up through version
1.3.x) do not support header crc's, and will report that it is a "multi-part
gzip file" and give up.
-
If deflateSetHeader is not used, the default gzip header has text false,
the time set to zero, and os set to 255, with no extra, name, or comment
fields. The gzip header is returned to the default state by deflateReset().
-
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
-
/*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
-
This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
before by the caller.
-
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used
@@ -706,7 +591,6 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
deflateInit2() was not used. If a compressed stream with a larger window
size is given as input, inflate() will return with the error code
Z_DATA_ERROR instead of trying to allocate a larger window.
-
windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
determines the window size. inflate() will then process raw deflate data,
not looking for a zlib or gzip header, not generating a check value, and not
@@ -718,13 +602,11 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
the uncompressed data as is done in the zlib, gzip, and zip formats. For
most applications, the zlib format should be used as is. Note that comments
above on the use in deflateInit2() applies to the magnitude of windowBits.
-
windowBits can also be greater than 15 for optional gzip decoding. Add
32 to windowBits to enable zlib and gzip decoding with automatic header
detection, or add 16 to decode only the gzip format (the zlib format will
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
a crc32 instead of an adler32.
-
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
is set to null if there is no error message. inflateInit2 does not perform
@@ -732,7 +614,6 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
be done by inflate(). (So next_in and avail_in may be modified, but next_out
and avail_out are unchanged.)
*/
-
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
@@ -746,7 +627,6 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
immediately after inflateInit2() or inflateReset() and before any call of
inflate() to set the dictionary. The application must insure that the
dictionary that was used for compression is provided.
-
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
@@ -754,13 +634,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
perform any decompression: this will be done by subsequent calls of
inflate().
*/
-
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
-
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
@@ -769,33 +647,27 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
application may repeatedly call inflateSync, providing more input each time,
until success or end of the input data.
*/
-
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.
-
This function can be useful when randomly accessing a large stream. The
first pass through the stream can periodically record the inflate state,
allowing restarting inflate at those points when randomly accessing the
stream.
-
inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
-
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
The stream will keep attributes that may have been set by inflateInit2.
-
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
-
ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
int bits,
int value));
@@ -807,11 +679,9 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
should be used before the first inflate() call after inflateInit2() or
inflateReset(). bits must be less than or equal to 16, and that many of the
least significant bits of value will be inserted in the input.
-
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
-
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
gz_headerp head));
/*
@@ -824,7 +694,6 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
no gzip header information forthcoming. Note that Z_BLOCK can be used to
force inflate() to return immediately after header processing is complete
and before any actual data is decompressed.
-
The text, time, xflags, and os fields are filled in with the gzip header
contents. hcrc is set to true if there is a header CRC. (The header CRC
was valid if done is set to one.) If extra is not Z_NULL, then extra_max
@@ -841,21 +710,17 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
structure to duplicate the header. However if those fields are set to
allocated memory, then the application will need to save those pointers
elsewhere so that they can be eventually freed.
-
If inflateGetHeader is not used, then the header information is simply
discarded. The header is always checked for validity, including the header
CRC if present. inflateReset() will reset the process to discard the header
information. The application would need to call inflateGetHeader() again to
retrieve the header from the next gzip stream.
-
inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
-
/*
ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
unsigned char FAR *window));
-
Initialize the internal stream state for decompression using inflateBack()
calls. The fields zalloc, zfree and opaque in strm must be initialized
before the call. If zalloc and zfree are Z_NULL, then the default library-
@@ -865,18 +730,14 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
assured that deflate was used with small window sizes, windowBits must be 15
and a 32K byte window must be supplied to be able to decompress general
deflate streams.
-
See inflateBack() for the usage of these routines.
-
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
the paramaters are invalid, Z_MEM_ERROR if the internal state could not
be allocated, or Z_VERSION_ERROR if the version of the library does not
match the version of the header file.
*/
-
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
-
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
in_func in, void FAR *in_desc,
out_func out, void FAR *out_desc));
@@ -887,13 +748,11 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
sliding window by simply making the window itself the output buffer. This
function trusts the application to not change the output buffer passed by
the output function, at least until inflateBack() returns.
-
inflateBackInit() must be called first to allocate the internal state
and to initialize the state with the user-provided window buffer.
inflateBack() may then be used multiple times to inflate a complete, raw
deflate stream with each call. inflateBackEnd() is then called to free
the allocated state.
-
A raw deflate stream is one with no zlib or gzip header or trailer.
This routine would normally be used in a utility that reads zip or gzip
files and writes out uncompressed files. The utility would decode the
@@ -901,7 +760,6 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
only the raw deflate stream to decompress. This is different from the
normal behavior of inflate(), which expects either a zlib or gzip header and
trailer around the deflate stream.
-
inflateBack() uses two subroutines supplied by the caller that are then
called by inflateBack() for input and output. inflateBack() calls those
routines until it reads a complete deflate stream and writes out all of the
@@ -918,7 +776,6 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
inflateBackInit(), which is also the buffer that out() uses to write from.
The length written by out() will be at most the window size. Any non-zero
amount of input may be provided by in().
-
For convenience, inflateBack() can be provided input on the first call by
setting strm->next_in and strm->avail_in. If that input is exhausted, then
in() will be called. Therefore strm->next_in must be initialized before
@@ -926,12 +783,10 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
must also be initialized, and then if strm->avail_in is not zero, input will
initially be taken from strm->next_in[0 .. strm->avail_in - 1].
-
The in_desc and out_desc parameters of inflateBack() is passed as the
first parameter of in() and out() respectively when they are called. These
descriptors can be optionally used to pass any information that the caller-
supplied in() and out() functions need to do their job.
-
On return, inflateBack() will set strm->next_in and strm->avail_in to
pass back any unused input that was provided by the last in() call. The
return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
@@ -945,59 +800,47 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
strm->next_in is assured to be defined if out() returns non-zero.) Note
that inflateBack() cannot return Z_OK.
*/
-
ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
/*
All memory allocated by inflateBackInit() is freed.
-
inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
state was inconsistent.
*/
-
ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
/* Return flags indicating compile-time options.
-
Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1.0: size of uInt
3.2: size of uLong
5.4: size of voidpf (pointer)
7.6: size of z_off_t
-
Compiler, assembler, and debug options:
8: DEBUG
9: ASMV or ASMINF -- use ASM code
10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
11: 0 (reserved)
-
One-time table building (smaller code, but not thread-safe if true):
12: BUILDFIXED -- build static block decoding tables when needed
13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
14,15: 0 (reserved)
-
Library content (indicates missing functionality):
16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
deflate code when not needed)
17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
and decode gzip streams (to avoid linking crc code)
18-19: 0 (reserved)
-
Operation variations (changes in library functionality):
20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
21: FASTEST -- deflate algorithm with only one, lowest compression level
22,23: 0 (reserved)
-
The sprintf variant used by gzprintf (zero is best):
24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
26: 0 = returns value, 1 = void -- 1 means inferred string length returned
-
Remainder:
27-31: 0 (reserved)
*/
-
/* utility functions */
-
/*
The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some
@@ -1005,7 +848,6 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
*/
-
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
@@ -1020,7 +862,6 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
*/
-
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level));
@@ -1031,19 +872,16 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
destination buffer, which must be at least the value returned by
compressBound(sourceLen). Upon exit, destLen is the actual size of the
compressed buffer.
-
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
-
ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
/*
compressBound() returns an upper bound on the compressed size after
compress() or compress2() on sourceLen bytes. It would be used before
a compress() or compress2() call to allocate the destination buffer.
*/
-
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
@@ -1056,15 +894,12 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
-
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
*/
-
typedef voidp gzFile;
-
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
@@ -1073,15 +908,12 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
Huffman only compression as in "wb1h", or 'R' for run-length encoding
as in "wb1R". (See the description of deflateInit2 for more information
about the strategy parameter.)
-
gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression.
-
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR). */
-
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
@@ -1094,7 +926,6 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
*/
-
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description
@@ -1102,7 +933,6 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
opened for writing.
*/
-
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
@@ -1110,7 +940,6 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
-
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
voidpc buf, unsigned len));
/*
@@ -1118,7 +947,6 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
-
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the args to the compressed file under
@@ -1131,14 +959,12 @@ ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
zlib was compiled with the insecure functions sprintf() or vsprintf()
because the secure snprintf() or vsnprintf() functions were not available.
*/
-
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
*/
-
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
Reads bytes from the compressed file until len-1 characters are read, or
@@ -1147,19 +973,16 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
character.
gzgets returns buf, or Z_NULL in case of error.
*/
-
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
*/
-
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
*/
-
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
/*
Push one character back onto the stream to be read again later.
@@ -1169,7 +992,6 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
character will be discarded if the stream is repositioned with gzseek()
or gzrewind().
*/
-
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
@@ -1179,7 +1001,6 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
gzflush should be called only when strictly necessary because it can
degrade compression.
*/
-
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
/*
@@ -1191,48 +1012,39 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new
starting position.
-
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
would be before the current position.
*/
-
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
Rewinds the given file. This function is supported only for reading.
-
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/
-
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
-
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
-
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
*/
-
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/*
Returns 1 if file is being read directly without decompression, otherwise
zero.
*/
-
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
-
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
@@ -1241,22 +1053,18 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
-
ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/*
Clears the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip
file that is being written concurrently.
*/
-
/* checksum functions */
-
/*
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
*/
-
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
@@ -1264,15 +1072,12 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
-
uLong adler = adler32(0L, Z_NULL, 0);
-
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
*/
-
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
z_off_t len2));
/*
@@ -1281,7 +1086,6 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
*/
-
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running CRC-32 with the bytes buf[0..len-1] and return the
@@ -1289,17 +1093,13 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
value for the for the crc. Pre- and post-conditioning (one's complement) is
performed within this function so it shouldn't be done by the application.
Usage example:
-
uLong crc = crc32(0L, Z_NULL, 0);
-
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
*/
-
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
-
/*
Combine two CRC-32 check values into one. For two sequences of bytes,
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
@@ -1308,9 +1108,7 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
len2.
*/
-
/* various hacks, don't look :) */
-
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
@@ -1341,18 +1139,14 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
inflateBackInit_((strm), (windowBits), (window), \
ZLIB_VERSION, sizeof(z_stream))
-
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
-
ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
-
#ifdef __cplusplus
}
#endif
-
#endif /* ZLIB_H */
diff --git a/dep/src/zlib/zutil.c b/dep/src/zlib/zutil.c
index d55f5948a37..09b456e54e4 100644
--- a/dep/src/zlib/zutil.c
+++ b/dep/src/zlib/zutil.c
@@ -2,15 +2,11 @@
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* @(#) $Id$ */
-
#include "zutil.h"
-
#ifndef NO_DUMMY_DECL
struct internal_state {int dummy;}; /* for buggy compilers */
#endif
-
const char * const z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */
@@ -23,16 +19,13 @@ const char * const z_errmsg[10] = {
"incompatible version",/* Z_VERSION_ERROR (-6) */
""};
-
const char * ZEXPORT zlibVersion()
{
return ZLIB_VERSION;
}
-
uLong ZEXPORT zlibCompileFlags()
{
uLong flags;
-
flags = 0;
switch (sizeof(uInt)) {
case 2: break;
@@ -111,14 +104,11 @@ uLong ZEXPORT zlibCompileFlags()
#endif
return flags;
}
-
#ifdef DEBUG
-
# ifndef verbose
# define verbose 0
# endif
int z_verbose = verbose;
-
void z_error (m)
char *m;
{
@@ -126,7 +116,6 @@ void z_error (m)
exit(1);
}
#endif
-
/* exported to allow conversion of error code to string for compress() and
* uncompress()
*/
@@ -135,7 +124,6 @@ const char * ZEXPORT zError(err)
{
return ERR_MSG(err);
}
-
#if defined(_WIN32_WCE)
/* The Microsoft C Run-Time Library for Windows CE doesn't have
* errno. We define it as a global variable to simplify porting.
@@ -143,9 +131,7 @@ const char * ZEXPORT zError(err)
*/
int errno = 0;
#endif
-
#ifndef HAVE_MEMCPY
-
void zmemcpy(dest, source, len)
Bytef* dest;
const Bytef* source;
@@ -156,20 +142,17 @@ void zmemcpy(dest, source, len)
*dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0);
}
-
int zmemcmp(s1, s2, len)
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j;
-
for (j = 0; j < len; j++) {
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
}
return 0;
}
-
void zmemzero(dest, len)
Bytef* dest;
uInt len;
@@ -181,30 +164,22 @@ void zmemzero(dest, len)
}
#endif
-
#ifdef SYS16BIT
-
#ifdef __TURBOC__
/* Turbo C in 16-bit mode */
-
# define MY_ZCALLOC
-
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
* and farmalloc(64K) returns a pointer with an offset of 8, so we
* must fix the pointer. Warning: the pointer must be put back to its
* original form in order to free it, use zcfree().
*/
-
#define MAX_PTR 10
/* 10*64K = 640K */
-
local int next_ptr = 0;
-
typedef struct ptr_table_s {
voidpf org_ptr;
voidpf new_ptr;
} ptr_table;
-
local ptr_table table[MAX_PTR];
/* This table is used to remember the original form of pointers
* to large buffers (64K). Such pointers are normalized with a zero offset.
@@ -212,12 +187,10 @@ local ptr_table table[MAX_PTR];
* protected from concurrent access. This hack doesn't work anyway on
* a protected system like OS/2. Use Microsoft C instead.
*/
-
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{
voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size;
-
/* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized.
*/
@@ -229,14 +202,12 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
}
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
table[next_ptr].org_ptr = buf;
-
/* Normalize the pointer to seg:0 */
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
*(ush*)&buf = 0;
table[next_ptr++].new_ptr = buf;
return buf;
}
-
void zcfree (voidpf opaque, voidpf ptr)
{
int n;
@@ -247,7 +218,6 @@ void zcfree (voidpf opaque, voidpf ptr)
/* Find the original pointer */
for (n = 0; n < next_ptr; n++) {
if (ptr != table[n].new_ptr) continue;
-
farfree(table[n].org_ptr);
while (++n < next_ptr) {
table[n-1] = table[n];
@@ -258,45 +228,34 @@ void zcfree (voidpf opaque, voidpf ptr)
ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found");
}
-
#endif /* __TURBOC__ */
-
#ifdef M_I86
/* Microsoft C in 16-bit mode */
-
# define MY_ZCALLOC
-
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
# define _halloc halloc
# define _hfree hfree
#endif
-
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{
if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size);
}
-
void zcfree (voidpf opaque, voidpf ptr)
{
if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr);
}
-
#endif /* M_I86 */
-
#endif /* SYS16BIT */
-
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
-
#ifndef STDC
extern voidp malloc OF((uInt size));
extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidpf ptr));
#endif
-
voidpf zcalloc (opaque, items, size)
voidpf opaque;
unsigned items;
@@ -306,7 +265,6 @@ voidpf zcalloc (opaque, items, size)
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size);
}
-
void zcfree (opaque, ptr)
voidpf opaque;
voidpf ptr;
@@ -314,5 +272,4 @@ void zcfree (opaque, ptr)
free(ptr);
if (opaque) return; /* make compiler happy */
}
-
#endif /* MY_ZCALLOC */
diff --git a/dep/src/zlib/zutil.h b/dep/src/zlib/zutil.h
index b8a722d904d..f55a94803cd 100644
--- a/dep/src/zlib/zutil.h
+++ b/dep/src/zlib/zutil.h
@@ -2,20 +2,15 @@
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
-
/* @(#) $Id$ */
-
#ifndef ZUTIL_H
#define ZUTIL_H
-
#define ZLIB_INTERNAL
#include "zlib.h"
-
#ifdef STDC
# ifndef _WIN32_WCE
# include <stddef.h>
@@ -38,54 +33,41 @@
# include <errno.h>
# endif
#endif
-
#ifndef local
# define local static
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
-
typedef unsigned char uch;
typedef uch FAR uchf;
typedef unsigned short ush;
typedef ush FAR ushf;
typedef unsigned long ulg;
-
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */
-
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
-
#define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */
-
/* common constants */
-
#ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
-
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
/* default memLevel */
-
#define STORED_BLOCK 0
#define STATIC_TREES 1
#define DYN_TREES 2
/* The three kinds of block type */
-
#define MIN_MATCH 3
#define MAX_MATCH 258
/* The minimum and maximum match lengths */
-
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
-
/* target dependencies */
-
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__)
@@ -100,28 +82,23 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# include <malloc.h>
# endif
#endif
-
#ifdef AMIGA
# define OS_CODE 0x01
#endif
-
#if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
-
#if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05
#endif
-
#ifdef OS2
# define OS_CODE 0x06
# ifdef M_I86
#include <malloc.h>
# endif
#endif
-
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
@@ -132,25 +109,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
# endif
#endif
-
#ifdef TOPS20
# define OS_CODE 0x0a
#endif
-
#ifdef WIN32
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
# define OS_CODE 0x0b
# endif
#endif
-
#ifdef __50SERIES /* Prime/PRIMOS */
# define OS_CODE 0x0f
#endif
-
#if defined(_BEOS_) || defined(RISCOS)
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif
-
#if (defined(_MSC_VER) && (_MSC_VER > 600))
# if defined(_WIN32_WCE)
# define fdopen(fd,mode) NULL /* No fdopen() */
@@ -162,19 +134,14 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define fdopen(fd,type) _fdopen(fd,type)
# endif
#endif
-
/* common defaults */
-
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
#endif
-
#ifndef F_OPEN
# define F_OPEN(name, mode) fopen((name), (mode))
#endif
-
/* functions */
-
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
@@ -207,7 +174,6 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef VMS
# define NO_vsnprintf
#endif
-
#if defined(pyr)
# define NO_MEMCPY
#endif
@@ -236,7 +202,6 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
extern void zmemzero OF((Bytef* dest, uInt len));
#endif
-
/* Diagnostic functions */
#ifdef DEBUG
# include <stdio.h>
@@ -257,14 +222,11 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define Tracecv(c,x)
#endif
-
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidpf opaque, voidpf ptr));
-
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
-
#endif /* ZUTIL_H */