set svn:eol-type=native for **.c

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1439 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
bushing 2008-12-08 04:58:11 +00:00
parent 30c883bcfc
commit 18ceeda47a
41 changed files with 40592 additions and 40592 deletions

View File

@ -1,213 +1,213 @@
// //
// Pseudo C // Pseudo C
// //
// //
// DSP: // DSP:
// //
// Memory USAGE // Memory USAGE
0x0B80 to 0x0C40 CurrentPB 0x0B80 to 0x0C40 CurrentPB
0x0B87 0x0B87
0x0E15 SrcSelectFunction // perhaps CMD0 setups some kind of jmp table at this addresses 0x0E15 SrcSelectFunction // perhaps CMD0 setups some kind of jmp table at this addresses
0x0E16 CoefFunction 0x0E16 CoefFunction
0x0E14 MixCtrlFunction 0x0E14 MixCtrlFunction
0x0e17 TmpBuffer exceptions 0x0e17 TmpBuffer exceptions
0x0e18 TmpBuffer exceptions 0x0e18 TmpBuffer exceptions
0x0e19 TmpBuffer exceptions 0x0e19 TmpBuffer exceptions
// instrcution memory // instrcution memory
0x0B31 to 0x0B33 some kind of JMP-Table to handle srcSelect ??? 0x0B31 to 0x0B33 some kind of JMP-Table to handle srcSelect ???
0x0B34 to 0x0B36 some kind of JMP-Table to handle coefSelect ??? 0x0B34 to 0x0B36 some kind of JMP-Table to handle coefSelect ???
0x0B11 to 0x0B1F some kind of JMP-Table to handle mixerCtrl ??? 0x0B11 to 0x0B1F some kind of JMP-Table to handle mixerCtrl ???
void CMD2() void CMD2()
{ {
// 0x1BC // 0x1BC
int_addrPB = (*r00 << 16) | *(r00+1) int_addrPB = (*r00 << 16) | *(r00+1)
DMA_From_Memory(0x0B80, _addrPB, 0xC0); // read first PB to 0x0B80 DMA_From_Memory(0x0B80, _addrPB, 0xC0); // read first PB to 0x0B80
// 0x1C7 // 0x1C7
*0x0E08 = 0x0000 *0x0E08 = 0x0000
*0x0E09 = 0x0140 *0x0E09 = 0x0140
*0x0E0A = 0x0280 *0x0E0A = 0x0280
*0x0E0B = 0x0400 *0x0E0B = 0x0400
*0x0E0C = 0x0540 *0x0E0C = 0x0540
*0x0E0D = 0x0680 *0x0E0D = 0x0680
*0x0E0E = 0x07C0 *0x0E0E = 0x07C0
*0x0E0F = 0x0900 *0x0E0F = 0x0900
*0x0E10 = 0x0A40 *0x0E10 = 0x0A40
// 0x1E4 // 0x1E4
WaitForDMATransfer() WaitForDMATransfer()
// 0x1E6 // 0x1E6
Addr = (*0x0BA7 << 16) | *0x0BA8 Addr = (*0x0BA7 << 16) | *0x0BA8
DMA_From_Memory(0x03C0, Addr, 0x80); // Copy Update Data to 0x03C0 (AXPBUPDATE dataHi, dataLo) DMA_From_Memory(0x03C0, Addr, 0x80); // Copy Update Data to 0x03C0 (AXPBUPDATE dataHi, dataLo)
// 0x1F4 // 0x1F4
R03 = (*0x0B84) + 0x0B31 // AXPB->srcSelect + 0x0B31 ??? some kind of flag handling ??? SRCSEL can be 0x0 to 0x2 R03 = (*0x0B84) + 0x0B31 // AXPB->srcSelect + 0x0B31 ??? some kind of flag handling ??? SRCSEL can be 0x0 to 0x2
AC0.M = *R03 AC0.M = *R03
*0x0E15 = *AC0.M *0x0E15 = *AC0.M
// 0x1FD // 0x1FD
R03 = (*0x0B85) + 0x0B34 // AXPB->coefSelect + 0x0B34 ??? some kind of flag handling ??? COEF can be 0x0 to 0x2 R03 = (*0x0B85) + 0x0B34 // AXPB->coefSelect + 0x0B34 ??? some kind of flag handling ??? COEF can be 0x0 to 0x2
AC0.M = *R03 AC0.M = *R03
*0x0E16 = *AC0.M *0x0E16 = *AC0.M
// 0x206 // 0x206
R03 = (*0x0B86) + 0x0B11 // AXPB->mixerCtrl + 0x0B36 ??? some kind of flag handling ??? MIXCTRL can be 0x0 to 0xE R03 = (*0x0B86) + 0x0B11 // AXPB->mixerCtrl + 0x0B36 ??? some kind of flag handling ??? MIXCTRL can be 0x0 to 0xE
AC0.M = *R03 AC0.M = *R03
*0x0E14 = *AC0.M *0x0E14 = *AC0.M
// 0x20F // 0x20F
if (*0x0B9B == 0) // AXPBITD->flag (on or off for this voice) if (*0x0B9B == 0) // AXPBITD->flag (on or off for this voice)
{ {
// jmp to 0x23a // jmp to 0x23a
*0x0E42 = 0x0CE0 *0x0E42 = 0x0CE0
*0x0E40 = 0x0CE0 *0x0E40 = 0x0CE0
*0x0E41 = 0x0CE0 *0x0E41 = 0x0CE0
*0x0E43 = 0x0CE0 *0x0E43 = 0x0CE0
WaitForDMATransfer() WaitForDMATransfer()
} }
else else
{ {
// code at 0x216 // code at 0x216
*0x0E40 = *0x0B9E + 0x0CC0 // AXPBITD->shiftL *0x0E40 = *0x0B9E + 0x0CC0 // AXPBITD->shiftL
*0x0E41 = *0x0B9F + 0x0CC0 // AXPBITD->shiftR *0x0E41 = *0x0B9F + 0x0CC0 // AXPBITD->shiftR
*0x0E42 = 0xCE0 *0x0E42 = 0xCE0
*0x0E43 = 0xCE0 *0x0E43 = 0xCE0
WaitForDMATransfer() WaitForDMATransfer()
// 0x22a // 0x22a
Addr = (*0x0B9C << 16) | *0x0B9D Addr = (*0x0B9C << 16) | *0x0B9D
DMA_From_Memory(0x0CC0, Addr, 0x40); // (AXPBITD->bufferHi << 16 | AXPBITD->bufferLo) -> 0xCC0 DMA_From_Memory(0x0CC0, Addr, 0x40); // (AXPBITD->bufferHi << 16 | AXPBITD->bufferLo) -> 0xCC0
WaitForDMATransfer() WaitForDMATransfer()
} }
} }
void CMD0() void CMD0()
{ {
} }
void CMD3() void CMD3()
{ {
0x0E07 = R00 0x0E07 = R00
R00 = 0x0BA2 // AXPBUPDATE->updNum R00 = 0x0BA2 // AXPBUPDATE->updNum
R01 = 0x03C0 R01 = 0x03C0
*0x0E04 = 0x05 *0x0E04 = 0x05
AC1 = 0 AC1 = 0
AC0 = 0 AC0 = 0
AX0.H = *R00++ // AXPBUPDATE->updNum[0] AX0.H = *R00++ // AXPBUPDATE->updNum[0]
AC1.M = 0x0B80 AC1.M = 0x0B80
// 0x256 // 0x256
for (i=0; i<AX0.H; i++) for (i=0; i<AX0.H; i++)
{ {
AC0.M = *R01++ AC0.M = *R01++
AC0.M = AC0.M + AC1.M AC0.M = AC0.M + AC1.M
AX1.L = *R01++ AX1.L = *R01++
R02 = AC0.M R02 = AC0.M
*R02 = AX1.L *R02 = AX1.L
} }
// 0x25c // 0x25c
R03 = 0x0E05 R03 = 0x0E05
*R03++ = R01 *R03++ = R01
*R03++ = R02 *R03++ = R02
// 0x260 // 0x260
AC0.M = *0x0B87 // AXPB->state AC0.M = *0x0B87 // AXPB->state
if (AC0.M == 1) if (AC0.M == 1)
{ {
// JMP 0x267 (AX_PB_STATE_RUN) // JMP 0x267 (AX_PB_STATE_RUN)
*0x0E1C = *0x0E42 *0x0E1C = *0x0E42
CALLR *0x0E15 // Load Sample (SrcSelectFunction) CALLR *0x0E15 // Load Sample (SrcSelectFunction)
// 0x270 // 0x270
AC0.M = *0xBB3 // AXPBVE->currentDelta (.15 volume at start of frame) AC0.M = *0xBB3 // AXPBVE->currentDelta (.15 volume at start of frame)
AC1.M = *0xBB2 // AXPBVE->currentVolume AC1.M = *0xBB2 // AXPBVE->currentVolume
// 0x278 // 0x278
AX0.L = AC1.M AX0.L = AC1.M
AC1.M = AC1.M + AC0.M AC1.M = AC1.M + AC0.M
AC0.M = AC0.M << 1 AC0.M = AC0.M << 1
SET15 // ???? SET15 // ????
AX1.H = AC0.M AX1.H = AC0.M
AC0.M = AX0.L AC0.M = AX0.L
AX0.L = 0x8000 AX0.L = 0x8000
R00 = 0x0E44 R00 = 0x0E44
// 0x27f // 0x27f
// scale volume table // scale volume table
. .
. .
. .
/* for (int i=0; i<32; i++) /* for (int i=0; i<32; i++)
{ {
*R00++ = AC0.M; *R00++ = AC0.M;
prod = AX0.L * AX1.H prod = AX0.L * AX1.H
*R00++ = AC1.M; *R00++ = AC1.M;
AC0 = AC0 + prod AC0 = AC0 + prod
prod = AX0.L * AX1.H prod = AX0.L * AX1.H
*R00++ = AC0.M; *R00++ = AC0.M;
AC1 = AC1 + prod AC1 = AC1 + prod
prod = AX0.L * AX1.H prod = AX0.L * AX1.H
}*/ }*/
// 0x29f // 0x29f
*0xBB2 = CurrentVolume *0xBB2 = CurrentVolume
// 0x2a1 // 0x2a1
// mutiply volume with sample // mutiply volume with sample
. .
. .
. .
// 0x2ea // 0x2ea
// Call mixer // Call mixer
// 0x02f0 // 0x02f0
} }
else else
{ {
// JMP 0x332 // JMP 0x332
. .
. .
. .
. .
} }
} }
// =============================================================== // ===============================================================
void Func_0x065D() void Func_0x065D()
{ {
} }

View File

@ -57,7 +57,7 @@ static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now);
* @return Returns 1 if handshake was successful, 0 if not. * @return Returns 1 if handshake was successful, 0 if not.
*/ */
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) { int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) {
int i; int i;
int offset = 0; int offset = 0;
cc->btns = 0; cc->btns = 0;
@ -69,30 +69,30 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
/* decrypt data */ /* decrypt data */
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17; data[i] = (data[i] ^ 0x17) + 0x17;
if (data[offset] == 0xFF) { if (data[offset] == 0xFF) {
/* /*
* Sometimes the data returned here is not correct. * Sometimes the data returned here is not correct.
* This might happen because the wiimote is lagging * This might happen because the wiimote is lagging
* behind our initialization sequence. * behind our initialization sequence.
* To fix this just request the handshake again. * To fix this just request the handshake again.
* *
* Other times it's just the first 16 bytes are 0xFF, * Other times it's just the first 16 bytes are 0xFF,
* but since the next 16 bytes are the same, just use * but since the next 16 bytes are the same, just use
* those. * those.
*/ */
if (data[offset + 16] == 0xFF) { if (data[offset + 16] == 0xFF) {
/* get the calibration data */ /* get the calibration data */
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again."); WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again.");
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
return 0; return 0;
} else } else
offset += 16; offset += 16;
} }
/* joystick stuff */ /* joystick stuff */
cc->ljs.max.x = data[0 + offset] / 4; cc->ljs.max.x = data[0 + offset] / 4;

View File

@ -107,12 +107,12 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
orient->pitch = y; orient->pitch = y;
orient->a_pitch = y; orient->a_pitch = y;
} }
/* smooth the angles if enabled */ /* smooth the angles if enabled */
if (smooth) { if (smooth) {
apply_smoothing(ac, orient, SMOOTH_ROLL); apply_smoothing(ac, orient, SMOOTH_ROLL);
apply_smoothing(ac, orient, SMOOTH_PITCH); apply_smoothing(ac, orient, SMOOTH_PITCH);
} }
} }
@ -191,7 +191,7 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) {
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) { void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
switch (type) { switch (type) {
case SMOOTH_ROLL: case SMOOTH_ROLL:
{ {
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */ /* it's possible last iteration was nan or inf, so set it to 0 if that happened */
if (isnan(ac->st_roll) || isinf(ac->st_roll)) if (isnan(ac->st_roll) || isinf(ac->st_roll))
ac->st_roll = 0.0f; ac->st_roll = 0.0f;

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@ static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now
* @return Returns 1 if handshake was successful, 0 if not. * @return Returns 1 if handshake was successful, 0 if not.
*/ */
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len) { int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len) {
int i; int i;
int offset = 0; int offset = 0;
/* /*
@ -74,29 +74,29 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
/* decrypt data */ /* decrypt data */
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17; data[i] = (data[i] ^ 0x17) + 0x17;
if (data[offset] == 0xFF) { if (data[offset] == 0xFF) {
/* /*
* Sometimes the data returned here is not correct. * Sometimes the data returned here is not correct.
* This might happen because the wiimote is lagging * This might happen because the wiimote is lagging
* behind our initialization sequence. * behind our initialization sequence.
* To fix this just request the handshake again. * To fix this just request the handshake again.
* *
* Other times it's just the first 16 bytes are 0xFF, * Other times it's just the first 16 bytes are 0xFF,
* but since the next 16 bytes are the same, just use * but since the next 16 bytes are the same, just use
* those. * those.
*/ */
if (data[offset + 16] == 0xFF) { if (data[offset + 16] == 0xFF) {
/* get the calibration data */ /* get the calibration data */
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again."); WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again.");
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
return 0; return 0;
} else } else
offset += 16; offset += 16;
} }
/* joystick stuff */ /* joystick stuff */
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X; gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;

View File

@ -59,8 +59,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
case 0: case 0:
{ {
/* send request to wiimote for accelerometer calibration */ /* send request to wiimote for accelerometer calibration */
byte* buf; byte* buf;
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
wiiuse_set_leds(wm, WIIMOTE_LED_NONE); wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
@ -68,8 +68,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7); wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
wm->handshake_state++; wm->handshake_state++;
wiiuse_set_leds(wm, WIIMOTE_LED_NONE); wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
break; break;
} }
case 1: case 1:
@ -94,23 +94,23 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z, accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z); accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
/* request the status of the wiimote to see if there is an expansion */ /* request the status of the wiimote to see if there is an expansion */
wiiuse_status(wm); wiiuse_status(wm);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
wm->handshake_state++; wm->handshake_state++;
/* now enable IR if it was set before the handshake completed */ /* now enable IR if it was set before the handshake completed */
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
WIIUSE_DEBUG("Handshake finished, enabling IR."); WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1); wiiuse_set_ir(wm, 1);
} }
break; break;
} }
default: default:
{ {
break; break;

View File

@ -32,14 +32,14 @@
*/ */
#ifdef WIN32 #ifdef WIN32
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
#include <hidsdi.h> #include <hidsdi.h>
#include <setupapi.h> #include <setupapi.h>
#include "definitions.h" #include "definitions.h"
#include "wiiuse_internal.h" #include "wiiuse_internal.h"
#include "io.h" #include "io.h"
@ -176,8 +176,8 @@ int wiiuse_io_read(struct wiimote_t* wm) {
if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) { if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) {
/* partial read */ /* partial read */
b = GetLastError(); b = GetLastError();
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) { if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) {
/* remote disconnect */ /* remote disconnect */
wiiuse_disconnected(wm); wiiuse_disconnected(wm);
@ -186,11 +186,11 @@ int wiiuse_io_read(struct wiimote_t* wm) {
r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout); r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout);
if (r == WAIT_TIMEOUT) { if (r == WAIT_TIMEOUT) {
/* timeout - cancel and continue */ /* timeout - cancel and continue */
if (*wm->event_buf) if (*wm->event_buf)
WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
CancelIo(wm->dev_handle); CancelIo(wm->dev_handle);
ResetEvent(wm->hid_overlap.hEvent); ResetEvent(wm->hid_overlap.hEvent);
return 0; return 0;
@ -203,25 +203,25 @@ int wiiuse_io_read(struct wiimote_t* wm) {
return 0; return 0;
} }
ResetEvent(wm->hid_overlap.hEvent); ResetEvent(wm->hid_overlap.hEvent);
return 1; return 1;
} }
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
DWORD bytes; DWORD bytes;
int i; int i;
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) if (!wm || !WIIMOTE_IS_CONNECTED(wm))
return 0; return 0;
switch (wm->stack) { switch (wm->stack) {
case WIIUSE_STACK_UNKNOWN: case WIIUSE_STACK_UNKNOWN:
{ {
/* try to auto-detect the stack type */ /* try to auto-detect the stack type */
if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) { if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) {
/* bluesoleil will always return 1 here, even if it's not connected */ /* bluesoleil will always return 1 here, even if it's not connected */
wm->stack = WIIUSE_STACK_BLUESOLEIL; wm->stack = WIIUSE_STACK_BLUESOLEIL;
return i; return i;
} }

View File

@ -53,9 +53,9 @@ static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
* @return Returns 1 if handshake was successful, 0 if not. * @return Returns 1 if handshake was successful, 0 if not.
*/ */
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) { int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) {
int i; int i;
int offset = 0; int offset = 0;
nc->btns = 0; nc->btns = 0;
nc->btns_held = 0; nc->btns_held = 0;
nc->btns_released = 0; nc->btns_released = 0;
@ -66,29 +66,29 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
/* decrypt data */ /* decrypt data */
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17; data[i] = (data[i] ^ 0x17) + 0x17;
if (data[offset] == 0xFF) { if (data[offset] == 0xFF) {
/* /*
* Sometimes the data returned here is not correct. * Sometimes the data returned here is not correct.
* This might happen because the wiimote is lagging * This might happen because the wiimote is lagging
* behind our initialization sequence. * behind our initialization sequence.
* To fix this just request the handshake again. * To fix this just request the handshake again.
* *
* Other times it's just the first 16 bytes are 0xFF, * Other times it's just the first 16 bytes are 0xFF,
* but since the next 16 bytes are the same, just use * but since the next 16 bytes are the same, just use
* those. * those.
*/ */
if (data[offset + 16] == 0xFF) { if (data[offset + 16] == 0xFF) {
/* get the calibration data */ /* get the calibration data */
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again."); WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again.");
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
return 0; return 0;
} else } else
offset += 16; offset += 16;
} }
nc->accel_calib.cal_zero.x = data[offset + 0]; nc->accel_calib.cal_zero.x = data[offset + 0];
@ -103,16 +103,16 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
nc->js.max.y = data[offset + 11]; nc->js.max.y = data[offset + 11];
nc->js.min.y = data[offset + 12]; nc->js.min.y = data[offset + 12];
nc->js.center.y = data[offset + 13]; nc->js.center.y = data[offset + 13];
/* default the thresholds to the same as the wiimote */ /* default the thresholds to the same as the wiimote */
nc->orient_threshold = wm->orient_threshold; nc->orient_threshold = wm->orient_threshold;
nc->accel_threshold = wm->accel_threshold; nc->accel_threshold = wm->accel_threshold;
/* handshake done */ /* handshake done */
wm->exp.type = EXP_NUNCHUK; wm->exp.type = EXP_NUNCHUK;
#ifdef WIN32 #ifdef WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif #endif
return 1; return 1;

File diff suppressed because it is too large Load Diff

View File

@ -1,196 +1,196 @@
/***************************************************************************** /*****************************************************************************
** Name: extended.c ** Name: extended.c
** Purpose: IEEE Extended<->Double routines to save floats to file ** Purpose: IEEE Extended<->Double routines to save floats to file
** Maintainer: Ryan Norton ** Maintainer: Ryan Norton
** Modified by: ** Modified by:
** Created: 11/24/04 ** Created: 11/24/04
** RCS-ID: $Id: extended.c 36952 2006-01-18 10:25:04Z JS $ ** RCS-ID: $Id: extended.c 36952 2006-01-18 10:25:04Z JS $
*****************************************************************************/ *****************************************************************************/
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
/* eVC cause warnings in its own headers: stdlib.h and winnt.h */ /* eVC cause warnings in its own headers: stdlib.h and winnt.h */
#pragma warning (disable:4115) #pragma warning (disable:4115)
#pragma warning (disable:4214) #pragma warning (disable:4214)
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include "wx/defs.h" #include "wx/defs.h"
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
#pragma warning (default:4115) #pragma warning (default:4115)
#pragma warning (default:4214) #pragma warning (default:4214)
#endif #endif
#if wxUSE_APPLE_IEEE #if wxUSE_APPLE_IEEE
#include "wx/math.h" #include "wx/math.h"
/* Copyright (C) 1989-1991 Ken Turkowski. <turk@computer.org> /* Copyright (C) 1989-1991 Ken Turkowski. <turk@computer.org>
* *
* All rights reserved. * All rights reserved.
* *
* Warranty Information * Warranty Information
* Even though I have reviewed this software, I make no warranty * Even though I have reviewed this software, I make no warranty
* or representation, either express or implied, with respect to this * or representation, either express or implied, with respect to this
* software, its quality, accuracy, merchantability, or fitness for a * software, its quality, accuracy, merchantability, or fitness for a
* particular purpose. As a result, this software is provided "as is," * particular purpose. As a result, this software is provided "as is,"
* and you, its user, are assuming the entire risk as to its quality * and you, its user, are assuming the entire risk as to its quality
* and accuracy. * and accuracy.
* *
* This code may be used and freely distributed as long as it includes * This code may be used and freely distributed as long as it includes
* this copyright notice and the above warranty information. * this copyright notice and the above warranty information.
* *
* Machine-independent I/O routines for IEEE floating-point numbers. * Machine-independent I/O routines for IEEE floating-point numbers.
* *
* NaN's and infinities are converted to HUGE_VAL or HUGE, which * NaN's and infinities are converted to HUGE_VAL or HUGE, which
* happens to be infinity on IEEE machines. Unfortunately, it is * happens to be infinity on IEEE machines. Unfortunately, it is
* impossible to preserve NaN's in a machine-independent way. * impossible to preserve NaN's in a machine-independent way.
* Infinities are, however, preserved on IEEE machines. * Infinities are, however, preserved on IEEE machines.
* *
* These routines have been tested on the following machines: * These routines have been tested on the following machines:
* Apple Macintosh, MPW 3.1 C compiler * Apple Macintosh, MPW 3.1 C compiler
* Apple Macintosh, THINK C compiler * Apple Macintosh, THINK C compiler
* Silicon Graphics IRIS, MIPS compiler * Silicon Graphics IRIS, MIPS compiler
* Cray X/MP and Y/MP * Cray X/MP and Y/MP
* Digital Equipment VAX * Digital Equipment VAX
* Sequent Balance (Multiprocesor 386) * Sequent Balance (Multiprocesor 386)
* NeXT * NeXT
* *
* *
* Implemented by Malcolm Slaney and Ken Turkowski. * Implemented by Malcolm Slaney and Ken Turkowski.
* *
* Malcolm Slaney contributions during 1988-1990 include big- and little- * Malcolm Slaney contributions during 1988-1990 include big- and little-
* endian file I/O, conversion to and from Motorola's extended 80-bit * endian file I/O, conversion to and from Motorola's extended 80-bit
* floating-point format, and conversions to and from IEEE single- * floating-point format, and conversions to and from IEEE single-
* precision floating-point format. * precision floating-point format.
* *
* In 1991, Ken Turkowski implemented the conversions to and from * In 1991, Ken Turkowski implemented the conversions to and from
* IEEE double-precision format, added more precision to the extended * IEEE double-precision format, added more precision to the extended
* conversions, and accommodated conversions involving +/- infinity, * conversions, and accommodated conversions involving +/- infinity,
* NaN's, and denormalized numbers. * NaN's, and denormalized numbers.
*/ */
#ifndef HUGE_VAL #ifndef HUGE_VAL
# define HUGE_VAL HUGE # define HUGE_VAL HUGE
#endif /*HUGE_VAL*/ #endif /*HUGE_VAL*/
/**************************************************************** /****************************************************************
* The following two routines make up for deficiencies in many * The following two routines make up for deficiencies in many
* compilers to convert properly between unsigned integers and * compilers to convert properly between unsigned integers and
* floating-point. Some compilers which have this bug are the * floating-point. Some compilers which have this bug are the
* THINK_C compiler for the Macintosh and the C compiler for the * THINK_C compiler for the Macintosh and the C compiler for the
* Silicon Graphics MIPS-based Iris. * Silicon Graphics MIPS-based Iris.
****************************************************************/ ****************************************************************/
#ifdef applec /* The Apple C compiler works */ #ifdef applec /* The Apple C compiler works */
# define FloatToUnsigned(f) ((wxUint32)(f)) # define FloatToUnsigned(f) ((wxUint32)(f))
# define UnsignedToFloat(u) ((wxFloat64)(u)) # define UnsignedToFloat(u) ((wxFloat64)(u))
#else /*applec*/ #else /*applec*/
# define FloatToUnsigned(f) ((wxUint32)(((wxInt32)((f) - 2147483648.0)) + 2147483647L) + 1) # define FloatToUnsigned(f) ((wxUint32)(((wxInt32)((f) - 2147483648.0)) + 2147483647L) + 1)
# define UnsignedToFloat(u) (((wxFloat64)((wxInt32)((u) - 2147483647L - 1))) + 2147483648.0) # define UnsignedToFloat(u) (((wxFloat64)((wxInt32)((u) - 2147483647L - 1))) + 2147483648.0)
#endif /*applec*/ #endif /*applec*/
/**************************************************************** /****************************************************************
* Extended precision IEEE floating-point conversion routines. * Extended precision IEEE floating-point conversion routines.
* Extended is an 80-bit number as defined by Motorola, * Extended is an 80-bit number as defined by Motorola,
* with a sign bit, 15 bits of exponent (offset 16383?), * with a sign bit, 15 bits of exponent (offset 16383?),
* and a 64-bit mantissa, with no hidden bit. * and a 64-bit mantissa, with no hidden bit.
****************************************************************/ ****************************************************************/
wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes) wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes)
{ {
wxFloat64 f; wxFloat64 f;
wxInt32 expon; wxInt32 expon;
wxUint32 hiMant, loMant; wxUint32 hiMant, loMant;
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24) hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24)
| ((wxUint32)(bytes[3] & 0xFF) << 16) | ((wxUint32)(bytes[3] & 0xFF) << 16)
| ((wxUint32)(bytes[4] & 0xFF) << 8) | ((wxUint32)(bytes[4] & 0xFF) << 8)
| ((wxUint32)(bytes[5] & 0xFF)); | ((wxUint32)(bytes[5] & 0xFF));
loMant = ((wxUint32)(bytes[6] & 0xFF) << 24) loMant = ((wxUint32)(bytes[6] & 0xFF) << 24)
| ((wxUint32)(bytes[7] & 0xFF) << 16) | ((wxUint32)(bytes[7] & 0xFF) << 16)
| ((wxUint32)(bytes[8] & 0xFF) << 8) | ((wxUint32)(bytes[8] & 0xFF) << 8)
| ((wxUint32)(bytes[9] & 0xFF)); | ((wxUint32)(bytes[9] & 0xFF));
if (expon == 0 && hiMant == 0 && loMant == 0) { if (expon == 0 && hiMant == 0 && loMant == 0) {
f = 0; f = 0;
} }
else { else {
if (expon == 0x7FFF) { /* Infinity or NaN */ if (expon == 0x7FFF) { /* Infinity or NaN */
f = HUGE_VAL; f = HUGE_VAL;
} }
else { else {
expon -= 16383; expon -= 16383;
f = ldexp(UnsignedToFloat(hiMant), expon-=31); f = ldexp(UnsignedToFloat(hiMant), expon-=31);
f += ldexp(UnsignedToFloat(loMant), expon-=32); f += ldexp(UnsignedToFloat(loMant), expon-=32);
} }
} }
if (bytes[0] & 0x80) if (bytes[0] & 0x80)
return -f; return -f;
else else
return f; return f;
} }
/****************************************************************/ /****************************************************************/
void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes) void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes)
{ {
wxInt32 sign; wxInt32 sign;
wxInt32 expon; wxInt32 expon;
wxFloat64 fMant, fsMant; wxFloat64 fMant, fsMant;
wxUint32 hiMant, loMant; wxUint32 hiMant, loMant;
if (num < 0) { if (num < 0) {
sign = 0x8000; sign = 0x8000;
num *= -1; num *= -1;
} else { } else {
sign = 0; sign = 0;
} }
if (num == 0) { if (num == 0) {
expon = 0; hiMant = 0; loMant = 0; expon = 0; hiMant = 0; loMant = 0;
} }
else { else {
fMant = frexp(num, &expon); fMant = frexp(num, &expon);
if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */ if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */
expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */ expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */
} }
else { /* Finite */ else { /* Finite */
expon += 16382; expon += 16382;
if (expon < 0) { /* denormalized */ if (expon < 0) { /* denormalized */
fMant = ldexp(fMant, expon); fMant = ldexp(fMant, expon);
expon = 0; expon = 0;
} }
expon |= sign; expon |= sign;
fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant); fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant);
fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant); fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant);
} }
} }
bytes[0] = expon >> 8; bytes[0] = expon >> 8;
bytes[1] = expon; bytes[1] = expon;
bytes[2] = hiMant >> 24; bytes[2] = hiMant >> 24;
bytes[3] = hiMant >> 16; bytes[3] = hiMant >> 16;
bytes[4] = hiMant >> 8; bytes[4] = hiMant >> 8;
bytes[5] = hiMant; bytes[5] = hiMant;
bytes[6] = loMant >> 24; bytes[6] = loMant >> 24;
bytes[7] = loMant >> 16; bytes[7] = loMant >> 16;
bytes[8] = loMant >> 8; bytes[8] = loMant >> 8;
bytes[9] = loMant; bytes[9] = loMant;
} }
#endif /* wxUSE_APPLE_IEEE */ #endif /* wxUSE_APPLE_IEEE */

View File

@ -1,45 +1,45 @@
/**************************************************************************** /****************************************************************************
* Name: winestub.cpp * Name: winestub.cpp
* Purpose: wxWINE module mapping main() to WinMain() * Purpose: wxWINE module mapping main() to WinMain()
* Author: Robert Roebling * Author: Robert Roebling
* Created: 04/01/98 * Created: 04/01/98
* RCS-ID: $Id: winestub.c 29038 2004-09-07 11:11:05Z ABX $ * RCS-ID: $Id: winestub.c 29038 2004-09-07 11:11:05Z ABX $
* Copyright: (c) Robert Roebling * Copyright: (c) Robert Roebling
* Licence: wxWidgets Licence * Licence: wxWidgets Licence
*****************************************************************************/ *****************************************************************************/
#include <string.h> #include <string.h>
#include "winuser.h" #include "winuser.h"
#include "xmalloc.h" #include "xmalloc.h"
extern int PASCAL WinMain( HINSTANCE, HINSTANCE, LPSTR, int ); extern int PASCAL WinMain( HINSTANCE, HINSTANCE, LPSTR, int );
extern HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] ); extern HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] );
/* Most Windows C/C++ compilers use something like this to */ /* Most Windows C/C++ compilers use something like this to */
/* access argc and argv globally: */ /* access argc and argv globally: */
int _ARGC; int _ARGC;
char **_ARGV; char **_ARGV;
int main( int argc, char *argv [] ) int main( int argc, char *argv [] )
{ {
HINSTANCE hInstance; HINSTANCE hInstance;
LPSTR lpszCmdParam; LPSTR lpszCmdParam;
int i, len = 0; int i, len = 0;
_ARGC = argc; _ARGC = argc;
_ARGV = (char **)argv; _ARGV = (char **)argv;
if (!(hInstance = MAIN_WinelibInit( &argc, argv ))) return 0; if (!(hInstance = MAIN_WinelibInit( &argc, argv ))) return 0;
/* Alloc szCmdParam */ /* Alloc szCmdParam */
for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1; for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1;
lpszCmdParam = (LPSTR) xmalloc(len + 1); lpszCmdParam = (LPSTR) xmalloc(len + 1);
/* Concatenate arguments */ /* Concatenate arguments */
if (argc > 1) strcpy(lpszCmdParam, argv[1]); if (argc > 1) strcpy(lpszCmdParam, argv[1]);
else lpszCmdParam[0] = '\0'; else lpszCmdParam[0] = '\0';
for (i = 2; i < argc; i++) strcat(strcat(lpszCmdParam, " "), argv[i]); for (i = 2; i < argc; i++) strcat(strcat(lpszCmdParam, " "), argv[i]);
return WinMain (hInstance, /* hInstance */ return WinMain (hInstance, /* hInstance */
0, /* hPrevInstance */ 0, /* hPrevInstance */
lpszCmdParam, /* lpszCmdParam */ lpszCmdParam, /* lpszCmdParam */
SW_NORMAL); /* nCmdShow */ SW_NORMAL); /* nCmdShow */
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,295 +1,295 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* libpng version 1.2.7 - September 12, 2004 * libpng version 1.2.7 - September 12, 2004
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all error handling. Users who * This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions * need special error handling are expected to write replacement functions
* and use png_set_error_fn() to use those functions. See the instructions * and use png_set_error_fn() to use those functions. See the instructions
* at each function. * at each function.
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
static void /* PRIVATE */ static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr, png_default_error PNGARG((png_structp png_ptr,
png_const_charp error_message)); png_const_charp error_message));
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning PNGARG((png_structp png_ptr, png_default_warning PNGARG((png_structp png_ptr,
png_const_charp warning_message)); png_const_charp warning_message));
/* This function is called whenever there is a fatal error. This function /* This function is called whenever there is a fatal error. This function
* should not be changed. If there is a need to handle errors differently, * should not be changed. If there is a need to handle errors differently,
* you should supply a replacement error function and use png_set_error_fn() * you should supply a replacement error function and use png_set_error_fn()
* to replace the error function at run-time. * to replace the error function at run-time.
*/ */
void PNGAPI void PNGAPI
png_error(png_structp png_ptr, png_const_charp error_message) png_error(png_structp png_ptr, png_const_charp error_message)
{ {
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16]; char msg[16];
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
{ {
if (*error_message == '#') if (*error_message == '#')
{ {
int offset; int offset;
for (offset=1; offset<15; offset++) for (offset=1; offset<15; offset++)
if (*(error_message+offset) == ' ') if (*(error_message+offset) == ' ')
break; break;
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{ {
int i; int i;
for (i=0; i<offset-1; i++) for (i=0; i<offset-1; i++)
msg[i]=error_message[i+1]; msg[i]=error_message[i+1];
msg[i]='\0'; msg[i]='\0';
error_message=msg; error_message=msg;
} }
else else
error_message+=offset; error_message+=offset;
} }
else else
{ {
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{ {
msg[0]='0'; msg[0]='0';
msg[1]='\0'; msg[1]='\0';
error_message=msg; error_message=msg;
} }
} }
} }
#endif #endif
if (png_ptr != NULL && png_ptr->error_fn != NULL) if (png_ptr != NULL && png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_ptr, error_message); (*(png_ptr->error_fn))(png_ptr, error_message);
/* If the custom handler doesn't exist, or if it returns, /* If the custom handler doesn't exist, or if it returns,
use the default handler, which will not return. */ use the default handler, which will not return. */
png_default_error(png_ptr, error_message); png_default_error(png_ptr, error_message);
} }
/* This function is called whenever there is a non-fatal error. This function /* This function is called whenever there is a non-fatal error. This function
* should not be changed. If there is a need to handle warnings differently, * should not be changed. If there is a need to handle warnings differently,
* you should supply a replacement warning function and use * you should supply a replacement warning function and use
* png_set_error_fn() to replace the warning function at run-time. * png_set_error_fn() to replace the warning function at run-time.
*/ */
void PNGAPI void PNGAPI
png_warning(png_structp png_ptr, png_const_charp warning_message) png_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
int offset = 0; int offset = 0;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
#endif #endif
{ {
if (*warning_message == '#') if (*warning_message == '#')
{ {
for (offset=1; offset<15; offset++) for (offset=1; offset<15; offset++)
if (*(warning_message+offset) == ' ') if (*(warning_message+offset) == ' ')
break; break;
} }
} }
if (png_ptr != NULL && png_ptr->warning_fn != NULL) if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, warning_message+offset); (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
else else
png_default_warning(png_ptr, warning_message+offset); png_default_warning(png_ptr, warning_message+offset);
} }
/* These utilities are used internally to build an error message that relates /* These utilities are used internally to build an error message that relates
* to the current chunk. The chunk name comes from png_ptr->chunk_name, * to the current chunk. The chunk name comes from png_ptr->chunk_name,
* this is used to prefix the message. The message is limited in length * this is used to prefix the message. The message is limited in length
* to 63 bytes, the name characters are output as hex digits wrapped in [] * to 63 bytes, the name characters are output as hex digits wrapped in []
* if the character is invalid. * if the character is invalid.
*/ */
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
static PNG_CONST char png_digit[16] = { static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' 'A', 'B', 'C', 'D', 'E', 'F'
}; };
static void /* PRIVATE */ static void /* PRIVATE */
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
error_message) error_message)
{ {
int iout = 0, iin = 0; int iout = 0, iin = 0;
while (iin < 4) while (iin < 4)
{ {
int c = png_ptr->chunk_name[iin++]; int c = png_ptr->chunk_name[iin++];
if (isnonalpha(c)) if (isnonalpha(c))
{ {
buffer[iout++] = '['; buffer[iout++] = '[';
buffer[iout++] = png_digit[(c & 0xf0) >> 4]; buffer[iout++] = png_digit[(c & 0xf0) >> 4];
buffer[iout++] = png_digit[c & 0x0f]; buffer[iout++] = png_digit[c & 0x0f];
buffer[iout++] = ']'; buffer[iout++] = ']';
} }
else else
{ {
buffer[iout++] = (png_byte)c; buffer[iout++] = (png_byte)c;
} }
} }
if (error_message == NULL) if (error_message == NULL)
buffer[iout] = 0; buffer[iout] = 0;
else else
{ {
buffer[iout++] = ':'; buffer[iout++] = ':';
buffer[iout++] = ' '; buffer[iout++] = ' ';
png_strncpy(buffer+iout, error_message, 63); png_strncpy(buffer+iout, error_message, 63);
buffer[iout+63] = 0; buffer[iout+63] = 0;
} }
} }
void PNGAPI void PNGAPI
png_chunk_error(png_structp png_ptr, png_const_charp error_message) png_chunk_error(png_structp png_ptr, png_const_charp error_message)
{ {
char msg[18+64]; char msg[18+64];
png_format_buffer(png_ptr, msg, error_message); png_format_buffer(png_ptr, msg, error_message);
png_error(png_ptr, msg); png_error(png_ptr, msg);
} }
void PNGAPI void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
char msg[18+64]; char msg[18+64];
png_format_buffer(png_ptr, msg, warning_message); png_format_buffer(png_ptr, msg, warning_message);
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
} }
/* This is the default error handling function. Note that replacements for /* This is the default error handling function. Note that replacements for
* this function MUST NOT RETURN, or the program will likely crash. This * this function MUST NOT RETURN, or the program will likely crash. This
* function is used by default, or if the program supplies NULL for the * function is used by default, or if the program supplies NULL for the
* error function pointer in png_set_error_fn(). * error function pointer in png_set_error_fn().
*/ */
static void /* PRIVATE */ static void /* PRIVATE */
png_default_error(png_structp png_ptr, png_const_charp error_message) png_default_error(png_structp png_ptr, png_const_charp error_message)
{ {
#ifndef PNG_NO_CONSOLE_IO #ifndef PNG_NO_CONSOLE_IO
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*error_message == '#') if (*error_message == '#')
{ {
int offset; int offset;
char error_number[16]; char error_number[16];
for (offset=0; offset<15; offset++) for (offset=0; offset<15; offset++)
{ {
error_number[offset] = *(error_message+offset+1); error_number[offset] = *(error_message+offset+1);
if (*(error_message+offset) == ' ') if (*(error_message+offset) == ' ')
break; break;
} }
if((offset > 1) && (offset < 15)) if((offset > 1) && (offset < 15))
{ {
error_number[offset-1]='\0'; error_number[offset-1]='\0';
fprintf(stderr, "libpng error no. %s: %s\n", error_number, fprintf(stderr, "libpng error no. %s: %s\n", error_number,
error_message+offset); error_message+offset);
} }
else else
fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset); fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
} }
else else
#endif #endif
fprintf(stderr, "libpng error: %s\n", error_message); fprintf(stderr, "libpng error: %s\n", error_message);
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
# ifdef USE_FAR_KEYWORD # ifdef USE_FAR_KEYWORD
{ {
jmp_buf jmpbuf; jmp_buf jmpbuf;
png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf)); png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf));
longjmp(jmpbuf, 1); longjmp(jmpbuf, 1);
} }
# else # else
longjmp(png_ptr->jmpbuf, 1); longjmp(png_ptr->jmpbuf, 1);
# endif # endif
#else #else
/* make compiler happy */ ; /* make compiler happy */ ;
if (png_ptr) if (png_ptr)
PNG_ABORT(); PNG_ABORT();
#endif #endif
#ifdef PNG_NO_CONSOLE_IO #ifdef PNG_NO_CONSOLE_IO
/* make compiler happy */ ; /* make compiler happy */ ;
if (&error_message != NULL) if (&error_message != NULL)
return; return;
#endif #endif
} }
/* This function is called when there is a warning, but the library thinks /* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything * it can continue anyway. Replacement functions don't have to do anything
* here if you don't want them to. In the default configuration, png_ptr is * here if you don't want them to. In the default configuration, png_ptr is
* not used, but it is passed in case it may be useful. * not used, but it is passed in case it may be useful.
*/ */
static void /* PRIVATE */ static void /* PRIVATE */
png_default_warning(png_structp png_ptr, png_const_charp warning_message) png_default_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
#ifndef PNG_NO_CONSOLE_IO #ifndef PNG_NO_CONSOLE_IO
# ifdef PNG_ERROR_NUMBERS_SUPPORTED # ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*warning_message == '#') if (*warning_message == '#')
{ {
int offset; int offset;
char warning_number[16]; char warning_number[16];
for (offset=0; offset<15; offset++) for (offset=0; offset<15; offset++)
{ {
warning_number[offset]=*(warning_message+offset+1); warning_number[offset]=*(warning_message+offset+1);
if (*(warning_message+offset) == ' ') if (*(warning_message+offset) == ' ')
break; break;
} }
if((offset > 1) && (offset < 15)) if((offset > 1) && (offset < 15))
{ {
warning_number[offset-1]='\0'; warning_number[offset-1]='\0';
fprintf(stderr, "libpng warning no. %s: %s\n", warning_number, fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
warning_message+offset); warning_message+offset);
} }
else else
fprintf(stderr, "libpng warning: %s\n", warning_message); fprintf(stderr, "libpng warning: %s\n", warning_message);
} }
else else
# endif # endif
fprintf(stderr, "libpng warning: %s\n", warning_message); fprintf(stderr, "libpng warning: %s\n", warning_message);
#else #else
/* make compiler happy */ ; /* make compiler happy */ ;
if (warning_message) if (warning_message)
return; return;
#endif #endif
/* make compiler happy */ ; /* make compiler happy */ ;
if (png_ptr) if (png_ptr)
return; return;
} }
/* This function is called when the application wants to use another method /* This function is called when the application wants to use another method
* of handling errors and warnings. Note that the error function MUST NOT * of handling errors and warnings. Note that the error function MUST NOT
* return to the calling routine or serious problems will occur. The return * return to the calling routine or serious problems will occur. The return
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
*/ */
void PNGAPI void PNGAPI
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warning_fn) png_error_ptr error_fn, png_error_ptr warning_fn)
{ {
png_ptr->error_ptr = error_ptr; png_ptr->error_ptr = error_ptr;
png_ptr->error_fn = error_fn; png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn; png_ptr->warning_fn = warning_fn;
} }
/* This function returns a pointer to the error_ptr associated with the user /* This function returns a pointer to the error_ptr associated with the user
* functions. The application should free any memory associated with this * functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called. * pointer before png_write_destroy and png_read_destroy are called.
*/ */
png_voidp PNGAPI png_voidp PNGAPI
png_get_error_ptr(png_structp png_ptr) png_get_error_ptr(png_structp png_ptr)
{ {
return ((png_voidp)png_ptr->error_ptr); return ((png_voidp)png_ptr->error_ptr);
} }
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
void PNGAPI void PNGAPI
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
{ {
if(png_ptr != NULL) if(png_ptr != NULL)
{ {
png_ptr->flags &= png_ptr->flags &=
((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
} }
} }
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,161 +1,161 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* libpng 1.2.7 - September 12, 2004 * libpng 1.2.7 - September 12, 2004
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all input. Users who need * This file provides a location for all input. Users who need
* special handling are expected to write a function that has the same * special handling are expected to write a function that has the same
* arguments as this and performs a similar function, but that possibly * arguments as this and performs a similar function, but that possibly
* has a different input method. Note that you shouldn't change this * has a different input method. Note that you shouldn't change this
* function, but rather write a replacement function and then make * function, but rather write a replacement function and then make
* libpng use it at run time with png_set_read_fn(...). * libpng use it at run time with png_set_read_fn(...).
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
/* Read the data from whatever input you are using. The default routine /* Read the data from whatever input you are using. The default routine
reads from a file pointer. Note that this routine sometimes gets called reads from a file pointer. Note that this routine sometimes gets called
with very small lengths, so you should implement some kind of simple with very small lengths, so you should implement some kind of simple
buffering if you are using unbuffered reads. This should never be asked buffering if you are using unbuffered reads. This should never be asked
to read more then 64K on a 16 bit machine. */ to read more then 64K on a 16 bit machine. */
void /* PRIVATE */ void /* PRIVATE */
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_debug1(4,"reading %d bytes\n", (int)length); png_debug1(4,"reading %d bytes\n", (int)length);
if (png_ptr->read_data_fn != NULL) if (png_ptr->read_data_fn != NULL)
(*(png_ptr->read_data_fn))(png_ptr, data, length); (*(png_ptr->read_data_fn))(png_ptr, data, length);
else else
png_error(png_ptr, "Call to NULL read function"); png_error(png_ptr, "Call to NULL read function");
} }
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
/* This is the function that does the actual reading of data. If you are /* This is the function that does the actual reading of data. If you are
not reading from a standard C stream, you should create a replacement not reading from a standard C stream, you should create a replacement
read_data function and use it at run time with png_set_read_fn(), rather read_data function and use it at run time with png_set_read_fn(), rather
than changing the library. */ than changing the library. */
#ifndef USE_FAR_KEYWORD #ifndef USE_FAR_KEYWORD
void PNGAPI void PNGAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_size_t check; png_size_t check;
/* fread() returns 0 on error, so it is OK to store this in a png_size_t /* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns. * instead of an int, which is what fread() actually returns.
*/ */
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0; check = 0;
#else #else
check = (png_size_t)fread(data, (png_size_t)1, length, check = (png_size_t)fread(data, (png_size_t)1, length,
(png_FILE_p)png_ptr->io_ptr); (png_FILE_p)png_ptr->io_ptr);
#endif #endif
if (check != length) if (check != length)
png_error(png_ptr, "Read Error"); png_error(png_ptr, "Read Error");
} }
#else #else
/* this is the model-independent version. Since the standard I/O library /* this is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy can't handle far buffers in the medium and small models, we have to copy
the data. the data.
*/ */
#define NEAR_BUF_SIZE 1024 #define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b) #define MIN(a,b) (a <= b ? a : b)
static void /* PRIVATE */ static void /* PRIVATE */
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
int check; int check;
png_byte *n_data; png_byte *n_data;
png_FILE_p io_ptr; png_FILE_p io_ptr;
/* Check if data really is near. If so, use usual code. */ /* Check if data really is near. If so, use usual code. */
n_data = (png_byte *)CVT_PTR_NOCHECK(data); n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)n_data == data) if ((png_bytep)n_data == data)
{ {
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0; check = 0;
#else #else
check = fread(n_data, 1, length, io_ptr); check = fread(n_data, 1, length, io_ptr);
#endif #endif
} }
else else
{ {
png_byte buf[NEAR_BUF_SIZE]; png_byte buf[NEAR_BUF_SIZE];
png_size_t read, remaining, err; png_size_t read, remaining, err;
check = 0; check = 0;
remaining = length; remaining = length;
do do
{ {
read = MIN(NEAR_BUF_SIZE, remaining); read = MIN(NEAR_BUF_SIZE, remaining);
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
err = 0; err = 0;
#else #else
err = fread(buf, (png_size_t)1, read, io_ptr); err = fread(buf, (png_size_t)1, read, io_ptr);
#endif #endif
png_memcpy(data, buf, read); /* copy far buffer to near buffer */ png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if(err != read) if(err != read)
break; break;
else else
check += err; check += err;
data += read; data += read;
remaining -= read; remaining -= read;
} }
while (remaining != 0); while (remaining != 0);
} }
if ((png_uint_32)check != (png_uint_32)length) if ((png_uint_32)check != (png_uint_32)length)
png_error(png_ptr, "read Error"); png_error(png_ptr, "read Error");
} }
#endif #endif
#endif #endif
/* This function allows the application to supply a new input function /* This function allows the application to supply a new input function
for libpng if standard C streams aren't being used. for libpng if standard C streams aren't being used.
This function takes as its arguments: This function takes as its arguments:
png_ptr - pointer to a png input data structure png_ptr - pointer to a png input data structure
io_ptr - pointer to user supplied structure containing info about io_ptr - pointer to user supplied structure containing info about
the input functions. May be NULL. the input functions. May be NULL.
read_data_fn - pointer to a new input function that takes as its read_data_fn - pointer to a new input function that takes as its
arguments a pointer to a png_struct, a pointer to arguments a pointer to a png_struct, a pointer to
a location where input data can be stored, and a 32-bit a location where input data can be stored, and a 32-bit
unsigned int that is the number of bytes to be read. unsigned int that is the number of bytes to be read.
To exit and output any fatal error messages the new write To exit and output any fatal error messages the new write
function should call png_error(png_ptr, "Error msg"). */ function should call png_error(png_ptr, "Error msg"). */
void PNGAPI void PNGAPI
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn) png_rw_ptr read_data_fn)
{ {
png_ptr->io_ptr = io_ptr; png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
if (read_data_fn != NULL) if (read_data_fn != NULL)
png_ptr->read_data_fn = read_data_fn; png_ptr->read_data_fn = read_data_fn;
else else
png_ptr->read_data_fn = png_default_read_data; png_ptr->read_data_fn = png_default_read_data;
#else #else
png_ptr->read_data_fn = read_data_fn; png_ptr->read_data_fn = read_data_fn;
#endif #endif
/* It is an error to write to a read device */ /* It is an error to write to a read device */
if (png_ptr->write_data_fn != NULL) if (png_ptr->write_data_fn != NULL)
{ {
png_ptr->write_data_fn = NULL; png_ptr->write_data_fn = NULL;
png_warning(png_ptr, png_warning(png_ptr,
"It's an error to set both read_data_fn and write_data_fn in the "); "It's an error to set both read_data_fn and write_data_fn in the ");
png_warning(png_ptr, png_warning(png_ptr,
"same structure. Resetting write_data_fn to NULL."); "same structure. Resetting write_data_fn to NULL.");
} }
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
png_ptr->output_flush_fn = NULL; png_ptr->output_flush_fn = NULL;
#endif #endif
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,228 +1,228 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* libpng 1.2.7 - September 12, 2004 * libpng 1.2.7 - September 12, 2004
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all output. Users who need * This file provides a location for all output. Users who need
* special handling are expected to write functions that have the same * special handling are expected to write functions that have the same
* arguments as these and perform similar functions, but that possibly * arguments as these and perform similar functions, but that possibly
* use different output methods. Note that you shouldn't change these * use different output methods. Note that you shouldn't change these
* functions, but rather write replacement functions and then change * functions, but rather write replacement functions and then change
* them at run time with png_set_write_fn(...). * them at run time with png_set_write_fn(...).
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
/* Write the data to whatever output you are using. The default routine /* Write the data to whatever output you are using. The default routine
writes to a file pointer. Note that this routine sometimes gets called writes to a file pointer. Note that this routine sometimes gets called
with very small lengths, so you should implement some kind of simple with very small lengths, so you should implement some kind of simple
buffering if you are using unbuffered writes. This should never be asked buffering if you are using unbuffered writes. This should never be asked
to write more than 64K on a 16 bit machine. */ to write more than 64K on a 16 bit machine. */
void /* PRIVATE */ void /* PRIVATE */
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
if (png_ptr->write_data_fn != NULL ) if (png_ptr->write_data_fn != NULL )
(*(png_ptr->write_data_fn))(png_ptr, data, length); (*(png_ptr->write_data_fn))(png_ptr, data, length);
else else
png_error(png_ptr, "Call to NULL write function"); png_error(png_ptr, "Call to NULL write function");
} }
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
/* This is the function that does the actual writing of data. If you are /* This is the function that does the actual writing of data. If you are
not writing to a standard C stream, you should create a replacement not writing to a standard C stream, you should create a replacement
write_data function and use it at run time with png_set_write_fn(), rather write_data function and use it at run time with png_set_write_fn(), rather
than changing the library. */ than changing the library. */
#ifndef USE_FAR_KEYWORD #ifndef USE_FAR_KEYWORD
void PNGAPI void PNGAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_uint_32 check; png_uint_32 check;
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0; check = 0;
#else #else
check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
#endif #endif
if (check != length) if (check != length)
png_error(png_ptr, "Write Error"); png_error(png_ptr, "Write Error");
} }
#else #else
/* this is the model-independent version. Since the standard I/O library /* this is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy can't handle far buffers in the medium and small models, we have to copy
the data. the data.
*/ */
#define NEAR_BUF_SIZE 1024 #define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b) #define MIN(a,b) (a <= b ? a : b)
void PNGAPI void PNGAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_uint_32 check; png_uint_32 check;
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
png_FILE_p io_ptr; png_FILE_p io_ptr;
/* Check if data really is near. If so, use usual code. */ /* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data); near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)near_data == data) if ((png_bytep)near_data == data)
{ {
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
check = 0; check = 0;
#else #else
check = fwrite(near_data, 1, length, io_ptr); check = fwrite(near_data, 1, length, io_ptr);
#endif #endif
} }
else else
{ {
png_byte buf[NEAR_BUF_SIZE]; png_byte buf[NEAR_BUF_SIZE];
png_size_t written, remaining, err; png_size_t written, remaining, err;
check = 0; check = 0;
remaining = length; remaining = length;
do do
{ {
written = MIN(NEAR_BUF_SIZE, remaining); written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* copy far buffer to near buffer */ png_memcpy(buf, data, written); /* copy far buffer to near buffer */
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
err = 0; err = 0;
#else #else
err = fwrite(buf, 1, written, io_ptr); err = fwrite(buf, 1, written, io_ptr);
#endif #endif
if (err != written) if (err != written)
break; break;
else else
check += err; check += err;
data += written; data += written;
remaining -= written; remaining -= written;
} }
while (remaining != 0); while (remaining != 0);
} }
if (check != length) if (check != length)
png_error(png_ptr, "Write Error"); png_error(png_ptr, "Write Error");
} }
#endif #endif
#endif #endif
/* This function is called to output any data pending writing (normally /* This function is called to output any data pending writing (normally
to disk). After png_flush is called, there should be no data pending to disk). After png_flush is called, there should be no data pending
writing in any buffers. */ writing in any buffers. */
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
void /* PRIVATE */ void /* PRIVATE */
png_flush(png_structp png_ptr) png_flush(png_structp png_ptr)
{ {
if (png_ptr->output_flush_fn != NULL) if (png_ptr->output_flush_fn != NULL)
(*(png_ptr->output_flush_fn))(png_ptr); (*(png_ptr->output_flush_fn))(png_ptr);
} }
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
void PNGAPI void PNGAPI
png_default_flush(png_structp png_ptr) png_default_flush(png_structp png_ptr)
{ {
#if !defined(_WIN32_WCE) #if !defined(_WIN32_WCE)
png_FILE_p io_ptr; png_FILE_p io_ptr;
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
if (io_ptr != NULL) if (io_ptr != NULL)
fflush(io_ptr); fflush(io_ptr);
#endif #endif
} }
#endif #endif
#endif #endif
/* This function allows the application to supply new output functions for /* This function allows the application to supply new output functions for
libpng if standard C streams aren't being used. libpng if standard C streams aren't being used.
This function takes as its arguments: This function takes as its arguments:
png_ptr - pointer to a png output data structure png_ptr - pointer to a png output data structure
io_ptr - pointer to user supplied structure containing info about io_ptr - pointer to user supplied structure containing info about
the output functions. May be NULL. the output functions. May be NULL.
write_data_fn - pointer to a new output function that takes as its write_data_fn - pointer to a new output function that takes as its
arguments a pointer to a png_struct, a pointer to arguments a pointer to a png_struct, a pointer to
data to be written, and a 32-bit unsigned int that is data to be written, and a 32-bit unsigned int that is
the number of bytes to be written. The new write the number of bytes to be written. The new write
function should call png_error(png_ptr, "Error msg") function should call png_error(png_ptr, "Error msg")
to exit and output any fatal error messages. to exit and output any fatal error messages.
flush_data_fn - pointer to a new flush function that takes as its flush_data_fn - pointer to a new flush function that takes as its
arguments a pointer to a png_struct. After a call to arguments a pointer to a png_struct. After a call to
the flush function, there should be no data in any buffers the flush function, there should be no data in any buffers
or pending transmission. If the output method doesn't do or pending transmission. If the output method doesn't do
any buffering of ouput, a function prototype must still be any buffering of ouput, a function prototype must still be
supplied although it doesn't have to do anything. If supplied although it doesn't have to do anything. If
PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
time, output_flush_fn will be ignored, although it must be time, output_flush_fn will be ignored, although it must be
supplied for compatibility. */ supplied for compatibility. */
void PNGAPI void PNGAPI
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
{ {
png_ptr->io_ptr = io_ptr; png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
if (write_data_fn != NULL) if (write_data_fn != NULL)
png_ptr->write_data_fn = write_data_fn; png_ptr->write_data_fn = write_data_fn;
else else
png_ptr->write_data_fn = png_default_write_data; png_ptr->write_data_fn = png_default_write_data;
#else #else
png_ptr->write_data_fn = write_data_fn; png_ptr->write_data_fn = write_data_fn;
#endif #endif
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
if (output_flush_fn != NULL) if (output_flush_fn != NULL)
png_ptr->output_flush_fn = output_flush_fn; png_ptr->output_flush_fn = output_flush_fn;
else else
png_ptr->output_flush_fn = png_default_flush; png_ptr->output_flush_fn = png_default_flush;
#else #else
png_ptr->output_flush_fn = output_flush_fn; png_ptr->output_flush_fn = output_flush_fn;
#endif #endif
#endif /* PNG_WRITE_FLUSH_SUPPORTED */ #endif /* PNG_WRITE_FLUSH_SUPPORTED */
/* It is an error to read while writing a png file */ /* It is an error to read while writing a png file */
if (png_ptr->read_data_fn != NULL) if (png_ptr->read_data_fn != NULL)
{ {
png_ptr->read_data_fn = NULL; png_ptr->read_data_fn = NULL;
png_warning(png_ptr, png_warning(png_ptr,
"Attempted to set both read_data_fn and write_data_fn in"); "Attempted to set both read_data_fn and write_data_fn in");
png_warning(png_ptr, png_warning(png_ptr,
"the same structure. Resetting read_data_fn to NULL."); "the same structure. Resetting read_data_fn to NULL.");
} }
} }
#if defined(USE_FAR_KEYWORD) #if defined(USE_FAR_KEYWORD)
#if defined(_MSC_VER) #if defined(_MSC_VER)
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
{ {
void *near_ptr; void *near_ptr;
void FAR *far_ptr; void FAR *far_ptr;
FP_OFF(near_ptr) = FP_OFF(ptr); FP_OFF(near_ptr) = FP_OFF(ptr);
far_ptr = (void FAR *)near_ptr; far_ptr = (void FAR *)near_ptr;
if(check != 0) if(check != 0)
if(FP_SEG(ptr) != FP_SEG(far_ptr)) if(FP_SEG(ptr) != FP_SEG(far_ptr))
png_error(png_ptr,"segment lost in conversion"); png_error(png_ptr,"segment lost in conversion");
return(near_ptr); return(near_ptr);
} }
# else # else
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
{ {
void *near_ptr; void *near_ptr;
void FAR *far_ptr; void FAR *far_ptr;
near_ptr = (void FAR *)ptr; near_ptr = (void FAR *)ptr;
far_ptr = (void FAR *)near_ptr; far_ptr = (void FAR *)near_ptr;
if(check != 0) if(check != 0)
if(far_ptr != ptr) if(far_ptr != ptr)
png_error(png_ptr,"segment lost in conversion"); png_error(png_ptr,"segment lost in conversion");
return(near_ptr); return(near_ptr);
} }
# endif # endif
# endif # endif
#endif /* PNG_WRITE_SUPPORTED */ #endif /* PNG_WRITE_SUPPORTED */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,149 +1,149 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream /* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
#define BASE 65521UL /* largest prime smaller than 65536 */ #define BASE 65521UL /* largest prime smaller than 65536 */
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* 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 DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8); #define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware */ /* use NO_DIVIDE if your processor does not do division in hardware */
#ifdef NO_DIVIDE #ifdef NO_DIVIDE
# define MOD(a) \ # define MOD(a) \
do { \ do { \
if (a >= (BASE << 16)) a -= (BASE << 16); \ if (a >= (BASE << 16)) a -= (BASE << 16); \
if (a >= (BASE << 15)) a -= (BASE << 15); \ if (a >= (BASE << 15)) a -= (BASE << 15); \
if (a >= (BASE << 14)) a -= (BASE << 14); \ if (a >= (BASE << 14)) a -= (BASE << 14); \
if (a >= (BASE << 13)) a -= (BASE << 13); \ if (a >= (BASE << 13)) a -= (BASE << 13); \
if (a >= (BASE << 12)) a -= (BASE << 12); \ if (a >= (BASE << 12)) a -= (BASE << 12); \
if (a >= (BASE << 11)) a -= (BASE << 11); \ if (a >= (BASE << 11)) a -= (BASE << 11); \
if (a >= (BASE << 10)) a -= (BASE << 10); \ if (a >= (BASE << 10)) a -= (BASE << 10); \
if (a >= (BASE << 9)) a -= (BASE << 9); \ if (a >= (BASE << 9)) a -= (BASE << 9); \
if (a >= (BASE << 8)) a -= (BASE << 8); \ if (a >= (BASE << 8)) a -= (BASE << 8); \
if (a >= (BASE << 7)) a -= (BASE << 7); \ if (a >= (BASE << 7)) a -= (BASE << 7); \
if (a >= (BASE << 6)) a -= (BASE << 6); \ if (a >= (BASE << 6)) a -= (BASE << 6); \
if (a >= (BASE << 5)) a -= (BASE << 5); \ if (a >= (BASE << 5)) a -= (BASE << 5); \
if (a >= (BASE << 4)) a -= (BASE << 4); \ if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \ if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \ if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \ if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \ if (a >= BASE) a -= BASE; \
} while (0) } while (0)
# define MOD4(a) \ # define MOD4(a) \
do { \ do { \
if (a >= (BASE << 4)) a -= (BASE << 4); \ if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \ if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \ if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \ if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \ if (a >= BASE) a -= BASE; \
} while (0) } while (0)
#else #else
# define MOD(a) a %= BASE # define MOD(a) a %= BASE
# define MOD4(a) a %= BASE # define MOD4(a) a %= BASE
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len) uLong ZEXPORT adler32(adler, buf, len)
uLong adler; uLong adler;
const Bytef *buf; const Bytef *buf;
uInt len; uInt len;
{ {
unsigned long sum2; unsigned long sum2;
unsigned n; unsigned n;
/* split Adler-32 into component sums */ /* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff; sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff; adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */ /* in case user likes doing a byte at a time, keep it fast */
if (len == 1) { if (len == 1) {
adler += buf[0]; adler += buf[0];
if (adler >= BASE) if (adler >= BASE)
adler -= BASE; adler -= BASE;
sum2 += adler; sum2 += adler;
if (sum2 >= BASE) if (sum2 >= BASE)
sum2 -= BASE; sum2 -= BASE;
return adler | (sum2 << 16); return adler | (sum2 << 16);
} }
/* initial Adler-32 value (deferred check for len == 1 speed) */ /* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL) if (buf == Z_NULL)
return 1L; return 1L;
/* in case short lengths are provided, keep it somewhat fast */ /* in case short lengths are provided, keep it somewhat fast */
if (len < 16) { if (len < 16) {
while (len--) { while (len--) {
adler += *buf++; adler += *buf++;
sum2 += adler; sum2 += adler;
} }
if (adler >= BASE) if (adler >= BASE)
adler -= BASE; adler -= BASE;
MOD4(sum2); /* only added so many BASE's */ MOD4(sum2); /* only added so many BASE's */
return adler | (sum2 << 16); return adler | (sum2 << 16);
} }
/* do length NMAX blocks -- requires just one modulo operation */ /* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) { while (len >= NMAX) {
len -= NMAX; len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */ n = NMAX / 16; /* NMAX is divisible by 16 */
do { do {
DO16(buf); /* 16 sums unrolled */ DO16(buf); /* 16 sums unrolled */
buf += 16; buf += 16;
} while (--n); } while (--n);
MOD(adler); MOD(adler);
MOD(sum2); MOD(sum2);
} }
/* do remaining bytes (less than NMAX, still just one modulo) */ /* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */ if (len) { /* avoid modulos if none remaining */
while (len >= 16) { while (len >= 16) {
len -= 16; len -= 16;
DO16(buf); DO16(buf);
buf += 16; buf += 16;
} }
while (len--) { while (len--) {
adler += *buf++; adler += *buf++;
sum2 += adler; sum2 += adler;
} }
MOD(adler); MOD(adler);
MOD(sum2); MOD(sum2);
} }
/* return recombined sums */ /* return recombined sums */
return adler | (sum2 << 16); return adler | (sum2 << 16);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2) uLong ZEXPORT adler32_combine(adler1, adler2, len2)
uLong adler1; uLong adler1;
uLong adler2; uLong adler2;
z_off_t len2; z_off_t len2;
{ {
unsigned long sum1; unsigned long sum1;
unsigned long sum2; unsigned long sum2;
unsigned rem; unsigned rem;
/* the derivation of this formula is left as an exercise for the reader */ /* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE); rem = (unsigned)(len2 % BASE);
sum1 = adler1 & 0xffff; sum1 = adler1 & 0xffff;
sum2 = rem * sum1; sum2 = rem * sum1;
MOD(sum2); MOD(sum2);
sum1 += (adler2 & 0xffff) + BASE - 1; sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 > BASE) sum1 -= BASE; if (sum1 > BASE) sum1 -= BASE;
if (sum1 > BASE) sum1 -= BASE; if (sum1 > BASE) sum1 -= BASE;
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
if (sum2 > BASE) sum2 -= BASE; if (sum2 > BASE) sum2 -= BASE;
return sum1 | (sum2 << 16); return sum1 | (sum2 << 16);
} }

View File

@ -1,79 +1,79 @@
/* compress.c -- compress a memory buffer /* compress.c -- compress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly. * Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
/* =========================================================================== /* ===========================================================================
Compresses the source buffer into the destination buffer. The level Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte 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 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 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. 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 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, memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest; Bytef *dest;
uLongf *destLen; uLongf *destLen;
const Bytef *source; const Bytef *source;
uLong sourceLen; uLong sourceLen;
int level; int level;
{ {
z_stream stream; z_stream stream;
int err; int err;
stream.next_in = (Bytef*)source; stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K #ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */ /* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif #endif
stream.next_out = dest; stream.next_out = dest;
stream.avail_out = (uInt)*destLen; stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.zfree = (free_func)0;
stream.opaque = (voidpf)0; stream.opaque = (voidpf)0;
err = deflateInit(&stream, level); err = deflateInit(&stream, level);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH); err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) { if (err != Z_STREAM_END) {
deflateEnd(&stream); deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err; return err == Z_OK ? Z_BUF_ERROR : err;
} }
*destLen = stream.total_out; *destLen = stream.total_out;
err = deflateEnd(&stream); err = deflateEnd(&stream);
return err; return err;
} }
/* =========================================================================== /* ===========================================================================
*/ */
int ZEXPORT compress (dest, destLen, source, sourceLen) int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest; Bytef *dest;
uLongf *destLen; uLongf *destLen;
const Bytef *source; const Bytef *source;
uLong sourceLen; uLong sourceLen;
{ {
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
} }
/* =========================================================================== /* ===========================================================================
If the default memLevel or windowBits for deflateInit() is changed, then If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated. this function needs to be updated.
*/ */
uLong ZEXPORT compressBound (sourceLen) uLong ZEXPORT compressBound (sourceLen)
uLong sourceLen; uLong sourceLen;
{ {
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
} }

846
Externals/zlib/crc32.c vendored
View File

@ -1,423 +1,423 @@
/* crc32.c -- compute the CRC-32 of a data stream /* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2005 Mark Adler * Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
* *
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
* tables for updating the shift register in one step with three exclusive-ors * tables for updating the shift register in one step with three exclusive-ors
* instead of four steps with four exclusive-ors. This results in about a * 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. * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
/* /*
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 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 protection on the static variables used to control the first-use generation
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32(). one thread to use crc32().
*/ */
#ifdef MAKECRCH #ifdef MAKECRCH
# include <stdio.h> # include <stdio.h>
# ifndef DYNAMIC_CRC_TABLE # ifndef DYNAMIC_CRC_TABLE
# define DYNAMIC_CRC_TABLE # define DYNAMIC_CRC_TABLE
# endif /* !DYNAMIC_CRC_TABLE */ # endif /* !DYNAMIC_CRC_TABLE */
#endif /* MAKECRCH */ #endif /* MAKECRCH */
#include "zutil.h" /* for STDC and FAR definitions */ #include "zutil.h" /* for STDC and FAR definitions */
#define local static #define local static
/* Find a four-byte integer type for crc32_little() and crc32_big(). */ /* Find a four-byte integer type for crc32_little() and crc32_big(). */
#ifndef NOBYFOUR #ifndef NOBYFOUR
# ifdef STDC /* need ANSI C limits.h to determine sizes */ # ifdef STDC /* need ANSI C limits.h to determine sizes */
# include <limits.h> # include <limits.h>
# define BYFOUR # define BYFOUR
# if (UINT_MAX == 0xffffffffUL) # if (UINT_MAX == 0xffffffffUL)
typedef unsigned int u4; typedef unsigned int u4;
# else # else
# if (ULONG_MAX == 0xffffffffUL) # if (ULONG_MAX == 0xffffffffUL)
typedef unsigned long u4; typedef unsigned long u4;
# else # else
# if (USHRT_MAX == 0xffffffffUL) # if (USHRT_MAX == 0xffffffffUL)
typedef unsigned short u4; typedef unsigned short u4;
# else # else
# undef BYFOUR /* can't find a four-byte integer type! */ # undef BYFOUR /* can't find a four-byte integer type! */
# endif # endif
# endif # endif
# endif # endif
# endif /* STDC */ # endif /* STDC */
#endif /* !NOBYFOUR */ #endif /* !NOBYFOUR */
/* Definitions for doing the crc four data bytes at a time. */ /* Definitions for doing the crc four data bytes at a time. */
#ifdef BYFOUR #ifdef BYFOUR
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \ # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
(((w)&0xff00)<<8)+(((w)&0xff)<<24)) (((w)&0xff00)<<8)+(((w)&0xff)<<24))
local unsigned long crc32_little OF((unsigned long, local unsigned long crc32_little OF((unsigned long,
const unsigned char FAR *, unsigned)); const unsigned char FAR *, unsigned));
local unsigned long crc32_big OF((unsigned long, local unsigned long crc32_big OF((unsigned long,
const unsigned char FAR *, unsigned)); const unsigned char FAR *, unsigned));
# define TBLS 8 # define TBLS 8
#else #else
# define TBLS 1 # define TBLS 1
#endif /* BYFOUR */ #endif /* BYFOUR */
/* Local functions for crc concatenation */ /* Local functions for crc concatenation */
local unsigned long gf2_matrix_times OF((unsigned long *mat, local unsigned long gf2_matrix_times OF((unsigned long *mat,
unsigned long vec)); unsigned long vec));
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
local volatile int crc_table_empty = 1; local volatile int crc_table_empty = 1;
local unsigned long FAR crc_table[TBLS][256]; local unsigned long FAR crc_table[TBLS][256];
local void make_crc_table OF((void)); local void make_crc_table OF((void));
#ifdef MAKECRCH #ifdef MAKECRCH
local void write_table OF((FILE *, const unsigned long FAR *)); local void write_table OF((FILE *, const unsigned long FAR *));
#endif /* MAKECRCH */ #endif /* MAKECRCH */
/* /*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 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. 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, Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials 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 is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the 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, 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. where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each 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 incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted 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 out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q. q and repeat for all eight bits of q.
The first table is simply the CRC of all possible eight bit values. This is 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 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 combinations of CRC register values and incoming bytes. The remaining tables
allow for word-at-a-time CRC calculation for both big-endian and little- allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes. endian machines, where a word is four bytes.
*/ */
local void make_crc_table() local void make_crc_table()
{ {
unsigned long c; unsigned long c;
int n, k; int n, k;
unsigned long poly; /* polynomial exclusive-or pattern */ unsigned long poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */ /* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */ 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}; 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 /* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in than nothing -- significantly reduces duration of vulnerability in
case the advice about DYNAMIC_CRC_TABLE is ignored) */ case the advice about DYNAMIC_CRC_TABLE is ignored) */
if (first) { if (first) {
first = 0; first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */ /* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly = 0UL; poly = 0UL;
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
poly |= 1UL << (31 - p[n]); poly |= 1UL << (31 - p[n]);
/* generate a crc for every 8-bit value */ /* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++) {
c = (unsigned long)n; c = (unsigned long)n;
for (k = 0; k < 8; k++) for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1; c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c; crc_table[0][n] = c;
} }
#ifdef BYFOUR #ifdef BYFOUR
/* generate crc for each value followed by one, two, and three zeros, /* 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 */ and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++) {
c = crc_table[0][n]; c = crc_table[0][n];
crc_table[4][n] = REV(c); crc_table[4][n] = REV(c);
for (k = 1; k < 4; k++) { for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8); c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c; crc_table[k][n] = c;
crc_table[k + 4][n] = REV(c); crc_table[k + 4][n] = REV(c);
} }
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
crc_table_empty = 0; crc_table_empty = 0;
} }
else { /* not first */ else { /* not first */
/* wait for the other guy to finish (not efficient, but rare) */ /* wait for the other guy to finish (not efficient, but rare) */
while (crc_table_empty) while (crc_table_empty)
; ;
} }
#ifdef MAKECRCH #ifdef MAKECRCH
/* write out CRC tables to crc32.h */ /* write out CRC tables to crc32.h */
{ {
FILE *out; FILE *out;
out = fopen("crc32.h", "w"); out = fopen("crc32.h", "w");
if (out == NULL) return; if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
fprintf(out, "local const unsigned long FAR "); fprintf(out, "local const unsigned long FAR ");
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
write_table(out, crc_table[0]); write_table(out, crc_table[0]);
# ifdef BYFOUR # ifdef BYFOUR
fprintf(out, "#ifdef BYFOUR\n"); fprintf(out, "#ifdef BYFOUR\n");
for (k = 1; k < 8; k++) { for (k = 1; k < 8; k++) {
fprintf(out, " },\n {\n"); fprintf(out, " },\n {\n");
write_table(out, crc_table[k]); write_table(out, crc_table[k]);
} }
fprintf(out, "#endif\n"); fprintf(out, "#endif\n");
# endif /* BYFOUR */ # endif /* BYFOUR */
fprintf(out, " }\n};\n"); fprintf(out, " }\n};\n");
fclose(out); fclose(out);
} }
#endif /* MAKECRCH */ #endif /* MAKECRCH */
} }
#ifdef MAKECRCH #ifdef MAKECRCH
local void write_table(out, table) local void write_table(out, table)
FILE *out; FILE *out;
const unsigned long FAR *table; const unsigned long FAR *table;
{ {
int n; int n;
for (n = 0; n < 256; n++) for (n = 0; n < 256; n++)
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
} }
#endif /* MAKECRCH */ #endif /* MAKECRCH */
#else /* !DYNAMIC_CRC_TABLE */ #else /* !DYNAMIC_CRC_TABLE */
/* ======================================================================== /* ========================================================================
* Tables of CRC-32s of all single-byte values, made by make_crc_table(). * Tables of CRC-32s of all single-byte values, made by make_crc_table().
*/ */
#include "crc32.h" #include "crc32.h"
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
/* ========================================================================= /* =========================================================================
* This function can be used by asm versions of crc32() * This function can be used by asm versions of crc32()
*/ */
const unsigned long FAR * ZEXPORT get_crc_table() const unsigned long FAR * ZEXPORT get_crc_table()
{ {
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) if (crc_table_empty)
make_crc_table(); make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
return (const unsigned long FAR *)crc_table; return (const unsigned long FAR *)crc_table;
} }
/* ========================================================================= */ /* ========================================================================= */
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* ========================================================================= */ /* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len) unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc; unsigned long crc;
const unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
if (buf == Z_NULL) return 0UL; if (buf == Z_NULL) return 0UL;
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) if (crc_table_empty)
make_crc_table(); make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
#ifdef BYFOUR #ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) { if (sizeof(void *) == sizeof(ptrdiff_t)) {
u4 endian; u4 endian;
endian = 1; endian = 1;
if (*((unsigned char *)(&endian))) if (*((unsigned char *)(&endian)))
return crc32_little(crc, buf, len); return crc32_little(crc, buf, len);
else else
return crc32_big(crc, buf, len); return crc32_big(crc, buf, len);
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
crc = crc ^ 0xffffffffUL; crc = crc ^ 0xffffffffUL;
while (len >= 8) { while (len >= 8) {
DO8; DO8;
len -= 8; len -= 8;
} }
if (len) do { if (len) do {
DO1; DO1;
} while (--len); } while (--len);
return crc ^ 0xffffffffUL; return crc ^ 0xffffffffUL;
} }
#ifdef BYFOUR #ifdef BYFOUR
/* ========================================================================= */ /* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \ #define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
/* ========================================================================= */ /* ========================================================================= */
local unsigned long crc32_little(crc, buf, len) local unsigned long crc32_little(crc, buf, len)
unsigned long crc; unsigned long crc;
const unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
register u4 c; register u4 c;
register const u4 FAR *buf4; register const u4 FAR *buf4;
c = (u4)crc; c = (u4)crc;
c = ~c; c = ~c;
while (len && ((ptrdiff_t)buf & 3)) { while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--; len--;
} }
buf4 = (const u4 FAR *)(const void FAR *)buf; buf4 = (const u4 FAR *)(const void FAR *)buf;
while (len >= 32) { while (len >= 32) {
DOLIT32; DOLIT32;
len -= 32; len -= 32;
} }
while (len >= 4) { while (len >= 4) {
DOLIT4; DOLIT4;
len -= 4; len -= 4;
} }
buf = (const unsigned char FAR *)buf4; buf = (const unsigned char FAR *)buf4;
if (len) do { if (len) do {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
} while (--len); } while (--len);
c = ~c; c = ~c;
return (unsigned long)c; return (unsigned long)c;
} }
/* ========================================================================= */ /* ========================================================================= */
#define DOBIG4 c ^= *++buf4; \ #define DOBIG4 c ^= *++buf4; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
/* ========================================================================= */ /* ========================================================================= */
local unsigned long crc32_big(crc, buf, len) local unsigned long crc32_big(crc, buf, len)
unsigned long crc; unsigned long crc;
const unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
register u4 c; register u4 c;
register const u4 FAR *buf4; register const u4 FAR *buf4;
c = REV((u4)crc); c = REV((u4)crc);
c = ~c; c = ~c;
while (len && ((ptrdiff_t)buf & 3)) { while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--; len--;
} }
buf4 = (const u4 FAR *)(const void FAR *)buf; buf4 = (const u4 FAR *)(const void FAR *)buf;
buf4--; buf4--;
while (len >= 32) { while (len >= 32) {
DOBIG32; DOBIG32;
len -= 32; len -= 32;
} }
while (len >= 4) { while (len >= 4) {
DOBIG4; DOBIG4;
len -= 4; len -= 4;
} }
buf4++; buf4++;
buf = (const unsigned char FAR *)buf4; buf = (const unsigned char FAR *)buf4;
if (len) do { if (len) do {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len); } while (--len);
c = ~c; c = ~c;
return (unsigned long)(REV(c)); return (unsigned long)(REV(c));
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
/* ========================================================================= */ /* ========================================================================= */
local unsigned long gf2_matrix_times(mat, vec) local unsigned long gf2_matrix_times(mat, vec)
unsigned long *mat; unsigned long *mat;
unsigned long vec; unsigned long vec;
{ {
unsigned long sum; unsigned long sum;
sum = 0; sum = 0;
while (vec) { while (vec) {
if (vec & 1) if (vec & 1)
sum ^= *mat; sum ^= *mat;
vec >>= 1; vec >>= 1;
mat++; mat++;
} }
return sum; return sum;
} }
/* ========================================================================= */ /* ========================================================================= */
local void gf2_matrix_square(square, mat) local void gf2_matrix_square(square, mat)
unsigned long *square; unsigned long *square;
unsigned long *mat; unsigned long *mat;
{ {
int n; int n;
for (n = 0; n < GF2_DIM; n++) for (n = 0; n < GF2_DIM; n++)
square[n] = gf2_matrix_times(mat, mat[n]); square[n] = gf2_matrix_times(mat, mat[n]);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT crc32_combine(crc1, crc2, len2) uLong ZEXPORT crc32_combine(crc1, crc2, len2)
uLong crc1; uLong crc1;
uLong crc2; uLong crc2;
z_off_t len2; z_off_t len2;
{ {
int n; int n;
unsigned long row; unsigned long row;
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
/* degenerate case */ /* degenerate case */
if (len2 == 0) if (len2 == 0)
return crc1; return crc1;
/* put operator for one zero bit in odd */ /* put operator for one zero bit in odd */
odd[0] = 0xedb88320L; /* CRC-32 polynomial */ odd[0] = 0xedb88320L; /* CRC-32 polynomial */
row = 1; row = 1;
for (n = 1; n < GF2_DIM; n++) { for (n = 1; n < GF2_DIM; n++) {
odd[n] = row; odd[n] = row;
row <<= 1; row <<= 1;
} }
/* put operator for two zero bits in even */ /* put operator for two zero bits in even */
gf2_matrix_square(even, odd); gf2_matrix_square(even, odd);
/* put operator for four zero bits in odd */ /* put operator for four zero bits in odd */
gf2_matrix_square(odd, even); gf2_matrix_square(odd, even);
/* apply len2 zeros to crc1 (first square will put the operator for one /* apply len2 zeros to crc1 (first square will put the operator for one
zero byte, eight zero bits, in even) */ zero byte, eight zero bits, in even) */
do { do {
/* apply zeros operator for this bit of len2 */ /* apply zeros operator for this bit of len2 */
gf2_matrix_square(even, odd); gf2_matrix_square(even, odd);
if (len2 & 1) if (len2 & 1)
crc1 = gf2_matrix_times(even, crc1); crc1 = gf2_matrix_times(even, crc1);
len2 >>= 1; len2 >>= 1;
/* if no more bits set, then done */ /* if no more bits set, then done */
if (len2 == 0) if (len2 == 0)
break; break;
/* another iteration of the loop with odd and even swapped */ /* another iteration of the loop with odd and even swapped */
gf2_matrix_square(odd, even); gf2_matrix_square(odd, even);
if (len2 & 1) if (len2 & 1)
crc1 = gf2_matrix_times(odd, crc1); crc1 = gf2_matrix_times(odd, crc1);
len2 >>= 1; len2 >>= 1;
/* if no more bits set, then done */ /* if no more bits set, then done */
} while (len2 != 0); } while (len2 != 0);
/* return combined crc */ /* return combined crc */
crc1 ^= crc2; crc1 ^= crc2;
return crc1; return crc1;
} }

3472
Externals/zlib/deflate.c vendored

File diff suppressed because it is too large Load Diff

2052
Externals/zlib/gzio.c vendored

File diff suppressed because it is too large Load Diff

1246
Externals/zlib/infback.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,318 +1,318 @@
/* inffast.c -- fast decoding /* inffast.c -- fast decoding
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
#ifndef ASMINF #ifndef ASMINF
/* Allow machine dependent optimization for post-increment or pre-increment. /* Allow machine dependent optimization for post-increment or pre-increment.
Based on testing to date, Based on testing to date,
Pre-increment preferred for: Pre-increment preferred for:
- PowerPC G3 (Adler) - PowerPC G3 (Adler)
- MIPS R5000 (Randers-Pehrson) - MIPS R5000 (Randers-Pehrson)
Post-increment preferred for: Post-increment preferred for:
- none - none
No measurable difference: No measurable difference:
- Pentium III (Anderson) - Pentium III (Anderson)
- M68060 (Nikl) - M68060 (Nikl)
*/ */
#ifdef POSTINC #ifdef POSTINC
# define OFF 0 # define OFF 0
# define PUP(a) *(a)++ # define PUP(a) *(a)++
#else #else
# define OFF 1 # define OFF 1
# define PUP(a) *++(a) # define PUP(a) *++(a)
#endif #endif
/* /*
Decode literal, length, and distance codes and write out the resulting Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is literal and match bytes until either not enough input or output is
available, an end-of-block is encountered, or a data error is encountered. available, an end-of-block is encountered, or a data error is encountered.
When large enough input and output buffers are supplied to inflate(), for 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 example, a 16K input buffer and a 64K output buffer, more than 95% of the
inflate execution time is spent in this routine. inflate execution time is spent in this routine.
Entry assumptions: Entry assumptions:
state->mode == LEN state->mode == LEN
strm->avail_in >= 6 strm->avail_in >= 6
strm->avail_out >= 258 strm->avail_out >= 258
start >= strm->avail_out start >= strm->avail_out
state->bits < 8 state->bits < 8
On return, state->mode is one of: On return, state->mode is one of:
LEN -- ran out of enough output space or enough available input LEN -- ran out of enough output space or enough available input
TYPE -- reached end of block code, inflate() to interpret next block TYPE -- reached end of block code, inflate() to interpret next block
BAD -- error in block data BAD -- error in block data
Notes: Notes:
- The maximum input bits used by a length/distance pair is 15 bits for the - 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, 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. 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 Therefore if strm->avail_in >= 6, then there is enough input to avoid
checking for available input while decoding. checking for available input while decoding.
- The maximum bytes that a single length/distance pair can output is 258 - 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() bytes, which is the maximum length that can be coded. inflate_fast()
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void inflate_fast(strm, start) void inflate_fast(strm, start)
z_streamp strm; z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */ unsigned start; /* inflate()'s starting value for strm->avail_out */
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */ unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* while in < last, enough input available */ unsigned char FAR *last; /* while in < last, enough input available */
unsigned char FAR *out; /* local strm->next_out */ unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */ unsigned char FAR *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
unsigned dmax; /* maximum distance from zlib header */ unsigned dmax; /* maximum distance from zlib header */
#endif #endif
unsigned wsize; /* window size or zero if not using window */ unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */ unsigned whave; /* valid bytes in the window */
unsigned write; /* window write index */ unsigned write; /* window write index */
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
unsigned long hold; /* local strm->hold */ unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */ unsigned bits; /* local strm->bits */
code const FAR *lcode; /* local strm->lencode */ code const FAR *lcode; /* local strm->lencode */
code const FAR *dcode; /* local strm->distcode */ code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */ unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */ unsigned dmask; /* mask for first level of distance codes */
code this; /* retrieved table entry */ code this; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */ unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */ /* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */ unsigned len; /* match length, unused bytes */
unsigned dist; /* match distance */ unsigned dist; /* match distance */
unsigned char FAR *from; /* where to copy match from */ unsigned char FAR *from; /* where to copy match from */
/* copy state to local variables */ /* copy state to local variables */
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF; in = strm->next_in - OFF;
last = in + (strm->avail_in - 5); last = in + (strm->avail_in - 5);
out = strm->next_out - OFF; out = strm->next_out - OFF;
beg = out - (start - strm->avail_out); beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257); end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
dmax = state->dmax; dmax = state->dmax;
#endif #endif
wsize = state->wsize; wsize = state->wsize;
whave = state->whave; whave = state->whave;
write = state->write; write = state->write;
window = state->window; window = state->window;
hold = state->hold; hold = state->hold;
bits = state->bits; bits = state->bits;
lcode = state->lencode; lcode = state->lencode;
dcode = state->distcode; dcode = state->distcode;
lmask = (1U << state->lenbits) - 1; lmask = (1U << state->lenbits) - 1;
dmask = (1U << state->distbits) - 1; dmask = (1U << state->distbits) - 1;
/* decode literals and length/distances until end-of-block or not enough /* decode literals and length/distances until end-of-block or not enough
input data or output space */ input data or output space */
do { do {
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
this = lcode[hold & lmask]; this = lcode[hold & lmask];
dolen: dolen:
op = (unsigned)(this.bits); op = (unsigned)(this.bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(this.op); op = (unsigned)(this.op);
if (op == 0) { /* literal */ if (op == 0) { /* literal */
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", this.val)); "inflate: literal 0x%02x\n", this.val));
PUP(out) = (unsigned char)(this.val); PUP(out) = (unsigned char)(this.val);
} }
else if (op & 16) { /* length base */ else if (op & 16) { /* length base */
len = (unsigned)(this.val); len = (unsigned)(this.val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) { if (op) {
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
len += (unsigned)hold & ((1U << op) - 1); len += (unsigned)hold & ((1U << op) - 1);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
} }
Tracevv((stderr, "inflate: length %u\n", len)); Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
this = dcode[hold & dmask]; this = dcode[hold & dmask];
dodist: dodist:
op = (unsigned)(this.bits); op = (unsigned)(this.bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(this.op); op = (unsigned)(this.op);
if (op & 16) { /* distance base */ if (op & 16) { /* distance base */
dist = (unsigned)(this.val); dist = (unsigned)(this.val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
} }
dist += (unsigned)hold & ((1U << op) - 1); dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
if (dist > dmax) { if (dist > dmax) {
strm->msg = (char *)"invalid distance too far back"; strm->msg = (char *)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
#endif #endif
hold >>= op; hold >>= op;
bits -= op; bits -= op;
Tracevv((stderr, "inflate: distance %u\n", dist)); Tracevv((stderr, "inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */ op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */ if (dist > op) { /* see if copy from window */
op = dist - op; /* distance back in window */ op = dist - op; /* distance back in window */
if (op > whave) { if (op > whave) {
strm->msg = (char *)"invalid distance too far back"; strm->msg = (char *)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
from = window - OFF; from = window - OFF;
if (write == 0) { /* very common case */ if (write == 0) { /* very common case */
from += wsize - op; from += wsize - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
else if (write < op) { /* wrap around window */ else if (write < op) { /* wrap around window */
from += wsize + write - op; from += wsize + write - op;
op -= write; op -= write;
if (op < len) { /* some from end of window */ if (op < len) { /* some from end of window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = window - OFF; from = window - OFF;
if (write < len) { /* some from start of window */ if (write < len) { /* some from start of window */
op = write; op = write;
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
} }
else { /* contiguous in window */ else { /* contiguous in window */
from += write - op; from += write - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
while (len > 2) { while (len > 2) {
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
len -= 3; len -= 3;
} }
if (len) { if (len) {
PUP(out) = PUP(from); PUP(out) = PUP(from);
if (len > 1) if (len > 1)
PUP(out) = PUP(from); PUP(out) = PUP(from);
} }
} }
else { else {
from = out - dist; /* copy direct from output */ from = out - dist; /* copy direct from output */
do { /* minimum length is three */ do { /* minimum length is three */
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
len -= 3; len -= 3;
} while (len > 2); } while (len > 2);
if (len) { if (len) {
PUP(out) = PUP(from); PUP(out) = PUP(from);
if (len > 1) if (len > 1)
PUP(out) = PUP(from); PUP(out) = PUP(from);
} }
} }
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else if ((op & 64) == 0) { /* 2nd level distance code */
this = dcode[this.val + (hold & ((1U << op) - 1))]; this = dcode[this.val + (hold & ((1U << op) - 1))];
goto dodist; goto dodist;
} }
else { else {
strm->msg = (char *)"invalid distance code"; strm->msg = (char *)"invalid distance code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} }
else if ((op & 64) == 0) { /* 2nd level length code */ else if ((op & 64) == 0) { /* 2nd level length code */
this = lcode[this.val + (hold & ((1U << op) - 1))]; this = lcode[this.val + (hold & ((1U << op) - 1))];
goto dolen; goto dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) { /* end-of-block */
Tracevv((stderr, "inflate: end of block\n")); Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE; state->mode = TYPE;
break; break;
} }
else { else {
strm->msg = (char *)"invalid literal/length code"; strm->msg = (char *)"invalid literal/length code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} while (in < last && out < end); } while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3; len = bits >> 3;
in -= len; in -= len;
bits -= len << 3; bits -= len << 3;
hold &= (1U << bits) - 1; hold &= (1U << bits) - 1;
/* update state and return */ /* update state and return */
strm->next_in = in + OFF; strm->next_in = in + OFF;
strm->next_out = out + OFF; strm->next_out = out + OFF;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ? strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end)); 257 + (end - out) : 257 - (out - end));
state->hold = hold; state->hold = hold;
state->bits = bits; state->bits = bits;
return; return;
} }
/* /*
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- Using bit fields for code structure - Using bit fields for code structure
- Different op definition to avoid & for extra bits (do & for table bits) - Different op definition to avoid & for extra bits (do & for table bits)
- Three separate decoding do-loops for direct, window, and write == 0 - Three separate decoding do-loops for direct, window, and write == 0
- Special case for distance > 1 copies to do overlapped load and store copy - Special case for distance > 1 copies to do overlapped load and store copy
- Explicit branch predictions (based on measured branch probabilities) - Explicit branch predictions (based on measured branch probabilities)
- Deferring match copy and interspersed it with decoding subsequent codes - Deferring match copy and interspersed it with decoding subsequent codes
- Swapping literal/length else - Swapping literal/length else
- Swapping window/direct else - Swapping window/direct else
- Larger unrolled copy loops (three is about right) - Larger unrolled copy loops (three is about right)
- Moving len -= 3 statement into middle of loop - Moving len -= 3 statement into middle of loop
*/ */
#endif /* !ASMINF */ #endif /* !ASMINF */

2736
Externals/zlib/inflate.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,329 +1,329 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2005 Mark Adler * Copyright (C) 1995-2005 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.3 Copyright 1995-2005 Mark Adler "; " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
include such an acknowledgment, I would appreciate that you keep this include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product. copyright string in the executable of your product.
*/ */
/* /*
Build a set of tables to decode the provided canonical Huffman code. 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, The code lengths are lens[0..codes-1]. The result starts at *table,
whose indices are 0..2^bits-1. work is a writable array of at least whose indices are 0..2^bits-1. work is a writable array of at least
lens shorts, which is used as a work area. type is the type of code lens shorts, which is used as a work area. type is the type of code
to be generated, CODES, LENS, or DISTS. On return, zero is success, to be generated, CODES, LENS, or DISTS. On return, zero is success,
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
on return points to the next available entry's address. bits is the on return points to the next available entry's address. bits is the
requested root table index bits, and on return it is the actual root requested root table index bits, and on return it is the actual root
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int inflate_table(type, lens, codes, table, bits, work) int inflate_table(type, lens, codes, table, bits, work)
codetype type; codetype type;
unsigned short FAR *lens; unsigned short FAR *lens;
unsigned codes; unsigned codes;
code FAR * FAR *table; code FAR * FAR *table;
unsigned FAR *bits; unsigned FAR *bits;
unsigned short FAR *work; unsigned short FAR *work;
{ {
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
unsigned root; /* number of index bits for root table */ unsigned root; /* number of index bits for root table */
unsigned curr; /* number of index bits for current table */ unsigned curr; /* number of index bits for current table */
unsigned drop; /* code bits to drop for sub-table */ unsigned drop; /* code bits to drop for sub-table */
int left; /* number of prefix codes available */ int left; /* number of prefix codes available */
unsigned used; /* code entries in table used */ unsigned used; /* code entries in table used */
unsigned huff; /* Huffman code */ unsigned huff; /* Huffman code */
unsigned incr; /* for incrementing code, index */ unsigned incr; /* for incrementing code, index */
unsigned fill; /* index for replicating entries */ unsigned fill; /* index for replicating entries */
unsigned low; /* low bits for current root entry */ unsigned low; /* low bits for current root entry */
unsigned mask; /* mask for low root bits */ unsigned mask; /* mask for low root bits */
code this; /* table entry for duplication */ code this; /* table entry for duplication */
code FAR *next; /* next available space in table */ code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */ const unsigned short FAR *base; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */ const unsigned short FAR *extra; /* extra bits table to use */
int end; /* use base and extra for symbol > end */ int end; /* use base and extra for symbol > end */
unsigned short count[MAXBITS+1]; /* number of codes of each length */ unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577, 0, 0}; 8193, 12289, 16385, 24577, 0, 0};
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 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, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
28, 28, 29, 29, 64, 64}; 28, 28, 29, 29, 64, 64};
/* /*
Process a set of code lengths to create a canonical Huffman code. The 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 code lengths are lens[0..codes-1]. Each length corresponds to the
symbols 0..codes-1. The Huffman code is generated by first sorting the symbols 0..codes-1. The Huffman code is generated by first sorting the
symbols by length from short to long, and retaining the symbol order symbols by length from short to long, and retaining the symbol order
for codes with equal lengths. Then the code starts with all zero bits for codes with equal lengths. Then the code starts with all zero bits
for the first code of the shortest length, and the codes are integer for the first code of the shortest length, and the codes are integer
increments for the same length, and zeros are appended as the length increments for the same length, and zeros are appended as the length
increases. For the deflate format, these bits are stored backwards increases. For the deflate format, these bits are stored backwards
from their more natural integer increment ordering, and so when the from their more natural integer increment ordering, and so when the
decoding tables are built in the large loop below, the integer codes decoding tables are built in the large loop below, the integer codes
are incremented backwards. are incremented backwards.
This routine assumes, but does not check, that all of the entries in 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. lens[] are in the range 0..MAXBITS. The caller must assure this.
1..MAXBITS is interpreted as that code length. zero means that that 1..MAXBITS is interpreted as that code length. zero means that that
symbol does not occur in this code. symbol does not occur in this code.
The codes are sorted by computing a count of codes for each length, 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 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 sorted table, and then entering the symbols in order in the sorted
table. The sorted table is work[], with that space being provided by table. The sorted table is work[], with that space being provided by
the caller. the caller.
The length counts are used for other purposes as well, i.e. finding The length counts are used for other purposes as well, i.e. finding
the minimum and maximum length codes, determining if there are any the minimum and maximum length codes, determining if there are any
codes at all, checking for a valid set of lengths, and looking ahead codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the at length counts to determine sub-table sizes when building the
decoding tables. decoding tables.
*/ */
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
for (len = 0; len <= MAXBITS; len++) for (len = 0; len <= MAXBITS; len++)
count[len] = 0; count[len] = 0;
for (sym = 0; sym < codes; sym++) for (sym = 0; sym < codes; sym++)
count[lens[sym]]++; count[lens[sym]]++;
/* bound code lengths, force root to be within code lengths */ /* bound code lengths, force root to be within code lengths */
root = *bits; root = *bits;
for (max = MAXBITS; max >= 1; max--) for (max = MAXBITS; max >= 1; max--)
if (count[max] != 0) break; if (count[max] != 0) break;
if (root > max) root = max; if (root > max) root = max;
if (max == 0) { /* no symbols to code at all */ if (max == 0) { /* no symbols to code at all */
this.op = (unsigned char)64; /* invalid code marker */ this.op = (unsigned char)64; /* invalid code marker */
this.bits = (unsigned char)1; this.bits = (unsigned char)1;
this.val = (unsigned short)0; this.val = (unsigned short)0;
*(*table)++ = this; /* make a table to force an error */ *(*table)++ = this; /* make a table to force an error */
*(*table)++ = this; *(*table)++ = this;
*bits = 1; *bits = 1;
return 0; /* no symbols, but wait for decoding to report error */ return 0; /* no symbols, but wait for decoding to report error */
} }
for (min = 1; min <= MAXBITS; min++) for (min = 1; min <= MAXBITS; min++)
if (count[min] != 0) break; if (count[min] != 0) break;
if (root < min) root = min; if (root < min) root = min;
/* check for an over-subscribed or incomplete set of lengths */ /* check for an over-subscribed or incomplete set of lengths */
left = 1; left = 1;
for (len = 1; len <= MAXBITS; len++) { for (len = 1; len <= MAXBITS; len++) {
left <<= 1; left <<= 1;
left -= count[len]; left -= count[len];
if (left < 0) return -1; /* over-subscribed */ if (left < 0) return -1; /* over-subscribed */
} }
if (left > 0 && (type == CODES || max != 1)) if (left > 0 && (type == CODES || max != 1))
return -1; /* incomplete set */ return -1; /* incomplete set */
/* generate offsets into symbol table for each length for sorting */ /* generate offsets into symbol table for each length for sorting */
offs[1] = 0; offs[1] = 0;
for (len = 1; len < MAXBITS; len++) for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + count[len]; offs[len + 1] = offs[len] + count[len];
/* sort symbols by length, by symbol order within each length */ /* sort symbols by length, by symbol order within each length */
for (sym = 0; sym < codes; sym++) for (sym = 0; sym < codes; sym++)
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
/* /*
Create and fill in decoding tables. In this loop, the table being 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 filled is at next and has curr index bits. The code being used is huff
with length len. That code is converted to an index by dropping drop with length len. That code is converted to an index by dropping drop
bits off of the bottom. For codes where len is less than drop + curr, 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 those top drop + curr - len bits are incremented through all values to
fill the table with replicated entries. fill the table with replicated entries.
root is the number of index bits for the root table. When len exceeds 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 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 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 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. 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 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 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 counts are used for this, and so count[] is decremented as codes are
entered in the tables. entered in the tables.
used keeps track of how many table entries have been allocated from the 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 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 against the space in *table, ENOUGH, minus the maximum space needed by
the worst case distance code, MAXD. This should never happen, but the the worst case distance code, MAXD. This should never happen, but the
sufficiency of ENOUGH has not been proven exhaustively, hence the check. sufficiency of ENOUGH has not been proven exhaustively, hence the check.
This assumes that when type == LENS, bits == 9. This assumes that when type == LENS, bits == 9.
sym increments through all symbols, and the loop terminates when sym increments through all symbols, and the loop terminates when
all codes of length max, i.e. all codes, have been processed. This all codes of length max, i.e. all codes, have been processed. This
routine permits incomplete codes, so another loop after this one fills routine permits incomplete codes, so another loop after this one fills
in the rest of the decoding tables with invalid code markers. in the rest of the decoding tables with invalid code markers.
*/ */
/* set up for code type */ /* set up for code type */
switch (type) { switch (type) {
case CODES: case CODES:
base = extra = work; /* dummy value--not used */ base = extra = work; /* dummy value--not used */
end = 19; end = 19;
break; break;
case LENS: case LENS:
base = lbase; base = lbase;
base -= 257; base -= 257;
extra = lext; extra = lext;
extra -= 257; extra -= 257;
end = 256; end = 256;
break; break;
default: /* DISTS */ default: /* DISTS */
base = dbase; base = dbase;
extra = dext; extra = dext;
end = -1; end = -1;
} }
/* initialize state for loop */ /* initialize state for loop */
huff = 0; /* starting code */ huff = 0; /* starting code */
sym = 0; /* starting code symbol */ sym = 0; /* starting code symbol */
len = min; /* starting code length */ len = min; /* starting code length */
next = *table; /* current table to fill in */ next = *table; /* current table to fill in */
curr = root; /* current table index bits */ curr = root; /* current table index bits */
drop = 0; /* current bits to drop from code for index */ drop = 0; /* current bits to drop from code for index */
low = (unsigned)(-1); /* trigger new sub-table when len > root */ low = (unsigned)(-1); /* trigger new sub-table when len > root */
used = 1U << root; /* use root table entries */ used = 1U << root; /* use root table entries */
mask = used - 1; /* mask for comparing low */ mask = used - 1; /* mask for comparing low */
/* check available table space */ /* check available table space */
if (type == LENS && used >= ENOUGH - MAXD) if (type == LENS && used >= ENOUGH - MAXD)
return 1; return 1;
/* process all codes and make table entries */ /* process all codes and make table entries */
for (;;) { for (;;) {
/* create table entry */ /* create table entry */
this.bits = (unsigned char)(len - drop); this.bits = (unsigned char)(len - drop);
if ((int)(work[sym]) < end) { if ((int)(work[sym]) < end) {
this.op = (unsigned char)0; this.op = (unsigned char)0;
this.val = work[sym]; this.val = work[sym];
} }
else if ((int)(work[sym]) > end) { else if ((int)(work[sym]) > end) {
this.op = (unsigned char)(extra[work[sym]]); this.op = (unsigned char)(extra[work[sym]]);
this.val = base[work[sym]]; this.val = base[work[sym]];
} }
else { else {
this.op = (unsigned char)(32 + 64); /* end of block */ this.op = (unsigned char)(32 + 64); /* end of block */
this.val = 0; this.val = 0;
} }
/* replicate for those indices with low len bits equal to huff */ /* replicate for those indices with low len bits equal to huff */
incr = 1U << (len - drop); incr = 1U << (len - drop);
fill = 1U << curr; fill = 1U << curr;
min = fill; /* save offset to next table */ min = fill; /* save offset to next table */
do { do {
fill -= incr; fill -= incr;
next[(huff >> drop) + fill] = this; next[(huff >> drop) + fill] = this;
} while (fill != 0); } while (fill != 0);
/* backwards increment the len-bit code huff */ /* backwards increment the len-bit code huff */
incr = 1U << (len - 1); incr = 1U << (len - 1);
while (huff & incr) while (huff & incr)
incr >>= 1; incr >>= 1;
if (incr != 0) { if (incr != 0) {
huff &= incr - 1; huff &= incr - 1;
huff += incr; huff += incr;
} }
else else
huff = 0; huff = 0;
/* go to next symbol, update count, len */ /* go to next symbol, update count, len */
sym++; sym++;
if (--(count[len]) == 0) { if (--(count[len]) == 0) {
if (len == max) break; if (len == max) break;
len = lens[work[sym]]; len = lens[work[sym]];
} }
/* create new sub-table if needed */ /* create new sub-table if needed */
if (len > root && (huff & mask) != low) { if (len > root && (huff & mask) != low) {
/* if first time, transition to sub-tables */ /* if first time, transition to sub-tables */
if (drop == 0) if (drop == 0)
drop = root; drop = root;
/* increment past last table */ /* increment past last table */
next += min; /* here min is 1 << curr */ next += min; /* here min is 1 << curr */
/* determine length of next table */ /* determine length of next table */
curr = len - drop; curr = len - drop;
left = (int)(1 << curr); left = (int)(1 << curr);
while (curr + drop < max) { while (curr + drop < max) {
left -= count[curr + drop]; left -= count[curr + drop];
if (left <= 0) break; if (left <= 0) break;
curr++; curr++;
left <<= 1; left <<= 1;
} }
/* check for enough space */ /* check for enough space */
used += 1U << curr; used += 1U << curr;
if (type == LENS && used >= ENOUGH - MAXD) if (type == LENS && used >= ENOUGH - MAXD)
return 1; return 1;
/* point entry in root table to sub-table */ /* point entry in root table to sub-table */
low = huff & mask; low = huff & mask;
(*table)[low].op = (unsigned char)curr; (*table)[low].op = (unsigned char)curr;
(*table)[low].bits = (unsigned char)root; (*table)[low].bits = (unsigned char)root;
(*table)[low].val = (unsigned short)(next - *table); (*table)[low].val = (unsigned short)(next - *table);
} }
} }
/* /*
Fill in rest of table for incomplete codes. This loop is similar to the 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 loop above in incrementing huff for table indices. It is assumed that
len is equal to curr + drop, so there is no loop needed to increment len is equal to curr + drop, so there is no loop needed to increment
through high index bits. When the current sub-table is filled, the loop through high index bits. When the current sub-table is filled, the loop
drops back to the root table to fill in any remaining entries there. drops back to the root table to fill in any remaining entries there.
*/ */
this.op = (unsigned char)64; /* invalid code marker */ this.op = (unsigned char)64; /* invalid code marker */
this.bits = (unsigned char)(len - drop); this.bits = (unsigned char)(len - drop);
this.val = (unsigned short)0; this.val = (unsigned short)0;
while (huff != 0) { while (huff != 0) {
/* when done with sub-table, drop back to root table */ /* when done with sub-table, drop back to root table */
if (drop != 0 && (huff & mask) != low) { if (drop != 0 && (huff & mask) != low) {
drop = 0; drop = 0;
len = root; len = root;
next = *table; next = *table;
this.bits = (unsigned char)len; this.bits = (unsigned char)len;
} }
/* put invalid code marker in table */ /* put invalid code marker in table */
next[huff >> drop] = this; next[huff >> drop] = this;
/* backwards increment the len-bit code huff */ /* backwards increment the len-bit code huff */
incr = 1U << (len - 1); incr = 1U << (len - 1);
while (huff & incr) while (huff & incr)
incr >>= 1; incr >>= 1;
if (incr != 0) { if (incr != 0) {
huff &= incr - 1; huff &= incr - 1;
huff += incr; huff += incr;
} }
else else
huff = 0; huff = 0;
} }
/* set return parameters */ /* set return parameters */
*table += used; *table += used;
*bits = root; *bits = root;
return 0; return 0;
} }

2438
Externals/zlib/trees.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +1,61 @@
/* uncompr.c -- decompress a memory buffer /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly. * Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
/* =========================================================================== /* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.) by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer. 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 This function can be used to decompress a whole file at once if the
input file is mmap'ed. input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 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 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. buffer, or Z_DATA_ERROR if the input data was corrupted.
*/ */
int ZEXPORT uncompress (dest, destLen, source, sourceLen) int ZEXPORT uncompress (dest, destLen, source, sourceLen)
Bytef *dest; Bytef *dest;
uLongf *destLen; uLongf *destLen;
const Bytef *source; const Bytef *source;
uLong sourceLen; uLong sourceLen;
{ {
z_stream stream; z_stream stream;
int err; int err;
stream.next_in = (Bytef*)source; stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */ /* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest; stream.next_out = dest;
stream.avail_out = (uInt)*destLen; stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.zfree = (free_func)0;
err = inflateInit(&stream); err = inflateInit(&stream);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = inflate(&stream, Z_FINISH); err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) { if (err != Z_STREAM_END) {
inflateEnd(&stream); inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR; return Z_DATA_ERROR;
return err; return err;
} }
*destLen = stream.total_out; *destLen = stream.total_out;
err = inflateEnd(&stream); err = inflateEnd(&stream);
return err; return err;
} }

636
Externals/zlib/zutil.c vendored
View File

@ -1,318 +1,318 @@
/* zutil.c -- target dependent utility functions for the compression library /* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#include "zutil.h" #include "zutil.h"
#ifndef NO_DUMMY_DECL #ifndef NO_DUMMY_DECL
struct internal_state {int dummy;}; /* for buggy compilers */ struct internal_state {int dummy;}; /* for buggy compilers */
#endif #endif
const char * const z_errmsg[10] = { const char * const z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */ "need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */ "stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */ "", /* Z_OK 0 */
"file error", /* Z_ERRNO (-1) */ "file error", /* Z_ERRNO (-1) */
"stream error", /* Z_STREAM_ERROR (-2) */ "stream error", /* Z_STREAM_ERROR (-2) */
"data error", /* Z_DATA_ERROR (-3) */ "data error", /* Z_DATA_ERROR (-3) */
"insufficient memory", /* Z_MEM_ERROR (-4) */ "insufficient memory", /* Z_MEM_ERROR (-4) */
"buffer error", /* Z_BUF_ERROR (-5) */ "buffer error", /* Z_BUF_ERROR (-5) */
"incompatible version",/* Z_VERSION_ERROR (-6) */ "incompatible version",/* Z_VERSION_ERROR (-6) */
""}; ""};
const char * ZEXPORT zlibVersion() const char * ZEXPORT zlibVersion()
{ {
return ZLIB_VERSION; return ZLIB_VERSION;
} }
uLong ZEXPORT zlibCompileFlags() uLong ZEXPORT zlibCompileFlags()
{ {
uLong flags; uLong flags;
flags = 0; flags = 0;
switch (sizeof(uInt)) { switch (sizeof(uInt)) {
case 2: break; case 2: break;
case 4: flags += 1; break; case 4: flags += 1; break;
case 8: flags += 2; break; case 8: flags += 2; break;
default: flags += 3; default: flags += 3;
} }
switch (sizeof(uLong)) { switch (sizeof(uLong)) {
case 2: break; case 2: break;
case 4: flags += 1 << 2; break; case 4: flags += 1 << 2; break;
case 8: flags += 2 << 2; break; case 8: flags += 2 << 2; break;
default: flags += 3 << 2; default: flags += 3 << 2;
} }
switch (sizeof(voidpf)) { switch (sizeof(voidpf)) {
case 2: break; case 2: break;
case 4: flags += 1 << 4; break; case 4: flags += 1 << 4; break;
case 8: flags += 2 << 4; break; case 8: flags += 2 << 4; break;
default: flags += 3 << 4; default: flags += 3 << 4;
} }
switch (sizeof(z_off_t)) { switch (sizeof(z_off_t)) {
case 2: break; case 2: break;
case 4: flags += 1 << 6; break; case 4: flags += 1 << 6; break;
case 8: flags += 2 << 6; break; case 8: flags += 2 << 6; break;
default: flags += 3 << 6; default: flags += 3 << 6;
} }
#ifdef DEBUG #ifdef DEBUG
flags += 1 << 8; flags += 1 << 8;
#endif #endif
#if defined(ASMV) || defined(ASMINF) #if defined(ASMV) || defined(ASMINF)
flags += 1 << 9; flags += 1 << 9;
#endif #endif
#ifdef ZLIB_WINAPI #ifdef ZLIB_WINAPI
flags += 1 << 10; flags += 1 << 10;
#endif #endif
#ifdef BUILDFIXED #ifdef BUILDFIXED
flags += 1 << 12; flags += 1 << 12;
#endif #endif
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
flags += 1 << 13; flags += 1 << 13;
#endif #endif
#ifdef NO_GZCOMPRESS #ifdef NO_GZCOMPRESS
flags += 1L << 16; flags += 1L << 16;
#endif #endif
#ifdef NO_GZIP #ifdef NO_GZIP
flags += 1L << 17; flags += 1L << 17;
#endif #endif
#ifdef PKZIP_BUG_WORKAROUND #ifdef PKZIP_BUG_WORKAROUND
flags += 1L << 20; flags += 1L << 20;
#endif #endif
#ifdef FASTEST #ifdef FASTEST
flags += 1L << 21; flags += 1L << 21;
#endif #endif
#ifdef STDC #ifdef STDC
# ifdef NO_vsnprintf # ifdef NO_vsnprintf
flags += 1L << 25; flags += 1L << 25;
# ifdef HAS_vsprintf_void # ifdef HAS_vsprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# else # else
# ifdef HAS_vsnprintf_void # ifdef HAS_vsnprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# endif # endif
#else #else
flags += 1L << 24; flags += 1L << 24;
# ifdef NO_snprintf # ifdef NO_snprintf
flags += 1L << 25; flags += 1L << 25;
# ifdef HAS_sprintf_void # ifdef HAS_sprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# else # else
# ifdef HAS_snprintf_void # ifdef HAS_snprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# endif # endif
#endif #endif
return flags; return flags;
} }
#ifdef DEBUG #ifdef DEBUG
# ifndef verbose # ifndef verbose
# define verbose 0 # define verbose 0
# endif # endif
int z_verbose = verbose; int z_verbose = verbose;
void z_error (m) void z_error (m)
char *m; char *m;
{ {
fprintf(stderr, "%s\n", m); fprintf(stderr, "%s\n", m);
exit(1); exit(1);
} }
#endif #endif
/* exported to allow conversion of error code to string for compress() and /* exported to allow conversion of error code to string for compress() and
* uncompress() * uncompress()
*/ */
const char * ZEXPORT zError(err) const char * ZEXPORT zError(err)
int err; int err;
{ {
return ERR_MSG(err); return ERR_MSG(err);
} }
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
/* The Microsoft C Run-Time Library for Windows CE doesn't have /* The Microsoft C Run-Time Library for Windows CE doesn't have
* errno. We define it as a global variable to simplify porting. * errno. We define it as a global variable to simplify porting.
* Its value is always 0 and should not be used. * Its value is always 0 and should not be used.
*/ */
int errno = 0; int errno = 0;
#endif #endif
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void zmemcpy(dest, source, len) void zmemcpy(dest, source, len)
Bytef* dest; Bytef* dest;
const Bytef* source; const Bytef* source;
uInt len; uInt len;
{ {
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = *source++; /* ??? to be unrolled */ *dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0); } while (--len != 0);
} }
int zmemcmp(s1, s2, len) int zmemcmp(s1, s2, len)
const Bytef* s1; const Bytef* s1;
const Bytef* s2; const Bytef* s2;
uInt len; uInt len;
{ {
uInt j; uInt j;
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
} }
return 0; return 0;
} }
void zmemzero(dest, len) void zmemzero(dest, len)
Bytef* dest; Bytef* dest;
uInt len; uInt len;
{ {
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = 0; /* ??? to be unrolled */ *dest++ = 0; /* ??? to be unrolled */
} while (--len != 0); } while (--len != 0);
} }
#endif #endif
#ifdef SYS16BIT #ifdef SYS16BIT
#ifdef __TURBOC__ #ifdef __TURBOC__
/* Turbo C in 16-bit mode */ /* Turbo C in 16-bit mode */
# define MY_ZCALLOC # define MY_ZCALLOC
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
* and farmalloc(64K) returns a pointer with an offset of 8, so we * 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 * must fix the pointer. Warning: the pointer must be put back to its
* original form in order to free it, use zcfree(). * original form in order to free it, use zcfree().
*/ */
#define MAX_PTR 10 #define MAX_PTR 10
/* 10*64K = 640K */ /* 10*64K = 640K */
local int next_ptr = 0; local int next_ptr = 0;
typedef struct ptr_table_s { typedef struct ptr_table_s {
voidpf org_ptr; voidpf org_ptr;
voidpf new_ptr; voidpf new_ptr;
} ptr_table; } ptr_table;
local ptr_table table[MAX_PTR]; local ptr_table table[MAX_PTR];
/* This table is used to remember the original form of pointers /* This table is used to remember the original form of pointers
* to large buffers (64K). Such pointers are normalized with a zero offset. * to large buffers (64K). Such pointers are normalized with a zero offset.
* Since MSDOS is not a preemptive multitasking OS, this table is not * Since MSDOS is not a preemptive multitasking OS, this table is not
* protected from concurrent access. This hack doesn't work anyway on * protected from concurrent access. This hack doesn't work anyway on
* a protected system like OS/2. Use Microsoft C instead. * a protected system like OS/2. Use Microsoft C instead.
*/ */
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{ {
voidpf buf = opaque; /* just to make some compilers happy */ voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
/* If we allocate less than 65520 bytes, we assume that farmalloc /* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized. * will return a usable pointer which doesn't have to be normalized.
*/ */
if (bsize < 65520L) { if (bsize < 65520L) {
buf = farmalloc(bsize); buf = farmalloc(bsize);
if (*(ush*)&buf != 0) return buf; if (*(ush*)&buf != 0) return buf;
} else { } else {
buf = farmalloc(bsize + 16L); buf = farmalloc(bsize + 16L);
} }
if (buf == NULL || next_ptr >= MAX_PTR) return NULL; if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
table[next_ptr].org_ptr = buf; table[next_ptr].org_ptr = buf;
/* Normalize the pointer to seg:0 */ /* Normalize the pointer to seg:0 */
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
*(ush*)&buf = 0; *(ush*)&buf = 0;
table[next_ptr++].new_ptr = buf; table[next_ptr++].new_ptr = buf;
return buf; return buf;
} }
void zcfree (voidpf opaque, voidpf ptr) void zcfree (voidpf opaque, voidpf ptr)
{ {
int n; int n;
if (*(ush*)&ptr != 0) { /* object < 64K */ if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr); farfree(ptr);
return; return;
} }
/* Find the original pointer */ /* Find the original pointer */
for (n = 0; n < next_ptr; n++) { for (n = 0; n < next_ptr; n++) {
if (ptr != table[n].new_ptr) continue; if (ptr != table[n].new_ptr) continue;
farfree(table[n].org_ptr); farfree(table[n].org_ptr);
while (++n < next_ptr) { while (++n < next_ptr) {
table[n-1] = table[n]; table[n-1] = table[n];
} }
next_ptr--; next_ptr--;
return; return;
} }
ptr = opaque; /* just to make some compilers happy */ ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found"); Assert(0, "zcfree: ptr not found");
} }
#endif /* __TURBOC__ */ #endif /* __TURBOC__ */
#ifdef M_I86 #ifdef M_I86
/* Microsoft C in 16-bit mode */ /* Microsoft C in 16-bit mode */
# define MY_ZCALLOC # define MY_ZCALLOC
#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
# define _halloc halloc # define _halloc halloc
# define _hfree hfree # define _hfree hfree
#endif #endif
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{ {
if (opaque) opaque = 0; /* to make compiler happy */ if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void zcfree (voidpf opaque, voidpf ptr) void zcfree (voidpf opaque, voidpf ptr)
{ {
if (opaque) opaque = 0; /* to make compiler happy */ if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr); _hfree(ptr);
} }
#endif /* M_I86 */ #endif /* M_I86 */
#endif /* SYS16BIT */ #endif /* SYS16BIT */
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc OF((uInt size));
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidpf ptr)); extern void free OF((voidpf ptr));
#endif #endif
voidpf zcalloc (opaque, items, size) voidpf zcalloc (opaque, items, size)
voidpf opaque; voidpf opaque;
unsigned items; unsigned items;
unsigned size; unsigned size;
{ {
if (opaque) items += size - size; /* make compiler happy */ if (opaque) items += size - size; /* make compiler happy */
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size); (voidpf)calloc(items, size);
} }
void zcfree (opaque, ptr) void zcfree (opaque, ptr)
voidpf opaque; voidpf opaque;
voidpf ptr; voidpf ptr;
{ {
free(ptr); free(ptr);
if (opaque) return; /* make compiler happy */ if (opaque) return; /* make compiler happy */
} }
#endif /* MY_ZCALLOC */ #endif /* MY_ZCALLOC */