// PCompress Library
// Copyright (C) 1999 Britt Yenne
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU Library General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// 
// To contact the author, visit:  http://www.jump.net/~syenne/pilot/

#if defined(_AIX) || defined(linux)
# define UNIX
#endif

// Types
//
typedef unsigned char	u8bit;
typedef signed char	s8bit;
typedef unsigned short	u16bit;
typedef signed short	s16bit;
typedef unsigned long	u32bit;
typedef signed long	s32bit;
#ifdef UNIX
  typedef u16bit	UInt;
#endif

typedef struct {
  u8bit *ptr;		// pointer, offset by vector start extent
  u32bit extent;	// extent from offset zero in database
  void *handle;		// caller-specific data
} Vector;

#if defined(PCOMP_INTERNAL) || !defined(PCOMP_SHLIB)
# include "pcomp_int.h"
# define FDECL(type,fn,trap,args) extern type fn args
#else
  typedef void *PCompCtl;
# define FDECL(type,fn,trap,args) type fn args SYS_TRAP(trap)
#endif

// Arguments for PCompGet() and PCompSet().
//
#define pCompLevel	1	// compression level
#define pCompProgress	2	// progress function ptr
#define pCompFlush	3	// flush function ptr
#define pCompNewRecord	4	// new record function ptr
#define pCompNewSection	5	// new section function ptr
#define pCompGetChunk	6	// get chunk function ptr
#define pCompUserData	7	// user data field

// Function return codes
//
#define rcFail		-1	// system or internal failure
#define rcNoMem		-2	// out of process memory
#define rcBadData	-3	// compressed data invalid or corrupted
#define rcBadVersion	-4	// data written by later PCompress version
#define rcCancel	-5	// cancelled at user request
#define rcCantCompress	-7	// file data cannot be compressed further

#define rcUserDefined	-100	// start of user defined return codes

// Prototypes
//
FDECL(s16bit, PCompLibOpen, sysLibTrapOpen, (u16bit));
FDECL(s16bit, PCompLibClose, sysLibTrapClose, (u16bit, u16bit*));
FDECL(s16bit, PCompLibSleep, sysLibTrapSleep, (u16bit));
FDECL(s16bit, PCompLibWake, sysLibTrapWake, (u16bit));
FDECL(PCompCtl, PCompOpen, sysLibTrapCustom,
  (u16bit, void*(*Alloc)(u32bit), void (*Free)(void*)));
FDECL(void, PCompClose, sysLibTrapCustom+1, (u16bit, PCompCtl));
FDECL(void*, PCompGet, sysLibTrapCustom+2, (u16bit, PCompCtl, u8bit));
FDECL(int, PCompSet, sysLibTrapCustom+3, (u16bit, PCompCtl, u8bit, void*));
FDECL(s32bit, PCompDeflate, sysLibTrapCustom+4,
  (u16bit, PCompCtl, Vector*, s32bit, u8bit));
FDECL(int, PCompBuildTree, sysLibTrapCustom+5, (u16bit, PCompCtl));
FDECL(s32bit, PCompEncode, sysLibTrapCustom+6, (u16bit, PCompCtl));
FDECL(s32bit, PCompDecode, sysLibTrapCustom+7, (u16bit, PCompCtl));
#undef FDECL
