Merged Ethan Lee's finishing Linux and MacOS X porting changes.

Added support for MacOS-specific keys to cl_keys.c.
This commit is contained in:
Knightmare66 2021-11-17 18:58:12 -05:00
parent 25d030bf19
commit 0dc88d405d
29 changed files with 4241 additions and 682 deletions

View file

@ -39,8 +39,15 @@ BUILD_DEBUG_DIR=build_debug
BUILD_RELEASE_DIR=build_release
BINDIR=quake2
ifeq ($(OSTYPE),Linux)
LDFLAGS+='-Wl,-rpath,$$ORIGIN/lib64'
else ifeq ($(OSTYPE),Darwin)
BASE_CFLAGS:=-mmacosx-version-min=10.9
LDFLAGS+='-Wl,-rpath,@executable_path/osx'
endif
CC?=gcc
BASE_CFLAGS=
BASE_CFLAGS?=
DEBUG_CFLAGS=$(BASE_CFLAGS) -g -ggdb -Wall -pipe
RELEASE_CFLAGS=$(BASE_CFLAGS) -O2 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations
@ -57,18 +64,11 @@ UNIX_DIR=$(MOUNT_DIR)/unix
GAME_DIR=$(MOUNT_DIR)/game
NULL_DIR=$(MOUNT_DIR)/null
ifeq ($(OSTYPE),FreeBSD)
LDFLAGS=-lm -lz
endif
ifeq ($(OSTYPE),Linux)
LDFLAGS=-lm -lz -lminizip
endif
#Ogg Vorbis support
LDFLAGS += \
-lvorbisfile \
-lvorbis \
-logg
LDFLAGS+=-lvorbisfile
#C runtime, zlib
LDFLAGS+=-lm -lz
#LOCALBASE?=/usr
LOCALBASE?=/usr/local
@ -99,7 +99,11 @@ ifeq ($(strip $(BUILD_LIBDIR)),YES)
BASE_CFLAGS+=-DLIBDIR='\"$(LIBDIR)\"'
endif
SHLIBEXT=so
ifeq ($(OSTYPE),Darwin)
SHLIBEXT=dylib
else
SHLIBEXT=so
endif
SHLIBCFLAGS=-fPIC
SHLIBLDFLAGS=-shared
@ -167,7 +171,7 @@ release:
$(BUILD_RELEASE_DIR)/ref_gl \
$(BUILD_RELEASE_DIR)/game
$(MAKE) targets BUILDDIR=$(BUILD_RELEASE_DIR) CFLAGS+="$(RELEASE_CFLAGS) -DKMQUAKE2_VERSION='\"$(VERSION)\"'"
$(MAKE) targets BUILDDIR=$(BUILD_RELEASE_DIR) CFLAGS+="$(RELEASE_CFLAGS) -DKMQUAKE2_VERSION='\"$(VERSION)\"' -DWINDOWNAME='\"$(WINDOWNAME)\"' -DSAVENAME='\"$(SAVENAME)\"'"
targets: $(TARGETS)
@ -241,6 +245,7 @@ QUAKE2_OBJS = \
$(BUILDDIR)/client/md4.o \
$(BUILDDIR)/client/net_chan.o \
$(BUILDDIR)/client/wildcard.o \
$(BUILDDIR)/client/zip.o \
$(BUILDDIR)/client/unzip.o \
$(BUILDDIR)/client/ioapi.o\
\
@ -290,9 +295,14 @@ QUAKE2_OBJS = \
$(BUILDDIR)/ref_gl/gl_sdl.o \
\
$(BUILDDIR)/ref_gl/qgl_unix.o \
$(BUILDDIR)/client/cd_unix.o \
$(BUILDDIR)/client/snd_sdl.o
ifeq ($(OSTYPE),Darwin)
QUAKE2_OBJS += $(BUILDDIR)/client/cd_null.o
else
QUAKE2_OBJS += $(BUILDDIR)/client/cd_unix.o
endif
QUAKE2_AS_OBJS = \
$(BUILDDIR)/client/snd_mixa.o
@ -524,6 +534,9 @@ $(BUILDDIR)/client/sv_world.o : $(SERVER_DIR)/sv_world.c
$(BUILDDIR)/client/cd_unix.o : $(UNIX_DIR)/cd_unix.c
$(DO_CC)
$(BUILDDIR)/client/cd_null.o : $(NULL_DIR)/cd_null.c
$(DO_CC)
$(BUILDDIR)/client/qsh_unix.o : $(UNIX_DIR)/qsh_unix.c
$(DO_CC)
@ -551,6 +564,9 @@ $(BUILDDIR)/client/net_udp.o : $(UNIX_DIR)/net_udp.c
$(BUILDDIR)/client/snd_sdl.o : $(UNIX_DIR)/snd_sdl.c
$(DO_CC) $(SDLCFLAGS)
$(BUILDDIR)/client/zip.o : $(UNIX_DIR)/zip/zip.c
$(DO_CC)
$(BUILDDIR)/client/unzip.o : $(UNIX_DIR)/zip/unzip.c
$(DO_CC)
@ -650,6 +666,7 @@ Q2DED_OBJS = \
$(BUILDDIR)/ded/md4.o \
$(BUILDDIR)/ded/net_chan.o \
$(BUILDDIR)/ded/wildcard.o \
$(BUILDDIR)/ded/zip.o \
$(BUILDDIR)/ded/unzip.o \
$(BUILDDIR)/ded/ioapi.o\
\
@ -703,6 +720,9 @@ $(BUILDDIR)/ded/net_chan.o : $(COMMON_DIR)/net_chan.c
$(BUILDDIR)/ded/wildcard.o : $(COMMON_DIR)/wildcard.c
$(DO_DED_CC)
$(BUILDDIR)/ded/zip.o : $(UNIX_DIR)/zip/zip.c
$(DO_DED_CC)
$(BUILDDIR)/ded/unzip.o : $(UNIX_DIR)/zip/unzip.c
$(DO_DED_CC)
@ -841,7 +861,7 @@ GAME_OBJS = \
$(BUILDDIR)/game/q_shared.o
$(BINDIR)/baseq2/kmq2game$(ARCH).$(SHLIBEXT) : $(GAME_OBJS)
$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(GAME_OBJS) -lGL
$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(GAME_OBJS)
$(BUILDDIR)/game/acebot_ai.o : $(GAME_DIR)/acebot_ai.c
$(DO_SHLIB_CC)

View file

@ -26,6 +26,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../win32/winquake.h"
#endif
#if defined(__APPLE__) || (MACOSX)
#include <ctype.h>
#endif // __APPLE__ || MACOSX
/*
key up events are sent even if in console mode
@ -67,7 +71,11 @@ keyname_t keynames[] =
{"LEFTARROW", K_LEFTARROW},
{"RIGHTARROW", K_RIGHTARROW},
#if defined(__APPLE__) || (MACOSX)
{"OPTION", K_ALT},
#else
{"ALT", K_ALT},
#endif // __APPLE__ || MACOSX
{"CTRL", K_CTRL},
{"SHIFT", K_SHIFT},
@ -94,6 +102,14 @@ keyname_t keynames[] =
{"NUMLOCK", K_NUMLOCK},
{"CAPSLOCK", K_CAPSLOCK},
{"SCROLLOCK", K_SCROLLOCK},
// {"PRINTSCRN", K_PRINTSCRN},
#if defined(__APPLE__) || (MACOSX)
{"F13", K_F13},
{"F14", K_F14},
{"F15", K_F15},
{"COMMAND", K_COMMAND},
#endif // __APPLE__ || MACOSX
{"MOUSE1", K_MOUSE1},
{"MOUSE2", K_MOUSE2},
@ -141,6 +157,25 @@ keyname_t keynames[] =
{"AUX31", K_AUX31},
{"AUX32", K_AUX32},
#if defined(__APPLE__) || (MACOSX)
{"KP_0", K_KP_INS},
{"KP_1", K_KP_END},
{"KP_2", K_KP_DOWNARROW},
{"KP_3", K_KP_PGDN},
{"KP_4", K_KP_LEFTARROW},
{"KP_5", K_KP_5},
{"KP_6", K_KP_RIGHTARROW},
{"KP_7", K_KP_HOME},
{"KP_8", K_KP_UPARROW},
{"KP_9", K_KP_PGUP},
{"KP_SLASH", K_KP_SLASH},
{"KP_MINUS", K_KP_MINUS},
{"KP_PLUS", K_KP_PLUS},
{"KP_MULT", K_KP_MULT},
{"KP_ENTER", K_KP_ENTER},
{"KP_DOT", K_KP_DEL},
{"KP_EQUAL", K_KP_EQUAL},
#else
{"KP_HOME", K_KP_HOME },
{"KP_UPARROW", K_KP_UPARROW },
{"KP_PGUP", K_KP_PGUP },
@ -157,6 +192,7 @@ keyname_t keynames[] =
{"KP_MINUS", K_KP_MINUS },
{"KP_PLUS", K_KP_PLUS },
{"KP_MULT", K_KP_MULT },
#endif // __APPLE__ || MACOSX
{"MWHEELUP", K_MWHEELUP },
{"MWHEELDOWN", K_MWHEELDOWN },
@ -205,6 +241,76 @@ void CompleteCommand (void)
}
}
/*
================
Key_ParseKeypad
================
*/
int Key_ParseKeypad (int inKey)
{
int outKey;
switch (inKey)
{
case K_KP_SLASH:
outKey = '/';
break;
case K_KP_MULT:
outKey = '*';
break;
case K_KP_MINUS:
outKey = '-';
break;
case K_KP_PLUS:
outKey = '+';
break;
case K_KP_HOME:
outKey = '7';
break;
case K_KP_UPARROW:
outKey = '8';
break;
case K_KP_PGUP:
outKey = '9';
break;
case K_KP_LEFTARROW:
outKey = '4';
break;
case K_KP_5:
outKey = '5';
break;
case K_KP_RIGHTARROW:
outKey = '6';
break;
case K_KP_END:
outKey = '1';
break;
case K_KP_DOWNARROW:
outKey = '2';
break;
case K_KP_PGDN:
outKey = '3';
break;
case K_KP_INS:
outKey = '0';
break;
case K_KP_DEL:
outKey = '.';
break;
#if defined(__APPLE__) || (MACOSX)
case K_KP_EQUAL:
outKey = '=';
break;
#endif // __APPLE__ || MACOSX
default:
outKey = inKey;
break;
}
return outKey;
}
/*
====================
Key_Console
@ -216,56 +322,13 @@ void Key_Console (int key)
{
int i;
switch ( key )
{
case K_KP_SLASH:
key = '/';
break;
case K_KP_MULT:
key = '*';
break;
case K_KP_MINUS:
key = '-';
break;
case K_KP_PLUS:
key = '+';
break;
case K_KP_HOME:
key = '7';
break;
case K_KP_UPARROW:
key = '8';
break;
case K_KP_PGUP:
key = '9';
break;
case K_KP_LEFTARROW:
key = '4';
break;
case K_KP_5:
key = '5';
break;
case K_KP_RIGHTARROW:
key = '6';
break;
case K_KP_END:
key = '1';
break;
case K_KP_DOWNARROW:
key = '2';
break;
case K_KP_PGDN:
key = '3';
break;
case K_KP_INS:
key = '0';
break;
case K_KP_DEL:
key = '.';
break;
}
key = Key_ParseKeypad (key);
#if defined(__APPLE__) || (MACOSX)
if ( ( toupper( key ) == 'V' && keydown[K_COMMAND] ) ||
#else
if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) ||
#endif // __APPLE__ || MACOSX
( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) )
{
char *cbd;
@ -628,6 +691,17 @@ int Key_StringToKeynum (char *str)
if (!str[1])
return str[0];
#if defined(__APPLE__) || (MACOSX)
if (!Q_strcasecmp (str, "ALT"))
{
for (kn=keynames ; kn->name ; kn++)
{
if (!Q_strcasecmp ("OPTION", kn->name))
return (kn->keynum);
}
}
#endif // __APPLE__ || MACOSX
for (kn=keynames ; kn->name ; kn++)
{
if (!Q_strcasecmp(str,kn->name))
@ -694,6 +768,15 @@ void Key_SetBinding (int keynum, char *binding)
Q_strncpyz (new, l+1, binding);
new[l] = 0;
keybindings[keynum] = new;
/*
#if defined(__APPLE__) || (MACOSX)
if (keynum == K_F12)
{
extern void IN_SetF12EjectEnabled (qboolean theState);
IN_SetF12EjectEnabled (keybindings[keynum][0] == 0x00);
}
#endif // __APPLE__ || MACOSX
*/
}
/*
@ -934,6 +1017,17 @@ void Key_Event (int key, qboolean down, unsigned time)
// update auto-repeat status
if (down)
{
/*
#if defined(__APPLE__) || (MACOSX)
extern int Sys_CheckSpecialKeys (int theKey);
// don't accept key down events at the loading screen!
if (cls.disable_screen == true || Sys_CheckSpecialKeys (key) != 0)
{
return;
}
#endif // __APPLE__ || MACOSX
*/
key_repeats[key]++;
if (key != K_BACKSPACE
&& key != K_UPARROW // added from Quake2max

View file

@ -2413,7 +2413,7 @@ Writes key bindings and archived cvars to config.cfg
qboolean CL_WriteConfiguration (char *cfgName)
{
FILE *f;
char path[MAX_QPATH];
char path[MAX_OSPATH];
if (!cfgName)
return false;

View file

@ -63,6 +63,13 @@ typedef enum {
K_CAPSLOCK,
K_SCROLLOCK,
#if defined(__APPLE__) || (MACOSX)
K_F13 = 156,
K_F14 = 157,
K_F15 = 158,
K_COMMAND = 159,
#endif // __APPLE__ || MACOSX
K_KP_HOME = 160,
K_KP_UPARROW,
K_KP_PGUP,
@ -80,6 +87,12 @@ typedef enum {
K_KP_PLUS,
K_KP_MULT,
#if defined(__APPLE__) || (MACOSX)
K_KP_EQUAL = 176,
#endif // __APPLE__ || MACOSX
// K_PRINTSCRN = 177,
K_PAUSE = 255,
//

View file

@ -358,13 +358,13 @@ sfxcache_t *S_LoadSound (sfx_t *s)
info = GetWavinfo (s->name, data, size);
/*if (info.channels != 1)
{
Com_Printf ("%s is a stereo sample\n",s->name);
Com_Printf ("%s is a stereo sample\n", s->name);
FS_FreeFile (data);
return NULL;
}*/
if (info.channels < 1 || info.channels > 2) //CDawg changed
if (info.channels < 1 || info.channels > 2) // CDawg changed
{
Com_Printf ("%s has an invalid number of channels\n", s->name);
Com_Printf ("%s has an invalid number of channels (%d)\n", s->name, info.channels);
FS_FreeFile (data);
return NULL;
}
@ -385,7 +385,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
sc->length = info.samples;
sc->loopstart = info.loopstart;
//sc->speed = info.rate;
sc->speed = info.rate * info.channels; //CDawg changed
sc->speed = info.rate * info.channels; // CDawg changed
sc->width = info.width;
sc->stereo = info.channels;
sc->music = !strncmp (namebuffer, "music/", 6);

View file

@ -78,11 +78,12 @@ typedef enum {false, true} qboolean;
# include <sys/types.h>
typedef SInt64 qint64;
typedef UInt64 uint64;
#elif defined(__APPLE__) || defined(MACOSX) // MacOS X Framework build
/*#elif defined(__APPLE__) || defined(MACOSX) // MacOS X Framework build
# include <sys/types.h>
typedef int64_t qint64;
typedef unsigned int64_t uint64;
#elif defined(__linux__) // Linux
#elif defined(__linux__) // Linux */
#elif defined(__linux__) || defined(__APPLE__) || defined(MACOSX) // Linux, MacOSX
# include <stdint.h>
typedef int64_t qint64;
typedef uint64_t uint64;

View file

@ -397,7 +397,7 @@ void ( APIENTRY * qglVertexPointer )(GLint size, GLenum type, GLsizei stride, co
void ( APIENTRY * qglViewport )(GLint x, GLint y, GLsizei width, GLsizei height);
// Knightmare added
void ( APIENTRY * qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
void ( APIENTRY * qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
void ( APIENTRY * qglLockArraysEXT)( GLint start, GLsizei count );
void ( APIENTRY * qglUnlockArraysEXT) ( void );
@ -3040,7 +3040,7 @@ void QGL_Shutdown( void )
qglXCopyContext = NULL;
qglXSwapBuffers = NULL;
qglDrawRangeElementsEXT = NULL;
qglDrawRangeElements = NULL;
qglLockArraysEXT = NULL;
qglUnlockArraysEXT = NULL;
//qglPointParameterfEXT = NULL;
@ -3505,7 +3505,7 @@ qboolean QGL_Init( const char *dllname )
qglXCopyContext = GPA("glXCopyContext");
qglXSwapBuffers = GPA("glXSwapBuffers");
qglDrawRangeElementsEXT = 0;
qglDrawRangeElements = 0;
qglLockArraysEXT = 0;
qglUnlockArraysEXT = 0;
//qglPointParameterfEXT = 0;

View file

@ -250,7 +250,7 @@ void *Sys_GetGameAPI (void *parms)
#elif defined __alpha__
const char *gamename = "kmq2gameaxp.so";
#elif defined __x86_64__
const char *gamename = "kmq2gamex86_64.so";
const char *gamename = "kmq2gamex64.so";
#elif defined __powerpc__
const char *gamename = "kmq2gameppc.so";
#elif defined __sparc__

View file

@ -22,32 +22,38 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../client/client.h"
void CDAudio_Play(int track, qboolean looping)
void CDAudio_Play (int track, qboolean looping)
{
}
void CDAudio_Stop(void)
void CDAudio_Stop (void)
{
}
void CDAudio_Resume(void)
void CDAudio_Resume (void)
{
}
void CDAudio_Update(void)
void CDAudio_Update (void)
{
}
int CDAudio_Init(void)
int CDAudio_Init (void)
{
return 0;
}
void CDAudio_Shutdown(void)
void CDAudio_Shutdown (void)
{
}
qboolean CDAudio_Active (void)
{
return 0;
}

View file

@ -143,7 +143,7 @@ void Com_Printf (char *fmt, ...)
// if (logfile_active && logfile_active->value)
if (logfile_active && logfile_active->integer)
{
char name[MAX_QPATH];
char name[MAX_OSPATH];
if (!logfile)
{
@ -1779,10 +1779,9 @@ void Qcommon_Frame (int msec)
if ( log_stats->modified )
{
log_stats->modified = false;
// if ( log_stats->value )
if ( log_stats->integer )
{
char name[MAX_QPATH];
char name[MAX_OSPATH];
if ( log_stats_file )
{

View file

@ -2532,7 +2532,11 @@ void FS_InitFilesystem (void)
// basedir <path>
// allows the game to run from outside the data tree
#if defined(__linux__) || defined(__APPLE__) || defined(MACOSX)
fs_basedir = Cvar_Get ("basedir", Sys_ExeDir(), CVAR_NOSET);
#else
fs_basedir = Cvar_Get ("basedir", ".", CVAR_NOSET);
#endif
Cvar_SetDescription ("basedir", "Sets the root folder where KMQuake2 mounts game directories. Only settable from the command line with +set basedir <dir>. Only change this if you want KMQ2 to run with data files outside the Quake2 folder.");
// cddir <path>
@ -2904,7 +2908,7 @@ FS_ExecAutoexec
void FS_ExecAutoexec (void)
{
char *dir;
char name[MAX_QPATH];
char name[MAX_OSPATH];
dir = Cvar_VariableString("gamedir");
if (*dir) {

View file

@ -28,6 +28,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../include/zlibpng/unzip.h"
#include "../include/zlibpng/zip.h"
#endif
#elif defined (__linux__)
#include "../unix/zip/unzip.h"
#include "../unix/zip/zip.h"
#else // _WIN32
#include <minizip/unzip.h>
#include <minizip/zip.h>

View file

@ -68,7 +68,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if defined (_M_X64) || defined (_M_AMD64) || defined (__x86_64__)
#define CPUSTRING "AMD64"
#define STOCK_Q2_GAME_LIBRARY_NAME "gamei386.so"
#define KMQ2_GAME_LIBRARY_NAME "kmq2gamex86_64.so"
#define KMQ2_GAME_LIBRARY_NAME "kmq2gamex64.so"
#elif defined __i386__
#define CPUSTRING "i386"
#define STOCK_Q2_GAME_LIBRARY_NAME "gamei386.so"
@ -99,8 +99,38 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define OS_STRING "MacOS"
// KMQ2 MacOSX port uses the Fruitz of Dojo plug system.
// Comment this out if you want to use dylibs.
#define USE_Q2PLUG
#if defined (_M_X64) || defined (_M_AMD64) || defined (__x86_64__)
#define CPUSTRING "AMD64"
#ifdef USE_Q2PLUG
#define STOCK_Q2_GAME_LIBRARY_NAME "GameMac.q2plug"
#define KMQ2_GAME_LIBRARY_NAME "GameMac.kmq2plug"
#else // USE_Q2PLUG
#define STOCK_Q2_GAME_LIBRARY_NAME "gamei386.dylib"
#define KMQ2_GAME_LIBRARY_NAME "kmq2gamex64.dylib"
#endif // USE_Q2PLUG
#elif defined __i386__
#define CPUSTRING "i386"
#ifdef USE_Q2PLUG
#define STOCK_Q2_GAME_LIBRARY_NAME "GameMac.q2plug"
#define KMQ2_GAME_LIBRARY_NAME "GameMac.kmq2plug"
#else // USE_Q2PLUG
#define STOCK_Q2_GAME_LIBRARY_NAME "gamei386.dylib"
#define KMQ2_GAME_LIBRARY_NAME "kmq2gamei386.dylib"
#endif // USE_Q2PLUG
#else
#define CPUSTRING "Unknown"
#endif
#else // !WIN32
@ -1051,5 +1081,11 @@ void SV_Init (void);
void SV_Shutdown (char *finalmsg, qboolean reconnect);
void SV_Frame (int msec);
#ifndef WINDOWNAME
#define WINDOWNAME "KMQuake2"
#endif
#ifndef SAVENAME
#define SAVENAME "quake2"
#endif
#endif // __QCOMMON_H

View file

@ -483,7 +483,8 @@ extern BOOL ( WINAPI * qwglSetDeviceGammaRamp3DFX ) ( HDC, LPVOID );
#endif
#ifdef __linux__
//#ifdef __linux__
#if defined(__linux__) || defined(__APPLE__) || defined(MACOSX)
// local function in dll
extern void *qwglGetProcAddress(char *symbol);

View file

@ -26,9 +26,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <stdio.h>
#if defined(__APPLE__) || (MACOSX)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include "glext.h" //Knightmare- MrG's shader waterwarp support
#endif // __APPLE__ || MACOSX
#include "glext.h" // Knightmare- MrG's shader waterwarp support
#include <math.h>
#ifndef __linux__

View file

@ -1209,7 +1209,7 @@ void R_Register (void)
r_3dlabs_broken = Cvar_Get( "r_3dlabs_broken", "1", CVAR_ARCHIVE );
Cvar_SetDescription ("r_3dlabs_broken", "Enables CDS hack for broken 3DLabs drivers.");
vid_fullscreen = Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE );
vid_fullscreen = Cvar_Get( "vid_fullscreen", "1", CVAR_ARCHIVE );
// Cvar_SetDescription ("vid_fullscreen", "Enables fullscreen video mode.");
Cvar_SetDescription ("vid_fullscreen", "Sets fullscreen or borderless video mode. 0 = windowed, 1 = fullscreen, 2 = borderless"); // borderless support
vid_gamma = Cvar_Get( "vid_gamma", "0.8", CVAR_ARCHIVE ); // was 1.0

View file

@ -8,19 +8,22 @@
glwstate_t glw_state;
int mx, my;
qboolean mouse_active = false;
int mx, my;
//qboolean mouse_active = false;
float controller_leftx, controller_lefty, controller_rightx, controller_righty;
extern cvar_t *in_joystick;
int GLimp_Init(void *hinstance, void *wndproc)
int GLimp_Init (void *hinstance, void *wndproc)
{
/* No-op */
return 1;
}
void GLimp_Shutdown(void)
void GLimp_Shutdown (void)
{
SDL_SetRelativeMouseMode(SDL_FALSE);
mouse_active = false;
// SDL_SetRelativeMouseMode(SDL_FALSE);
// mouse_active = false;
/* No-op */
}
void GLimp_BeginFrame(float camera_seperation)
@ -28,20 +31,29 @@ void GLimp_BeginFrame(float camera_seperation)
/* No-op */
}
void GLimp_EndFrame(void)
void GLimp_EndFrame (void)
{
SDL_GL_SwapWindow(glw_state.glWindow);
}
int GLimp_SetMode(int *pwidth, int *pheight, int mode, dispType_t fullscreen)
int GLimp_SetMode (int *pwidth, int *pheight, int mode, dispType_t fullscreen)
{
int width, height;
int width, height;
const char *steam_tenfoot = NULL;
if (!VID_GetModeInfo(&width, &height, mode))
{
Com_Printf(" invalid mode\n");
return rserr_invalid_mode;
}
/* For Big Picture/SteamOS, unconditionally use fullscreen */
steam_tenfoot = SDL_getenv("SteamTenfoot");
if (steam_tenfoot != NULL && SDL_strcmp(steam_tenfoot, "1") == 0)
{
fullscreen = dt_fullscreen;
}
if (fullscreen == dt_fullscreen)
{
/* Override the vidmode with the desktop resolution.
@ -79,19 +91,19 @@ int GLimp_SetMode(int *pwidth, int *pheight, int mode, dispType_t fullscreen)
return rserr_ok;
}
void UpdateGammaRamp(void)
void UpdateGammaRamp (void)
{
/* Unsupported in 2021 */
}
char *Sys_GetClipboardData(void)
char *Sys_GetClipboardData (void)
{
return SDL_GetClipboardText();
}
void IN_Activate(qboolean active)
void IN_Activate (qboolean active)
{
if (active)
/* if (active)
{
if (!mouse_active)
{
@ -107,7 +119,8 @@ void IN_Activate(qboolean active)
SDL_SetRelativeMouseMode(SDL_FALSE);
mouse_active = false;
}
}
} */
/* No-op */
}
/* IN_Translate functions taken from yquake2 */
@ -117,7 +130,7 @@ void IN_Activate(qboolean active)
* the id Tech 2 engines interal representation.
*/
static int
IN_TranslateSDLtoQ2Key(unsigned int keysym)
IN_TranslateSDLtoQ2Key (unsigned int keysym)
{
int key = 0;
@ -156,7 +169,6 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym)
key = K_RIGHTARROW;
break;
case SDLK_RALT:
case SDLK_LALT:
key = K_ALT;
@ -225,7 +237,6 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym)
key = K_F12;
break;
case SDLK_KP_7:
key = K_KP_HOME;
break;
@ -282,7 +293,64 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym)
return key;
}
void HandleEvents(void)
/* This however was devised by flibit to match the old TFOL binding layout */
static int
IN_TranslateSDLtoQ2Button(SDL_GameControllerButton button)
{
int key = 0;
switch (button)
{
case SDL_CONTROLLER_BUTTON_A:
key = K_JOY1;
break;
case SDL_CONTROLLER_BUTTON_B:
key = K_JOY2;
break;
case SDL_CONTROLLER_BUTTON_X:
key = K_JOY3;
break;
case SDL_CONTROLLER_BUTTON_Y:
key = K_JOY4;
break;
case SDL_CONTROLLER_BUTTON_BACK:
key = K_AUX7;
break;
case SDL_CONTROLLER_BUTTON_START:
key = K_AUX8;
break;
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
key = K_AUX9;
break;
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
key = K_AUX10;
break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
key = K_AUX5;
break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
key = K_AUX6;
break;
case SDL_CONTROLLER_BUTTON_DPAD_UP:
key = K_AUX29;
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
key = K_AUX31;
break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
key = K_AUX32;
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
key = K_AUX30;
break;
default:
break;
}
return key;
}
void HandleEvents (void)
{
int multiclicktime = 750;
SDL_Event evt;
@ -361,12 +429,14 @@ void HandleEvents(void)
}
else if (evt.type == SDL_MOUSEMOTION)
{
if (mouse_active)
/* if (mouse_active)
{
/* Relative should be on here */
// Relative should be on here
mx += evt.motion.xrel;
my += evt.motion.yrel;
}
} */
mx += evt.motion.xrel;
my += evt.motion.yrel;
}
else if (evt.type == SDL_MOUSEBUTTONDOWN)
{
@ -435,5 +505,96 @@ void HandleEvents(void)
Key_Event(dir, 1, Sys_Milliseconds());
Key_Event(dir, 0, Sys_Milliseconds());
}
// flibitijibibo added
else if (evt.type == SDL_CONTROLLERDEVICEADDED)
{
SDL_GameController *c = SDL_GameControllerOpen(evt.cdevice.which);
Com_DPrintf ("Connected %s\n", SDL_GameControllerName(c));
}
else if (evt.type == SDL_CONTROLLERDEVICEREMOVED)
{
SDL_GameController *c = SDL_GameControllerFromInstanceID(evt.cdevice.which);
Com_DPrintf ("Disconnected %s\n", SDL_GameControllerName(c));
SDL_GameControllerClose(c);
}
else if (evt.type == SDL_CONTROLLERBUTTONDOWN)
{
if (in_joystick->value)
{
Key_Event (
IN_TranslateSDLtoQ2Button(evt.cbutton.button),
1,
Sys_Milliseconds()
);
}
}
else if (evt.type == SDL_CONTROLLERBUTTONUP)
{
Key_Event (
IN_TranslateSDLtoQ2Button(evt.cbutton.button),
0,
Sys_Milliseconds()
);
}
else if (evt.type == SDL_CONTROLLERAXISMOTION)
{
if (evt.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT)
{
if (!in_joystick->value)
{
evt.caxis.value = 0;
}
Key_Event (
K_AUX27,
evt.caxis.value > 3855,
Sys_Milliseconds()
);
}
else if (evt.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
{
if (!in_joystick->value)
{
evt.caxis.value = 0;
}
Key_Event (
K_AUX28,
evt.caxis.value > 3855,
Sys_Milliseconds()
);
}
else if (evt.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX)
{
if ( !in_joystick->value || (SDL_abs(evt.caxis.value) <= 7849) )
{
evt.caxis.value = 0;
}
controller_leftx = evt.caxis.value / 32768.0f;
}
else if (evt.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY)
{
if ( !in_joystick->value || (SDL_abs(evt.caxis.value) <= 7849) )
{
evt.caxis.value = 0;
}
controller_lefty = evt.caxis.value / 32768.0f;
}
else if (evt.caxis.axis == SDL_CONTROLLER_AXIS_RIGHTX)
{
if ( !in_joystick->value || (SDL_abs(evt.caxis.value) <= 8689) )
{
evt.caxis.value = 0;
}
controller_rightx = evt.caxis.value / 32768.0f;
}
else if (evt.caxis.axis == SDL_CONTROLLER_AXIS_RIGHTY)
{
if ( !in_joystick->value || (SDL_abs(evt.caxis.value) <= 8689) )
{
evt.caxis.value = 0;
}
controller_righty = evt.caxis.value / 32768.0f;
}
}
// end flibitijibibo
}
}

View file

@ -20,14 +20,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#ifndef __linux__
#ifndef __FreeBSD__
#error You shouldnt be including this file on non-Linux platforms
#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__APPLE__)
#error You shouldn't be including this file on non-Linux platforms
#endif
#endif
#ifndef __GLW_LINUX_H__
#define __GLW_LINUX_H__
#ifndef __GLW_UNIX_H__
#define __GLW_UNIX_H__
typedef struct
{
@ -39,4 +38,4 @@ typedef struct
extern glwstate_t glw_state;
#endif
#endif // __GLW_UNIX_H__

View file

@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *in_mouse;
cvar_t *in_joystick;
extern int mx, my;
extern float controller_leftx, controller_lefty, controller_rightx, controller_righty;
static qboolean mouse_avail;
static int old_mouse_x, old_mouse_y;
@ -75,7 +76,11 @@ void IN_Init (void)
Cmd_AddCommand ("-mlook", IN_MLookUp);
Cmd_AddCommand ("force_centerview", Force_CenterView_f);
mx = my = 0.0;
mx = my = 0;
controller_leftx = 0.0f;
controller_lefty = 0.0f;
controller_rightx = 0.0f;
controller_righty = 0.0f;
if (in_mouse->value)
mouse_avail = true;
@ -107,6 +112,8 @@ void IN_Commands (void)
void IN_Move (usercmd_t *cmd)
{
float speed, aspeed;
if (!mouse_avail)
return;
@ -138,6 +145,9 @@ void IN_Move (usercmd_t *cmd)
if (ui_mousecursor.x > viddef.width) ui_mousecursor.x = viddef.width;
if (ui_mousecursor.y < 0) ui_mousecursor.y = 0;
if (ui_mousecursor.y > viddef.height) ui_mousecursor.y = viddef.height;
if (!cls.consoleActive)
UI_MouseCursor_Think ();
}
// psychospaz - zooming in preserves sensitivity

View file

@ -2669,10 +2669,11 @@ static void APIENTRY logViewport(GLint x, GLint y, GLsizei width, GLsizei height
**
** Unloads the specified DLL then nulls out all the proc pointers.
*/
void QGL_Shutdown( void )
void QGL_Shutdown (void)
{
if ( glw_state.glContext )
{
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_GL_DeleteContext(glw_state.glContext);
SDL_DestroyWindow(glw_state.glWindow);
}
@ -3028,7 +3029,7 @@ void QGL_Shutdown( void )
#define GPA( a ) SDL_GL_GetProcAddress( a )
void *qwglGetProcAddress(char *symbol)
void *qwglGetProcAddress (char *symbol)
{
if (glw_state.glContext)
return GPA ( symbol );
@ -3046,7 +3047,7 @@ void *qwglGetProcAddress(char *symbol)
**
*/
qboolean QGL_Init( const char *dllname )
qboolean QGL_Init (const char *dllnam )
{
// update 3Dfx gamma irrespective of underlying DLL
{
@ -3060,7 +3061,15 @@ qboolean QGL_Init( const char *dllname )
putenv( envbuffer );
}
SDL_Init(SDL_INIT_VIDEO);
// SDL_Init (SDL_INIT_VIDEO);
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
glw_state.glWindow = SDL_CreateWindow(
WINDOWNAME,
SDL_WINDOWPOS_CENTERED,
@ -3069,9 +3078,16 @@ qboolean QGL_Init( const char *dllname )
720,
SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN
);
#ifdef __linux__
SDL_Surface *icon = SDL_LoadBMP(WINDOWNAME ".bmp");
SDL_SetWindowIcon(glw_state.glWindow, icon);
SDL_FreeSurface(icon);
#endif
glw_state.glContext = SDL_GL_CreateContext(glw_state.glWindow);
SDL_SetRelativeMouseMode (SDL_TRUE);
glConfig.allowCDS = true;
glConfig.have_stencil = true;
qglAccum = dllAccum = GPA( "glAccum" );
qglAlphaFunc = dllAlphaFunc = GPA( "glAlphaFunc" );
@ -3472,7 +3488,7 @@ qboolean QGL_Init( const char *dllname )
return true;
}
void GLimp_EnableLogging( qboolean enable )
void GLimp_EnableLogging (qboolean enable)
{
if ( enable )
{
@ -4172,7 +4188,7 @@ void GLimp_EnableLogging( qboolean enable )
}
void GLimp_LogNewFrame( void )
void GLimp_LogNewFrame (void)
{
fprintf( glw_state.log_fp, "*** R_BeginFrame ***\n" );
}

View file

@ -239,22 +239,28 @@ Loads the game dll
void *Sys_GetGameAPI (void *parms)
{
void *(*GetGameAPI) (void *);
char name[MAX_OSPATH];
char curpath[MAX_OSPATH];
char *path;
#ifdef (__APPLE__)
// KMQ2 MacOSX port uses the Fruitz of Dojo plug system. So this will go unused.
#define LIB_SUFFIX "dylib"
#else
#define LIB_SUFFIX "so"
#endif
// Knightmare- changed game library name for better cohabitation
#ifdef __i386__
const char *gamename = "kmq2gamei386.so";
const char *gamename = "kmq2gamei386." LIB_SUFFIX;
#elif defined __alpha__
const char *gamename = "kmq2gameaxp.so";
const char *gamename = "kmq2gameaxp." LIB_SUFFIX;
#elif defined __x86_64__
const char *gamename = "kmq2gamex86_64.so";
const char *gamename = "kmq2gamex64." LIB_SUFFIX;
#elif defined __powerpc__
const char *gamename = "kmq2gameppc.so";
const char *gamename = "kmq2gameppc." LIB_SUFFIX;
#elif defined __sparc__
const char *gamename = "kmq2gamesparc.so";
const char *gamename = "kmq2gamesparc." LIB_SUFFIX;
#else
#error Unknown arch
#endif
@ -276,7 +282,14 @@ void *Sys_GetGameAPI (void *parms)
path = FS_NextPath (path);
if (!path)
return NULL; // couldn't find one anywhere
sprintf (name, "%s/%s/%s", curpath, path, gamename);
// Com_sprintf (name, sizeof(name), "%s/%s/%s", curpath, path, gamename);
if (path[0] == '/') {
// Path is rooted, override curpath
Com_sprintf (name, sizeof(name), "%s/%s", path, gamename);
}
else {
Com_sprintf (name, sizeof(name), "%s/%s/%s", curpath, path, gamename);
}
game_library = SDL_LoadObject (name);
if (game_library)
{
@ -381,8 +394,9 @@ int main (int argc, char **argv)
printf ("\n");
printf ("========= Initialization =================\n");
printf ("KMQuake2 -- Version 0.20\n");
printf ("KMQuake2 -- Version 0.20u8\n");
printf ("Linux Port by QuDos\n");
printf ("SDL2 Port by flibitijibibo\n");
printf ("http://qudos.quakedev.com/\n");
printf ("Compiled: "__DATE__" -- "__TIME__"\n");
printf ("==========================================\n\n");

View file

@ -286,7 +286,7 @@ void VID_Init (void)
Cvar_SetDescription ("vid_xpos", "Sets horizontal desktop position of window in windowed mode.");
vid_ypos = Cvar_Get ("vid_ypos", "22", CVAR_ARCHIVE);
Cvar_SetDescription ("vid_ypos", "Sets vertical desktop position of window in windowed mode.");
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE);
vid_fullscreen = Cvar_Get ("vid_fullscreen", "1", CVAR_ARCHIVE);
// Cvar_SetDescription ("vid_fullscreen", "Enables fullscreen video mode.");
Cvar_SetDescription ("vid_fullscreen", "Sets fullscreen or borderless video mode. 0 = windowed, 1 = fullscreen, 2 = borderless"); // borderless support
vid_gamma = Cvar_Get( "vid_gamma", "0.8", CVAR_ARCHIVE );

View file

@ -32,7 +32,7 @@
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
@ -45,7 +45,7 @@ static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
{
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
@ -62,7 +62,7 @@ static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int
* Initialize the encryption keys and the random header according to
* the given password.
*/
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
@ -87,13 +87,12 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned lon
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
const char *passwd; /* password string */
unsigned char *buf; /* where to write header */
int bufSize;
unsigned long* pkeys;
const unsigned long* pcrc_32_tab;
unsigned long crcForCrypting;
static int crypthead(const char* passwd, /* password string */
unsigned char* buf, /* where to write header */
int bufSize,
unsigned long* pkeys,
const z_crc_t* pcrc_32_tab,
unsigned long crcForCrypting)
{
int n; /* index in random header */
int t; /* temporary */
@ -124,8 +123,8 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
{
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
}
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
return n;
}

View file

@ -1,74 +1,98 @@
/* ioapi.c -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
/* ioapi.h -- IO base function header for compress/uncompress .zip
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
For more info read MiniZip_info.txt
Copyright (C) 1998-2005 Gilles Vollant
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
#define _CRT_SECURE_NO_WARNINGS
#endif
#if defined(__APPLE__) || defined(IOAPI_NO_64)
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
#define FTELLO_FUNC(stream) ftello(stream)
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
#else
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
#define FTELLO_FUNC(stream) ftello64(stream)
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
#endif
#include "zlib.h"
#include "ioapi.h"
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
{
if (pfilefunc->zfile_func64.zopen64_file != NULL)
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
else
{
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
}
}
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
{
if (pfilefunc->zfile_func64.zseek64_file != NULL)
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
else
{
uLong offsetTruncated = (uLong)offset;
if (offsetTruncated != offset)
return -1;
else
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
}
}
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
{
if (pfilefunc->zfile_func64.zseek64_file != NULL)
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
else
{
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
if ((tell_uLong) == MAXU32)
return (ZPOS64_T)-1;
else
return tell_uLong;
}
}
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
{
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
}
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
#ifndef SEEK_END
#define SEEK_END 2
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
voidpf ZCALLBACK fopen_file_func OF((
voidpf opaque,
const char* filename,
int mode));
uLong ZCALLBACK fread_file_func OF((
voidpf opaque,
voidpf stream,
void* buf,
uLong size));
uLong ZCALLBACK fwrite_file_func OF((
voidpf opaque,
voidpf stream,
const void* buf,
uLong size));
long ZCALLBACK ftell_file_func OF((
voidpf opaque,
voidpf stream));
long ZCALLBACK fseek_file_func OF((
voidpf opaque,
voidpf stream,
uLong offset,
int origin));
int ZCALLBACK fclose_file_func OF((
voidpf opaque,
voidpf stream));
int ZCALLBACK ferror_file_func OF((
voidpf opaque,
voidpf stream));
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
voidpf opaque;
const char* filename;
int mode;
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
{
FILE* file = NULL;
const char* mode_fopen = NULL;
@ -86,44 +110,55 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
return file;
}
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
{
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
mode_fopen = "r+b";
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
mode_fopen = "wb";
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
void* buf;
uLong size;
if ((filename!=NULL) && (mode_fopen != NULL))
file = FOPEN_FUNC((const char*)filename, mode_fopen);
return file;
}
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
{
uLong ret;
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
const void* buf;
uLong size;
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
{
uLong ret;
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
long ZCALLBACK ftell_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
{
long ret;
ret = ftell((FILE *)stream);
return ret;
}
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
uLong offset;
int origin;
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
{
ZPOS64_T ret;
ret = FTELLO_FUNC((FILE *)stream);
return ret;
}
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
{
int fseek_origin=0;
long ret;
@ -141,22 +176,45 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
default: return -1;
}
ret = 0;
fseek((FILE *)stream, offset, fseek_origin);
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
ret = -1;
return ret;
}
int ZCALLBACK fclose_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
{
int fseek_origin=0;
long ret;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
fseek_origin = SEEK_CUR;
break;
case ZLIB_FILEFUNC_SEEK_END :
fseek_origin = SEEK_END;
break;
case ZLIB_FILEFUNC_SEEK_SET :
fseek_origin = SEEK_SET;
break;
default: return -1;
}
ret = 0;
if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
ret = -1;
return ret;
}
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
{
int ret;
ret = fclose((FILE *)stream);
return ret;
}
int ZCALLBACK ferror_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
{
int ret;
ret = ferror((FILE *)stream);
@ -175,3 +233,15 @@ void fill_fopen_filefunc (pzlib_filefunc_def)
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
pzlib_filefunc_def->zread_file = fread_file_func;
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
pzlib_filefunc_def->zclose_file = fclose_file_func;
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}

View file

@ -1,13 +1,112 @@
/* ioapi.h -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
For more info read MiniZip_info.txt
Changes
Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
More if/def section may be needed to support other platforms
Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
(but you should use iowin32.c for windows instead)
Copyright (C) 1998-2005 Gilles Vollant
*/
#ifndef _ZLIBIOAPI_H
#define _ZLIBIOAPI_H
#ifndef _ZLIBIOAPI64_H
#define _ZLIBIOAPI64_H
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
// Linux needs this to support file operation on files larger then 4+GB
// But might need better if/def to select just the platforms that needs them.
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BIT
#define _FILE_OFFSET_BIT 64
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include "zlib.h"
#if defined(USE_FILE32API)
#define fopen64 fopen
#define ftello64 ftell
#define fseeko64 fseek
#else
#ifdef __FreeBSD__
#define fopen64 fopen
#define ftello64 ftello
#define fseeko64 fseeko
#endif
#ifdef _MSC_VER
#define fopen64 fopen
#if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
#define ftello64 _ftelli64
#define fseeko64 _fseeki64
#else // old MSC
#define ftello64 ftell
#define fseeko64 fseek
#endif
#endif
#endif
/*
#ifndef ZPOS64_T
#ifdef _WIN32
#define ZPOS64_T fpos_t
#else
#include <stdint.h>
#define ZPOS64_T uint64_t
#endif
#endif
*/
#ifdef HAVE_MINIZIP64_CONF_H
#include "mz64conf.h"
#endif
/* a type choosen by DEFINE */
#ifdef HAVE_64BIT_INT_CUSTOM
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
#else
#ifdef HAS_STDINT_H
#include "stdint.h"
typedef uint64_t ZPOS64_T;
#else
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
#define MAXU32 0xffffffff
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ZPOS64_T;
#else
typedef unsigned long long int ZPOS64_T;
#endif
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define ZLIB_FILEFUNC_SEEK_CUR (1)
@ -23,26 +122,27 @@
#ifndef ZCALLBACK
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
#define ZCALLBACK CALLBACK
#else
#define ZCALLBACK
#endif
#if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
#define ZCALLBACK CALLBACK
#else
#define ZCALLBACK
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
/* here is the "old" 32 bits structure structure */
typedef struct zlib_filefunc_def_s
{
open_file_func zopen_file;
@ -55,21 +155,54 @@ typedef struct zlib_filefunc_def_s
voidpf opaque;
} zlib_filefunc_def;
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
typedef struct zlib_filefunc64_def_s
{
open64_file_func zopen64_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell64_file_func ztell64_file;
seek64_file_func zseek64_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
voidpf opaque;
} zlib_filefunc64_def;
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
/* now internal definition, only for zip.c and unzip.h */
typedef struct zlib_filefunc64_32_def_s
{
zlib_filefunc64_def zfile_func64;
open_file_func zopen32_file;
tell_file_func ztell32_file;
seek_file_func zseek32_file;
} zlib_filefunc64_32_def;
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,20 +1,20 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.01e, February 12th, 2005
Version 1.1, February 14h, 2010
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Copyright (C) 1998-2005 Gilles Vollant
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Multi volume ZipFile (span) are not supported.
Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
For more info read MiniZip_info.txt
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
---------------------------------------------------------------------------------
Condition of use and distribution are the same than zlib :
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -32,18 +32,16 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
---------------------------------------------------------------------------------
Changes
See header of unzip64.c
*/
/* for more info about .ZIP format, see
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
http://www.info-zip.org/pub/infozip/doc/
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _unz_H
#define _unz_H
#ifndef _unz64_H
#define _unz64_H
#ifdef __cplusplus
extern "C" {
@ -53,10 +51,16 @@ extern "C" {
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#ifdef HAVE_BZIP2
#include "bzlib.h"
#endif
#define Z_BZIP2ED 12
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
@ -89,15 +93,42 @@ typedef struct tm_unz_s
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info64_s
{
ZPOS64_T number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info64;
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info64_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
ZPOS64_T compressed_size; /* compressed size 8 bytes */
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
} unz_file_info64;
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
@ -133,6 +164,7 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
extern unzFile ZEXPORT unzOpen OF((const char *path));
extern unzFile ZEXPORT unzOpen64 OF((const void *path));
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
@ -141,8 +173,14 @@ extern unzFile ZEXPORT unzOpen OF((const char *path));
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
the "64" function take a const void* pointer, because the path is just the
value passed to the open64_file_func callback.
Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
does not describe the reality
*/
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
zlib_filefunc_def* pzlib_filefunc_def));
/*
@ -150,15 +188,25 @@ extern unzFile ZEXPORT unzOpen2 OF((const char *path,
for read/write the zip file (see ioapi.h)
*/
extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
zlib_filefunc64_def* pzlib_filefunc_def));
/*
Open a Zip file, like unz64Open, but provide a set of file low level API
for read/write the zip file (see ioapi.h)
*/
extern int ZEXPORT unzClose OF((unzFile file));
/*
Close a ZipFile opened with unzipOpen.
Close a ZipFile opened with unzOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
these files MUST be closed with unzCloseCurrentFile before call unzClose.
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
unz_global_info *pglobal_info));
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
unz_global_info64 *pglobal_info));
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
@ -221,8 +269,31 @@ extern int ZEXPORT unzGoToFilePos(
unzFile file,
unz_file_pos* file_pos);
typedef struct unz64_file_pos_s
{
ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
ZPOS64_T num_of_file; /* # of file */
} unz64_file_pos;
extern int ZEXPORT unzGetFilePos64(
unzFile file,
unz64_file_pos* file_pos);
extern int ZEXPORT unzGoToFilePos64(
unzFile file,
const unz64_file_pos* file_pos);
/* ****************************************** */
extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
unz_file_info64 *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize));
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
unz_file_info *pfile_info,
char *szFileName,
@ -244,6 +315,14 @@ extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
(commentBufferSize is the size of the buffer)
*/
/** Addition for GDAL : START */
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
/** Addition for GDAL : END */
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
@ -312,6 +391,8 @@ extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
*/
extern z_off_t ZEXPORT unztell OF((unzFile file));
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
/*
Give the current position in uncompressed data
*/
@ -340,9 +421,11 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
/***************************************************************************/
/* Get the current file offset */
extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
extern uLong ZEXPORT unzGetOffset (unzFile file);
/* Set the current file offset */
extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
@ -351,4 +434,4 @@ extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
}
#endif
#endif /* _unz_H */
#endif /* _unz64_H */

2007
unix/zip/zip.c Normal file

File diff suppressed because it is too large Load diff

362
unix/zip/zip.h Normal file
View file

@ -0,0 +1,362 @@
/* zip.h -- IO on .zip files using zlib
Version 1.1, February 14h, 2010
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
For more info read MiniZip_info.txt
---------------------------------------------------------------------------
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
---------------------------------------------------------------------------
Changes
See header of zip.h
*/
#ifndef _zip12_H
#define _zip12_H
#ifdef __cplusplus
extern "C" {
#endif
//#define HAVE_BZIP2
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#ifdef HAVE_BZIP2
#include "bzlib.h"
#endif
#define Z_BZIP2ED 12
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagzipFile__ { int unused; } zipFile__;
typedef zipFile__ *zipFile;
#else
typedef voidp zipFile;
#endif
#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_PARAMERROR (-102)
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
# else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
# endif
#endif
/* default memLevel */
/* tm_zip contain date/time info */
typedef struct tm_zip_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_zip;
typedef struct
{
tm_zip tmz_date; /* date in understandable format */
uLong dosDate; /* if dos_date == 0, tmu_date is used */
/* uLong flag; */ /* general purpose bit flag 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
typedef const char* zipcharpc;
#define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2)
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
/*
Create a zipfile.
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
an Unix computer "zlib/zlib113.zip".
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
will be created at the end of the file.
(useful if the file contain a self extractor code)
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
add files in existing zip (be sure you don't add file that doesn't exist)
If the zipfile cannot be opened, the return value is NULL.
Else, the return value is a zipFile Handle, usable with other function
of this zip package.
*/
/* Note : there is no delete function into a zipfile.
If you want delete file into a zipfile, you must open a zipfile, and create another
Of couse, you can use RAW reading and writing to copy the file you did not want delte
*/
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
int append,
zipcharpc* globalcomment,
zlib_filefunc_def* pzlib_filefunc_def));
extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
int append,
zipcharpc* globalcomment,
zlib_filefunc64_def* pzlib_filefunc_def));
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level));
extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int zip64));
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
this MUST be '1' if the uncompressed size is >= 0xffffffff.
*/
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw));
extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int zip64));
/*
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
*/
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCrypting));
extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCrypting,
int zip64
));
/*
Same than zipOpenNewFileInZip2, except
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
password : crypting password (NULL for no crypting)
crcForCrypting : crc of file to compress (needed for crypting)
*/
extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCrypting,
uLong versionMadeBy,
uLong flagBase
));
extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCrypting,
uLong versionMadeBy,
uLong flagBase,
int zip64
));
/*
Same than zipOpenNewFileInZip4, except
versionMadeBy : value for Version made by field
flag : value for flag field (compression level info will be added)
*/
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
const void* buf,
unsigned len));
/*
Write data in the zipfile
*/
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
/*
Close the current file in the zipfile
*/
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
uLong uncompressed_size,
uLong crc32));
extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
ZPOS64_T uncompressed_size,
uLong crc32));
/*
Close the current file in the zipfile, for file opened with
parameter raw=1 in zipOpenNewFileInZip2
uncompressed_size and crc32 are value for the uncompressed size
*/
extern int ZEXPORT zipClose OF((zipFile file,
const char* global_comment));
/*
Close the zipfile
*/
extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
/*
zipRemoveExtraInfoBlock - Added by Mathias Svensson
Remove extra information block from a extra information data for the local file header or central directory header
It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
0x0001 is the signature header for the ZIP64 extra information blocks
usage.
Remove ZIP64 Extra information from a central director extra field data
zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
Remove ZIP64 Extra information from a Local File Header extra field data
zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
*/
#ifdef __cplusplus
}
#endif
#endif /* _zip64_H */