ran clang on *.c files, which I missed earlier.

This commit is contained in:
Kevin Bentley 2024-04-16 14:44:22 -06:00
parent cce1a49671
commit e9435eaa1e
10 changed files with 1513 additions and 1889 deletions

View File

@ -15,7 +15,9 @@
#include "loki_utils.h"
#define BAIL_IF_MACRO(x, y, z) if (x) return (z);
#define BAIL_IF_MACRO(x, y, z) \
if (x) \
return (z);
#define BAIL_MACRO(x, z) return (z);
#if MACOSX
@ -32,179 +34,158 @@
* http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
*/
static int darwinIsWholeMedia(io_service_t service)
{
int retval = 0;
CFTypeRef wholeMedia;
static int darwinIsWholeMedia(io_service_t service) {
int retval = 0;
CFTypeRef wholeMedia;
if (!IOObjectConformsTo(service, kIOMediaClass))
return(0);
wholeMedia = IORegistryEntryCreateCFProperty(service,
CFSTR(kIOMediaWholeKey),
kCFAllocatorDefault, 0);
if (wholeMedia == NULL)
return(0);
if (!IOObjectConformsTo(service, kIOMediaClass))
return (0);
retval = CFBooleanGetValue(wholeMedia);
CFRelease(wholeMedia);
wholeMedia = IORegistryEntryCreateCFProperty(service, CFSTR(kIOMediaWholeKey), kCFAllocatorDefault, 0);
if (wholeMedia == NULL)
return (0);
return retval;
retval = CFBooleanGetValue(wholeMedia);
CFRelease(wholeMedia);
return retval;
} /* darwinIsWholeMedia */
static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort) {
int retval = 0;
CFMutableDictionaryRef matchingDict;
kern_return_t rc;
io_iterator_t iter;
io_service_t service;
static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort)
{
int retval = 0;
CFMutableDictionaryRef matchingDict;
kern_return_t rc;
io_iterator_t iter;
io_service_t service;
if ((matchingDict = IOBSDNameMatching(masterPort, 0, bsdName)) == NULL)
return (0);
if ((matchingDict = IOBSDNameMatching(masterPort, 0, bsdName)) == NULL)
return(0);
rc = IOServiceGetMatchingServices(masterPort, matchingDict, &iter);
if ((rc != KERN_SUCCESS) || (!iter))
return (0);
rc = IOServiceGetMatchingServices(masterPort, matchingDict, &iter);
if ((rc != KERN_SUCCESS) || (!iter))
return(0);
service = IOIteratorNext(iter);
IOObjectRelease(iter);
if (!service)
return (0);
service = IOIteratorNext(iter);
rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
kIORegistryIterateRecursively | kIORegistryIterateParents, &iter);
if (!iter)
return (0);
if (rc != KERN_SUCCESS) {
IOObjectRelease(iter);
if (!service)
return(0);
return (0);
} /* if */
rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
kIORegistryIterateRecursively | kIORegistryIterateParents, &iter);
if (!iter)
return(0);
IOObjectRetain(service); /* add an extra object reference... */
if (rc != KERN_SUCCESS)
{
IOObjectRelease(iter);
return(0);
} /* if */
IOObjectRetain(service); /* add an extra object reference... */
do
{
if (darwinIsWholeMedia(service))
{
if ( (IOObjectConformsTo(service, kIOCDMediaClass)) ||
(IOObjectConformsTo(service, kIODVDMediaClass)) )
{
retval = 1;
} /* if */
} /* if */
IOObjectRelease(service);
} while ((service = IOIteratorNext(iter)) && (!retval));
IOObjectRelease(iter);
do {
if (darwinIsWholeMedia(service)) {
if ((IOObjectConformsTo(service, kIOCDMediaClass)) || (IOObjectConformsTo(service, kIODVDMediaClass))) {
retval = 1;
} /* if */
} /* if */
IOObjectRelease(service);
} while ((service = IOIteratorNext(iter)) && (!retval));
return(retval);
IOObjectRelease(iter);
IOObjectRelease(service);
return (retval);
} /* darwinIsMountedDisc */
int loki_getmountpoint(const char *device, char *mountpoint, int max_size)
{
const char *devPrefix = "/dev/";
int prefixLen = strlen(devPrefix);
const char *dev = device + prefixLen;
mach_port_t masterPort = 0;
struct statfs *mntbufp;
int i, mounts;
int loki_getmountpoint(const char *device, char *mountpoint, int max_size) {
const char *devPrefix = "/dev/";
int prefixLen = strlen(devPrefix);
const char *dev = device + prefixLen;
mach_port_t masterPort = 0;
struct statfs *mntbufp;
int i, mounts;
if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
return(0);
if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
return (0);
mounts = getmntinfo(&mntbufp, MNT_WAIT); /* NOT THREAD SAFE! */
for (i = 0; i < mounts; i++)
{
char *dev = mntbufp[i].f_mntfromname;
char *mnt = mntbufp[i].f_mntonname;
mounts = getmntinfo(&mntbufp, MNT_WAIT); /* NOT THREAD SAFE! */
for (i = 0; i < mounts; i++) {
char *dev = mntbufp[i].f_mntfromname;
char *mnt = mntbufp[i].f_mntonname;
if (strcmp(dev, device) != 0)
continue;
if (strcmp(dev, device) != 0)
continue;
dev += prefixLen;
if (darwinIsMountedDisc(dev, masterPort))
{
strncpy(mountpoint, mnt, max_size);
mountpoint[max_size-1] = '\0';
return 1;
} /* if */
} /* for */
dev += prefixLen;
if (darwinIsMountedDisc(dev, masterPort)) {
strncpy(mountpoint, mnt, max_size);
mountpoint[max_size - 1] = '\0';
return 1;
} /* if */
} /* for */
return 0;
return 0;
} /* loki_getmountpoint */
#else // not MACOSX
#include <mntent.h>
int loki_getmountpoint(const char *device, char *mountpoint, int max_size)
{
FILE *mounts = NULL;
struct mntent *ent = NULL;
int retval = 0;
int loki_getmountpoint(const char *device, char *mountpoint, int max_size) {
FILE *mounts = NULL;
struct mntent *ent = NULL;
int retval = 0;
mounts = setmntent("/etc/mtab", "r");
if (mounts == NULL)
return 0;
mounts = setmntent("/etc/mtab", "r");
if (mounts == NULL)
return 0;
while ( (ent = getmntent(mounts)) != NULL )
{
if (strcmp(ent->mnt_dir, device) == 0)
{
strncpy(mountpoint, ent->mnt_fsname, max_size);
mountpoint[max_size-1] = '\0';
retval = 1;
break;
}
} /* while */
while ((ent = getmntent(mounts)) != NULL) {
if (strcmp(ent->mnt_dir, device) == 0) {
strncpy(mountpoint, ent->mnt_fsname, max_size);
mountpoint[max_size - 1] = '\0';
retval = 1;
break;
}
} /* while */
endmntent(mounts);
endmntent(mounts);
return(retval);
return (retval);
}
#endif
char *__PHYSFS_platformCurrentDir(void)
{
int allocSize = 0;
char *retval = NULL;
char *ptr;
char *__PHYSFS_platformCurrentDir(void) {
int allocSize = 0;
char *retval = NULL;
char *ptr;
do
{
allocSize += 100;
ptr = (char *) realloc(retval, allocSize);
if (ptr == NULL)
{
if (retval != NULL)
free(retval);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
retval = ptr;
ptr = getcwd(retval, allocSize);
} while (ptr == NULL && errno == ERANGE);
if (ptr == NULL && errno)
{
/*
* getcwd() failed for some reason, for example current
* directory not existing.
*/
if (retval != NULL)
free(retval);
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
do {
allocSize += 100;
ptr = (char *)realloc(retval, allocSize);
if (ptr == NULL) {
if (retval != NULL)
free(retval);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
return(retval);
} /* __PHYSFS_platformCurrentDir */
retval = ptr;
ptr = getcwd(retval, allocSize);
} while (ptr == NULL && errno == ERANGE);
if (ptr == NULL && errno) {
/*
* getcwd() failed for some reason, for example current
* directory not existing.
*/
if (retval != NULL)
free(retval);
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
} /* if */
return (retval);
} /* __PHYSFS_platformCurrentDir */
/*
* See where program (bin) resides in the $PATH specified by (envr).
@ -215,309 +196,268 @@ char *__PHYSFS_platformCurrentDir(void)
* (envr) will be scribbled over, and you are expected to free() the
* return value when you're done with it.
*/
static char *findBinaryInPath(const char *bin, char *envr)
{
size_t alloc_size = 0;
char *exe = NULL;
char *start = envr;
char *ptr;
static char *findBinaryInPath(const char *bin, char *envr) {
size_t alloc_size = 0;
char *exe = NULL;
char *start = envr;
char *ptr;
BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL);
BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL);
BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL);
BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL);
do
do {
size_t size;
ptr = strchr(start, ':'); /* find next $PATH separator. */
if (ptr)
*ptr = '\0';
size = strlen(start) + strlen(bin) + 2;
if (size > alloc_size) {
char *x = (char *)realloc(exe, size);
if (x == NULL) {
if (exe != NULL)
free(exe);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
alloc_size = size;
exe = x;
} /* if */
/* build full binary path... */
strcpy(exe, start);
if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/'))
strcat(exe, "/");
strcat(exe, bin);
if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */
{
size_t size;
ptr = strchr(start, ':'); /* find next $PATH separator. */
if (ptr)
*ptr = '\0';
strcpy(exe, start); /* i'm lazy. piss off. */
return (exe);
} /* if */
size = strlen(start) + strlen(bin) + 2;
if (size > alloc_size)
{
char *x = (char *) realloc(exe, size);
if (x == NULL)
{
if (exe != NULL)
free(exe);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
alloc_size = size;
exe = x;
} /* if */
if (exe != NULL)
free(exe);
/* build full binary path... */
strcpy(exe, start);
if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/'))
strcat(exe, "/");
strcat(exe, bin);
if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */
{
strcpy(exe, start); /* i'm lazy. piss off. */
return(exe);
} /* if */
start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
if (exe != NULL)
free(exe);
return(NULL); /* doesn't exist in path. */
return (NULL); /* doesn't exist in path. */
} /* findBinaryInPath */
char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname) {
const char *envr = getenv(varname);
char *retval = NULL;
char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname)
{
const char *envr = getenv(varname);
char *retval = NULL;
if (envr != NULL) {
retval = (char *)malloc(strlen(envr) + 1);
if (retval != NULL)
strcpy(retval, envr);
} /* if */
if (envr != NULL)
{
retval = (char *) malloc(strlen(envr) + 1);
if (retval != NULL)
strcpy(retval, envr);
} /* if */
return(retval);
return (retval);
} /* __PHYSFS_platformCopyEnvironmentVariable */
static char *getUserNameByUID(void) {
uid_t uid = getuid();
struct passwd *pw;
char *retval = NULL;
static char *getUserNameByUID(void)
{
uid_t uid = getuid();
struct passwd *pw;
char *retval = NULL;
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_name != NULL)) {
retval = (char *)malloc(strlen(pw->pw_name) + 1);
if (retval != NULL)
strcpy(retval, pw->pw_name);
} /* if */
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_name != NULL))
{
retval = (char *) malloc(strlen(pw->pw_name) + 1);
if (retval != NULL)
strcpy(retval, pw->pw_name);
} /* if */
return(retval);
return (retval);
} /* getUserNameByUID */
static char *getUserDirByUID(void) {
uid_t uid = getuid();
struct passwd *pw;
char *retval = NULL;
static char *getUserDirByUID(void)
{
uid_t uid = getuid();
struct passwd *pw;
char *retval = NULL;
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_dir != NULL)) {
retval = (char *)malloc(strlen(pw->pw_dir) + 1);
if (retval != NULL)
strcpy(retval, pw->pw_dir);
} /* if */
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_dir != NULL))
{
retval = (char *) malloc(strlen(pw->pw_dir) + 1);
if (retval != NULL)
strcpy(retval, pw->pw_dir);
} /* if */
return(retval);
return (retval);
} /* getUserDirByUID */
char *__PHYSFS_platformGetUserName(void)
{
char *retval = getUserNameByUID();
if (retval == NULL)
retval = __PHYSFS_platformCopyEnvironmentVariable("USER");
return(retval);
char *__PHYSFS_platformGetUserName(void) {
char *retval = getUserNameByUID();
if (retval == NULL)
retval = __PHYSFS_platformCopyEnvironmentVariable("USER");
return (retval);
} /* __PHYSFS_platformGetUserName */
char *__PHYSFS_platformGetUserDir(void)
{
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
if (retval == NULL)
retval = getUserDirByUID();
return(retval);
char *__PHYSFS_platformGetUserDir(void) {
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
if (retval == NULL)
retval = getUserDirByUID();
return (retval);
} /* __PHYSFS_platformGetUserDir */
static int appendDirSep(char **dir) {
const char *dirsep = "/";
char *ptr;
static int appendDirSep(char **dir)
{
const char *dirsep = "/";
char *ptr;
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
return (1);
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
return(1);
ptr = (char *)realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
if (!ptr) {
free(*dir);
return (0);
} /* if */
ptr = (char *)realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
if (!ptr)
{
free(*dir);
return(0);
} /* if */
strcat(ptr, dirsep);
*dir = ptr;
return(1);
strcat(ptr, dirsep);
*dir = ptr;
return (1);
} /* appendDirSep */
static char *unixCalcBaseDir(const char *argv0) {
/* If there isn't a path on argv0, then look through the $PATH for it. */
static char *unixCalcBaseDir(const char *argv0)
{
/* If there isn't a path on argv0, then look through the $PATH for it. */
char *retval;
char *envr;
char *retval;
char *envr;
if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */
return (NULL);
if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */
return(NULL);
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
BAIL_IF_MACRO(!envr, NULL, NULL);
retval = findBinaryInPath(argv0, envr);
free(envr);
return(retval);
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
BAIL_IF_MACRO(!envr, NULL, NULL);
retval = findBinaryInPath(argv0, envr);
free(envr);
return (retval);
}
static char *calcBaseDir(const char *argv0) {
const char *dirsep = "/";
char *retval;
char *ptr;
static char *calcBaseDir(const char *argv0)
{
const char *dirsep = "/";
char *retval;
char *ptr;
/*
* See if the platform driver wants to handle this for us...
*/
retval = unixCalcBaseDir(argv0);
if (retval != NULL)
return (retval);
/*
* See if the platform driver wants to handle this for us...
*/
retval = unixCalcBaseDir(argv0);
if (retval != NULL)
return(retval);
/*
* Determine if there's a path on argv0. If there is, that's the base dir.
*/
ptr = strstr(argv0, dirsep);
if (ptr != NULL) {
char *p = ptr;
size_t size;
while (p != NULL) {
ptr = p;
p = strstr(p + 1, dirsep);
} /* while */
/*
* Determine if there's a path on argv0. If there is, that's the base dir.
*/
ptr = strstr(argv0, dirsep);
if (ptr != NULL)
{
char *p = ptr;
size_t size;
while (p != NULL)
{
ptr = p;
p = strstr(p + 1, dirsep);
} /* while */
size = (size_t)(ptr - argv0);
retval = (char *)malloc(size + 1);
if (retval == NULL)
return NULL;
memcpy(retval, argv0, size);
retval[size] = '\0';
return (retval);
} /* if */
size = (size_t) (ptr - argv0);
retval = (char *) malloc(size + 1);
if (retval == NULL) return NULL;
memcpy(retval, argv0, size);
retval[size] = '\0';
return(retval);
} /* if */
/*
* Last ditch effort: it's the current working directory. (*shrug*)
*/
retval = __PHYSFS_platformCurrentDir();
if (retval != NULL) {
return (retval);
}
/*
* Last ditch effort: it's the current working directory. (*shrug*)
*/
retval = __PHYSFS_platformCurrentDir();
if(retval != NULL) {
return(retval);
}
/*
* Ok, current directory doesn't exist, use the root directory.
* Not a good alternative, but it only happens if the current
* directory was deleted from under the program.
*/
retval = (char *) malloc(strlen(dirsep) + 1);
strcpy(retval, dirsep);
return(retval);
/*
* Ok, current directory doesn't exist, use the root directory.
* Not a good alternative, but it only happens if the current
* directory was deleted from under the program.
*/
retval = (char *)malloc(strlen(dirsep) + 1);
strcpy(retval, dirsep);
return (retval);
}
static char *basepath = NULL;
static char *prefpath = NULL;
const char *loki_getdatapath(void)
{
return basepath;
}
const char *loki_getdatapath(void) { return basepath; }
const char *loki_getprefpath(void)
{
return prefpath;
}
const char *loki_getprefpath(void) { return prefpath; }
void loki_initialize(int argc, char **argv, char *desc)
{
char resolved_path[MAXPATHLEN];
char *ptr = __PHYSFS_platformGetUserDir();
if (!ptr)
{
fprintf(stderr, "ERROR: environment variable HOME not set?!");
exit(42);
}
void loki_initialize(int argc, char **argv, char *desc) {
char resolved_path[MAXPATHLEN];
char *ptr = __PHYSFS_platformGetUserDir();
if (!ptr) {
fprintf(stderr, "ERROR: environment variable HOME not set?!");
exit(42);
}
#if MACOSX
const char *extra = "Library/Application Support/Descent 3";
#else
const char *extra = ".loki/descent3";
#endif
#if MACOSX
const char *extra = "Library/Application Support/Descent 3";
#else
const char *extra = ".loki/descent3";
#endif
prefpath = (char *) malloc(strlen(ptr) + strlen(extra) + 3);
strcpy(prefpath, ptr);
if (prefpath[strlen(prefpath)-1] != '/')
strcat(prefpath, "/");
prefpath = (char *)malloc(strlen(ptr) + strlen(extra) + 3);
strcpy(prefpath, ptr);
if (prefpath[strlen(prefpath) - 1] != '/')
strcat(prefpath, "/");
free(ptr);
free(ptr);
strcat(prefpath, extra);
ptr = prefpath;
while ((ptr = strchr(ptr, '/')) != NULL)
{
*ptr = '\0';
mkdir(prefpath, S_IRWXU);
*ptr = '/';
ptr++;
}
strcat(prefpath, extra);
ptr = prefpath;
while ((ptr = strchr(ptr, '/')) != NULL) {
*ptr = '\0';
mkdir(prefpath, S_IRWXU);
*ptr = '/';
ptr++;
}
mkdir(prefpath, S_IRWXU);
basepath = calcBaseDir(argv[0]);
if (basepath == NULL)
{
fprintf(stderr, "ERROR: Couldn't find game directory!\n");
exit(43);
basepath = calcBaseDir(argv[0]);
if (basepath == NULL) {
fprintf(stderr, "ERROR: Couldn't find game directory!\n");
exit(43);
}
if (realpath(prefpath, resolved_path)) {
ptr = (char *)realloc(prefpath, strlen(resolved_path) + 1);
if (ptr) {
strcpy(ptr, resolved_path);
prefpath = ptr;
}
}
if (realpath(prefpath, resolved_path))
{
ptr = (char *) realloc(prefpath, strlen(resolved_path) + 1);
if (ptr)
{
strcpy(ptr, resolved_path);
prefpath = ptr;
}
if (realpath(basepath, resolved_path)) {
ptr = (char *)realloc(basepath, strlen(resolved_path) + 1);
if (ptr) {
strcpy(ptr, resolved_path);
basepath = ptr;
}
}
if (realpath(basepath, resolved_path))
{
ptr = (char *) realloc(basepath, strlen(resolved_path) + 1);
if (ptr)
{
strcpy(ptr, resolved_path);
basepath = ptr;
}
}
// Strip out Application Bundle...
#if MACOSX
{
// !!! FIXME
}
#endif
// Strip out Application Bundle...
#if MACOSX
{
// !!! FIXME
}
#endif
// printf("base path: %s\n", basepath);
// printf("pref path: %s\n", prefpath);
//printf("base path: %s\n", basepath);
//printf("pref path: %s\n", prefpath);
printf("%s\n", desc);
printf("%s\n", desc);
} /* loki_initialize */
/* end of loki_utils.c ... */

View File

@ -25,11 +25,11 @@ unsigned int nfHPkDecomp_h;
#ifdef __cplusplus /* Avoid C++ name mangling - AH */
extern "C" {
#endif
void _asm_sndDecompM16(void);
void _asm_sndDecompS16(void);
void _asm_nfPkConfig(void);
void _asm_nfHPkDecomp(void);
void _asm_selfModify(void);
void _asm_sndDecompM16(void);
void _asm_sndDecompS16(void);
void _asm_nfPkConfig(void);
void _asm_nfHPkDecomp(void);
void _asm_selfModify(void);
#ifdef __cplusplus
}
#endif
@ -37,189 +37,149 @@ extern "C" {
#define MAX_MEM_UNLOCK_POINTS 20
int global_unlock_memory_pointers[MAX_MEM_UNLOCK_POINTS]; // _asm_selfModify() sets these
int allow_self_modification(void)
{
int i;
unsigned int page_start;
int allow_self_modification(void) {
int i;
unsigned int page_start;
for (i = 0; i < MAX_MEM_UNLOCK_POINTS; i++)
global_unlock_memory_pointers[i] = 0;
for (i = 0; i < MAX_MEM_UNLOCK_POINTS; i++)
global_unlock_memory_pointers[i] = 0;
_asm_selfModify();
_asm_selfModify();
for (i = 0; i < MAX_MEM_UNLOCK_POINTS; i++)
if (global_unlock_memory_pointers[i] != 0)
{
page_start = global_unlock_memory_pointers[i] - (global_unlock_memory_pointers[i] % getpagesize());
mprotect((void *)page_start, getpagesize() * 2, PROT_READ | PROT_WRITE | PROT_EXEC);
//fprintf(stderr, "Unlocked memory location %x for location %x.\n",page_start, global_unlock_memory_pointers[i]);
}
return(1);
}
unsigned sndDecompM16(unsigned short *dst, unsigned char *src,unsigned len, unsigned prev)
{
sndDecompM16_dst = dst;
sndDecompM16_src = src;
sndDecompM16_len = len;
sndDecompM16_prev = prev;
__asm__ (" call _asm_sndDecompM16"
: : : "%esi", "%edi", "%ebx", "cc", "memory");
return(sndDecompM16_return);
for (i = 0; i < MAX_MEM_UNLOCK_POINTS; i++)
if (global_unlock_memory_pointers[i] != 0) {
page_start = global_unlock_memory_pointers[i] - (global_unlock_memory_pointers[i] % getpagesize());
mprotect((void *)page_start, getpagesize() * 2, PROT_READ | PROT_WRITE | PROT_EXEC);
// fprintf(stderr, "Unlocked memory location %x for location %x.\n",page_start, global_unlock_memory_pointers[i]);
}
return (1);
}
unsigned sndDecompM16(unsigned short *dst, unsigned char *src, unsigned len, unsigned prev) {
sndDecompM16_dst = dst;
sndDecompM16_src = src;
sndDecompM16_len = len;
sndDecompM16_prev = prev;
__asm__(" call _asm_sndDecompM16" : : : "%esi", "%edi", "%ebx", "cc", "memory");
return (sndDecompM16_return);
}
unsigned sndDecompS16(unsigned short *dst, unsigned char *src, unsigned len, unsigned prev)
{
sndDecompS16_dst = dst;
sndDecompS16_src = src;
sndDecompS16_len = len;
sndDecompS16_prev = prev;
__asm__ ("call _asm_sndDecompS16"
: : : "%esi", "%edi", "%ebx", "cc", "memory");
return(sndDecompS16_return);
unsigned sndDecompS16(unsigned short *dst, unsigned char *src, unsigned len, unsigned prev) {
sndDecompS16_dst = dst;
sndDecompS16_src = src;
sndDecompS16_len = len;
sndDecompS16_prev = prev;
__asm__("call _asm_sndDecompS16" : : : "%esi", "%edi", "%ebx", "cc", "memory");
return (sndDecompS16_return);
}
void nfPkConfig(void)
{
__asm__ ("call _asm_nfPkConfig"
: : : "%esi", "%edi", "%ebx", "cc", "memory");
return;
void nfPkConfig(void) {
__asm__("call _asm_nfPkConfig" : : : "%esi", "%edi", "%ebx", "cc", "memory");
return;
}
void nfHPkDecomp(unsigned char *ops,unsigned char *comp, unsigned int x, unsigned int y, unsigned int w,unsigned int h)
{
nfHPkDecomp_ops = ops;
nfHPkDecomp_comp = comp;
nfHPkDecomp_x = x;
nfHPkDecomp_y = y;
nfHPkDecomp_w = w;
nfHPkDecomp_h = h;
__asm__ ("call _asm_nfHPkDecomp"
: : : "%esi", "%edi", "%ebx", "cc", "memory");
return;
void nfHPkDecomp(unsigned char *ops, unsigned char *comp, unsigned int x, unsigned int y, unsigned int w,
unsigned int h) {
nfHPkDecomp_ops = ops;
nfHPkDecomp_comp = comp;
nfHPkDecomp_x = x;
nfHPkDecomp_y = y;
nfHPkDecomp_w = w;
nfHPkDecomp_h = h;
__asm__("call _asm_nfHPkDecomp" : : : "%esi", "%edi", "%ebx", "cc", "memory");
return;
}
/***********************************************************/
/* Non-Implemented functions (from inside mveasm.cpp - AH) */
/***********************************************************/
void nfHiColorDecomp(unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h);
void nfHiColorDecompChg(unsigned short *chgs,unsigned short *parms,unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h);
void nfDecomp(unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h);
void nfDecompChg(unsigned short *chgs,unsigned short *parms,unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h);
void nfHiColorDecomp(unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h);
void nfHiColorDecompChg(unsigned short *chgs, unsigned short *parms, unsigned char *comp, unsigned x, unsigned y,
unsigned w, unsigned h);
void nfDecomp(unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h);
void nfDecompChg(unsigned short *chgs, unsigned short *parms, unsigned char *comp, unsigned x, unsigned y, unsigned w,
unsigned h);
void nfPkPal(void);
void nfPkDecomp(unsigned char *ops,unsigned char *comp,unsigned x,unsigned y,unsigned w,unsigned h);
void nfPkDecompH(unsigned char *ops,unsigned char *comp,unsigned x,unsigned y,unsigned w,unsigned h);
void nfPkDecompD(unsigned char *ops,unsigned char *comp,unsigned x,unsigned y,unsigned w,unsigned h);
void mve_ShowFrameField(unsigned char *buf, unsigned bufw, unsigned bufh,unsigned sx, unsigned sy, unsigned w, unsigned h,unsigned dstx, unsigned dsty, unsigned field);
void mve_ShowFrameFieldHi(unsigned char *buf, unsigned bufw, unsigned bufh,unsigned sx, unsigned sy, unsigned w, unsigned h,unsigned dstx, unsigned dsty, unsigned field);
void mve_sfShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned short *chgs,unsigned dstx, unsigned dsty);
void mve_sfHiColorShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned short *chgs,unsigned dstx, unsigned dsty);
void mve_sfPkShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned char *ops,unsigned dstx, unsigned dsty);
void mve_sfPkHiColorShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned char *ops,unsigned dstx, unsigned dsty);
void nfPkDecomp(unsigned char *ops, unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h);
void nfPkDecompH(unsigned char *ops, unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h);
void nfPkDecompD(unsigned char *ops, unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h);
void mve_ShowFrameField(unsigned char *buf, unsigned bufw, unsigned bufh, unsigned sx, unsigned sy, unsigned w,
unsigned h, unsigned dstx, unsigned dsty, unsigned field);
void mve_ShowFrameFieldHi(unsigned char *buf, unsigned bufw, unsigned bufh, unsigned sx, unsigned sy, unsigned w,
unsigned h, unsigned dstx, unsigned dsty, unsigned field);
void mve_sfShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned short *chgs,
unsigned dstx, unsigned dsty);
void mve_sfHiColorShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned short *chgs,
unsigned dstx, unsigned dsty);
void mve_sfPkShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned char *ops,
unsigned dstx, unsigned dsty);
void mve_sfPkHiColorShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned char *ops,
unsigned dstx, unsigned dsty);
void MVE_SetPalette(unsigned char *p, unsigned start, unsigned count);
void palLoadCompPalette(unsigned char *buf);
void gfxMode(unsigned mode);
void gfxLoadCrtc(unsigned char *crtc,unsigned char chain4,unsigned char res);
void gfxLoadCrtc(unsigned char *crtc, unsigned char chain4, unsigned char res);
void gfxGetCrtc(unsigned char *crtc);
void gfxVres(unsigned char misc,unsigned char *crtc);
void gfxVres(unsigned char misc, unsigned char *crtc);
void MVE_gfxWaitRetrace(int state);
void MVE_gfxSetSplit(unsigned line);
// rcg07272000
// need this on non-Intel platforms. Intel uses int $3.
#if (defined __i386__)
#define int3 __asm__ __volatile__ ( "int $3" );
#define int3 __asm__ __volatile__("int $3");
#else
#define int3 raise(SIGTRAP);
#endif
void nfHiColorDecomp(unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h)
{
int3
void nfHiColorDecomp(unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h) { int3 }
void nfHiColorDecompChg(unsigned short *chgs, unsigned short *parms, unsigned char *comp, unsigned x, unsigned y,
unsigned w, unsigned h) {
int3
}
void nfHiColorDecompChg(unsigned short *chgs,unsigned short *parms,unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h)
{
int3
void nfDecomp(unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h) { int3 }
void nfDecompChg(unsigned short *chgs, unsigned short *parms, unsigned char *comp, unsigned x, unsigned y, unsigned w,
unsigned h) {
int3
}
void nfDecomp(unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h)
{
int3
void nfPkPal(void) { int3 }
void nfPkDecomp(unsigned char *ops, unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h) { int3 }
void nfPkDecompH(unsigned char *ops, unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h) { int3 }
void nfPkDecompD(unsigned char *ops, unsigned char *comp, unsigned x, unsigned y, unsigned w, unsigned h) { int3 }
void mve_ShowFrameField(unsigned char *buf, unsigned bufw, unsigned bufh, unsigned sx, unsigned sy, unsigned w,
unsigned h, unsigned dstx, unsigned dsty, unsigned field) {
int3
}
void nfDecompChg(unsigned short *chgs,unsigned short *parms,unsigned char *comp,unsigned x, unsigned y, unsigned w, unsigned h)
{
int3
void mve_ShowFrameFieldHi(unsigned char *buf, unsigned bufw, unsigned bufh, unsigned sx, unsigned sy, unsigned w,
unsigned h, unsigned dstx, unsigned dsty, unsigned field) {
int3
}
void nfPkPal(void)
{
int3
void mve_sfShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned short *chgs,
unsigned dstx, unsigned dsty) {
int3
}
void nfPkDecomp(unsigned char *ops,unsigned char *comp,unsigned x,unsigned y,unsigned w,unsigned h)
{
int3
void mve_sfHiColorShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned short *chgs,
unsigned dstx, unsigned dsty) {
int3
}
void nfPkDecompH(unsigned char *ops,unsigned char *comp,unsigned x,unsigned y,unsigned w,unsigned h)
{
int3
void mve_sfPkShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned char *ops,
unsigned dstx, unsigned dsty) {
int3
}
void nfPkDecompD(unsigned char *ops,unsigned char *comp,unsigned x,unsigned y,unsigned w,unsigned h)
{
int3
}
void mve_ShowFrameField(unsigned char *buf, unsigned bufw, unsigned bufh,unsigned sx, unsigned sy, unsigned w, unsigned h,unsigned dstx, unsigned dsty, unsigned field)
{
int3
}
void mve_ShowFrameFieldHi(unsigned char *buf, unsigned bufw, unsigned bufh,unsigned sx, unsigned sy, unsigned w, unsigned h,unsigned dstx, unsigned dsty, unsigned field)
{
int3
}
void mve_sfShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned short *chgs,unsigned dstx, unsigned dsty)
{
int3
}
void mve_sfHiColorShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned short *chgs,unsigned dstx, unsigned dsty)
{
int3
}
void mve_sfPkShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned char *ops,unsigned dstx, unsigned dsty)
{
int3
}
void mve_sfPkHiColorShowFrameChg(bool prvbuf,unsigned x, unsigned y, unsigned w, unsigned h,unsigned char *ops,unsigned dstx, unsigned dsty)
{
int3
void mve_sfPkHiColorShowFrameChg(bool prvbuf, unsigned x, unsigned y, unsigned w, unsigned h, unsigned char *ops,
unsigned dstx, unsigned dsty) {
int3
}
/* Avoid name mangling issues by moving this into mvelibl.cpp - AH
void MVE_SetPalette(unsigned char *p, unsigned start, unsigned count)
{
int3
int3
} */
void palLoadCompPalette(unsigned char *buf)
{
int3
}
void gfxMode(unsigned mode)
{
int3
}
void gfxLoadCrtc(unsigned char *crtc,unsigned char chain4,unsigned char res)
{
int3
}
void gfxGetCrtc(unsigned char *crtc)
{
int3
}
void gfxVres(unsigned char misc,unsigned char *crtc)
{
int3
}
void MVE_gfxWaitRetrace(int state)
{
int3
}
void MVE_gfxSetSplit(unsigned line)
{
int3
}
void palLoadCompPalette(unsigned char *buf) { int3 }
void gfxMode(unsigned mode) { int3 }
void gfxLoadCrtc(unsigned char *crtc, unsigned char chain4, unsigned char res) { int3 }
void gfxGetCrtc(unsigned char *crtc) { int3 }
void gfxVres(unsigned char misc, unsigned char *crtc) { int3 }
void MVE_gfxWaitRetrace(int state) { int3 }
void MVE_gfxSetSplit(unsigned line) { int3 }

View File

@ -14,464 +14,292 @@
#define USE_MOUSE
//#endif
//#define MOUSE_MAX 32768.0f
#define MOUSE_MAX 48000.0f
#define MOUSE_MAX 48000.0f
//#define MOUSE_MAX 65336.0f
#undef USE_KEYBOARD //NOT on you life
#undef USE_KEYBOARD // NOT on you life
Boolean iSprocket_inited = false;
ISpNeed ISp_needs[kNeed_COUNT] =
{
{ "\pHeading", kIconSuiteID_Yaw, 0, 0,
kISpElementKind_Axis,
kISpElementLabel_Axis_Yaw,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pPitch", kIconSuiteID_Pitch, 0, 0,
kISpElementKind_Axis,
kISpElementLabel_Axis_Pitch,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pBank", kIconSuiteID_Roll, 0, 0,
kISpElementKind_Axis,
kISpElementLabel_Axis_Roll,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pSideways", kIconSuiteID_SlideHorz, 0, 0,
kISpElementKind_Axis,
kISpElementLabel_Axis_XAxis,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pThrust", kIconSuiteID_Thrust, 0, 0,
kISpElementKind_Axis,
kISpElementLabel_Axis_ZAxis,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pVertical", kIconSuiteID_SlideVert, 0, 0,
kISpElementKind_Axis,
kISpElementLabel_Axis_YAxis,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
// Mouse Related Input
{ "\pMouse Heading", kIconSuiteID_Yaw, 0, 0,
kISpElementKind_Delta,
kISpElementLabel_Delta_Yaw,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pMouse Pitch", kIconSuiteID_Pitch, 0, 0,
kISpElementKind_Delta,
kISpElementLabel_Delta_Pitch,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pMouse Bank", kIconSuiteID_Roll, 0, 0,
kISpElementKind_Delta,
kISpElementLabel_Delta_Roll,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pMouse Sideways", kIconSuiteID_SlideHorz, 0, 0,
kISpElementKind_Delta,
kISpElementLabel_Delta_X,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pMouse Thrust", kIconSuiteID_Thrust, 0, 0,
kISpElementKind_Delta,
kISpElementLabel_Delta_Z,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
{ "\pMouse Vertical", kIconSuiteID_SlideVert, 0, 0,
kISpElementKind_Delta,
kISpElementLabel_Delta_Y,
kISpNeedFlag_NoMultiConfig, 0, 0, 0
},
// The buttons
{ "\pForward", kIconSuiteID_Foward, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
ISpNeed ISp_needs[kNeed_COUNT] = {
{"\pHeading", kIconSuiteID_Yaw, 0, 0, kISpElementKind_Axis, kISpElementLabel_Axis_Yaw, kISpNeedFlag_NoMultiConfig,
0, 0, 0},
{"\pPitch", kIconSuiteID_Pitch, 0, 0, kISpElementKind_Axis, kISpElementLabel_Axis_Pitch, kISpNeedFlag_NoMultiConfig,
0, 0, 0},
{"\pBank", kIconSuiteID_Roll, 0, 0, kISpElementKind_Axis, kISpElementLabel_Axis_Roll, kISpNeedFlag_NoMultiConfig, 0,
0, 0},
{"\pSideways", kIconSuiteID_SlideHorz, 0, 0, kISpElementKind_Axis, kISpElementLabel_Axis_XAxis,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pThrust", kIconSuiteID_Thrust, 0, 0, kISpElementKind_Axis, kISpElementLabel_Axis_ZAxis,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pVertical", kIconSuiteID_SlideVert, 0, 0, kISpElementKind_Axis, kISpElementLabel_Axis_YAxis,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
// Mouse Related Input
{"\pMouse Heading", kIconSuiteID_Yaw, 0, 0, kISpElementKind_Delta, kISpElementLabel_Delta_Yaw,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pMouse Pitch", kIconSuiteID_Pitch, 0, 0, kISpElementKind_Delta, kISpElementLabel_Delta_Pitch,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pMouse Bank", kIconSuiteID_Roll, 0, 0, kISpElementKind_Delta, kISpElementLabel_Delta_Roll,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pMouse Sideways", kIconSuiteID_SlideHorz, 0, 0, kISpElementKind_Delta, kISpElementLabel_Delta_X,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pMouse Thrust", kIconSuiteID_Thrust, 0, 0, kISpElementKind_Delta, kISpElementLabel_Delta_Z,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
{"\pMouse Vertical", kIconSuiteID_SlideVert, 0, 0, kISpElementKind_Delta, kISpElementLabel_Delta_Y,
kISpNeedFlag_NoMultiConfig, 0, 0, 0},
// The buttons
{"\pForward", kIconSuiteID_Foward, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{ "\pReverse", kIconSuiteID_Back, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pSlide Left", kIconSuiteID_SlideLeft, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pSlide Right", kIconSuiteID_SlideRight, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pSlide Up", kIconSuiteID_SlideUp, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pSlide Down", kIconSuiteID_SlideDown, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pTurn Left", kIconSuiteID_YawL, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pTurn Right", kIconSuiteID_YawR, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pPitch Up", kIconSuiteID_PitchU, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pPitch Down", kIconSuiteID_PitchD, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pBank Left", kIconSuiteID_RollL, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pBank Right", kIconSuiteID_RollR, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{"\pReverse", kIconSuiteID_Back, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pSlide Left", kIconSuiteID_SlideLeft, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pSlide Right", kIconSuiteID_SlideRight, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pSlide Up", kIconSuiteID_SlideUp, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pSlide Down", kIconSuiteID_SlideDown, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pTurn Left", kIconSuiteID_YawL, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pTurn Right", kIconSuiteID_YawR, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pPitch Up", kIconSuiteID_PitchU, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pPitch Down", kIconSuiteID_PitchD, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pBank Left", kIconSuiteID_RollL, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pBank Right", kIconSuiteID_RollR, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{ "\p-", 0, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
// seperator
{ "\pFire Primary", kIconSuiteID_FirePrim, 0, 0,
kISpElementKind_Button,
kISpElementLabel_Btn_Fire,
0, 0, 0, 0
},
{ "\pFire Secondary", kIconSuiteID_FireSecond, 0, 0,
kISpElementKind_Button,
kISpElementLabel_Btn_SecondaryFire,
0, 0, 0, 0
},
{ "\pNext Primary", kIconSuiteID_NextPrim, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pNext Secondary", kIconSuiteID_NextSecond, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pAfterburner", kIconSuiteID_AfterBurn, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pHeadlight", kIconSuiteID_HeadLight, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None, 0, 0, 0, 0
},
{ "\pFlare", kIconSuiteID_Flare, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pRear View", kIconSuiteID_RearView, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pMap", kIconSuiteID_Map, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pUse Inventory", kIconSuiteID_UseInv, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pNext Inventory", kIconSuiteID_NextInv, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pPrevious Inventory", kIconSuiteID_PrevInv, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pUse Counter Measure", kIconSuiteID_UseCM, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pNext Counter Measure", kIconSuiteID_NextCM, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pPrevious Counter Measure", kIconSuiteID_PrevCM, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None, 0, 0, 0, 0
},
{ "\pBank On", kIconSuiteID_BankOn, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
},
{ "\pSlide On", kIconSuiteID_SlideOn, 0, 0,
kISpElementKind_Button,
kISpElementLabel_None,
0, 0, 0, 0
}
};
void inSprocket_Init(void)
{
int i;
{"\p-", 0, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
// seperator
{"\pFire Primary", kIconSuiteID_FirePrim, 0, 0, kISpElementKind_Button, kISpElementLabel_Btn_Fire, 0, 0, 0, 0},
{"\pFire Secondary", kIconSuiteID_FireSecond, 0, 0, kISpElementKind_Button, kISpElementLabel_Btn_SecondaryFire, 0,
0, 0, 0},
{"\pNext Primary", kIconSuiteID_NextPrim, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pNext Secondary", kIconSuiteID_NextSecond, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pAfterburner", kIconSuiteID_AfterBurn, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pHeadlight", kIconSuiteID_HeadLight, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pFlare", kIconSuiteID_Flare, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pRear View", kIconSuiteID_RearView, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pMap", kIconSuiteID_Map, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pUse Inventory", kIconSuiteID_UseInv, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pNext Inventory", kIconSuiteID_NextInv, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pPrevious Inventory", kIconSuiteID_PrevInv, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pUse Counter Measure", kIconSuiteID_UseCM, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pNext Counter Measure", kIconSuiteID_NextCM, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pPrevious Counter Measure", kIconSuiteID_PrevCM, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0,
0},
{"\pBank On", kIconSuiteID_BankOn, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0},
{"\pSlide On", kIconSuiteID_SlideOn, 0, 0, kISpElementKind_Button, kISpElementLabel_None, 0, 0, 0, 0}};
void inSprocket_Init(void) {
int i;
if (iSprocket_inited)
return;
mprintf((1, "inSprocket_init: need_count %d\n", kNeed_COUNT));
if(iSprocket_inited)
return;
mprintf((1, "inSprocket_init: need_count %d\n", kNeed_COUNT));
#ifdef USE_MOUSE
ISpDevices_ActivateClass (kISpDeviceClass_Mouse);
ISpDevices_ActivateClass(kISpDeviceClass_Mouse);
#endif
#ifdef USE_KEYBOARD
ISpDevices_ActivateClass (kISpDeviceClass_Keyboard);
ISpDevices_ActivateClass(kISpDeviceClass_Keyboard);
#endif
ISpElement_NewVirtualFromNeeds(kNeed_COUNT, ISp_needs, gInputElement, 0);
char pilot_name[40];
Current_pilot.get_name(pilot_name);
if(pilot_name[0])
ISpInit(kNeed_COUNT, ISp_needs, gInputElement, 'DNT3', (ulong)pilot_name, 0, kSetListID, 0);
else
ISpInit(kNeed_COUNT, ISp_needs, gInputElement, 'DNT3', kNeedsVersion, 0, kSetListID, 0);
ISpElementList_New(0, NULL, &gInputEventList, 0);
ISpElementList_New(0, NULL, &gInputHoldDownEventList, 0);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_FirePrim_On,1, &gInputElement[kNeed_FirePrim]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_FireSecond_On,1, &gInputElement[kNeed_FireSecond]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_AfterBurn_On, 1, &gInputElement[kNeed_AfterBurn]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_RearView_On, 1, &gInputElement[kNeed_RearView]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Bank_On, 1, &gInputElement[kNeed_BankOn]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Slide_On, 1, &gInputElement[kNeed_SlideOn]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Accelerate_On, 1, &gInputElement[kNeed_Accelerate]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Reverse_On, 1, &gInputElement[kNeed_Reverse]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideLeft_On, 1, &gInputElement[kNeed_SlideLeft]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideRight_On, 1, &gInputElement[kNeed_SlideRight]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideUp_On, 1, &gInputElement[kNeed_SlideUp]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideDown_On, 1, &gInputElement[kNeed_SlideDown]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_TurnLeft_On, 1, &gInputElement[kNeed_TurnLeft]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_TurnRight_On, 1, &gInputElement[kNeed_TurnRight]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_PitchUp_On, 1, &gInputElement[kNeed_PitchUp]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_PitchDown_On, 1, &gInputElement[kNeed_PitchDown]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_BankLeft_On, 1, &gInputElement[kNeed_BankLeft]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_BankRight_On, 1, &gInputElement[kNeed_BankRight]);
ISpElementList_AddElements(gInputEventList, kInputEvent_NextPrim, 1, &gInputElement[kNeed_NextPrim]);
ISpElementList_AddElements(gInputEventList, kInputEvent_NextSecond, 1, &gInputElement[kNeed_NextSecond]);
ISpElementList_AddElements(gInputEventList, kInputEvent_HeadLight, 1, &gInputElement[kNeed_HeadLight]);
ISpElementList_AddElements(gInputEventList, kInputEvent_Flare, 1, &gInputElement[kNeed_Flare]);
ISpElementList_AddElements(gInputEventList, kInputEvent_Map, 1, &gInputElement[kNeed_Map]);
ISpElementList_AddElements(gInputEventList, kInputEvent_InventoryUse, 1, &gInputElement[kNeed_InventoryUse]);
ISpElementList_AddElements(gInputEventList, kInputEvent_InventoryNext, 1, &gInputElement[kNeed_InventoryNext]);
ISpElementList_AddElements(gInputEventList, kInputEvent_InventoryPrev, 1, &gInputElement[kNeed_InventoryPrev]);
ISpElementList_AddElements(gInputEventList, kInputEvent_CounterUse, 1, &gInputElement[kNeed_CounterUse]);
ISpElementList_AddElements(gInputEventList, kInputEvent_CounterNext, 1, &gInputElement[kNeed_CounterNext]);
ISpElementList_AddElements(gInputEventList, kInputEvent_CounterPrev, 1, &gInputElement[kNeed_CounterPrev]);
/*
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt1, 1, &gInputElement[kNeed_ATaunt1]);
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt2, 1, &gInputElement[kNeed_ATaunt2]);
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt3, 1, &gInputElement[kNeed_ATaunt3]);
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt4, 1, &gInputElement[kNeed_ATaunt4]);
*/
ISpElementList_Flush(gInputEventList);
ISpElementList_Flush(gInputHoldDownEventList);
for(i = 0; i < 12; i++)
ISpElement_Flush(gInputElement[i]);
ISpSuspend();
iSprocket_inited = true;
ISpElement_NewVirtualFromNeeds(kNeed_COUNT, ISp_needs, gInputElement, 0);
char pilot_name[40];
Current_pilot.get_name(pilot_name);
if (pilot_name[0])
ISpInit(kNeed_COUNT, ISp_needs, gInputElement, 'DNT3', (ulong)pilot_name, 0, kSetListID, 0);
else
ISpInit(kNeed_COUNT, ISp_needs, gInputElement, 'DNT3', kNeedsVersion, 0, kSetListID, 0);
ISpElementList_New(0, NULL, &gInputEventList, 0);
ISpElementList_New(0, NULL, &gInputHoldDownEventList, 0);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_FirePrim_On, 1, &gInputElement[kNeed_FirePrim]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_FireSecond_On, 1, &gInputElement[kNeed_FireSecond]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_AfterBurn_On, 1, &gInputElement[kNeed_AfterBurn]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_RearView_On, 1, &gInputElement[kNeed_RearView]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Bank_On, 1, &gInputElement[kNeed_BankOn]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Slide_On, 1, &gInputElement[kNeed_SlideOn]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Accelerate_On, 1, &gInputElement[kNeed_Accelerate]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_Reverse_On, 1, &gInputElement[kNeed_Reverse]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideLeft_On, 1, &gInputElement[kNeed_SlideLeft]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideRight_On, 1, &gInputElement[kNeed_SlideRight]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideUp_On, 1, &gInputElement[kNeed_SlideUp]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_SlideDown_On, 1, &gInputElement[kNeed_SlideDown]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_TurnLeft_On, 1, &gInputElement[kNeed_TurnLeft]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_TurnRight_On, 1, &gInputElement[kNeed_TurnRight]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_PitchUp_On, 1, &gInputElement[kNeed_PitchUp]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_PitchDown_On, 1, &gInputElement[kNeed_PitchDown]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_BankLeft_On, 1, &gInputElement[kNeed_BankLeft]);
ISpElementList_AddElements(gInputHoldDownEventList, kInputEvent_BankRight_On, 1, &gInputElement[kNeed_BankRight]);
ISpElementList_AddElements(gInputEventList, kInputEvent_NextPrim, 1, &gInputElement[kNeed_NextPrim]);
ISpElementList_AddElements(gInputEventList, kInputEvent_NextSecond, 1, &gInputElement[kNeed_NextSecond]);
ISpElementList_AddElements(gInputEventList, kInputEvent_HeadLight, 1, &gInputElement[kNeed_HeadLight]);
ISpElementList_AddElements(gInputEventList, kInputEvent_Flare, 1, &gInputElement[kNeed_Flare]);
ISpElementList_AddElements(gInputEventList, kInputEvent_Map, 1, &gInputElement[kNeed_Map]);
ISpElementList_AddElements(gInputEventList, kInputEvent_InventoryUse, 1, &gInputElement[kNeed_InventoryUse]);
ISpElementList_AddElements(gInputEventList, kInputEvent_InventoryNext, 1, &gInputElement[kNeed_InventoryNext]);
ISpElementList_AddElements(gInputEventList, kInputEvent_InventoryPrev, 1, &gInputElement[kNeed_InventoryPrev]);
ISpElementList_AddElements(gInputEventList, kInputEvent_CounterUse, 1, &gInputElement[kNeed_CounterUse]);
ISpElementList_AddElements(gInputEventList, kInputEvent_CounterNext, 1, &gInputElement[kNeed_CounterNext]);
ISpElementList_AddElements(gInputEventList, kInputEvent_CounterPrev, 1, &gInputElement[kNeed_CounterPrev]);
/*
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt1, 1, &gInputElement[kNeed_ATaunt1]);
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt2, 1, &gInputElement[kNeed_ATaunt2]);
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt3, 1, &gInputElement[kNeed_ATaunt3]);
ISpElementList_AddElements(gInputEventList, kInputEvent_ATaunt4, 1, &gInputElement[kNeed_ATaunt4]);
*/
ISpElementList_Flush(gInputEventList);
ISpElementList_Flush(gInputHoldDownEventList);
for (i = 0; i < 12; i++)
ISpElement_Flush(gInputElement[i]);
ISpSuspend();
iSprocket_inited = true;
}
void inSprocket_Configure(void)
{
#if defined USE_GLIDE
rend_Close();
void inSprocket_Configure(void) {
#if defined USE_GLIDE
rend_Close();
#elif defined USE_OPENGL
PauseDSpContext();
PauseDSpContext();
#endif
AudioStream::PauseAll();
inSprocket_Init(); //Just incase the config gets called before noral init
ISpConfigure(NULL);
AudioStream::PauseAll();
AudioStream::ResumeAll();
inSprocket_Init(); // Just incase the config gets called before noral init
ISpConfigure(NULL);
AudioStream::ResumeAll();
#ifdef USE_MOUSE
HideCursor();
HideCursor();
#endif
#if defined USE_GLIDE
rend_Init (PreferredRenderer, Descent,&Render_preferred_state);
rend_Init(PreferredRenderer, Descent, &Render_preferred_state);
#elif defined USE_OPENGL
ResumeDSpContext();
ResumeDSpContext();
#endif
}
void inSprocket_Activate( Boolean inActivate)
{
Boolean doActivate;
int i;
doActivate = inActivate;
if (gInputActive != doActivate)
{
gInputActive = doActivate;
if (gInputActive)
{
#ifdef USE_MOUSE
HideCursor();
#endif
ISpResume();
}
else
{
ISpSuspend();
#ifdef USE_MOUSE
// ShowCursor();
#endif
}
}
void inSprocket_Activate(Boolean inActivate) {
Boolean doActivate;
int i;
doActivate = inActivate;
if (gInputActive != doActivate) {
gInputActive = doActivate;
if (gInputActive) {
#ifdef USE_MOUSE
HideCursor();
#endif
ISpResume();
} else {
ISpSuspend();
#ifdef USE_MOUSE
// ShowCursor();
#endif
}
}
}
void InSprocket_Flush(void)
{
ISpElementList_Flush(gInputEventList);
ISpElementList_Flush(gInputHoldDownEventList);
for(int i = 0; i < 12; i++)
ISpElement_Flush(gInputElement[i]);
void InSprocket_Flush(void) {
ISpElementList_Flush(gInputEventList);
ISpElementList_Flush(gInputHoldDownEventList);
for (int i = 0; i < 12; i++)
ISpElement_Flush(gInputElement[i]);
}
float inSprocket_GetAllAxis(int axis)
{
ISpAxisData axisValue = kISpAxisMiddle;
OSStatus err;
ISpElementEvent event;
Boolean gotEvent;
float val = 0, fval;
signed int maxval = 0;
while (!(err = ISpElement_GetNextEvent(gInputElement[axis+6], sizeof(event), &event, &gotEvent)) && gotEvent) {
maxval += (signed int)event.data;
}
if(maxval)
return maxval/MOUSE_MAX;
err = ISpElement_GetNextEvent(gInputElement[axis], sizeof(event), &event, &gotEvent);
if (!err && gotEvent) {
return ISpSymmetricAxisToFloat (event.data);
}
err = ISpElement_GetSimpleState(gInputElement[axis], &axisValue);
if(!err) {
return ISpSymmetricAxisToFloat (axisValue);
}
return val;
float inSprocket_GetAllAxis(int axis) {
ISpAxisData axisValue = kISpAxisMiddle;
OSStatus err;
ISpElementEvent event;
Boolean gotEvent;
float val = 0, fval;
signed int maxval = 0;
while (!(err = ISpElement_GetNextEvent(gInputElement[axis + 6], sizeof(event), &event, &gotEvent)) && gotEvent) {
maxval += (signed int)event.data;
}
if (maxval)
return maxval / MOUSE_MAX;
err = ISpElement_GetNextEvent(gInputElement[axis], sizeof(event), &event, &gotEvent);
if (!err && gotEvent) {
return ISpSymmetricAxisToFloat(event.data);
}
err = ISpElement_GetSimpleState(gInputElement[axis], &axisValue);
if (!err) {
return ISpSymmetricAxisToFloat(axisValue);
}
return val;
}
float inSprocket_GetMouse(int axis)
{
OSStatus err;
ISpElementEvent event;
Boolean gotEvent = false;
float val = 0;
signed int maxval = 0;
err = ISpElement_GetNextEvent(gInputElement[axis+6], sizeof(event), &event, &gotEvent);
while (!err && gotEvent) {
maxval += (signed int)event.data;
err = ISpElement_GetNextEvent(gInputElement[axis+6], sizeof(event), &event, &gotEvent);
}
if(maxval)
return val = maxval/MOUSE_MAX;
return val;
float inSprocket_GetMouse(int axis) {
OSStatus err;
ISpElementEvent event;
Boolean gotEvent = false;
float val = 0;
signed int maxval = 0;
err = ISpElement_GetNextEvent(gInputElement[axis + 6], sizeof(event), &event, &gotEvent);
while (!err && gotEvent) {
maxval += (signed int)event.data;
err = ISpElement_GetNextEvent(gInputElement[axis + 6], sizeof(event), &event, &gotEvent);
}
if (maxval)
return val = maxval / MOUSE_MAX;
return val;
}
float inSprocket_GetAxis(int axis)
{
ISpAxisData axisValue = kISpAxisMiddle;
OSStatus err;
float val = 0;
ISpElementEvent event;
Boolean gotEvent;
if (!(err = ISpElement_GetNextEvent(gInputElement[axis], sizeof(event), &event, &gotEvent)) && gotEvent) {
val = ISpSymmetricAxisToFloat (event.data);
} else if (!(err = ISpElement_GetSimpleState(gInputElement[axis], &axisValue))) {
val = ISpSymmetricAxisToFloat (axisValue);
}
return val;
float inSprocket_GetAxis(int axis) {
ISpAxisData axisValue = kISpAxisMiddle;
OSStatus err;
float val = 0;
ISpElementEvent event;
Boolean gotEvent;
if (!(err = ISpElement_GetNextEvent(gInputElement[axis], sizeof(event), &event, &gotEvent)) && gotEvent) {
val = ISpSymmetricAxisToFloat(event.data);
} else if (!(err = ISpElement_GetSimpleState(gInputElement[axis], &axisValue))) {
val = ISpSymmetricAxisToFloat(axisValue);
}
return val;
}
int inSprocket_GetAxisInt(int axis)
{
ISpAxisData axisValue = kISpAxisMiddle;
OSStatus err;
int val = 0;
ISpElementEvent event;
Boolean gotEvent;
if (!(err = ISpElement_GetSimpleState(gInputElement[axis], &axisValue))) {
val = (int)((axisValue >> 24) - 0x7F);
}
return val;
int inSprocket_GetAxisInt(int axis) {
ISpAxisData axisValue = kISpAxisMiddle;
OSStatus err;
int val = 0;
ISpElementEvent event;
Boolean gotEvent;
if (!(err = ISpElement_GetSimpleState(gInputElement[axis], &axisValue))) {
val = (int)((axisValue >> 24) - 0x7F);
}
return val;
}
TInputEvent inSprocket_GetButtonEvent(void)
{
OSErr err;
// TInputEvent result = kInputEvent_None;
int result = kInputEvent_None;
ISpElementEvent event;
Boolean gotEvent;
if (gInputActive)
{
err = ISpElementList_GetNextEvent(gInputHoldDownEventList, sizeof(event), &event, &gotEvent);
if (err == noErr && gotEvent)
{
result = (TInputEvent) event.refCon;
if (event.data == kISpButtonUp)
result += 1; // Note: we rely on off being on+1 (ie kInputEvent_InertialDampers_Off == kInputEvent_InertialDampers_On + 1)
}
else
{
err = ISpElementList_GetNextEvent(gInputEventList, sizeof(event), &event, &gotEvent);
if (err == noErr && gotEvent && event.data == kISpButtonDown)
result = (TInputEvent) event.refCon;
}
}
return (TInputEvent)result;
TInputEvent inSprocket_GetButtonEvent(void) {
OSErr err;
// TInputEvent result = kInputEvent_None;
int result = kInputEvent_None;
ISpElementEvent event;
Boolean gotEvent;
if (gInputActive) {
err = ISpElementList_GetNextEvent(gInputHoldDownEventList, sizeof(event), &event, &gotEvent);
if (err == noErr && gotEvent) {
result = (TInputEvent)event.refCon;
if (event.data == kISpButtonUp)
result += 1; // Note: we rely on off being on+1 (ie kInputEvent_InertialDampers_Off ==
// kInputEvent_InertialDampers_On + 1)
} else {
err = ISpElementList_GetNextEvent(gInputEventList, sizeof(event), &event, &gotEvent);
if (err == noErr && gotEvent && event.data == kISpButtonDown)
result = (TInputEvent)event.refCon;
}
}
return (TInputEvent)result;
}
void inSprocket_Exit(void)
{
if (gInputActive)
{
inSprocket_Activate(false);
}
ISpElementList_Dispose(gInputEventList);
ISpStop();
//?? ISpElement_DisposeVirtual(kNeed_COUNT, gInputElement);
void inSprocket_Exit(void) {
if (gInputActive) {
inSprocket_Activate(false);
}
ISpElementList_Dispose(gInputEventList);
ISpStop();
//?? ISpElement_DisposeVirtual(kNeed_COUNT, gInputElement);
}

View File

@ -1,21 +1,19 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-1998 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$ */
@ -26,35 +24,48 @@
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
#define DO1(buf, i) \
{ \
s1 += buf[i]; \
s2 += s1; \
}
#define DO2(buf, i) \
DO1(buf, i); \
DO1(buf, i + 1);
#define DO4(buf, i) \
DO2(buf, i); \
DO2(buf, i + 2);
#define DO8(buf, i) \
DO4(buf, i); \
DO4(buf, i + 4);
#define DO16(buf) \
DO8(buf, 0); \
DO8(buf, 8);
/* ========================================================================= */
uLong ZEXPORT adler32(uLong adler,const Bytef *buf,uInt len)
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
if (buf == Z_NULL) return 1L;
if (buf == Z_NULL)
return 1L;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
return (s2 << 16) | s1;
if (k != 0)
do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
}
return (s2 << 16) | s1;
}

View File

@ -1,21 +1,19 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* infblock.c -- interpret and process block types to last block
* Copyright (C) 1995-1998 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"
@ -24,15 +22,17 @@
#include "infcodes.h"
#include "infutil.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
struct inflate_codes_state {
int dummy;
}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
/* Table for deflate from PKZIP's appnote.txt. */
local const uInt border[] = { /* Order of the bit length code lengths */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
local const uInt border[] = {/* Order of the bit length code lengths */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
/*
Notes beyond the 1.93a appnote.txt:
@ -79,9 +79,7 @@ local const uInt border[] = { /* Order of the bit length code lengths */
the two sets of lengths.
*/
void inflate_blocks_reset(inflate_blocks_statef *s,z_streamp z,uLongf *c)
{
void inflate_blocks_reset(inflate_blocks_statef *s, z_streamp z, uLongf *c) {
if (c != Z_NULL)
*c = s->check;
if (s->mode == BTREE || s->mode == DTREE)
@ -97,22 +95,16 @@ void inflate_blocks_reset(inflate_blocks_statef *s,z_streamp z,uLongf *c)
Tracev((stderr, "inflate: blocks reset\n"));
}
inflate_blocks_statef *inflate_blocks_new(z_streamp z,check_func c,uInt w)
{
inflate_blocks_statef *inflate_blocks_new(z_streamp z, check_func c, uInt w) {
inflate_blocks_statef *s;
if ((s = (inflate_blocks_statef *)ZALLOC
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
if ((s = (inflate_blocks_statef *)ZALLOC(z, 1, sizeof(struct inflate_blocks_state))) == Z_NULL)
return s;
if ((s->hufts =
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
{
if ((s->hufts = (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL) {
ZFREE(z, s);
return Z_NULL;
}
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
{
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) {
ZFREE(z, s->hufts);
ZFREE(z, s);
return Z_NULL;
@ -125,253 +117,228 @@ inflate_blocks_statef *inflate_blocks_new(z_streamp z,check_func c,uInt w)
return s;
}
int inflate_blocks(inflate_blocks_statef *s,z_streamp z,int r)
{
uInt t; /* temporary storage */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r) {
uInt t; /* temporary storage */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD
/* process input based on current state */
while (1) switch (s->mode)
{
case TYPE:
NEEDBITS(3)
t = (uInt)b & 7;
s->last = t & 1;
switch (t >> 1)
{
case 0: /* stored */
Tracev((stderr, "inflate: stored block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
t = k & 7; /* go to byte boundary */
DUMPBITS(t)
s->mode = LENS; /* get length of stored block */
break;
case 1: /* fixed */
Tracev((stderr, "inflate: fixed codes block%s\n",
s->last ? " (last)" : ""));
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
if (s->sub.decode.codes == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
}
DUMPBITS(3)
s->mode = CODES;
break;
case 2: /* dynamic */
Tracev((stderr, "inflate: dynamic codes block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
s->mode = TABLE;
break;
case 3: /* illegal */
DUMPBITS(3)
s->mode = BAD;
z->msg = (char*)"invalid block type";
r = Z_DATA_ERROR;
LEAVE
}
/* process input based on current state */
while (1) switch (s->mode) {
case TYPE:
NEEDBITS(3)
t = (uInt)b & 7;
s->last = t & 1;
switch (t >> 1) {
case 0: /* stored */
Tracev((stderr, "inflate: stored block%s\n", s->last ? " (last)" : ""));
DUMPBITS(3)
t = k & 7; /* go to byte boundary */
DUMPBITS(t)
s->mode = LENS; /* get length of stored block */
break;
case LENS:
NEEDBITS(32)
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
{
s->mode = BAD;
z->msg = (char*)"invalid stored block lengths";
r = Z_DATA_ERROR;
LEAVE
}
s->sub.left = (uInt)b & 0xffff;
b = k = 0; /* dump bits */
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
break;
case STORED:
if (n == 0)
LEAVE
NEEDOUT
t = s->sub.left;
if (t > n) t = n;
if (t > m) t = m;
zmemcpy(q, p, t);
p += t; n -= t;
q += t; m -= t;
if ((s->sub.left -= t) != 0)
break;
Tracev((stderr, "inflate: stored end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
(s->end - s->read) + (q - s->window))));
s->mode = s->last ? DRY : TYPE;
break;
case TABLE:
NEEDBITS(14)
s->sub.trees.table = t = (uInt)b & 0x3fff;
#ifndef PKZIP_BUG_WORKAROUND
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
{
s->mode = BAD;
z->msg = (char*)"too many length or distance symbols";
r = Z_DATA_ERROR;
LEAVE
}
#endif
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
DUMPBITS(14)
s->sub.trees.index = 0;
Tracev((stderr, "inflate: table sizes ok\n"));
s->mode = BTREE;
case BTREE:
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
{
NEEDBITS(3)
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
DUMPBITS(3)
}
while (s->sub.trees.index < 19)
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.bb = 7;
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
&s->sub.trees.tb, s->hufts, z);
if (t != Z_OK)
{
ZFREE(z, s->sub.trees.blens);
r = t;
if (r == Z_DATA_ERROR)
s->mode = BAD;
LEAVE
}
s->sub.trees.index = 0;
Tracev((stderr, "inflate: bits tree ok\n"));
s->mode = DTREE;
case DTREE:
while (t = s->sub.trees.table,
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
{
inflate_huft *h;
uInt i, j, c;
t = s->sub.trees.bb;
NEEDBITS(t)
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
t = h->bits;
c = h->base;
if (c < 16)
{
DUMPBITS(t)
s->sub.trees.blens[s->sub.trees.index++] = c;
}
else /* c == 16..18 */
{
i = c == 18 ? 7 : c - 14;
j = c == 18 ? 11 : 3;
NEEDBITS(t + i)
DUMPBITS(t)
j += (uInt)b & inflate_mask[i];
DUMPBITS(i)
i = s->sub.trees.index;
t = s->sub.trees.table;
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
(c == 16 && i < 1))
{
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
z->msg = (char*)"invalid bit length repeat";
r = Z_DATA_ERROR;
LEAVE
}
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
do {
s->sub.trees.blens[i++] = c;
} while (--j);
s->sub.trees.index = i;
}
}
s->sub.trees.tb = Z_NULL;
case 1: /* fixed */
Tracev((stderr, "inflate: fixed codes block%s\n", s->last ? " (last)" : ""));
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_codes_statef *c;
bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table;
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
s->sub.trees.blens, &bl, &bd, &tl, &td,
s->hufts, z);
ZFREE(z, s->sub.trees.blens);
if (t != Z_OK)
{
if (t == (uInt)Z_DATA_ERROR)
s->mode = BAD;
r = t;
LEAVE
}
Tracev((stderr, "inflate: trees ok\n"));
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
{
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
if (s->sub.decode.codes == Z_NULL) {
r = Z_MEM_ERROR;
LEAVE
}
s->sub.decode.codes = c;
}
DUMPBITS(3)
s->mode = CODES;
case CODES:
UPDATE
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
return inflate_flush(s, z, r);
r = Z_OK;
inflate_codes_free(s->sub.decode.codes, z);
LOAD
Tracev((stderr, "inflate: codes end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
(s->end - s->read) + (q - s->window))));
if (!s->last)
{
s->mode = TYPE;
break;
}
s->mode = DRY;
case DRY:
FLUSH
if (s->read != s->write)
LEAVE
s->mode = DONE;
case DONE:
r = Z_STREAM_END;
LEAVE
case BAD:
break;
case 2: /* dynamic */
Tracev((stderr, "inflate: dynamic codes block%s\n", s->last ? " (last)" : ""));
DUMPBITS(3)
s->mode = TABLE;
break;
case 3: /* illegal */
DUMPBITS(3)
s->mode = BAD;
z->msg = (char *)"invalid block type";
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
}
break;
case LENS:
NEEDBITS(32)
if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) {
s->mode = BAD;
z->msg = (char *)"invalid stored block lengths";
r = Z_DATA_ERROR;
LEAVE
}
s->sub.left = (uInt)b & 0xffff;
b = k = 0; /* dump bits */
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
break;
case STORED:
if (n == 0)
LEAVE
NEEDOUT
t = s->sub.left;
if (t > n)
t = n;
if (t > m)
t = m;
zmemcpy(q, p, t);
p += t;
n -= t;
q += t;
m -= t;
if ((s->sub.left -= t) != 0)
break;
Tracev((stderr, "inflate: stored end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read : (s->end - s->read) + (q - s->window))));
s->mode = s->last ? DRY : TYPE;
break;
case TABLE:
NEEDBITS(14)
s->sub.trees.table = t = (uInt)b & 0x3fff;
#ifndef PKZIP_BUG_WORKAROUND
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
s->mode = BAD;
z->msg = (char *)"too many length or distance symbols";
r = Z_DATA_ERROR;
LEAVE
}
#endif
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
if ((s->sub.trees.blens = (uIntf *)ZALLOC(z, t, sizeof(uInt))) == Z_NULL) {
r = Z_MEM_ERROR;
LEAVE
}
DUMPBITS(14)
s->sub.trees.index = 0;
Tracev((stderr, "inflate: table sizes ok\n"));
s->mode = BTREE;
case BTREE:
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) {
NEEDBITS(3)
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
DUMPBITS(3)
}
while (s->sub.trees.index < 19)
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.bb = 7;
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, &s->sub.trees.tb, s->hufts, z);
if (t != Z_OK) {
ZFREE(z, s->sub.trees.blens);
r = t;
if (r == Z_DATA_ERROR)
s->mode = BAD;
LEAVE
}
s->sub.trees.index = 0;
Tracev((stderr, "inflate: bits tree ok\n"));
s->mode = DTREE;
case DTREE:
while (t = s->sub.trees.table, s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) {
inflate_huft *h;
uInt i, j, c;
t = s->sub.trees.bb;
NEEDBITS(t)
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
t = h->bits;
c = h->base;
if (c < 16) {
DUMPBITS(t)
s->sub.trees.blens[s->sub.trees.index++] = c;
} else /* c == 16..18 */
{
i = c == 18 ? 7 : c - 14;
j = c == 18 ? 11 : 3;
NEEDBITS(t + i)
DUMPBITS(t)
j += (uInt)b & inflate_mask[i];
DUMPBITS(i)
i = s->sub.trees.index;
t = s->sub.trees.table;
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
z->msg = (char *)"invalid bit length repeat";
r = Z_DATA_ERROR;
LEAVE
}
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
do {
s->sub.trees.blens[i++] = c;
} while (--j);
s->sub.trees.index = i;
}
}
s->sub.trees.tb = Z_NULL;
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_codes_statef *c;
bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table;
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), s->sub.trees.blens, &bl, &bd, &tl, &td,
s->hufts, z);
ZFREE(z, s->sub.trees.blens);
if (t != Z_OK) {
if (t == (uInt)Z_DATA_ERROR)
s->mode = BAD;
r = t;
LEAVE
}
Tracev((stderr, "inflate: trees ok\n"));
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) {
r = Z_MEM_ERROR;
LEAVE
}
s->sub.decode.codes = c;
}
s->mode = CODES;
case CODES:
UPDATE
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
return inflate_flush(s, z, r);
r = Z_OK;
inflate_codes_free(s->sub.decode.codes, z);
LOAD Tracev((stderr, "inflate: codes end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read : (s->end - s->read) + (q - s->window))));
if (!s->last) {
s->mode = TYPE;
break;
}
s->mode = DRY;
case DRY:
FLUSH
if (s->read != s->write)
LEAVE
s->mode = DONE;
case DONE:
r = Z_STREAM_END;
LEAVE
case BAD:
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
LEAVE
}
}
int inflate_blocks_free(inflate_blocks_statef *s,z_streamp z)
{
int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z) {
inflate_blocks_reset(s, z, Z_NULL);
ZFREE(z, s->window);
ZFREE(z, s->hufts);
@ -380,19 +347,13 @@ int inflate_blocks_free(inflate_blocks_statef *s,z_streamp z)
return Z_OK;
}
void inflate_set_dictionary(inflate_blocks_statef *s,const Bytef *d,uInt n)
{
void inflate_set_dictionary(inflate_blocks_statef *s, const Bytef *d, uInt n) {
zmemcpy(s->window, d, n);
s->read = s->write = s->window + n;
}
/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
* IN assertion: s != Z_NULL
*/
int inflate_blocks_sync_point(inflate_blocks_statef *s)
{
return s->mode == LENS;
}
int inflate_blocks_sync_point(inflate_blocks_statef *s) { return s->mode == LENS; }

View File

@ -1,21 +1,19 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* infcodes.c -- process literals and length/distance pairs
* Copyright (C) 1995-1998 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"
@ -29,55 +27,51 @@
#define exop word.what.Exop
#define bits word.what.Bits
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BADCODE} /* x: got error */
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BADCODE
} /* x: got error */
inflate_codes_mode;
/* inflate codes private state */
struct inflate_codes_state {
/* mode */
inflate_codes_mode mode; /* current inflate_codes mode */
inflate_codes_mode mode; /* current inflate_codes mode */
/* mode dependent information */
uInt len;
union {
struct {
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
struct {
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
/* mode independent information */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
};
inflate_codes_statef *inflate_codes_new(uInt bl,uInt bd,inflate_huft *tl,inflate_huft *td,z_streamp z)
{
inflate_codes_statef *inflate_codes_new(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, z_streamp z) {
inflate_codes_statef *c;
if ((c = (inflate_codes_statef *)
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
{
if ((c = (inflate_codes_statef *)ZALLOC(z, 1, sizeof(struct inflate_codes_state))) != Z_NULL) {
c->mode = START;
c->lbits = (Byte)bl;
c->dbits = (Byte)bd;
@ -88,176 +82,165 @@ inflate_codes_statef *inflate_codes_new(uInt bl,uInt bd,inflate_huft *tl,inflate
return c;
}
int inflate_codes(inflate_blocks_statef *s,z_streamp z,int r)
{
uInt j; /* temporary storage */
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
Bytef *f; /* pointer to copy strings from */
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
int inflate_codes(inflate_blocks_statef *s, z_streamp z, int r) {
uInt j; /* temporary storage */
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
Bytef *f; /* pointer to copy strings from */
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD
/* process input and output based on current state */
while (1) switch (c->mode)
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
case START: /* x: set up for LEN */
/* process input and output based on current state */
while (1) switch (c->mode) { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
case START: /* x: set up for LEN */
#ifndef SLOW
if (m >= 258 && n >= 10)
{
UPDATE
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
LOAD
if (r != Z_OK)
{
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
break;
}
if (m >= 258 && n >= 10) {
UPDATE
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
LOAD if (r != Z_OK) {
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
break;
}
}
#endif /* !SLOW */
c->sub.code.need = c->lbits;
c->sub.code.tree = c->ltree;
c->mode = LEN;
case LEN: /* i: get length/literal/eob next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e == 0) /* literal */
{
c->sub.lit = t->base;
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", t->base));
c->mode = LIT;
break;
}
if (e & 16) /* length */
{
c->sub.copy.get = e & 15;
c->len = t->base;
c->mode = LENEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
if (e & 32) /* end of block */
{
Tracevv((stderr, "inflate: end of block\n"));
c->mode = WASH;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid literal/length code";
r = Z_DATA_ERROR;
LEAVE
case LENEXT: /* i: getting length extra (have base) */
j = c->sub.copy.get;
NEEDBITS(j)
c->len += (uInt)b & inflate_mask[j];
DUMPBITS(j)
c->sub.code.need = c->dbits;
c->sub.code.tree = c->dtree;
Tracevv((stderr, "inflate: length %u\n", c->len));
c->mode = DIST;
case DIST: /* i: get distance next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e & 16) /* distance */
{
c->sub.copy.get = e & 15;
c->sub.copy.dist = t->base;
c->mode = DISTEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid distance code";
r = Z_DATA_ERROR;
LEAVE
case DISTEXT: /* i: getting distance extra */
j = c->sub.copy.get;
NEEDBITS(j)
c->sub.copy.dist += (uInt)b & inflate_mask[j];
DUMPBITS(j)
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
c->mode = COPY;
case COPY: /* o: copying bytes in window, waiting for space */
c->sub.code.need = c->lbits;
c->sub.code.tree = c->ltree;
c->mode = LEN;
case LEN: /* i: get length/literal/eob next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e == 0) /* literal */
{
c->sub.lit = t->base;
Tracevv(
(stderr,
t->base >= 0x20 && t->base < 0x7f ? "inflate: literal '%c'\n" : "inflate: literal 0x%02x\n",
t->base));
c->mode = LIT;
break;
}
if (e & 16) /* length */
{
c->sub.copy.get = e & 15;
c->len = t->base;
c->mode = LENEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
if (e & 32) /* end of block */
{
Tracevv((stderr, "inflate: end of block\n"));
c->mode = WASH;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char *)"invalid literal/length code";
r = Z_DATA_ERROR;
LEAVE
case LENEXT: /* i: getting length extra (have base) */
j = c->sub.copy.get;
NEEDBITS(j)
c->len += (uInt)b & inflate_mask[j];
DUMPBITS(j)
c->sub.code.need = c->dbits;
c->sub.code.tree = c->dtree;
Tracevv((stderr, "inflate: length %u\n", c->len));
c->mode = DIST;
case DIST: /* i: get distance next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e & 16) /* distance */
{
c->sub.copy.get = e & 15;
c->sub.copy.dist = t->base;
c->mode = DISTEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char *)"invalid distance code";
r = Z_DATA_ERROR;
LEAVE
case DISTEXT: /* i: getting distance extra */
j = c->sub.copy.get;
NEEDBITS(j)
c->sub.copy.dist += (uInt)b & inflate_mask[j];
DUMPBITS(j)
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
c->mode = COPY;
case COPY: /* o: copying bytes in window, waiting for space */
#ifndef __TURBOC__ /* Turbo C bug for following expression */
f = (uInt)(q - s->window) < c->sub.copy.dist ?
s->end - (c->sub.copy.dist - (q - s->window)) :
q - c->sub.copy.dist;
f = (uInt)(q - s->window) < c->sub.copy.dist ? s->end - (c->sub.copy.dist - (q - s->window)) : q - c->sub.copy.dist;
#else
f = q - c->sub.copy.dist;
if ((uInt)(q - s->window) < c->sub.copy.dist)
f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
f = q - c->sub.copy.dist;
if ((uInt)(q - s->window) < c->sub.copy.dist)
f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
#endif
while (c->len)
{
NEEDOUT
OUTBYTE(*f++)
if (f == s->end)
f = s->window;
c->len--;
}
c->mode = START;
break;
case LIT: /* o: got literal, waiting for output space */
while (c->len) {
NEEDOUT
OUTBYTE(c->sub.lit)
c->mode = START;
break;
case WASH: /* o: got eob, possibly more output */
if (k > 7) /* return unused byte, if any */
{
Assert(k < 16, "inflate_codes grabbed too many bytes")
k -= 8;
n++;
p--; /* can always return one */
}
FLUSH
if (s->read != s->write)
LEAVE
c->mode = END;
case END:
r = Z_STREAM_END;
LEAVE
case BADCODE: /* x: got error */
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
OUTBYTE(*f++)
if (f == s->end)
f = s->window;
c->len--;
}
c->mode = START;
break;
case LIT: /* o: got literal, waiting for output space */
NEEDOUT
OUTBYTE(c->sub.lit)
c->mode = START;
break;
case WASH: /* o: got eob, possibly more output */
if (k > 7) /* return unused byte, if any */
{
Assert(k < 16, "inflate_codes grabbed too many bytes") k -= 8;
n++;
p--; /* can always return one */
}
FLUSH
if (s->read != s->write)
LEAVE
c->mode = END;
case END:
r = Z_STREAM_END;
LEAVE
case BADCODE: /* x: got error */
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
LEAVE
}
#ifdef NEED_DUMMY_RETURN
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
#endif
}
void inflate_codes_free(inflate_codes_statef *c,z_streamp z)
{
void inflate_codes_free(inflate_codes_statef *c, z_streamp z) {
ZFREE(z, c);
Tracev((stderr, "inflate: codes free\n"));
}

View File

@ -1,21 +1,19 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* inffast.c -- process literals and length/distance pairs fast
* Copyright (C) 1995-1998 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"
@ -25,62 +23,75 @@
#include "infutil.h"
#include "inffast.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
struct inflate_codes_state {
int dummy;
}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
/* macros for bit input with no checking and for returning unused bytes */
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
#define GRABBITS(j) \
{ \
while (k < (j)) { \
b |= ((uLong)NEXTBYTE) << k; \
k += 8; \
} \
}
#define UNGRAB \
{ \
c = z->avail_in - n; \
c = (k >> 3) < c ? k >> 3 : c; \
n += c; \
p -= c; \
k -= c << 3; \
}
/* Called with number of bytes left to write in window at least 258
(the maximum string length) and number of input bytes available
at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer. */
int inflate_fast(uInt bl,uInt bd,inflate_huft *tl,inflate_huft *td,inflate_blocks_statef *s,z_streamp z)
{
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
uInt ml; /* mask for literal/length tree */
uInt md; /* mask for distance tree */
uInt c; /* bytes to copy */
uInt d; /* distance back to copy from */
Bytef *r; /* copy source pointer */
int inflate_fast(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, inflate_blocks_statef *s, z_streamp z) {
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
uInt ml; /* mask for literal/length tree */
uInt md; /* mask for distance tree */
uInt c; /* bytes to copy */
uInt d; /* distance back to copy from */
Bytef *r; /* copy source pointer */
/* load input, output, bit values */
LOAD
/* initialize masks */
ml = inflate_mask[bl];
/* initialize masks */
ml = inflate_mask[bl];
md = inflate_mask[bd];
/* do until not enough input or output space for fast loop */
do { /* assume called with m >= 258 && n >= 10 */
do { /* assume called with m >= 258 && n >= 10 */
/* get literal/length code */
GRABBITS(20) /* max bits for literal/length code */
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
{
GRABBITS(20) /* max bits for literal/length code */
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) {
DUMPBITS(t->bits)
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: * literal '%c'\n" :
"inflate: * literal 0x%02x\n", t->base));
Tracevv((stderr,
t->base >= 0x20 && t->base < 0x7f ? "inflate: * literal '%c'\n"
: "inflate: * literal 0x%02x\n",
t->base));
*q++ = (Byte)t->base;
m--;
continue;
}
do {
DUMPBITS(t->bits)
if (e & 16)
{
if (e & 16) {
/* get extra bits for length */
e &= 15;
c = t->base + ((uInt)b & inflate_mask[e]);
@ -88,53 +99,49 @@ int inflate_fast(uInt bl,uInt bd,inflate_huft *tl,inflate_huft *td,inflate_block
Tracevv((stderr, "inflate: * length %u\n", c));
/* decode distance base of block to copy */
GRABBITS(15); /* max bits for distance code */
GRABBITS(15); /* max bits for distance code */
e = (t = td + ((uInt)b & md))->exop;
do {
DUMPBITS(t->bits)
if (e & 16)
{
if (e & 16) {
/* get extra bits to add to distance base */
e &= 15;
GRABBITS(e) /* get extra bits (up to 13) */
GRABBITS(e) /* get extra bits (up to 13) */
d = t->base + ((uInt)b & inflate_mask[e]);
DUMPBITS(e)
Tracevv((stderr, "inflate: * distance %u\n", d));
/* do the copy */
m -= c;
if ((uInt)(q - s->window) >= d) /* offset before dest */
{ /* just copy */
if ((uInt)(q - s->window) >= d) /* offset before dest */
{ /* just copy */
r = q - d;
*q++ = *r++; c--; /* minimum count is three, */
*q++ = *r++; c--; /* so unroll loop a little */
}
else /* else offset after destination */
*q++ = *r++;
c--; /* minimum count is three, */
*q++ = *r++;
c--; /* so unroll loop a little */
} else /* else offset after destination */
{
e = d - (uInt)(q - s->window); /* bytes from offset to end */
r = s->end - e; /* pointer to offset */
if (c > e) /* if source crosses, */
r = s->end - e; /* pointer to offset */
if (c > e) /* if source crosses, */
{
c -= e; /* copy to end of window */
c -= e; /* copy to end of window */
do {
*q++ = *r++;
} while (--e);
r = s->window; /* copy rest from start of window */
r = s->window; /* copy rest from start of window */
}
}
do { /* copy all or what's left */
do { /* copy all or what's left */
*q++ = *r++;
} while (--c);
break;
}
else if ((e & 64) == 0)
{
} else if ((e & 64) == 0) {
t += t->base;
e = (t += ((uInt)b & inflate_mask[e]))->exop;
}
else
{
z->msg = (char*)"invalid distance code";
} else {
z->msg = (char *)"invalid distance code";
UNGRAB
UPDATE
return Z_DATA_ERROR;
@ -142,30 +149,25 @@ int inflate_fast(uInt bl,uInt bd,inflate_huft *tl,inflate_huft *td,inflate_block
} while (1);
break;
}
if ((e & 64) == 0)
{
if ((e & 64) == 0) {
t += t->base;
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
{
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) {
DUMPBITS(t->bits)
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: * literal '%c'\n" :
"inflate: * literal 0x%02x\n", t->base));
Tracevv((stderr,
t->base >= 0x20 && t->base < 0x7f ? "inflate: * literal '%c'\n"
: "inflate: * literal 0x%02x\n",
t->base));
*q++ = (Byte)t->base;
m--;
break;
}
}
else if (e & 32)
{
} else if (e & 32) {
Tracevv((stderr, "inflate: * end of block\n"));
UNGRAB
UPDATE
return Z_STREAM_END;
}
else
{
z->msg = (char*)"invalid literal/length code";
} else {
z->msg = (char *)"invalid literal/length code";
UNGRAB
UPDATE
return Z_DATA_ERROR;

View File

@ -1,85 +1,82 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* inflate.c -- zlib interface to inflate modules
* Copyright (C) 1995-1998 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 "infblock.h"
// needed by zlib
voidpf zcalloc (voidpf opaque,unsigned items,unsigned size)
{
if (opaque) items += size - size; /* make compiler happy */
return (voidpf)calloc(items, size);
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size) {
if (opaque)
items += size - size; /* make compiler happy */
return (voidpf)calloc(items, size);
}
void zcfree (voidpf opaque,voidpf ptr)
{
free(ptr);
if (opaque) return; /* make compiler happy */
void zcfree(voidpf opaque, voidpf ptr) {
free(ptr);
if (opaque)
return; /* make compiler happy */
}
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
struct inflate_blocks_state {
int dummy;
}; /* for buggy compilers */
typedef enum {
METHOD, /* waiting for method byte */
FLAG, /* waiting for flag byte */
DICT4, /* four dictionary check bytes to go */
DICT3, /* three dictionary check bytes to go */
DICT2, /* two dictionary check bytes to go */
DICT1, /* one dictionary check byte to go */
DICT0, /* waiting for inflateSetDictionary */
BLOCKS, /* decompressing blocks */
CHECK4, /* four check bytes to go */
CHECK3, /* three check bytes to go */
CHECK2, /* two check bytes to go */
CHECK1, /* one check byte to go */
DONE, /* finished check, done */
BAD} /* got an error--stay here */
METHOD, /* waiting for method byte */
FLAG, /* waiting for flag byte */
DICT4, /* four dictionary check bytes to go */
DICT3, /* three dictionary check bytes to go */
DICT2, /* two dictionary check bytes to go */
DICT1, /* one dictionary check byte to go */
DICT0, /* waiting for inflateSetDictionary */
BLOCKS, /* decompressing blocks */
CHECK4, /* four check bytes to go */
CHECK3, /* three check bytes to go */
CHECK2, /* two check bytes to go */
CHECK1, /* one check byte to go */
DONE, /* finished check, done */
BAD
} /* got an error--stay here */
inflate_mode;
/* inflate private state */
struct internal_state {
/* mode */
inflate_mode mode; /* current inflate mode */
inflate_mode mode; /* current inflate mode */
/* mode dependent information */
union {
uInt method; /* if FLAGS, method byte */
uInt method; /* if FLAGS, method byte */
struct {
uLong was; /* computed check value */
uLong need; /* stream check value */
} check; /* if CHECK, check values to compare */
uInt marker; /* if BAD, inflateSync's marker bytes count */
} sub; /* submode */
uLong was; /* computed check value */
uLong need; /* stream check value */
} check; /* if CHECK, check values to compare */
uInt marker; /* if BAD, inflateSync's marker bytes count */
} sub; /* submode */
/* mode independent information */
int nowrap; /* flag for no wrapper */
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
inflate_blocks_statef
*blocks; /* current inflate_blocks state */
int nowrap; /* flag for no wrapper */
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
inflate_blocks_statef *blocks; /* current inflate_blocks state */
};
int ZEXPORT inflateReset(z_streamp z)
{
int ZEXPORT inflateReset(z_streamp z) {
if (z == Z_NULL || z->state == Z_NULL)
return Z_STREAM_ERROR;
z->total_in = z->total_out = 0;
@ -90,9 +87,7 @@ int ZEXPORT inflateReset(z_streamp z)
return Z_OK;
}
int ZEXPORT inflateEnd(z_streamp z)
{
int ZEXPORT inflateEnd(z_streamp z) {
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->blocks != Z_NULL)
@ -103,49 +98,40 @@ int ZEXPORT inflateEnd(z_streamp z)
return Z_OK;
}
int ZEXPORT inflateInit2_(z_streamp z,int w, const char *version, int stream_size)
{
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != sizeof(z_stream))
return Z_VERSION_ERROR;
int ZEXPORT inflateInit2_(z_streamp z, int w, const char *version, int stream_size) {
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || stream_size != sizeof(z_stream))
return Z_VERSION_ERROR;
/* initialize state */
if (z == Z_NULL)
return Z_STREAM_ERROR;
z->msg = Z_NULL;
if (z->zalloc == Z_NULL)
{
if (z->zalloc == Z_NULL) {
z->zalloc = zcalloc;
z->opaque = (voidpf)0;
}
if (z->zfree == Z_NULL) z->zfree = zcfree;
if ((z->state = (struct internal_state FAR *)
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
if (z->zfree == Z_NULL)
z->zfree = zcfree;
if ((z->state = (struct internal_state FAR *)ZALLOC(z, 1, sizeof(struct internal_state))) == Z_NULL)
return Z_MEM_ERROR;
z->state->blocks = Z_NULL;
/* handle undocumented nowrap option (no zlib header or check) */
z->state->nowrap = 0;
if (w < 0)
{
w = - w;
if (w < 0) {
w = -w;
z->state->nowrap = 1;
}
/* set window size */
if (w < 8 || w > 15)
{
if (w < 8 || w > 15) {
inflateEnd(z);
return Z_STREAM_ERROR;
}
z->state->wbits = (uInt)w;
/* create inflate_blocks state */
if ((z->state->blocks =
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
== Z_NULL)
{
if ((z->state->blocks = inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) == Z_NULL) {
inflateEnd(z);
return Z_MEM_ERROR;
}
@ -156,18 +142,19 @@ int ZEXPORT inflateInit2_(z_streamp z,int w, const char *version, int stream_siz
return Z_OK;
}
int ZEXPORT inflateInit_(z_streamp z, const char *version, int stream_size)
{
int ZEXPORT inflateInit_(z_streamp z, const char *version, int stream_size) {
return inflateInit2_(z, DEF_WBITS, version, stream_size);
}
#define NEEDBYTE \
{ \
if (z->avail_in == 0) \
return r; \
r = f; \
}
#define NEXTBYTE (z->avail_in--, z->total_in++, *z->next_in++)
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
int ZEXPORT inflate(z_streamp z, int f)
{
int ZEXPORT inflate(z_streamp z, int f) {
int r;
uInt b;
@ -175,38 +162,34 @@ int ZEXPORT inflate(z_streamp z, int f)
return Z_STREAM_ERROR;
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
r = Z_BUF_ERROR;
while (1) switch (z->state->mode)
{
while (1)
switch (z->state->mode) {
case METHOD:
NEEDBYTE
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
{
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) {
z->state->mode = BAD;
z->msg = (char*)"unknown compression method";
z->state->sub.marker = 5; /* can't try inflateSync */
z->msg = (char *)"unknown compression method";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
{
if ((z->state->sub.method >> 4) + 8 > z->state->wbits) {
z->state->mode = BAD;
z->msg = (char*)"invalid window size";
z->state->sub.marker = 5; /* can't try inflateSync */
z->msg = (char *)"invalid window size";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
z->state->mode = FLAG;
case FLAG:
NEEDBYTE
b = NEXTBYTE;
if (((z->state->sub.method << 8) + b) % 31)
{
if (((z->state->sub.method << 8) + b) % 31) {
z->state->mode = BAD;
z->msg = (char*)"incorrect header check";
z->state->sub.marker = 5; /* can't try inflateSync */
z->msg = (char *)"incorrect header check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib header ok\n"));
if (!(b & PRESET_DICT))
{
if (!(b & PRESET_DICT)) {
z->state->mode = BLOCKS;
break;
}
@ -231,15 +214,14 @@ int ZEXPORT inflate(z_streamp z, int f)
return Z_NEED_DICT;
case DICT0:
z->state->mode = BAD;
z->msg = (char*)"need dictionary";
z->state->sub.marker = 0; /* can try inflateSync */
z->msg = (char *)"need dictionary";
z->state->sub.marker = 0; /* can try inflateSync */
return Z_STREAM_ERROR;
case BLOCKS:
r = inflate_blocks(z->state->blocks, z, r);
if (r == Z_DATA_ERROR)
{
if (r == Z_DATA_ERROR) {
z->state->mode = BAD;
z->state->sub.marker = 0; /* can try inflateSync */
z->state->sub.marker = 0; /* can try inflateSync */
break;
}
if (r == Z_OK)
@ -248,8 +230,7 @@ int ZEXPORT inflate(z_streamp z, int f)
return r;
r = f;
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
if (z->state->nowrap)
{
if (z->state->nowrap) {
z->state->mode = DONE;
break;
}
@ -270,11 +251,10 @@ int ZEXPORT inflate(z_streamp z, int f)
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
if (z->state->sub.check.was != z->state->sub.check.need)
{
if (z->state->sub.check.was != z->state->sub.check.need) {
z->state->mode = BAD;
z->msg = (char*)"incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */
z->msg = (char *)"incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib check ok\n"));
@ -285,26 +265,24 @@ int ZEXPORT inflate(z_streamp z, int f)
return Z_DATA_ERROR;
default:
return Z_STREAM_ERROR;
}
}
#ifdef NEED_DUMMY_RETURN
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
#endif
}
int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef *dictionary, uInt dictLength)
{
int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef *dictionary, uInt dictLength) {
uInt length = dictLength;
if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
return Z_STREAM_ERROR;
if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
if (adler32(1L, dictionary, dictLength) != z->adler)
return Z_DATA_ERROR;
z->adler = 1L;
if (length >= ((uInt)1<<z->state->wbits))
{
length = (1<<z->state->wbits)-1;
if (length >= ((uInt)1 << z->state->wbits)) {
length = (1 << z->state->wbits) - 1;
dictionary += dictLength - length;
}
inflate_set_dictionary(z->state->blocks, dictionary, length);
@ -312,19 +290,16 @@ int ZEXPORT inflateSetDictionary(z_streamp z, const Bytef *dictionary, uInt dic
return Z_OK;
}
int ZEXPORT inflateSync(z_streamp z)
{
uInt n; /* number of bytes to look at */
Bytef *p; /* pointer to bytes */
uInt m; /* number of marker bytes found in a row */
uLong r, w; /* temporaries to save total_in and total_out */
int ZEXPORT inflateSync(z_streamp z) {
uInt n; /* number of bytes to look at */
Bytef *p; /* pointer to bytes */
uInt m; /* number of marker bytes found in a row */
uLong r, w; /* temporaries to save total_in and total_out */
/* set up */
if (z == Z_NULL || z->state == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->mode != BAD)
{
if (z->state->mode != BAD) {
z->state->mode = BAD;
z->state->sub.marker = 0;
}
@ -334,8 +309,7 @@ int ZEXPORT inflateSync(z_streamp z)
m = z->state->sub.marker;
/* search */
while (n && m < 4)
{
while (n && m < 4) {
static const Byte mark[4] = {0, 0, 0xff, 0xff};
if (*p == mark[m])
m++;
@ -355,14 +329,15 @@ int ZEXPORT inflateSync(z_streamp z)
/* return no joy or set up to restart on a new block */
if (m != 4)
return Z_DATA_ERROR;
r = z->total_in; w = z->total_out;
r = z->total_in;
w = z->total_out;
inflateReset(z);
z->total_in = r; z->total_out = w;
z->total_in = r;
z->total_out = w;
z->state->mode = BLOCKS;
return Z_OK;
}
/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
* implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
@ -370,8 +345,7 @@ int ZEXPORT inflateSync(z_streamp z)
* decompressing, PPP checks that at the end of input packet, inflate is
* waiting for these length bytes.
*/
int ZEXPORT inflateSyncPoint(z_streamp z)
{
int ZEXPORT inflateSyncPoint(z_streamp z) {
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
return Z_STREAM_ERROR;
return inflate_blocks_sync_point(z->state->blocks);

View File

@ -1,73 +1,68 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-1998 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 "inftrees.h"
#if !defined(BUILDFIXED) && !defined(STDC)
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
#define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
#endif
const char inflate_copyright[] =
" inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
const char inflate_copyright[] = " inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
/*
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
include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product.
*/
struct internal_state {int dummy;}; /* for buggy compilers */
struct internal_state {
int dummy;
}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
local int huft_build OF((
uIntf *, /* code lengths in bits */
uInt, /* number of codes */
uInt, /* number of "simple" codes */
const uIntf *, /* list of base values for non-simple codes */
const uIntf *, /* list of extra bits for non-simple codes */
inflate_huft * FAR*,/* result: starting table */
uIntf *, /* maximum lookup bits (returns actual) */
inflate_huft *, /* space for trees */
uInt *, /* hufts used in space */
uIntf * )); /* space for values */
local int huft_build OF((uIntf *, /* code lengths in bits */
uInt, /* number of codes */
uInt, /* number of "simple" codes */
const uIntf *, /* list of base values for non-simple codes */
const uIntf *, /* list of extra bits for non-simple codes */
inflate_huft *FAR *, /* result: starting table */
uIntf *, /* maximum lookup bits (returns actual) */
inflate_huft *, /* space for trees */
uInt *, /* hufts used in space */
uIntf *)); /* space for values */
/* Tables for deflate from PKZIP's appnote.txt. */
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
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};
/* see note #13 above about 258 */
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
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,
8193, 12289, 16385, 24577};
local const uInt cpdext[30] = { /* Extra bits for distance codes */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
local const uInt cplens[31] = {/* Copy lengths for literal codes 257..285 */
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};
/* see note #13 above about 258 */
local const uInt cplext[31] = {/* Extra bits for literal codes 257..285 */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
local const uInt cpdist[30] = {/* Copy offsets for distance codes 0..29 */
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, 8193, 12289, 16385, 24577};
local const uInt cpdext[30] = {/* Extra bits for distance codes */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
/*
Huffman code decoding is performed using a multi-level table lookup.
@ -101,9 +96,8 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */
possibly even between compilers. Your mileage may vary.
*/
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
#define BMAX 15 /* maximum bit length of any code */
#define BMAX 15 /* maximum bit length of any code */
/*
uIntf *b; code lengths in bits (all assumed <= BMAX)
uInt n; number of codes (assumed <= 288)
@ -120,65 +114,63 @@ uIntf *v; working area: values in order of bit length
if the given code set is incomplete (the tables are still built in this
case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
lengths), or Z_MEM_ERROR if not enough memory. */
local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d, const uIntf *e, inflate_huft * FAR *t, uIntf *m, inflate_huft *hp, uInt *hn, uIntf *v)
{
uInt a; /* counter for codes of length k */
uInt c[BMAX+1]; /* bit length count table */
uInt f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
register uInt i; /* counter, current code */
register uInt j; /* counter */
register int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
register uIntf *p; /* pointer into c[], b[], or v[] */
inflate_huft *q; /* points to current table */
struct inflate_huft_s r; /* table entry for structure assignment */
inflate_huft *u[BMAX]; /* table stack */
register int w; /* bits before this table == (l * h) */
uInt x[BMAX+1]; /* bit offsets, then code stack */
uIntf *xp; /* pointer into x */
int y; /* number of dummy codes added */
uInt z; /* number of entries in current table */
local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d, const uIntf *e, inflate_huft *FAR *t, uIntf *m,
inflate_huft *hp, uInt *hn, uIntf *v) {
uInt a; /* counter for codes of length k */
uInt c[BMAX + 1]; /* bit length count table */
uInt f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
register uInt i; /* counter, current code */
register uInt j; /* counter */
register int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
register uIntf *p; /* pointer into c[], b[], or v[] */
inflate_huft *q; /* points to current table */
struct inflate_huft_s r; /* table entry for structure assignment */
inflate_huft *u[BMAX]; /* table stack */
register int w; /* bits before this table == (l * h) */
uInt x[BMAX + 1]; /* bit offsets, then code stack */
uIntf *xp; /* pointer into x */
int y; /* number of dummy codes added */
uInt z; /* number of entries in current table */
/* Generate counts for each bit length */
p = c;
#define C0 *p++ = 0;
#define C2 C0 C0 C0 C0
#define C4 C2 C2 C2 C2
C4 /* clear c[]--assume BMAX+1 is 16 */
p = b; i = n;
C4 /* clear c[]--assume BMAX+1 is 16 */
p = b;
i = n;
do {
c[*p++]++; /* assume all entries <= BMAX */
c[*p++]++; /* assume all entries <= BMAX */
} while (--i);
if (c[0] == n) /* null input--all zero length codes */
if (c[0] == n) /* null input--all zero length codes */
{
*t = (inflate_huft *)Z_NULL;
*m = 0;
return Z_OK;
}
/* Find minimum and maximum length, bound *m by those */
l = *m;
for (j = 1; j <= BMAX; j++)
if (c[j])
break;
k = j; /* minimum code length */
k = j; /* minimum code length */
if ((uInt)l < j)
l = j;
for (i = BMAX; i; i--)
if (c[i])
break;
g = i; /* maximum code length */
g = i; /* maximum code length */
if ((uInt)l > i)
l = i;
*m = l;
/* Adjust last length count to fill out codes, if needed */
for (y = 1 << j; j < i; j++, y <<= 1)
if ((y -= c[j]) < 0)
@ -187,95 +179,86 @@ local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d, const uIntf *e, i
return Z_DATA_ERROR;
c[i] += y;
/* Generate starting offsets into the value table for each length */
x[1] = j = 0;
p = c + 1; xp = x + 2;
while (--i) { /* note that i == g from above */
p = c + 1;
xp = x + 2;
while (--i) { /* note that i == g from above */
*xp++ = (j += *p++);
}
/* Make a table of values in order of bit lengths */
p = b; i = 0;
p = b;
i = 0;
do {
if ((j = *p++) != 0)
v[x[j]++] = i;
} while (++i < n);
n = x[g]; /* set n to length of v */
n = x[g]; /* set n to length of v */
/* Generate the Huffman codes and for each, make the table entries */
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
q = (inflate_huft *)Z_NULL; /* ditto */
z = 0; /* ditto */
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
q = (inflate_huft *)Z_NULL; /* ditto */
z = 0; /* ditto */
/* go through the bit lengths (k already is bits in shortest code) */
for (; k <= g; k++)
{
for (; k <= g; k++) {
a = c[k];
while (a--)
{
while (a--) {
/* here i is the Huffman code of length k bits for value *p */
/* make tables up to required level */
while (k > w + l)
{
while (k > w + l) {
h++;
w += l; /* previous table always l bits */
w += l; /* previous table always l bits */
/* compute minimum size table less than or equal to l bits */
z = g - w;
z = z > (uInt)l ? l : z; /* table size upper limit */
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
z = z > (uInt)l ? l : z; /* table size upper limit */
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
xp = c + k;
if (j < z)
while (++j < z) /* try smaller tables up to z bits */
while (++j < z) /* try smaller tables up to z bits */
{
if ((f <<= 1) <= *++xp)
break; /* enough codes to use up j bits */
f -= *xp; /* else deduct codes from patterns */
break; /* enough codes to use up j bits */
f -= *xp; /* else deduct codes from patterns */
}
}
z = 1 << j; /* table entries for j-bit table */
z = 1 << j; /* table entries for j-bit table */
/* allocate new table */
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
return Z_MEM_ERROR; /* not enough memory */
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
return Z_MEM_ERROR; /* not enough memory */
u[h] = q = hp + *hn;
*hn += z;
/* connect to last table, if there is one */
if (h)
{
x[h] = i; /* save pattern for backing up */
r.bits = (Byte)l; /* bits to dump before this table */
r.exop = (Byte)j; /* bits in this table */
if (h) {
x[h] = i; /* save pattern for backing up */
r.bits = (Byte)l; /* bits to dump before this table */
r.exop = (Byte)j; /* bits in this table */
j = i >> (w - l);
r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
u[h-1][j] = r; /* connect to last table */
}
else
*t = q; /* first table is returned result */
r.base = (uInt)(q - u[h - 1] - j); /* offset to this table */
u[h - 1][j] = r; /* connect to last table */
} else
*t = q; /* first table is returned result */
}
/* set up table entry in r */
r.bits = (Byte)(k - w);
if (p >= v + n)
r.exop = 128 + 64; /* out of values--invalid code */
else if (*p < s)
{
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
r.base = *p++; /* simple code is just the value */
}
else
{
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
r.exop = 128 + 64; /* out of values--invalid code */
else if (*p < s) {
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
r.base = *p++; /* simple code is just the value */
} else {
r.exop = (Byte)(e[*p - s] + 16 + 64); /* non-simple--look up in lists */
r.base = d[*p++ - s];
}
@ -290,17 +273,15 @@ local int huft_build(uIntf *b, uInt n, uInt s, const uIntf *d, const uIntf *e, i
i ^= j;
/* backup over finished tables */
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
while ((i & mask) != x[h])
{
h--; /* don't need to update q */
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
while ((i & mask) != x[h]) {
h--; /* don't need to update q */
w -= l;
mask = (1 << w) - 1;
}
}
}
/* Return Z_BUF_ERROR if we were given an incomplete table */
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
}
@ -312,21 +293,18 @@ inflate_huft * FAR *tb; bits tree result
inflate_huft *hp; space for trees
z_streamp z; for messages
*/
int inflate_trees_bits(uIntf *c, uIntf *bb, inflate_huft * FAR *tb, inflate_huft *hp, z_streamp z)
{
int inflate_trees_bits(uIntf *c, uIntf *bb, inflate_huft *FAR *tb, inflate_huft *hp, z_streamp z) {
int r;
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
if ((v = (uIntf *)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
tb, bb, hp, &hn, v);
r = huft_build(c, 19, 19, (uIntf *)Z_NULL, (uIntf *)Z_NULL, tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
else if (r == Z_BUF_ERROR || *bb == 0)
{
z->msg = (char*)"incomplete dynamic bit lengths tree";
z->msg = (char *)"oversubscribed dynamic bit lengths tree";
else if (r == Z_BUF_ERROR || *bb == 0) {
z->msg = (char *)"incomplete dynamic bit lengths tree";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
@ -337,32 +315,30 @@ int inflate_trees_bits(uIntf *c, uIntf *bb, inflate_huft * FAR *tb, inflate_huft
uInt nl; number of literal/length codes
uInt nd; number of distance codes
uIntf *c; that many (total) code lengths
uIntf *bl; literal desired/actual bit depth
uIntf *bl; literal desired/actual bit depth
uIntf *bd; distance desired/actual bit depth
inflate_huft * FAR *tl; literal/length tree result
inflate_huft * FAR *td; distance tree result
inflate_huft *hp; space for trees
z_streamp z; for messages
*/
int inflate_trees_dynamic(uInt nl, uInt nd, uIntf *c, uIntf *bl, uIntf *bd, inflate_huft * FAR *tl, inflate_huft * FAR *td, inflate_huft *hp, z_streamp z)
{
int inflate_trees_dynamic(uInt nl, uInt nd, uIntf *c, uIntf *bl, uIntf *bd, inflate_huft *FAR *tl,
inflate_huft *FAR *td, inflate_huft *hp, z_streamp z) {
int r;
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
/* allocate work area */
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
if ((v = (uIntf *)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
/* build literal/length tree */
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
if (r != Z_OK || *bl == 0)
{
if (r != Z_OK || *bl == 0) {
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed literal/length tree";
else if (r != Z_MEM_ERROR)
{
z->msg = (char*)"incomplete literal/length tree";
z->msg = (char *)"oversubscribed literal/length tree";
else if (r != Z_MEM_ERROR) {
z->msg = (char *)"incomplete literal/length tree";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
@ -371,21 +347,18 @@ int inflate_trees_dynamic(uInt nl, uInt nd, uIntf *c, uIntf *bl, uIntf *bd, infl
/* build distance tree */
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
if (r != Z_OK || (*bd == 0 && nl > 257))
{
if (r != Z_OK || (*bd == 0 && nl > 257)) {
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed distance tree";
z->msg = (char *)"oversubscribed distance tree";
else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND
r = Z_OK;
}
#else
z->msg = (char*)"incomplete distance tree";
z->msg = (char *)"incomplete distance tree";
r = Z_DATA_ERROR;
}
else if (r != Z_MEM_ERROR)
{
z->msg = (char*)"empty distance tree with lengths";
} else if (r != Z_MEM_ERROR) {
z->msg = (char *)"empty distance tree with lengths";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
@ -398,11 +371,10 @@ int inflate_trees_dynamic(uInt nl, uInt nd, uIntf *c, uIntf *bl, uIntf *bd, infl
return Z_OK;
}
/* build fixed tables only once--keep them here */
#ifdef BUILDFIXED
local int fixed_built = 0;
#define FIXEDH 544 /* number of hufts used by fixed tables */
#define FIXEDH 544 /* number of hufts used by fixed tables */
local inflate_huft fixed_mem[FIXEDH];
local uInt fixed_bl;
local uInt fixed_bd;
@ -413,28 +385,25 @@ local inflate_huft *fixed_td;
#endif
/*
uIntf *bl; literal desired/actual bit depth
uIntf *bl; literal desired/actual bit depth
uIntf *bd; distance desired/actual bit depth
inflate_huft * FAR *tl; literal/length tree result
inflate_huft * FAR *td; distance tree result
inflate_huft * FAR *tl; literal/length tree result
inflate_huft * FAR *td; distance tree result
z_streamp z; for memory allocation
*/
int inflate_trees_fixed(uIntf *bl, uIntf *bd, inflate_huft * FAR *tl, inflate_huft * FAR *td, z_streamp z)
{
int inflate_trees_fixed(uIntf *bl, uIntf *bd, inflate_huft *FAR *tl, inflate_huft *FAR *td, z_streamp z) {
#ifdef BUILDFIXED
/* build fixed tables if not already */
if (!fixed_built)
{
int k; /* temporary variable */
uInt f = 0; /* number of hufts used in fixed_mem */
uIntf *c; /* length list for huft_build */
uIntf *v; /* work area for huft_build */
if (!fixed_built) {
int k; /* temporary variable */
uInt f = 0; /* number of hufts used in fixed_mem */
uIntf *c; /* length list for huft_build */
uIntf *v; /* work area for huft_build */
/* allocate memory */
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
if ((c = (uIntf *)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
{
if ((v = (uIntf *)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) {
ZFREE(z, c);
return Z_MEM_ERROR;
}
@ -449,15 +418,13 @@ int inflate_trees_fixed(uIntf *bl, uIntf *bd, inflate_huft * FAR *tl, inflate_hu
for (; k < 288; k++)
c[k] = 8;
fixed_bl = 9;
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
fixed_mem, &f, v);
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, fixed_mem, &f, v);
/* distance table */
for (k = 0; k < 30; k++)
c[k] = 5;
fixed_bd = 5;
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
fixed_mem, &f, v);
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, fixed_mem, &f, v);
/* done */
ZFREE(z, v);

View File

@ -1,21 +1,19 @@
/*
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
* $Logfile: $
* $Revision: $
* $Date: $
* $Author: $
*
* <insert description of file here>
*
* $Log: $
*
* $NoKeywords: $
*/
/* inflate_util.c -- data and routines common to blocks and codes
* Copyright (C) 1995-1998 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"
@ -24,19 +22,16 @@
#include "infcodes.h"
#include "infutil.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
struct inflate_codes_state {
int dummy;
}; /* for buggy compilers */
/* And'ing with mask[n] masks the lower n bits */
uInt inflate_mask[17] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
uInt inflate_mask[17] = {0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff};
/* copy as much as possible from the sliding window to the output area */
int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
{
int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r) {
uInt n;
Bytef *p;
Bytef *q;
@ -47,8 +42,10 @@ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
/* compute number of bytes to copy as far as end of window */
n = (uInt)((q <= s->write ? s->write : s->end) - q);
if (n > z->avail_out) n = z->avail_out;
if (n && r == Z_BUF_ERROR) r = Z_OK;
if (n > z->avail_out)
n = z->avail_out;
if (n && r == Z_BUF_ERROR)
r = Z_OK;
/* update counters */
z->avail_out -= n;
@ -64,8 +61,7 @@ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
q += n;
/* see if more to copy at beginning of window */
if (q == s->end)
{
if (q == s->end) {
/* wrap pointers */
q = s->window;
if (s->write == s->end)
@ -73,8 +69,10 @@ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r)
/* compute bytes to copy */
n = (uInt)(s->write - q);
if (n > z->avail_out) n = z->avail_out;
if (n && r == Z_BUF_ERROR) r = Z_OK;
if (n > z->avail_out)
n = z->avail_out;
if (n && r == Z_BUF_ERROR)
r = Z_OK;
/* update counters */
z->avail_out -= n;