This commit is contained in:
Daveo 2000-12-04 14:13:40 +00:00
parent 8788076d39
commit 1c5c1b4011
59 changed files with 24871 additions and 56 deletions

138
Utils/Libs/GLib/BITS.CPP Normal file
View File

@ -0,0 +1,138 @@
//===========================================================================
//
// BITS.CPP
//
// Author: Graeme Webb
// Created: 3rd August 1996
// Project: General C++ Library
// Purpose: Bit stream object
//
// Copyright (c) 1996 Graeme Webb
//
//===========================================================================
// Revision history:
//===========================================================================
#include "gtypes.h"
#include "bits.hpp"
//===========================================================================
BitStream::BitStream(byte *ptr)
{
baseptr = (byte *) ptr;
currptr = (byte *) ptr;
bitpos = 0;
mask = 0x01;
}
BitStream::~BitStream()
{
}
void BitStream::IncCurPtr(void)
{
currptr++;
}
void BitStream::PutBit(uint bit)
{
if (mask == 0x01)
{
*currptr = (bit ? mask : 0);
bitpos++;
mask <<= 1;
}
else
{
*currptr |= (bit ? mask : 0);
bitpos++;
if (mask == 0x80)
{
IncCurPtr();
mask = 0x01;
}
else
{
mask <<= 1;
}
}
}
void BitStream::PutBits(ulong bits, uint len)
{
uint i;
for (i = 0; i < len; i++)
{
PutBit(bits & 1);
bits >>= 1;
}
}
uint BitStream::GetBit()
{
uint bit;
bit = (*currptr & mask) ? 1 : 0;
bitpos++;
if (mask == 0x80)
{
IncCurPtr();
mask = 0x01;
}
else
{
mask <<= 1;
}
return bit;
}
ulong BitStream::GetBits(uint len)
{
uint i;
ulong bits, mbit;
bits = 0;
mbit = 1;
for (i = 0; i < len; i++)
{
if (GetBit())
bits |= mbit;
mbit <<= 1;
}
return bits;
}
static inline ulong RoundUp(ulong value, uint align)
{
value += align - 1;
return (value - value % align);
}
void BitStream::Align(uint bytes)
{
ulong bytepos, nextpos;
bytepos = ByteLength();
nextpos = RoundUp(bytepos,bytes);
currptr = baseptr + bytepos;
while (bytepos < nextpos)
{
*currptr=0;
IncCurPtr();
bytepos++;
}
bitpos = bytepos * 8;
mask = 0x01;
}
//===========================================================================

49
Utils/Libs/GLib/BITS.HPP Normal file
View File

@ -0,0 +1,49 @@
//===========================================================================
//
// BITS.HPP
//
// Author: Graeme Webb
// Created: 3rd August 1996
// Project: General C++ Library
// Purpose: Bit stream declarations
//
// Copyright (c) 1996 Graeme Webb
//
//===========================================================================
// Revision history:
//===========================================================================
#ifndef __BITS_HPP__
#define __BITS_HPP__
//===========================================================================
#include <gtypes.h>
//===========================================================================
class BitStream
{
byte * baseptr;
byte * currptr;
ulong bitpos;
byte mask;
void IncCurPtr(void);
public:
BitStream(byte *ptr);
~BitStream();
void PutBit(uint bit);
void PutBits(ulong bits, uint len);
uint GetBit();
ulong GetBits(uint len);
void Align(uint bytes=1);
byte *CurrPtr() { return currptr; }
ulong BitLength() { return bitpos; }
ulong ByteLength() { return (bitpos+7)/8; }
};
//===========================================================================
#endif

1049
Utils/Libs/GLib/Dpanim.cpp Normal file

File diff suppressed because it is too large Load Diff

180
Utils/Libs/GLib/Dpanim.hpp Normal file
View File

@ -0,0 +1,180 @@
/*=========================================================================
DPANM.HPP
Author: Gary Liddon @ Fareham
Created:
Project:
Purpose:
Copyright (c) 1997 Gary Liddon
===========================================================================*/
#ifndef __DPANM_HPP__
#define __DPANM_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <fstream>
#include <vector>
/* Glib
---- */
/* Local
----- */
#include "gtypes.h"
#include "ganim.hpp"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
#define MAX_LARGE_PAGE 256
#define MAX_RECORDS_PER_LP 256
/*----------------------------------------------------------------------
Class defintions
---------------- */
class CompFrame;
class LpObj;
typedef std::vector<LpObj> LpObjVec;
class GLIB_API DpAnimFilter : public GAnimFilter
{
public:
DpAnimFilter();
~DpAnimFilter(void);
DpAnimFilter(char const * FName);
virtual bool Load(GAnim & Anm);
virtual bool Save(GAnim & Anm);
virtual GAnimFilter * Create(char const * Name) {return (new DpAnimFilter(Name));}
protected:
class AnimHdr
{
public:
AnimHdr();
void InitHdr(void);
ULONG id; // ID == "IPF "
UWORD maxLps; // Maximum Number of LPs
UWORD nLps; // Number of LPs in file
ULONG lRecords; // Number of records in file
UWORD maxRecsPerLp; // Maximum number of records per LP
UWORD lpfTableOffset; // Offset to start of LP Table
ULONG contentType; // == "ANIM"
UWORD width; // Width in pixels of drawing
UWORD height; // Height in pixel of drawing
UBYTE variant;
UBYTE version;
UBYTE hasLastDelta; // Has a delta for first to last
UBYTE lastDeltaValid; // The delta is valid
UBYTE pixelType;
UBYTE highestBBComp;
UBYTE otherRecordsPerFrame;
UBYTE bitmapRecordsPerFrame;
UBYTE recordTypes[32];
ULONG nFrames; // Number of frames in the file
UWORD framesPerSecond;
UWORD pad2[29];
};
struct ColCycles
{
ColCycles();
UWORD count;
UWORD rate;
UWORD flags;
UBYTE low, high;
};
struct LpTable
{
UWORD baseRecord;
UWORD nRecords;
UWORD nBytes;
};
struct LpTableMem
{
UWORD baseRecord;
UWORD nRecords;
UWORD nBytes;
UWORD size[MAX_RECORDS_PER_LP];
};
protected:
void GetPal(Palette & MyPal);
ULONG anm_init2(char const * filename);
ULONG anm_init(FILE * filename);
int anm_read_next_frame(void);
void anm_read_first_frame(void);
void read_LP(UWORD LP_to_load);
void PlayRunSkipDump(UBYTE const *src, UBYTE *dst);
UWORD loaded_LP; // Which LP is currently loaded
UWORD current_Frame; // Which frame is being displayed
FILE * inANM; // Input anm file
UBYTE * lp_buffer; // Input buffer for the currently loaded LP
UBYTE * dst_buffer; // Location to play the frames to
void InitVars(void);
void MakeVars(void);
void DeleteVars(void);
AnimHdr lpfHdr;
ColCycles Color_Cycles;
LpTable * lpfTable;
LpTableMem * current_LP;
void MakeAnim(void);
void WriteHdr(std::ofstream & Out,AnimHdr & A);
void WriteCycs(std::ofstream & Out);
void WritePal(std::ofstream & Out,Palette const & P);
void WriteLpTable(std::ofstream & Out,LpObjVec & LpTable);
void WriteLps(std::ofstream & Out,LpObjVec & LpTable);
void DiscardAnim(void);
void Encode(Frame const & Fr,CompFrame & Cfr);
void WriteRun(u8 Val,int Length,CompFrame &Cfr);
void WriteDataRun(u8 const * Data,int Length,CompFrame &Cfr);
int GetDataLength(u8 const * Src,int BytesLeft);
int GetRunLength(u8 const * Src,int BytesLeft);
void WriteEnd(CompFrame &Cfr);
enum
{
// MAX_RUN_WRITE = 16384-10
MAX_RUN_WRITE = 10240
};
};
/*---------------------------------------------------------------------- */
#endif /* __DPANM_HPP__ */
/*===========================================================================
end */

1658
Utils/Libs/GLib/Frame.cpp Normal file

File diff suppressed because it is too large Load Diff

183
Utils/Libs/GLib/Frame.hpp Normal file
View File

@ -0,0 +1,183 @@
/*=========================================================================
FRAME.CPP
Author: Gary Liddon @ Fareham
Created:
Project:
Purpose:
Copyright (c) 1997 G R Liddon
===========================================================================*/
#ifndef __FRAME_HPP__
#define __FRAME_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <iostream>
#include <vector>
/* Glib
---- */
#include "gobject.hpp"
#include "gtypes.h"
#include "gstring.hpp"
/* Local
----- */
#include "pal.hpp"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class GLIB_API Rect : public GObject
{
public:
Rect(Rect const & R)
{ MakeCopy(R);}
void operator=(Rect const & R)
{ MakeCopy(R);}
Rect(void);
Rect(int nX,int nY,int nW,int nH)
{
X=nX;
Y=nY;
W=nW;
H=nH;
}
/* Compare by volume */
bool operator< (Rect const & R) const
{
return((W*H)<(R.W*R.H));
}
bool IsColiding(Rect const & NewRect) const;
void ClipRect(Rect & RectToClip) const;
int Area(void) const {return(W*H);}
operator int() const{return(W || H);}
GLIB_API friend std::ostream & operator<<(std::ostream & str,Rect const & Fr);
int X,Y;
int W,H;
protected:
void MakeCopy(Rect const & R)
{
X=R.X;
Y=R.Y;
W=R.W;
H=R.H;
}
};
class GLIB_API Frame : public GObject
{
public:
void ReduceColours(int TargColours);
void Expand(int BorderWidth,bool DupeEdges);
void AddPixelSurround(int Col);
void MakeRGBA(u8 * Dest,bool ZeroIsTrans=true);
Frame(void);
Frame(Frame const &);
~Frame(void);
void Plot(Frame & Dest,int X,int Y);
void PlotTrans(Frame & Dest,int X,int Y,int TrCol=0);
void PlotBox(Rect const & R,int Col);
void operator=(Frame const &Fr){CopyFrame(Fr);}
operator Rect() const{return(Rect(X,Y,Width,Height));}
bool operator<(Frame const &Fr) const;
bool operator==(Frame const &Fr) const;
void SetFrame(u8 const * nBuffa,int W,int H,Palette const & NewPal);
void ReduceSinglePixels(int Threshold);
void SaveLbm(char const * Lbm);
void ReduceSize(void);
Rect FindBoundingRect(void);
void Crop(Rect const & RetRect);
bool Grab(Frame const & Fr,Rect const & RetRect);
bool IsBlank(u8 BlankVal=0);
u8 const * SeeData(void) const {return(Buffa);}
int GetWidth(void) const {return(Width);}
int GetHeight(void)const {return(Height);}
int GetNumOfCols(void) const;
bool DrawBox(Rect const & R,u8 Col);
const Palette & GetPal(void) const {return(MyPal);}
Palette & GetPal(void){return(MyPal);}
void SetPal(Palette const & NewPal){MyPal=NewPal;}
void Remap(Palette const & P);
void LoadLbm(char const * Lbm);
void ReplaceColour(int ColNum,int RepNum);
void SetX(int nX) {X=nX;}
void SetY(int nY) {Y=nY;}
int GetX(void) const {return(X);}
int GetY(void) const {return(Y);}
const char * GetName(void) const { return(Name); }
void SetName(const char * NewName) { Name=NewName; }
void ReducePal(void);
void Clear(int Col);
void LoadBMP(char const * Lbm);
void FlipX(void);
void FlipY(void);
void Resize(int NewWidth,int NewHeight);
protected:
void CopyFrame(Frame const &);
void DumpStuff(void);
void InitFrame(void);
Palette MyPal;
GString Name;
u8 * Buffa;
int Width;
int Height;
int X,Y;
};
/*---------------------------------------------------------------------- */
#endif /* __FRAME_HPP__ */
/*===========================================================================
end */

195
Utils/Libs/GLib/GSYS.C Normal file
View File

@ -0,0 +1,195 @@
/* ===========================================================================
File: GSYS.C
Notes: MSVS PC implemtatiom of GSYS.H api
Author: G Robert Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 DCI Ltd All rights reserved.
============================================================================ */
/* ---------------------------------------------------------------------------
Includes
-------- */
/* Standard Lib
------------ */
#include "setjmp.h"
/* Glib
---- */
#include "gtypes.h"
#include "gsys.h"
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Function Prototypes
------------------- */
static void MyFunc(void);
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Exterenal Variables
------------------- */
/* ---------------------------------------------------------------------------
Variables
--------- */
/* ---------------------------------------------------------------------------
Define the PSX stack
-------------------- */
extern int _stacksize;
/* ---------------------------------------------------------------------------
Tables
------ */
MEM_INFO WorkMemInfo=
{
NULL,
0,
};
/* ---------------------------------------------------------------------------
Function: const MEM_INFO *GSYS_GetMemInfo(MEM_ID Id)
Purpose: Get description of a free mem type for this system
Returns: -> struct containg info
--------------------------------------------------------------------------- */
const MEM_INFO *GSYS_GetWorkMemInfo(void)
{
return(&WorkMemInfo);
}
/* ---------------------------------------------------------------------------
Function: void GSYS_SetStackAndJump(void *Stack,void(*Func)(void *),void *Param)
Purpose: Set the stack pointer and jump to a routine on PSX
Params: Stack -> New Stack Ptr
Func -> Routine to jump to
Param Parameter to pass to function
--------------------------------------------------------------------------- */
static void * SaveParam;
void (*SaveFunc)(void *);
void GSYS_SetStackAndJump(void *Stack,void(*Func)(void *),void *Param)
{
jmp_buf GazBuff;
_JUMP_BUFFER * PcBuff;
SaveParam=Param;
SaveFunc=Func;
PcBuff=(_JUMP_BUFFER *) GazBuff;
setjmp(GazBuff);
PcBuff->Eip=(unsigned long)MyFunc;
PcBuff->Esp=(unsigned long)Stack;
longjmp(GazBuff,0);
Func(Param);
}
void MyFunc(void)
{
SaveFunc(SaveParam);
}
/* ---------------------------------------------------------------------------
Function: void GSYS_MarkStack(void * Stack, U32 StackSize)
Purpose: Marks a stack so that it can be checked to see if it's
been corrupted. In GSYS to account for stack direction
on different platforms
Params: Stack -> Stack
StackSize Stack Size
--------------------------------------------------------------------------- */
#define STACK_MARK_CODE 0xabcd0123
void GSYS_MarkStack(void * Stack, U32 StackSize)
{
U32 * StackStart;
StackStart=Stack;
(*StackStart)=STACK_MARK_CODE;
}
/* ---------------------------------------------------------------------------
Function: BOOL GSYS_IsStackCorrupted(void * Stack, U32 StackSize)
Purpose: Check to see if a previously marked stack has been corrupted
Params: Stack -> Stack
StackSize Stack Size
Returns: TRUE if it has
--------------------------------------------------------------------------- */
BOOL GSYS_IsStackCorrupted(void * Stack, U32 StackSize)
{
U32 * StackStart;
StackStart=Stack;
return (*StackStart!=STACK_MARK_CODE);
}
/* ---------------------------------------------------------------------------
Function: BOOL GSYS_InitMachine(void)
Purpose: Initialise the machine for work
Returns: Succesful of not
--------------------------------------------------------------------------- */
BOOL GSYS_InitMachine(void)
{
return(TRUE);
}
/* ---------------------------------------------------------------------------
Function: BOOL GSYS_CheckPtr(void *Ptr)
Purpose: See if this ptr -> to an address within the machines
memor
Returns: Succesful of not
--------------------------------------------------------------------------- */
BOOL GSYS_CheckPtr(void *Ptr)
{
return(TRUE);
}
/* ---------------------------------------------------------------------------
Function: BOOL GSYS_IsStackOutOfBounds(void* Stack, U32 StackSize)
Purpose: Is the current sp outside the range of the stack
Returns: TRUE if so
--------------------------------------------------------------------------- */
BOOL GSYS_IsStackOutOfBounds(void* Stack, U32 StackSize)
{
return(FALSE);
}
/* ---------------------------------------------------------------------------
ends */

64
Utils/Libs/GLib/GTIMSYS.C Normal file
View File

@ -0,0 +1,64 @@
/* ===========================================================================
File: GTIMSYS.C
Notes: Timing system stuff needed by gtim
Author: G Robert Liddon @ 73b
Copyright (C) 1996 DCI Ltd All rights reserved.
============================================================================ */
/* ---------------------------------------------------------------------------
Standard Lib Includes
--------------------- */
/* Standard Lib
------------ */
#include "stdio.h"
/* PSX Os
------ */
/* Glib
---- */
#include "gdebug.h"
/* Headers
------- */
#include "gtimsys.h"
/* ---------------------------------------------------------------------------
Defines and Enums
----------------- */
/* ---------------------------------------------------------------------------
Structs
------- */
/* ---------------------------------------------------------------------------
Vars
---- */
/* ---------------------------------------------------------------------------
Code n that
--------------------------------------------------------------------------- */
U32 GTIMSYS_GetTimer(void)
{
return(0);
}
void GTIMSYS_ResetTimer(void)
{
}
U32 GTIMSYS_InitTimer(void)
{
return(0);
}
/* ---------------------------------------------------------------------------
ends */

164
Utils/Libs/GLib/Ganim.cpp Normal file
View File

@ -0,0 +1,164 @@
/*=========================================================================
GANIM.CPP
Author: Gary Liddon @ Fareham
Created:
Project:
Purpose:
Copyright (c) 1997 Gary Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* STL
--- */
/* Glib
---- */
#include "gfname.hpp"
/* Local
----- */
#include "ganim.hpp"
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Function types
-------------- */
/*----------------------------------------------------------------------
Vars
---- */
std::vector<FilterDetails> FilterDetails::AllDetails ;
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function: GAnim::GAnim(void)
Notes: Constructor
---------------------------------------------------------------------- */
GAnim::GAnim(void)
{
TheFrames.reserve(2000);
}
GAnim::~GAnim(void)
{
}
bool GAnim::Load(GAnimFilter & Af,char const * IoName)
{
bool RetVal;
if (IoName)
Af.SetName(IoName);
RetVal=Af.Load(*this);
return(RetVal);
}
bool GAnim::Save(GAnimFilter & Af,char const * IoName)
{
bool RetVal;
if (IoName)
Af.SetName(IoName);
RetVal=Af.Save(*this);
return(RetVal);
}
Frame & GAnim::GetNewFrame(void)
{
return(operator[](TheFrames.size()));
}
int GAnim::AddPalette(Palette & P)
{
for (int f=0;f<ThePals.size();f++)
{
if (P==ThePals[f])
return(f);
}
ThePals.push_back(P);
return(ThePals.size()-1);
}
/*----------------------------------------------------------------------
Function: GAnimFilter::GAnimFilter(char const * FName)
Notes: Constructor
---------------------------------------------------------------------- */
GAnimFilter::GAnimFilter(char const * FName)
{
FileName=FName;
}
FilterDetails::FilterDetails(GAnimFilter & nAnmFilter,char const * nExt)
{
Ext=nExt;
Ext.Lower();
AnmFilter=nAnmFilter.Create(NULL);
AllDetails.push_back(*this);
}
GAnimFilter * FilterDetails::GetFilter(char const * Fname)
{
GAnimFilter * RetFilter;
GString ExtStr(GFName(Fname).Ext());
ExtStr.Lower();
RetFilter=NULL;
for (int f=0;f<AllDetails.size() && !RetFilter;f++)
{
if (AllDetails[f].Ext==ExtStr)
RetFilter=AllDetails[f].AnmFilter->Create(Fname);
}
return(RetFilter);
}
Frame & GAnim::operator[](int Index)
{
if (Index >= TheFrames.capacity())
TheFrames.reserve(TheFrames.capacity()+1000);
if (Index >= TheFrames.size())
TheFrames.resize(TheFrames.size()+1);
return(TheFrames[Index]);
}
/*===========================================================================
end */

127
Utils/Libs/GLib/Ganim.hpp Normal file
View File

@ -0,0 +1,127 @@
/*=========================================================================
GANIM.HPP
Author: Gary Liddon @ Fareham
Created:
Project:
Purpose:
Copyright (c) 1997 Gary Liddon
===========================================================================*/
#ifndef __GANIM_HPP__
#define __GANIM_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* STL
--- */
#include <vector>
/* Glib
---- */
#include "gobject.hpp"
#include "gstring.hpp"
/* Local
----- */
#include "frame.hpp"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API GAnimFilter;
class GLIB_API GAnim : public GObject
{
public:
GAnim(void);
~GAnim(void);
bool Load(GAnimFilter & Af,char const * Name=NULL);
bool Save(GAnimFilter & Af,char const * Name=NULL);
Frame & GetNewFrame(void);
int AddPalette(Palette & Pal);
int NumOfFrames(void) {return(TheFrames.size());}
Palette & GetPal(int PalId)
{
if (PalId >= ThePals.size())
Error(ERR_FATAL,"Bounds error pals %d",PalId);
return(ThePals[PalId]);
}
Frame & operator[](int Index);
protected:
typedef std::vector<Palette> PalVec;
typedef PalVec::iterator PalVecIt;
typedef std::vector<Frame> FrameVec;
typedef FrameVec::iterator FrameVecIt;
PalVec ThePals;
FrameVec TheFrames;
};
class GLIB_API GAnimFilter : public GObject
{
public:
GAnimFilter(){;}
GAnimFilter(char const * FName);
virtual bool Load(GAnim & Anm)=0;
virtual bool Save(GAnim & Anm)=0;
virtual GAnimFilter * Create(char const *)=0;
void SetName(char const * NewName) {FileName=NewName;}
char const * GetName(void) const {return(FileName);}
protected:
GString FileName;
};
class GLIB_API FilterDetails
{
public:
FilterDetails();
FilterDetails(GAnimFilter & nAnmFilter,char const * nExt);
static GAnimFilter * GetFilter(char const * Fname);
bool operator<(FilterDetails const &) const;
bool operator==(FilterDetails const &) const;
protected:
GString Ext;
GAnimFilter * AnmFilter;
static std::vector<FilterDetails> AllDetails;
};
/*---------------------------------------------------------------------- */
#endif /* __GANIM_HPP__ */
/*===========================================================================
end */

123
Utils/Libs/GLib/Gdebug.c Normal file
View File

@ -0,0 +1,123 @@
/* ===========================================================================
File: GDEBUG.C
Notes: PSX Implementation of glib debug api
Author: G Robert Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 DCI Ltd All rights reserved.
============================================================================ */
/* ---------------------------------------------------------------------------
Standard Lib Includes
--------------------- */
#include "stdio.h"
/* ---------------------------------------------------------------------------
Glib Includes
------------- */
#include "gdebug.h"
/* ---------------------------------------------------------------------------
Game Includes
------------- */
/* ---------------------------------------------------------------------------
Function Prototypes
------------------- */
/* ---------------------------------------------------------------------------
Vars
---- */
void (*MsgFunc)(char *e,va_list argptr);
void (*ErrorFunc)(char *Text,char *File,int Line);
/* ---------------------------------------------------------------------------
Function: BOOL DBG_OpenModule(void);
Purpose: Initialise the debug module
Returns: FALSE if unable to init
--------------------------------------------------------------------------- */
GLIB_API BOOL DBG_OpenModule(void)
{
return(TRUE);
}
/* ---------------------------------------------------------------------------
Function: void DBG_PollHost(void)
Purpose: Poll the host to enable debugging
--------------------------------------------------------------------------- */
GLIB_API void DBG_PollHost(void)
{
}
/* ---------------------------------------------------------------------------
Function: void DBG_Halt(void)
Purpose: Stop where I am
--------------------------------------------------------------------------- */
GLIB_API void DBG_Halt(void)
{
while (1);
}
/* ---------------------------------------------------------------------------
Function: void DBG_SendMessage(char *e,...)
Purpose: Send a diagnostic messgae
--------------------------------------------------------------------------- */
GLIB_API void DBG_SendMessage(char *e,...)
{
}
/* ---------------------------------------------------------------------------
Function: void DBG_SetMessageHandler(void (*Func)(char *e,va_list argptr))
Purpose: Set the message handler
--------------------------------------------------------------------------- */
GLIB_API void DBG_SetMessageHandler(void (*Func)(char *e,va_list argptr))
{
MsgFunc=Func;
}
/* ---------------------------------------------------------------------------
Function: void DBG_Error(char *Text,char *File,int Line);
Purpose: Send a msg to psyq host
--------------------------------------------------------------------------- */
GLIB_API void DBG_Error(char *Text,char *File,int Line)
{
}
GLIB_API void DBG_SetErrorFunc(void (*EFunc)(char *Text,char *File,int Line))
{
ErrorFunc=EFunc;
}
/* ---------------------------------------------------------------------------
Function: static void SendPsyqString(char *e)
Purpose: Send a msg to psyq host
--------------------------------------------------------------------------- */
void SendPsyqString(char *e)
{
}
/* ---------------------------------------------------------------------------
ends */

326
Utils/Libs/GLib/Gfname.cpp Normal file
View File

@ -0,0 +1,326 @@
/*=========================================================================
GFNAME.HPP
Author: Gary Liddon @ Watford
Created: 2nd March 1991
Purpose: Filename manipulation class
Copyright (c) 1991-1997 Gary Lidon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <fstream>
/* Glib
---- */
/* Local
----- */
#include "gfname.hpp"
#include "gstring.hpp"
using namespace std;
/*----------------------------------------------------------------------
Function: Destructor
---------------------------------------------------------------------- */
GFName::~GFName(void)
{
}
/*----------------------------------------------------------------------
Function: Constructor
---------------------------------------------------------------------- */
GFName::GFName(void)
{
TDrive[0]=0;
TPath[0]=0;
TDir[0]=0;
TFile[0]=0;
}
/*----------------------------------------------------------------------
Function: Constructor witn
---------------------------------------------------------------------- */
GFName::GFName(const char *zfname)
{
FullName(zfname);
}
void GFName::FullName(const char *zfname)
{
if (zfname)
{
_splitpath(zfname,TDrive,TDir,TFile,TExt);
if (strlen(TDir) > 1)
{
if (TDir[strlen(TDir)-1]=='\\')
TDir[strlen(TDir)-1]=0;
}
Ext(TExt);
}
else
{
TDrive[0]=0;
TPath[0]=0;
TDir[0]=0;
TFile[0]=0;
}
}
/*----------------------------------------------------------------------
Function: Make a full name
---------------------------------------------------------------------- */
char const *GFName::FullName(void)
{
_makepath(TPath,TDrive,TDir,TFile,TExt);
return RetStr(TPath);
}
const char * GFName::RetStr(const char * Val)
{
if (Val[0]=='\0')
return(NULL);
else
return(Val);
}
void GFName::SetStr(char * Dest,char const * Source)
{
if (Source)
{
char Temp[1000];
strcpy(Temp,Source);
strcpy(Dest,Temp);
}
else
Dest[0]=0;
}
/*----------------------------------------------------------------------
Function: Make a full name
---------------------------------------------------------------------- */
void GFName::AddDir(char const *add)
{
GString CurrDir;
CurrDir=Dir();
CurrDir+="\\";
CurrDir+=add;
Dir(CurrDir);
}
#define FF_PATHNAMEMAX _MAX_PATH+1
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Convert relative to absolute paths
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
char *GFName::makeabsolute(char const *basepath,char const *offset, char * outstr)
{
int i, j, len;
char basefilename[FF_PATHNAMEMAX];
if (offset[1] == ':') // Drive letter makes it absolute
strcpy(outstr, offset);
else
{
// Find path of the file
strcpy(outstr, basepath);
j = 0;
len = strlen(outstr);
for (i = len - 1; i >= 0; i--)
if (outstr[i] == '\\')
break;
else
outstr[i] = 0;
// Find the filename
if (i > 0)
strcpy(basefilename, &basepath[i+1]);
else
basefilename[0] = 0;
len = strlen(basefilename);
for (i = len - 1; i >= 0; i--)
{
if (basefilename[i] == '.')
{
basefilename[i] = 0;
break;
}
else
basefilename[i] = 0;
}
// Is it from the root directory?
if (offset[0] == '\\')
{
outstr[2] = 0; // Leave only the drive letter
}
else
{
// Parse the ../ paths
while ((offset[j] == '.') && (offset[j+1] == '.') &&
(offset[j+2] == '\\'))
{
len = strlen(outstr);
if (len > 1)
outstr[len-1] = 0;
for (i = len - 2; i >= 0; i--)
if (outstr[i] == '\\')
break;
else
outstr[i] = 0;
j += 3;
}
}
// Add the remaining offset to the name
len = strlen(outstr);
while (offset[j])
{
/* if (offset[j] == '#') // Same filename
{
strcat(outstr, basefilename);
len = strlen(outstr);
}
else
{
outstr[len++] = offset[j];
outstr[len] = 0;
}
*/
outstr[len++] = offset[j];
outstr[len] = 0;
j++;
}
}
return outstr;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Convert absolute to relative paths
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
char *GFName::makerelative(char const *basepath,char const *newpath, char *outstr)
{
char temp1[FF_PATHNAMEMAX];
char temp2[FF_PATHNAMEMAX];
int i, j, match;
// Are the filenames the same?
match = 0;
for (j = 0; j < FF_PATHNAMEMAX; j++)
{
if (basepath[j] != newpath[j])
{
match = 0;
break;
}
else if (basepath[j] == '.') // Matching
{
match = 1;
break;
}
else if (basepath[j] == 0) // Identical
{
match = 0;
break;
}
}
if (match) // Matching paths and filenames
{
strcpy(outstr, "#");
strcat(outstr, &newpath[j]);
}
else if (basepath[0] != newpath[0]) // Drive letters are different
strcpy(outstr, newpath);
else
{
// Find the paths
strcpy(temp1, basepath);
for (i = strlen(temp1) - 1; i >= 0; i--)
if (temp1[i] == '\\')
break;
else
temp1[i] = 0;
strcpy(temp2, newpath);
for (i = strlen(temp2) - 1; i >= 0; i--)
if (temp2[i] == '\\')
break;
else
temp2[i] = 0;
// Are the paths the same?
strcpy(outstr, "");
if (strcmp(temp1, temp2) == 0) // Paths are the same
{
j = strlen(temp1);
}
else // Paths are different
{
j = 2; // Drives are the same
// Find different bits
for (i = 0; i < (int) strlen(temp1); i++)
{
if ((temp1[i] == '\\') && (temp2[i] == '\\'))
j = i + 1;
else
if (temp1[i] != temp2[i])
break;
}
if (j > 3)
{
for (i = j; i < (int) strlen(temp1); i++)
if (temp1[i] == '\\')
strcat(outstr,"..\\");
}
else
j = 2;
}
strcat(outstr, &newpath[j]);
}
return outstr;
}
ostream & operator<<(ostream & str,GFName & Name)
{
str<<"!";
if (Name.FullName())
str<<Name.FullName();
if (Name.Dir())
str<<"!"<<Name.Dir();
if (Name.File())
str<<"!"<<Name.File();
if (Name.Ext())
str<<"!"<<Name.Ext();
str<<"!";
return(str);
}
/*===========================================================================
end */

107
Utils/Libs/GLib/Gfname.hpp Normal file
View File

@ -0,0 +1,107 @@
/*=========================================================================
GFNAME.HPP
Author: Gary Liddon @ Watford
Created: 2nd March 1991
Purpose: Filename manipulation class
Copyright (c) 1991-1997 Gary Lidon
===========================================================================*/
#ifndef __GL_PC_GFNAME__
#define __GL_PC_GFNAME__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
/* Glib
---- */
#include "gtypes.h"
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API GFName
{
protected:
char TDrive[_MAX_DRIVE+1];
char TDir[_MAX_DIR+1];
char TPath[_MAX_PATH+1];
char TFile[_MAX_FNAME+1];
char TExt[_MAX_EXT+1];
public:
GFName(void);
GFName(char const *zfname);
~GFName(void);
char const *FullName(void);
char const *Drive(){return RetStr(TDrive);}
char const *Dir(){return RetStr(TDir);}
char const *File(){return RetStr(TFile);}
char const *Ext(){return RetStr(TExt);}
void Drive(char const *new_drive){SetStr(TDrive,new_drive);}
void Dir(char const *new_dir){SetStr(TDir,new_dir);}
void File(char const *new_file){SetStr(TFile,new_file);}
void Ext(char const *new_ext)
{
if (new_ext)
{
if (new_ext[0]=='.')
SetStr(TExt,new_ext+1);
else
SetStr(TExt,new_ext);
}
else
TExt[0]=0;
}
void FullName(const char *zfname);
void operator=(const char * zfname) {FullName(zfname);}
void AddDir(char const *add);
static char *makerelative(const char *basepath, const char *newpath, char *outstr);
static char *makeabsolute(const char *basepath, const char *offset, char *outstr);
friend std::ostream &operator<<(std::ostream & str,GFName & Name);
private:
const char * RetStr(const char *);
void SetStr(char * Dest,char const * Source);
};
/*---------------------------------------------------------------------- */
#endif /* __GL_PC_GFNAME__ */
/*===========================================================================
end */

View File

@ -85,35 +85,35 @@ LIB32=link.exe -lib
# PROP Default_Filter ""
# Begin Source File
SOURCE=Source\Gal.c
SOURCE=Gal.c
# End Source File
# Begin Source File
SOURCE=Source\Gmain.c
SOURCE=Gmain.c
# End Source File
# Begin Source File
SOURCE=Source\Gtimer.c
SOURCE=Gtimer.c
# End Source File
# Begin Source File
SOURCE=Source\Gutils.c
SOURCE=Gutils.c
# End Source File
# Begin Source File
SOURCE=Source\Ll.c
SOURCE=Ll.c
# End Source File
# Begin Source File
SOURCE=Source\Objs.c
SOURCE=Objs.c
# End Source File
# Begin Source File
SOURCE=Source\Tasker.c
SOURCE=Tasker.c
# End Source File
# Begin Source File
SOURCE=Source\Tick.c
SOURCE=Tick.c
# End Source File
# End Group
# Begin Group "Core Headers"
@ -121,51 +121,51 @@ SOURCE=Source\Tick.c
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Glib\Include\Gal.h
SOURCE=Gal.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gdebug.h
SOURCE=Gdebug.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gmain.h
SOURCE=Gmain.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gsys.h
SOURCE=Gsys.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gtimer.h
SOURCE=Gtimer.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gtimsys.h
SOURCE=Gtimsys.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gtypes.h
SOURCE=Gtypes.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Gutils.h
SOURCE=Gutils.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Ll.h
SOURCE=Ll.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Objs.h
SOURCE=Objs.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Tasker.h
SOURCE=Tasker.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Tick.h
SOURCE=Tick.h
# End Source File
# End Group
# Begin Group "PC Source"
@ -173,67 +173,67 @@ SOURCE=..\..\Glib\Include\Tick.h
# PROP Default_Filter ""
# Begin Source File
SOURCE=Source\Pc\Dpanim.cpp
SOURCE=Dpanim.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Frame.cpp
SOURCE=Frame.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Ganim.cpp
SOURCE=Ganim.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Gdebug.c
SOURCE=Gdebug.c
# End Source File
# Begin Source File
SOURCE=Source\Pc\Gfname.cpp
SOURCE=Gfname.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Gobject.cpp
SOURCE=Gobject.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Gstring.cpp
SOURCE=Gstring.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Gsys.c
SOURCE=Gsys.c
# End Source File
# Begin Source File
SOURCE=Source\Pc\Gtimsys.c
SOURCE=Gtimsys.c
# End Source File
# Begin Source File
SOURCE=Source\Pc\Iff.cpp
SOURCE=Iff.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Ilbm.cpp
SOURCE=Ilbm.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Misc.cpp
SOURCE=Misc.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Niff.cpp
SOURCE=Niff.cpp
# End Source File
# Begin Source File
SOURCE=Source\Pc\Pal.cpp
SOURCE=Pal.cpp
# End Source File
# Begin Source File
SOURCE=Source\PC\REGEX.C
SOURCE=REGEX.C
# End Source File
# Begin Source File
SOURCE=Source\Pc\tquant.cpp
SOURCE=tquant.cpp
# End Source File
# End Group
# Begin Group "PC Headers"
@ -241,59 +241,59 @@ SOURCE=Source\Pc\tquant.cpp
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Dpanim.hpp
SOURCE=Dpanim.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Frame.hpp
SOURCE=Frame.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Ganim.hpp
SOURCE=Ganim.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Gfname.hpp
SOURCE=Gfname.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Gobject.hpp
SOURCE=Gobject.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Gstring.hpp
SOURCE=Gstring.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Iff.hpp
SOURCE=Iff.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Ilbm.hpp
SOURCE=Ilbm.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Misc.hpp
SOURCE=Misc.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Mtypes.h
SOURCE=Mtypes.h
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Niff.hpp
SOURCE=Niff.hpp
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\Pal.hpp
SOURCE=Pal.hpp
# End Source File
# Begin Source File
SOURCE=..\..\GLIB\Include\PC\REGEX.H
SOURCE=REGEX.H
# End Source File
# Begin Source File
SOURCE=..\..\Glib\Include\Pc\tquant.h
SOURCE=tquant.h
# End Source File
# End Group
# Begin Group "Template"
@ -319,27 +319,27 @@ SOURCE=..\..\Template\Template.h
# PROP Default_Filter ""
# Begin Source File
SOURCE=Source\PC\pcre\chartables.c
SOURCE=chartables.c
# End Source File
# Begin Source File
SOURCE=Source\PC\pcre\internal.h
SOURCE=internal.h
# End Source File
# Begin Source File
SOURCE=Source\PC\pcre\maketables.c
SOURCE=maketables.c
# End Source File
# Begin Source File
SOURCE=Source\PC\pcre\pcre.c
SOURCE=pcre.c
# End Source File
# Begin Source File
SOURCE=..\..\GLIB\Include\PC\pcre.h
SOURCE=pcre.h
# End Source File
# Begin Source File
SOURCE=Source\PC\pcre\study.c
SOURCE=study.c
# End Source File
# End Group
# End Target

133
Utils/Libs/GLib/Gobject.cpp Normal file
View File

@ -0,0 +1,133 @@
/*=========================================================================
GOBJECT.CPP
Author: Gary Liddon @ Watford
Created: 4th May 1991
Purpose: Base object
Copyright (c) 1991 - 1997 Gary Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
#include <stdarg.h>
/* Local
----- */
#include "gobject.hpp"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Positional Vars
--------------- */
/*----------------------------------------------------------------------
Static Vars
----------- */
int GObject::NumOfErrors=0;
int GObject::MaxErrors=3;
int GObject::NumOfGobjs=0;
int GObject::NumOfWarnings=0;
unsigned int GObject::BigObjFlags=0;
/*----------------------------------------------------------------------
Data
---- */
char const * const GObject::ErrorText[]=
{
"Too Many Errors",
"Out of Memory",
};
/*----------------------------------------------------------------------
Function: Gobject Constructor
---------------------------------------------------------------------- */
GObject::GObject()
{
NumOfGobjs++;
}
/*----------------------------------------------------------------------
Function: Gobject Destructor
---------------------------------------------------------------------- */
GObject::~GObject()
{
NumOfGobjs--;
}
/*----------------------------------------------------------------------
Function: Flag a Gobject error
---------------------------------------------------------------------- */
void GObject::Error(int ErrNum)
{
cerr<<"Internal GObject Error\n";
Error(ERR_FATAL,ErrorText[ErrNum]);
}
/*----------------------------------------------------------------------
Function: Flag General purpose error
---------------------------------------------------------------------- */
void GObject::Error(int Etype,char const *e, ...)
{
if (e)
{
switch (Etype)
{
case ERR_FATAL:
cerr<<"Fatal Error: ";
break;
case ERR_SERIOUS:
cerr<<"Serious Error: ";
break;
case ERR_WARNING:
NumOfWarnings++;
cerr<<"Warning: ";
break;
}
va_list argptr;
va_start(argptr,e);
vprintf(e,argptr);
va_end(argptr);
}
switch (Etype)
{
case ERR_FATAL:
exit(10);
break;
case ERR_SERIOUS:
if (NumOfErrors==MaxErrors)
Error(ERM_TOOMANYERRORS);
else
NumOfErrors++;
}
}
/*===========================================================================
end */

View File

@ -0,0 +1,86 @@
/*=========================================================================
GOBJECT.HPP
Author: Gary Liddon @ Watford
Created: 4th May 1991
Purpose: Base object
Copyright (c) 1991 - 1997 Gary Liddon
===========================================================================*/
#ifndef __PC_GLIB_GOBJECT_HPP__
#define __PC_GLIB_GOBJECT_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <fstream>
/* Glib
---- */
#include "gtypes.h"
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
enum
{
ERR_FATAL,
ERR_WARNING,
ERR_SERIOUS,
};
enum
{
ERM_TOOMANYERRORS,
};
/*----------------------------------------------------------------------
Class defintions
---------------- */
#define ERM_OUTOFMEM ERR_FATAL,"Mem flood line %d,file %s,",__LINE__,__FILE__
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API GObject
{
public:
GObject();
~GObject();
static void Error(int Etype,char const *e, ...);
static void Error(int ErrNum);
// static int GetNumOfGobjs(void){return NumOfGobjs;}
// static int GetNumOfWarnings(void){return NumOfWarnings;}
protected:
private:
static int NumOfWarnings;
static int NumOfErrors;
static int MaxErrors;
static char const * const ErrorText[];
static int NumOfGobjs;
static unsigned int BigObjFlags;
};
/*---------------------------------------------------------------------- */
#endif /* __PC_GLIB_GOBJECT_HPP__ */
/*===========================================================================
end */

338
Utils/Libs/GLib/Gstring.cpp Normal file
View File

@ -0,0 +1,338 @@
/*=========================================================================
GSTRING.CPP
Author: Gary Liddon @ Farehame
Created: 4th April 1997
Purpose: Generic string class
Copyright (c) 1997 Gary Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include "string.h"
/* Glib
---- */
/* Local
----- */
#include "gstring.hpp"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Positional Vars
--------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function: GString::GString()
Notes: Blank constructor
---------------------------------------------------------------------- */
GString::GString()
{
Init();
}
/*----------------------------------------------------------------------
Function: GString::~GString()
Notes: Destructor
---------------------------------------------------------------------- */
GString::~GString()
{
Dump();
}
/*----------------------------------------------------------------------
Function: GString::GString(GString const & Gs)
Notes: Copy constructor
---------------------------------------------------------------------- */
GString::GString(GString const & Gs)
{
Init();
(*this)=Gs;
}
/*----------------------------------------------------------------------
Function: GString & GString::operator+(GString const & Gs)
Notes: Add one string to another
---------------------------------------------------------------------- */
GString GString::operator+(GString const & Gs)
{
GString RetStr;
if (Gs.Len())
{
if (Len())
{
char * NewStr;
if (!(NewStr=new char[Gs.Len()+Len()+1]))
Error(ERM_OUTOFMEM);
strcpy(NewStr,*this);
strcat(NewStr,Gs);
RetStr=NewStr;
delete NewStr;
}
else
RetStr=Gs;
}
else
RetStr=*this;
return(RetStr);
}
/*----------------------------------------------------------------------
Function:
Notes:
---------------------------------------------------------------------- */
GString & GString::operator+=(GString const & Str)
{
*this=operator+(Str);
return(*this);
}
/*----------------------------------------------------------------------
Function: int GString::Len(void)
Notes: Get the length
---------------------------------------------------------------------- */
int GString::Len(void) const
{
if (Text)
return(strlen(Text));
else
return(0);
}
/*----------------------------------------------------------------------
---------------------------------------------------------------------- */
bool GString::operator<(GString const & Str) const
{
char defaultString[]="";
char const * stringOne;
char const * stringTwo;
if (Empty())
stringOne=defaultString;
else
stringOne=*this;
if (Str,Empty())
stringTwo=defaultString;
else
stringTwo=Str;
return(strcmp(stringOne,stringTwo) < 0 );
}
/*----------------------------------------------------------------------
Function: void GString::AssignStr(char const *NewStr)
Notes: Set this objs string
---------------------------------------------------------------------- */
void GString::AssignStr(char const *NewStr)
{
/* Chuck string we're copying from into a temp
str in case the text being copied from
is ours
*/
char * ReplaceStr=NULL;
if (NewStr)
{
if (!(ReplaceStr=new char[strlen(NewStr)+1]))
Error(ERM_OUTOFMEM);
strcpy(ReplaceStr,NewStr);
}
Dump();
Text=ReplaceStr;
}
/*----------------------------------------------------------------------
Function: void GString::Init(void)
Notes: Init this str
---------------------------------------------------------------------- */
void GString::Init(void)
{
Text=NULL;
}
/*----------------------------------------------------------------------
Function: void GString::Init(void)
Notes: Init this str
---------------------------------------------------------------------- */
void GString::Filter(char const * CharsToFilterOut,char ReplacementChar)
{
if (Text)
{
for (unsigned int f=0;f<strlen(Text);f++)
{
for (unsigned int g=0;g<strlen(CharsToFilterOut);g++)
{
if (Text[f]==CharsToFilterOut[g])
Text[f]=ReplacementChar;
}
}
}
}
/*----------------------------------------------------------------------
Function: void GString::Init(void)
Notes: Init this str
---------------------------------------------------------------------- */
void GString::Append(char c)
{
if (Text)
{
char * NewText;
NewText=new char[strlen(Text)+2];
strcpy(NewText,Text);
NewText[strlen(Text)]=c;
NewText[strlen(Text)+1]=0;
delete Text;
Text=NewText;
}
else
{
Text=new char[2];
Text[0]=c;
Text[1]=0;
}
}
/*----------------------------------------------------------------------
Function: void GString::Init(void)
Notes: Init this str
---------------------------------------------------------------------- */
void GString::Replace(char const * SearchString,char const * ReplaceString)
{
if (Text && strlen(Text) >= strlen(SearchString))
{
GString NewString;
int RepLen;
bool LastMatch;
RepLen=strlen(ReplaceString);
for (unsigned int Checks=0;Checks <= strlen(Text)-strlen(SearchString);Checks++)
{
bool Failed;
Failed=false;
for (unsigned int f=0;f<strlen(SearchString) && !Failed;f++)
{
if (SearchString[f] != Text[Checks+f])
Failed=true;
}
if (Failed)
{
NewString.Append(Text[Checks]);
LastMatch=false;
}
else
{
NewString=NewString+GString(ReplaceString);
Checks+=strlen(SearchString)-1;
LastMatch=true;
}
}
if ((strlen(Text)-Checks) > 0)
NewString+=GString(&Text[Checks]);
*this=NewString;
}
}
/*----------------------------------------------------------------------
Function: void GString::Dump(void)
Notes: Dump all the data
---------------------------------------------------------------------- */
void GString::Dump(void)
{
if (Text)
delete Text;
Init();
}
/*----------------------------------------------------------------------
Function: void GString::Dump(void)
Notes: Dump all the data
---------------------------------------------------------------------- */
void GString::Lower(void)
{
if (!Empty())
strlwr(Text);
}
/*----------------------------------------------------------------------
Function: void GString::Dump(void)
Notes: Dump all the data
---------------------------------------------------------------------- */
void GString::Upper(void)
{
if (!Empty())
strupr(Text);
}
/*----------------------------------------------------------------------
Function: void GString::Dump(void)
Notes: Dump all the data
---------------------------------------------------------------------- */
bool GString::operator==(GString const & Gs) const
{
if (Empty() && Gs.Empty())
return(true);
if (Empty() || Gs.Empty())
return(false);
return(strcmp(Gs,Text)==0);
}
/*----------------------------------------------------------------------
Function: void GString::Dump(void)
Notes: Dump all the data
---------------------------------------------------------------------- */
ostream & operator<<(ostream & Out,GString const & G)
{
if (!G.Empty())
Out<<G.Text;
return(Out);
}
/*===========================================================================
end */

124
Utils/Libs/GLib/Gstring.hpp Normal file
View File

@ -0,0 +1,124 @@
/*=========================================================================
GSTRING.HPP
Author: Gary Liddon @ Farehame
Created: 4th April 1997
Purpose: Generic string class
Copyright (c) 1997 Gary Liddon
===========================================================================*/
#ifndef __GSTRING_HPP__
#define __GSTRING_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <string.h>
#include <fstream>
/* Stl
--- */
/* Glib
---- */
#include "gtypes.h"
#include "gobject.hpp"
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API GString : public GObject
{
public:
GString();
~GString();
GString(GString const &);
GString(const char * Txt)
{
Init();
*this=Txt;
}
GString(const char * Txt,int StrLength)
{
Init();
Text=new char[StrLength+1];
memcpy(Text,Txt,StrLength);
Text[StrLength]=0;
}
bool operator==(GString const & Gs) const;
bool operator==(char const * Txt) const
{
GString MyStr;
MyStr=Txt;
return(MyStr == *this);
}
GString & operator=(GString const & Gs)
{
/* Check for self assignment */
if (this!=&Gs)
AssignStr(Gs);
return *this;
}
GString & operator=(char const * NewStr)
{
AssignStr(NewStr);
return *this;
}
GString operator+(GString const &);
GString & operator+=(GString const &);
bool operator<(GString const & Str) const;
friend std::ostream & operator<<(std::ostream & Out,GString const & G);
int Len(void) const;
operator char const *() const {return(Text);}
bool Empty() const {return(Len()==0);}
void Lower(void);
void Upper(void);
void Filter(char const * CharsToFilterOut,char ReplacementChar='_');
void Append(char c);
void Replace(char const * SearchString,char const * ReplaceString);
protected:
void Init(void);
void Dump(void);
void AssignStr(char const *NewStr);
char * Text;
};
/*---------------------------------------------------------------------- */
#endif /* __GSTRING_HPP__ */
/*===========================================================================
end */

131
Utils/Libs/GLib/IFF.CPP Normal file
View File

@ -0,0 +1,131 @@
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ ³
³ FILE: IFF.CPP ³
³ ³
³ Written by Carl Muller 25 Sep 1990 ³
³ Modified by Carl Muller 13 Sep 1991 ³
³ ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
#include "iff.hpp"
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Start writing an IFF file ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
FILE *IFF_FILE::write(char const *filename)
{
stackptr = 0;
file = fopen(filename, "wb");
return file;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Close an IFF file ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
void IFF_FILE::close()
{
fclose(file);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Start an IFF form ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
void IFF_FILE::form(char name[5])
{
fputc('F', file);
fputc('O', file);
fputc('R', file);
fputc('M', file);
push(ftell(file));
fputc(0, file);
fputc(0, file);
fputc(0, file);
fputc(0, file);
fputc(name[0], file);
fputc(name[1], file);
fputc(name[2], file);
fputc(name[3], file);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Finish an IFF form ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
void IFF_FILE::endform()
{
long pos1, pos2, len;
pos2 = ftell(file);
if (pos2 & 1)
{
fputc(0, file);
pos2++;
}
pos1 = pop();
len = pos2 - pos1 - 4L;
fseek(file, pos1, SEEK_SET);
fputc((UCHAR)(len>>24), file);
fputc((UCHAR)(len>>16) & 255, file);
fputc((UCHAR)(len>>8) & 255, file);
fputc((UCHAR)(len&0xff), file);
fseek(file,pos2,SEEK_SET);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Start an IFF chunk ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
void IFF_FILE::chunk(char name[5])
{
fputc(name[0], file);
fputc(name[1], file);
fputc(name[2], file);
fputc(name[3], file);
push(ftell(file));
fputc(0, file);
fputc(0, file);
fputc(0, file);
fputc(0, file);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Finish an IFF chunk ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
void IFF_FILE::endchunk()
{
long pos1, pos2, len;
pos2 = ftell(file);
if (pos2 & 1)
{
fputc(0, file);
pos2++;
}
pos1 = pop();
len = pos2 - pos1 - 4L;
fseek(file, pos1, SEEK_SET);
fputc((UCHAR)(len>>24), file);
fputc((UCHAR)(len>>16) & 255, file);
fputc((UCHAR)(len>>8) & 255, file);
fputc((UCHAR)(len&255), file);
fseek(file, pos2, SEEK_SET);
}
long IFF_FILE::tell()
{
return ftell(file);
}

122
Utils/Libs/GLib/IFF.HPP Normal file
View File

@ -0,0 +1,122 @@
/*=========================================================================
IFF.HPP
Author: Carl Muller
Created: 25 Sep 1990
Purpose: IFF write stuff, a bit manky
Copyright (c) 1990 - 1997 Carl Muller
===========================================================================*/
#ifndef __CP_GLIB_IFF_HPP__
#define __CP_GLIB_IFF_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <stdlib.h>
#include <stdio.h>
/* Glib
---- */
#include "gtypes.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
const MAXIFFNESTING = 16;
enum Masking
{
mskNone = 0,
mskHasMask = 1,
mskHasTransparentColor = 2,
mskLasso = 3
};
enum Compression
{
cmpNone = 0,
cmpByteRun1 = 1
};
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API IFF_FILE
{
private :
FILE * file;
int stackptr;
long stack[MAXIFFNESTING];
public :
FILE * write(char const *filename);
void close(void);
long tell(void);
void form(char name[5]);
void endform(void);
void chunk(char name[5]);
void endchunk(void);
void writeword(U16 it) { fputc(it >> 8, file); fputc(it & 255, file); }
void writelong(ULONG it) { fputc((UCHAR)((it >> 24)&0xff), file);fputc((UCHAR)((it >> 16)&0xff), file);fputc((UCHAR)((it >> 8)&0xff), file); fputc((UCHAR)(it & 0xff), file); }
U16 readword(void) { U16 ch=fgetc(file); return (ch<<8)+(U16)fgetc(file); }
void writechar(U16 it) { fputc(it, file); }
U16 readchar(void) { return fgetc(file); }
void push(long it) { stack[stackptr++] = it; }
long pop(void) { return stack[--stackptr]; }
};
/*----------------------------------------------------------------------
Inline Functions
---------------- */
inline U16 getword(FILE *file)
{
U16 ch = fgetc(file);
return (ch << 8) + (U16) (fgetc(file));
}
inline void putword(U16 theword, FILE *file)
{
fputc(theword >> 8, file);
fputc(theword & 255, file);
}
inline long getlong(FILE *file)
{
long ch;
ch = ((long) fgetc(file)) << 24;
ch |= ((long) fgetc(file)) << 16;
ch |= ((long) fgetc(file)) << 8;
ch |= ((long) fgetc(file));
return ch;
}
inline void get4chars(char *name, FILE *file)
{
name[0] = fgetc(file);
name[1] = fgetc(file);
name[2] = fgetc(file);
name[3] = fgetc(file);
name[4] = 0;
}
/*---------------------------------------------------------------------- */
#endif /* __CP_GLIB_IFF_HPP__ */
/*===========================================================================
end */

446
Utils/Libs/GLib/Ilbm.cpp Normal file
View File

@ -0,0 +1,446 @@
/*=========================================================================
ILBM.HPP
Author: Gary Liddon @ Watford
Created: 30/03/92
Purpose: Crappy ilbm reader
Copyright (c) 1992 - 1997 Gary Liddon
===========================================================================*/
/* -----------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <string.h>
/* Glib
---- */
#include "gutils.h"
/* Local
----- */
#include "ilbm.hpp"
#include "iff.hpp"
/* Graphics
-------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Positional Vars
--------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
nilbm::nilbm(char const *name) : niff(name,ILBM)
{
if (err_no==NOT_FORM)
{
if (open(name,PBM))
{
err_no=NO_ERROR;
}
}
if (!err_no)
starta();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
nilbm::nilbm(FILE *fp) : niff(fp,ILBM)
{
if (err_no==PASSED_ERR)
if (mount_form(PBM))
err_no=NO_ERROR;
starta();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
nilbm::~nilbm()
{
DiscardCmap();
DiscardBmap();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void nilbm::starta()
{
cmap=NULL;
Bmap=NULL;
if (err_no)
return;
if ((!file_opened) && (!form_mounted))
return;
GetBmHeadFromDisk();
if (goto_hunk(CMAP))
cmap=get_hunk();
Bmap=GetBmapFromDisk();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
U8 *nilbm::TakeBmap()
{
U8* Retp=Bmap;
Bmap=NULL;
return Retp;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
U8 *nilbm::TakeCmap()
{
U8* Retp=cmap;
cmap=NULL;
return Retp;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void nilbm::DiscardBmap()
{
if (Bmap)
delete Bmap;
Bmap=NULL;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void nilbm::DiscardCmap()
{
if (cmap)
delete cmap;
cmap=NULL;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void nilbm::GetBmHeadFromDisk()
{
if (goto_hunk(BMHD))
{
GetIntelLong();
GetIntelLong();
w=GetIntelWord();
h=GetIntelWord();
GetIntelWord();
GetIntelWord();
planes=fgetc(fp);
fgetc(fp);
comp=fgetc(fp);
rh = h;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
U8 *nilbm::GetBmapFromDisk()
{
U8 *buffa=NULL;
U8 *Ptr;
if (file_opened)
{
if (goto_hunk(BODY))
{
long temp;
fread(&temp,1,sizeof(ULONG),fp);
fread(&temp,1,sizeof(ULONG),fp);
if (!(buffa=new U8[w*h]))
Error(ERR_FATAL,"Allocating ILBM body (%ld)",(long)w*(long)h);
U8 *line_buffer;
int NormWidth=((w+7)&(0xfff8));
int bwidth=NormWidth/8;
if (!(line_buffer=new U8[NormWidth*4])) //MA increased for safety incase of bad encoding
return NULL;
else
{
int z,dest; // Init source count
for (int line=0;line<(h);line++)
{
dest=0; // Destination count
memset(line_buffer,0,NormWidth); // Clear out buffer
if (form_name==PBM)
{
if (comp)
{
dest=0;
while (dest < w)
{
s8 val = fgetc(fp);
if (val<0)
{
val=(0-val)+1;
U8 ch=fgetc(fp);
while (val--)
{
line_buffer[dest]=ch;
dest++;
}
}
else if (val>=0)
{
val++;
while (val--)
{
line_buffer[dest]=fgetc(fp);
dest++;
}
}
}
}
else
{
int WidthToRead = GU_AlignVal(w, 2);
fread(line_buffer,WidthToRead,1,fp);
}
}
else
{
for (int p=0;p<planes;p++)
{
dest=0;
if (comp)
{
while (dest < bwidth)
{
S8 val = fgetc(fp);
Ptr=&line_buffer[dest*8];
if (val<0)
{
val=(0-val)+1;
U8 ch=fgetc(fp);
while (val--)
{
for (z=7;z>=0;z--)
*Ptr++ |= ((ch>>(z))&1)<<p;
dest++;
}
}
else if (val>=0)
{
val++;
while (val--)
{
U8 ch=fgetc(fp);
for (z=7;z>=0;z--)
*Ptr++ |= ((ch>>(z))&1)<<p;
dest++;
}
}
}
}
else
{
for (int x=0;x<bwidth;x++)
{
Ptr=&line_buffer[dest*8];
U8 ch=fgetc(fp);
for (z=7;z>=0;z--)
*Ptr++ |= ((ch>>(z))&1)<<p;
dest++;
}
}
}
}
memcpy(&buffa[line*w],line_buffer,w);
}
}
delete line_buffer;
}
}
return buffa;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void nilbm::SavePbm(char *Name,U8 *Palette,U8 *Body,int W,int H)
{
if (Palette && Body)
{
IFF_FILE outfile;
if (outfile.write(Name) != 0)
{
int i, j;
outfile.form("PBM ");
outfile.chunk("BMHD");
outfile.writeword(W);
outfile.writeword(H);
outfile.writeword(0); // xpos
outfile.writeword(0); // ypos
outfile.writechar(8); // num-planes
outfile.writechar(mskNone); // masking
outfile.writechar(cmpNone); // compression
outfile.writechar(0); // Pad byte
outfile.writeword(0); // Transparent colour
outfile.writechar(1); // xAspect
outfile.writechar(1); // yAspect
outfile.writeword(320);
outfile.writeword(200);
outfile.endchunk();
if (256)
{
outfile.chunk("CMAP");
for (i = 0; i < 3*256; i++)
outfile.writechar(Palette[i]);
outfile.endchunk();
}
U8 *ptr;
outfile.chunk("BODY");
for (i = 0; i < H; i++)
{
// Save out a planar scanline
ptr = &Body[(long) i * (long) W];
j = W;
while (j--)
outfile.writechar(*ptr++);
if (W&1)
{
int l = W&1;
for (int k=0; k<l; k++)
outfile.writechar(0xfe);
}
}
outfile.endchunk();
outfile.endform();
outfile.close();
}
else
Error(ERR_FATAL,"Error trying to write %s",Name);
}
else
Error(ERR_FATAL,"Image not defined so can't write %s",Name);
}
/*===========================================================================
end */

94
Utils/Libs/GLib/Ilbm.hpp Normal file
View File

@ -0,0 +1,94 @@
/*=========================================================================
ILBM.HPP
Author: Gary Liddon @ Watford
Created: 30/03/92
Purpose: Crappy ilbm reader
Copyright (c) 1992 - 1997 Gary Liddon
===========================================================================*/
#ifndef __PC_GLIB_ILBM_HPP__
#define __PC_GLIB_ILBM_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include "gtypes.h"
/* Local
----- */
#include "niff.hpp"
#include "gobject.hpp"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API nilbm : public niff, public GObject
{
public:
nilbm(char const *name);
nilbm(FILE *fp);
~nilbm();
int GetWidth(void) { return w; };
int GetHeight(void) { return h; };
int GetRH(void) { return rh; };
int GetPlanes(void) { return planes;}
U8 * GetPalAddr() { return cmap;}
void DiscardBmap(void);
U8 * TakeBmap(void);
void DiscardCmap();
U8 *TakeCmap();
u8 const * SeeBmap(){return(Bmap);}
u8 const * SeeCmap(){return(cmap);}
static void SavePbm(char *Name,U8 *Palette,U8 *Body,int W,int H);
protected:
U8 *GetBmapFromDisk();
void GetBmHeadFromDisk();
void starta();
int w, h, rh;
int planes;
int comp;
U8 *cmap;
U8 *Bmap;
struct bmhd // Bit map header for ilbm
{
U16 w,h;
S16 x,y;
U8 planes;
U8 masking;
U8 compression;
U8 pad;
U16 trans_col;
U8 x_ratio, y_ratio;
U16 page_width,page_height;
};
};
/*---------------------------------------------------------------------- */
#endif /* __PC_GLIB_ILBM_HPP__ */
/*===========================================================================
end */

425
Utils/Libs/GLib/MISC.CPP Normal file
View File

@ -0,0 +1,425 @@
//--------------------------------------------------------------------------
// Miscellaneous functions
// Box Files
//
// Gary Liddon @ Probe
// 21/11/92
//
// (c)1992-1998 Gary Robert Liddon
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Includes
// --------
#include "gtypes.h"
#include <vector>
#include <io.h>
#include <string.h>
#include <conio.h>
#include <fstream>
#include "misc.hpp"
#include "gfname.hpp"
using namespace std;
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool copyFile(char const * Dest,char const * Source,bool Overwrite)
{
ifstream InFile;
vector<u8> Data;
int Size;
Size=FileSize(Source);
if (Size >= 0)
{
Data.resize(Size);
ifstream In;
In.open(Source,ios::binary);
In.read((char *)(&Data[0]),Size);
In.close();
if (In)
{
ofstream OutFile;
int OpenMode;
OpenMode=ios::binary;
if (Overwrite)
OpenMode|=ios::trunc;
OutFile.open(Dest,OpenMode);
if (OutFile)
{
OutFile.write((char*)&Data[0],Data.size());
OutFile.close();
}
else
GObject::Error(ERR_FATAL,"Unable to open out file %s",Dest);
}
else
GObject::Error(ERR_FATAL,"Unable to open in file %s",Source);
}
return(true);
}
int FileCycler::DoCycle(char const *Spec,bool Recurse)
{
int FileNum=0;
int Handle;
GFName InName(Spec);
char * Speccy;
if(!(Speccy=strdup(Spec)))
GObject::Error(ERM_OUTOFMEM);
_finddata_t FindBlock;
/* Do dirs first */
if (Recurse)
{
GFName DirName(Spec);
DirName.File("*");
DirName.Ext("*");
if ((Handle = _findfirst((char *) DirName.FullName(),&FindBlock))!=-1)
{
BOOL Done;
Done=FALSE;
while (!Done)
{
if (FindBlock.attrib&_A_SUBDIR)
{
if (strcmp(FindBlock.name,".") && strcmp(FindBlock.name,".."))
{
GFName TempName(InName.FullName());
if (TempName.Dir())
{
char * NewSub;
if (!(NewSub=new char [strlen(TempName.Dir()) +strlen (FindBlock.name)+1+2] ))
GObject::Error(ERM_OUTOFMEM);
sprintf(NewSub,"%s\\%s",TempName.Dir(),FindBlock.name);
TempName.Dir(NewSub);
delete NewSub;
}
else
TempName.Dir(FindBlock.name);
DoCycle(TempName.FullName(),Recurse);
}
}
Done=_findnext(Handle,&FindBlock);
}
}
}
if ((Handle = _findfirst(Speccy,&FindBlock))!=-1)
{
BOOL Done;
Done=FALSE;
while (!Done)
{
if (!(FindBlock.attrib&_A_SUBDIR))
{
GFName TempName(InName.FullName());
GFName Temp2(FindBlock.name);
TempName.File(Temp2.File());
TempName.Ext(Temp2.Ext());
FileCallback(TempName.FullName(),FileNum++);
}
Done=_findnext(Handle,&FindBlock);
}
}
free(Speccy);
return FileNum;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Cycle through files of a particular spec, Returns Number of Files found
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
int CycleFiles(char const *Spec,void (*Func)(char const *Fname,int Num),BOOL Recurse)
{
int FileNum=0;
int Handle;
GFName InName(Spec);
char * Speccy;
if(!(Speccy=strdup(Spec)))
GObject::Error(ERM_OUTOFMEM);
_finddata_t FindBlock;
/* Do dirs first */
if (Recurse)
{
GFName DirName(Spec);
DirName.File("*");
DirName.Ext("*");
if ((Handle = _findfirst((char *) DirName.FullName(),&FindBlock))!=-1)
{
BOOL Done;
Done=FALSE;
while (!Done)
{
if (FindBlock.attrib&_A_SUBDIR)
{
if (strcmp(FindBlock.name,".") && strcmp(FindBlock.name,".."))
{
GFName TempName(InName.FullName());
if (TempName.Dir())
{
char * NewSub;
if (!(NewSub=new char [strlen(TempName.Dir()) +strlen (FindBlock.name)+1+2] ))
GObject::Error(ERM_OUTOFMEM);
sprintf(NewSub,"%s\\%s",TempName.Dir(),FindBlock.name);
TempName.Dir(NewSub);
delete NewSub;
}
else
TempName.Dir(FindBlock.name);
CycleFiles(TempName.FullName(),Func,Recurse);
}
}
Done=_findnext(Handle,&FindBlock);
}
}
}
if ((Handle = _findfirst(Speccy,&FindBlock))!=-1)
{
BOOL Done;
Done=FALSE;
while (!Done)
{
if (!(FindBlock.attrib&_A_SUBDIR))
{
GFName TempName(InName.FullName());
GFName Temp2(FindBlock.name);
TempName.File(Temp2.File());
TempName.Ext(Temp2.Ext());
Func(TempName.FullName(),FileNum++);
}
Done=_findnext(Handle,&FindBlock);
}
}
free(Speccy);
return FileNum;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Get Switch Info
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
BOOL SwitchInfo(char *String)
{
if (strlen(String)!=3 || (String[2] != '+' && String[2] != '-'))
{
GObject::Error(ERR_FATAL,"%s option formatted incorrectly",String);
return 0;
}
else
return String[2]=='+' ? 1 : 0;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Command Line Constructor
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
CommandLine::CommandLine(int argc,char **argv,char *(*Func)(char *String,int Num))
{
LastItem=NULL;
InStream=NULL;
CommandItem=0;
if (!(LastItem=new char[1000]))
Error(ERM_OUTOFMEM);
MyArgc=argc;
MyArgv=argv;
GetNextItem(); // Skip progname
int x=0;
char *SpamString;
while ((SpamString=GetNextItem()))
{
Func(SpamString,x);
x++;
}
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Command Line Destructor
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
CommandLine::~CommandLine()
{
if (InStream)
delete InStream;
if (LastItem)
delete LastItem;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Get The Next Item in the Commandline string
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
char *CommandLine::GetNextItem()
{
char *RetStuff=NULL;
if (!InStream)
RetStuff=GetNextCommandLineItem();
else
RetStuff=GetNextScriptFileItem();
return RetStuff;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Get The Next Item in the Argv list
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
char *CommandLine::GetNextCommandLineItem()
{
char *RetStuff=NULL;
if (CommandItem!=MyArgc)
{
strcpy(LastItem,MyArgv[CommandItem]);
RetStuff=LastItem;
CommandItem++;
if (*RetStuff=='@')
{
if (InStream)
delete InStream;
if (!(InStream = new ifstream (&RetStuff[1])))
Error(ERM_OUTOFMEM);
if (!(*InStream))
Error(ERR_FATAL,"Cannot open script file %s",&RetStuff[1]);
if (!(RetStuff=GetNextScriptFileItem()))
RetStuff=GetNextCommandLineItem();
}
}
return RetStuff;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Get The Next Item from the currently open script file
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
char *CommandLine::GetNextScriptFileItem()
{
char *RetStuff=NULL;
(*InStream)>>LastItem;
if (InStream->eof())
{
delete InStream;
InStream=NULL;
RetStuff=GetNextCommandLineItem();
}
else
RetStuff=LastItem;
return RetStuff;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Does this file exist?
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
bool FileExists(const char *String)
{
ifstream InStream;
bool RetVal;
InStream.open(String,ios::in);
if (InStream)
RetVal=true;
else
RetVal=false;
InStream.close();
return(RetVal);
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// What is the size of this file?
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
int FileSize(const char *String)
{
ifstream InStream;
int RetVal;
RetVal=-1;
InStream.open(String,ios::in);
if (InStream)
{
InStream.seekg(0,ios::end);
RetVal=InStream.tellg();
InStream.close();
}
return(RetVal);
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
//ends

297
Utils/Libs/GLib/MISC.HPP Normal file
View File

@ -0,0 +1,297 @@
/*=========================================================================
MISC.HPP
Author: Gary Liddon @ Watford
Created: 4th May 1991
Purpose: Shitey misc stuff
Copyright (c) 1991 - 1997 Gary Liddon
===========================================================================*/
#ifndef __PC_GLIB_MISC_HPP__
#define __PC_GLIB_MISC_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <list>
#include <fstream>
/* Glib
---- */
#include "gtypes.h"
/* Local
----- */
#include "gobject.hpp"
#include "gstring.hpp"
#include "gutils.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API CommandLine : public GObject
{
public:
CommandLine(int argc,char **argv,char *(*Func)(char *String,int Num));
~CommandLine();
char *GetNextItem();
protected:
std::ifstream *InStream;
char *InStreamFile;
char *GetNextScriptFileItem();
char *GetNextCommandLineItem();
private:
int CommandItem;
int MyArgc;
char **MyArgv;
char *LastItem;
};
class GLIB_API Gofstream : public std::ofstream
{
public:
enum ENDIAN
{
BIG_ENDIAN,
LITTLE_ENDIAN,
};
Gofstream(ENDIAN NewEndian=BIG_ENDIAN)
{SetEndian(NewEndian);}
void SetEndian(ENDIAN NewEndian)
{Endian=NewEndian;}
void Put16(u16 PVal)
{
switch(Endian)
{
case BIG_ENDIAN:
put(u8(PVal>>8));
put(u8(PVal&0xff));
break;
case LITTLE_ENDIAN:
put(u8(PVal&0xff));
put(u8(PVal>>8));
break;
}
}
void Put32(u32 PVal)
{
switch(Endian)
{
case BIG_ENDIAN:
put(u8(PVal>>24));
put(u8(PVal>>16));
put(u8(PVal>>8));
put(u8(PVal>>0));
break;
case LITTLE_ENDIAN:
put(u8(PVal>>0));
put(u8(PVal>>8));
put(u8(PVal>>16));
put(u8(PVal>>24));
break;
}
}
int Align(int Alignment,char const * Pad=NULL)
{
int NewPos;
int CurrPos;
CurrPos=tellp();
if (Alignment && CurrPos)
{
NewPos=CurrPos+((CurrPos%Alignment) == 0 ? 0 : Alignment-(CurrPos%Alignment));
if (NewPos != CurrPos)
{
if (Pad)
{
int StrSize;
StrSize=strlen(Pad);
for (;CurrPos<NewPos;CurrPos++)
put((u8)Pad[CurrPos%StrSize]);
}
else
{
for (;CurrPos<NewPos;CurrPos++)
put((u8)0);
}
}
}
else
NewPos=0;
return NewPos;
}
protected:
ENDIAN Endian;
};
class GLIB_API Gifstream : public std::ifstream
{
public:
enum ENDIAN
{
BIG_ENDIAN,
LITTLE_ENDIAN,
};
Gifstream(ENDIAN NewEndian=BIG_ENDIAN)
{
SetEndian(NewEndian);
}
void SetEndian(ENDIAN NewEndian)
{
Endian=NewEndian;
}
u16 Get16(void)
{
u8 Byte0,Byte1;
switch(Endian)
{
case BIG_ENDIAN:
Byte1=get();
Byte0=get();
break;
case LITTLE_ENDIAN:
Byte0=get();
Byte1=get();
break;
}
return(u16(Byte0)|(u16(Byte1)<<8));
}
u32 Get32(void)
{
u8 Byte0,Byte1,Byte2,Byte3;
switch(Endian)
{
case BIG_ENDIAN:
Byte3=get();
Byte2=get();
Byte1=get();
Byte0=get();
break;
case LITTLE_ENDIAN:
Byte0=get();
Byte1=get();
Byte2=get();
Byte3=get();
break;
}
return(u32(Byte0)|(u32(Byte1)<<8)|(u32(Byte2)<<16)|(u32(Byte3)<<24));
}
void Align(int Alignment)
{
int CurrPos;
CurrPos=tellg();
if (Alignment && CurrPos)
{
int NewPos;
NewPos=GU_AlignVal(CurrPos,Alignment);
seekg(NewPos);
}
}
protected:
ENDIAN Endian;
};
class FileCycler
{
public:
virtual int DoCycle(char const *Spec,bool Recurse);
protected:
virtual void FileCallback(char const * FName,int FileNum)
{
}
};
class FileToStrList : FileCycler
{
public:
FileToStrList(char const * FileSpec,bool Recurse,std::list<GString> & NewList) : List(NewList)
{
DoCycle(FileSpec,Recurse);
}
protected:
virtual void FileCallback(char const * FName,int FileNum)
{
List.push_front(FName);
}
std::list<GString> & List;
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
GLIB_API int CycleFiles(char const *Spec,void (*Func)(char const *Fname,int Num),BOOL Recurse);
GLIB_API BOOL SwitchInfo(char *String);
GLIB_API bool FileExists(const char *String);
GLIB_API int FileSize(const char *String);
GLIB_API bool copyFile(char const * Dest,char const * Source,bool Overwrite = false);
/*---------------------------------------------------------------------- */
#endif /* __PC_GLIB_MISC_HPP__ */
/*===========================================================================
end */

49
Utils/Libs/GLib/Mtypes.h Normal file
View File

@ -0,0 +1,49 @@
/* Ä--------------------------------------------------------------------------
File: MTYPES.H
Notes: Machine dependant typedefs for msvc
Target: PC MSVC
Author: G Robert Liddon @ Cliffs
Created: 18th February 1996
Copyright (C) 1997 Gary Liddon
All rights reserved.
--------------------------------------------------------------------------- */
#ifndef __MTYPES_H__
#define __MTYPES_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
/* ---------------------------------------------------------------------------
Defines
------- */
#define __GLIB_No64__
#define __GLIB_BOOLAsInt__
#ifdef __GL_WIN32DLL__
#define GLIB_API __declspec(dllexport)
#endif
/* ---------------------------------------------------------------------------
Typedefs
-------- */
typedef signed char s8;
typedef signed short s16;
typedef signed long int s32;
typedef double long s64;
typedef unsigned char u8;
typedef unsigned short int u16;
typedef unsigned long int u32;
/* --------------------------------------------------------------------------- */
#endif /* __MTYPES_H__ */
/* ---------------------------------------------------------------------------
ends */

128
Utils/Libs/GLib/NIFF.HPP Normal file
View File

@ -0,0 +1,128 @@
/*=========================================================================
NIFF.HPP
Author: Gary Liddon @ Watford
Created: 27th May 1991
Purpose: Base (and i do mean base) iff class
Copyright (c) 1991 - 1997 Gary Liddon
===========================================================================*/
#ifndef __PC_GLIB_NIFF_HPP__
#define __PC_GLIB_NIFF_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <stdio.h>
/* Glib
---- */
#include "gtypes.h"
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
#define NIFF_SEEK_SET SEEK_SET
#define NIFF_SEEK_CUR SEEK_CUR
#define NIFF_SEEK_END SEEK_END
#define MAKE_ID(a,b,c,d) (U32) ((U32)(d)<<24|(U32)(c)<<16|(U32)(b)<<8|(U32)(a))
#define FORM MAKE_ID('F','O','R','M')
#define PROP MAKE_ID('P','R','O','P')
#define LIST MAKE_ID('L','I','S','T')
#define CAT MAKE_ID('C','A','T',' ')
#define ILBM MAKE_ID('I','L','B','M')
#define PBM MAKE_ID('P','B','M',' ')
#define BMHD MAKE_ID('B','M','H','D')
#define BODY MAKE_ID('B','O','D','Y')
#define CMAP MAKE_ID('C','M','A','P')
//#define ANIM MAKE_ID('A','N','I','M')
#define DLTA MAKE_ID('D','L','T','A')
enum errors
{
NO_ERROR,
OPEN_ERROR,
NOT_IFF,
LOST_FORM,
LOST_HUNK,
CORRUPT_BMHD,
LOST_BODY,
NO_MEM,
MANGLED_IFF,
LOST_COLOUR,
NOT_PBM,
PASSED_ERR,
ANIM_PIC_E,
NOT_FORM,
};
/*----------------------------------------------------------------------
Class defintions
---------------- */
class GLIB_API niff
{
public:
niff(char const *name=NULL,U32 form=0L);
niff(FILE *fp,U32 form=0L);
~niff();
int GetNumOfHunks(U32 FormName);
BOOL open(char const *name,U32 form=0L);
BOOL close();
FILE *get_fp() {return fp;}
char *error();
BOOL next_form(U32 form=0L);
BOOL next_hunk(U32 form=0L);
BOOL mount_form(U32 form=0L);
U8 *get_hunk();
BOOL goto_hunk(U32 form);
void goto_form_start();
U32 rev_long(U32);
U16 rev_word(U16 val);
U32 GetIntelLong();
U16 GetIntelWord();
int seek(long offset,int orig);
long tell();
void Read(U8 *Buf,long bytes);
protected:
U32 full_len(U32 val);
BOOL form_mounted,passed_file,file_opened;
FILE *fp;
int err_no;
U32 form_name,hunk_name,splen;
long form_start,form_end,iff_base;
};
/*---------------------------------------------------------------------- */
#endif /* __PC_GLIB_NIFF_HPP__ */
/*===========================================================================
end */

452
Utils/Libs/GLib/Niff.cpp Normal file
View File

@ -0,0 +1,452 @@
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ ³
³ IA - Deluxe Paint 3 Animation player ³
³ ³
³ NIFF.CPP ³
³ ³
³ Written by Gary Liddon 27 May 1991 ³
³ Modified by Carl Muller 30 Oct 1991 ³
³ ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
#include "stdio.h"
#include "conio.h"
#include "niff.hpp"
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ IFF error messages ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
char *niff_error_text[] =
{
NULL,
"Error opening IFF file",
"Not an IFF file",
"Can't find FORM",
"Can't find HUNK",
"Corrupted bit map header in picture file",
"Can't find BODY",
"All out of memory",
"Mangled IFF file",
"Can't find CMAP",
"No ILBM's yet",
"Error with passed IFF file",
"Error with ILBM in ANIM",
"Not aksed for FORM type",
};
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Create an IFF descriptor from a filename ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
niff::niff(char const *name, U32 form)
{
form_mounted = FALSE;
err_no = NO_ERROR;
file_opened = FALSE;
fp = NULL;
passed_file = FALSE;
if (name)
open(name,form);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Create an IFF descriptor from a file pointer ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
niff::niff(FILE * new_file, U32 form)
{
form_mounted = FALSE;
err_no = NO_ERROR;
file_opened = TRUE; // File pre-opened
fp = new_file;
iff_base = ftell(fp); // Get base pos
passed_file = TRUE; // This is a passed file
if (!mount_form(form))
err_no = PASSED_ERR;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Open an IFF file for reading ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
BOOL niff::open(char const *name, U32 form)
{
if (passed_file) // Passed files can't be re-opened
{
err_no = OPEN_ERROR;
return FALSE;
}
if (file_opened) // Already open so don't bother
{
err_no = OPEN_ERROR;
return FALSE;
}
if (!(fp = fopen(name,"rb")))
{
err_no = OPEN_ERROR;
return FALSE;
}
if (!mount_form(form)) // Mount this form
{
fclose(fp);
if (!err_no)
err_no = NOT_FORM;
return FALSE;
}
iff_base = 0L; // Set position to zero
file_opened = TRUE;
return TRUE;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Read an IFF hunk into memory ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
U8 *niff::get_hunk()
{
if ((!file_opened) && (!form_mounted))
return NULL;
U8 *hunk=NULL;
long name,len,temp;
temp = ftell(fp);
fread(&name, 1, sizeof(U32), fp);
fread(&len, 1, sizeof(U32), fp);
len = rev_long(len);
hunk = new U8[len];
splen = len;
if (hunk)
fread(hunk,1,len,fp);
fseek(fp,temp,SEEK_SET);
return hunk;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Reset to beginning of form ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
void niff::goto_form_start()
{
fseek(fp, form_start, SEEK_SET);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Mount form at filepos ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
BOOL niff::mount_form(U32 form)
{
form_mounted=FALSE;
U32 temp,temp_name; // Check to see if we've an iff
if (fread(&temp,sizeof(U32),1,fp) != 1)
{
err_no= MANGLED_IFF;
return(false);
}
if (temp != FORM) // We haven't.
return FALSE;
fread(&temp,1,sizeof(U32),fp);
form_end = full_len(temp)+ftell(fp);
fread (&temp_name,1,sizeof(U32),fp);
if (form) // Are we checking for a specific
{ // form?
if (temp_name != form)
return FALSE;
}
form_name=temp_name;
form_start=ftell(fp);
form_mounted=TRUE;
return TRUE;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Goto a hunk ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
BOOL niff::goto_hunk(U32 form)
{
U32 len, namer;
if ((!form_mounted) || (!file_opened))
return FALSE;
goto_form_start();
fread(&namer, 1, sizeof(U32), fp);
fread(&len, 1, sizeof(U32), fp);
goto_form_start();
if (namer == form)
return TRUE;
return next_hunk(form);
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Get the number of hunks of a certain name in this file
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
int niff::GetNumOfHunks(U32 FormName)
{
int NumOfHunks=0;
if (goto_hunk(FormName))
{
do
{
NumOfHunks++;
}
while (next_hunk(FormName));
}
return NumOfHunks;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Goto next hunk in current form ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
BOOL niff::next_hunk(U32 form)
{
if ((!form_mounted) || (!file_opened))
return FALSE;
U32 temp = ftell(fp);
long len;
U32 name = 0L;
BOOL found = FALSE;
fread(&name, 1, sizeof(U32), fp);
fread(&len, 1, sizeof(U32), fp);
while ((ftell(fp) < form_end) && (!found))
{
fseek(fp, full_len(len), SEEK_CUR);
fread(&name, 1, sizeof(U32), fp);
fread(&len, 1, sizeof(U32), fp);
if (form)
{
if (form == name)
found = TRUE;
}
else
{
if (form != FORM)
found = TRUE;
}
}
if (found && (ftell(fp) < form_end))
{
fseek(fp, -8L, SEEK_CUR);
return TRUE;
}
fseek(fp, temp, SEEK_SET);
return FALSE;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Goto Next form in current form ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
BOOL niff::next_form(U32 form)
{
if ((!form_mounted) || (!file_opened))
return FALSE;
U32 len;
U32 name = 0L;
U32 fname = 0L;
BOOL found=FALSE;
fread(&name, 1, sizeof(U32), fp);
fread(&len, 1, sizeof(U32), fp);
do {
fseek(fp, full_len(len), SEEK_CUR);
fread(&name, 1, sizeof(U32), fp);
fread(&len, 1, sizeof(U32), fp);
if (name == FORM)
{
fread(&fname, 1, sizeof(U32), fp);
if (!form)
found = TRUE;
else if (form == fname)
found = TRUE;
len -= 4L;
}
} while (!found && (ftell(fp) < form_end));
if (found) // If we got what we wanted
{ // then seek back to start of
fseek(fp, -12L, SEEK_CUR); // header and flag success
return TRUE;
}
goto_form_start(); // Else back to start of form
return FALSE;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Close an IFF file ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
BOOL niff::close()
{
if (passed_file || (!file_opened)) // Passed or unopened files
return FALSE; // can't be closed
else if (fclose(fp) == 0) // If close succesful
{
file_opened=FALSE; // Flag file as closed
return TRUE; // Return Success
}
else
return FALSE; // Else an error
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Do a Iff file seek
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
int niff::seek(long offset,int orig)
{
return fseek(fp,offset,orig);
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Do a Iff file seek
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
long niff::tell()
{
return ftell(fp);
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Read Data from current pos
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
void niff::Read(U8 *Buf,long bytes)
{
fread(Buf,bytes,1,fp);
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Return an Intel Word from current file pos
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
U16 niff::GetIntelWord()
{
U16 Word=0;
if (file_opened)
{
fread((U8 *) &Word,sizeof(U16),1,fp);
return rev_word(Word);
}
else
return 0;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Return an Intel U32 from current file pos
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
U32 niff::GetIntelLong()
{
U32 Long=0;
if (file_opened)
{
fread((U8 *) &Long,sizeof(U32),1,fp);
return rev_long(Long);
}
else
return 0;
}
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
// Return the error string
// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
char *niff::error()
{
return niff_error_text[err_no];
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Destroy an IFF descriptor ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
niff::~niff()
{
close();
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Return full chunk length ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
U32 niff::full_len(U32 val)
{
return (rev_long(val)+1)&0xfffffffeL;
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Reverse a long: Motorola <-> Intel ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
U32 niff::rev_long(U32 val)
{
return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) |
((val << 24) & 0xff000000) | ((val << 8) & 0x00ff0000);
}
/* ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Reverse a long: Motorola <-> Intel ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */
U16 niff::rev_word(U16 val)
{
return ((val >> 8) & 0x000000ff) | ((val << 8) & 0x0000ff00);
}

293
Utils/Libs/GLib/Pal.cpp Normal file
View File

@ -0,0 +1,293 @@
/*=========================================================================
PAL.CPP
Author: Gary Liddon @ Fareham
Created:
Project:
Purpose:
Copyright (c) 1997 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <fstream.h>
#include <math.h>
#include <minmax.h>
/* STL
--- */
/* Glib
---- */
#include "ilbm.hpp"
/* Local
----- */
#include "pal.hpp"
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Palette Class Stuff
---------------------------------------------------------------------- */
Palette::Palette(void)
{
// TheColours.reserve(300);
}
Palette::Palette(Palette const &Fr)
{
CopyPal(Fr);
}
Palette::~Palette(void)
{
}
void Palette::operator=(Palette const &Fr)
{
CopyPal(Fr);
}
void Palette::CopyPal(Palette const &Fr)
{
TheColours.resize(Fr.TheColours.size());
for (int f=0;f<Fr.TheColours.size();f++)
{
TheColours[f]=Fr.TheColours[f];
}
}
Colour & Palette::operator[](int f)
{
if (f>=TheColours.capacity())
{
TheColours.reserve(TheColours.capacity()+300);
}
if (f>=TheColours.size())
TheColours.resize(f+1);
return(TheColours[f]);
}
Colour const & Palette::operator[](int f) const
{
if (f>=TheColours.size())
return(DummyCol);
else
return(TheColours[f]);
}
u8 * Palette::MakeDpPal() const
{
u8 * Pals;
if (!(Pals=new u8[256*3]))
Error(ERM_OUTOFMEM);
memset(Pals,0,256*3);
for (int f=0;f<TheColours.size();f++)
{
Pals[f*3+0]=TheColours[f].GetR();
Pals[f*3+1]=TheColours[f].GetG();
Pals[f*3+2]=TheColours[f].GetB();
}
return(Pals);
}
bool Palette::operator==(Palette const &Fr) const
{
if (TheColours.size()==Fr.TheColours.size())
{
for (unsigned int f=0;f<TheColours.size();f++)
{
if (TheColours[f]!=Fr.TheColours[f])
return(false);
}
return(true);
}
return(false);
}
bool Palette::FromLbm(char const * Name)
{
nilbm MyLbm(Name);
if (MyLbm.error())
return(false);
else
{
u8 const * CMap;
int NumOfCols=1<<MyLbm.GetPlanes();
CMap=MyLbm.SeeCmap();
for (int f=0;f<NumOfCols;f++)
{
(*this)[f].SetR(CMap[f*3]);
(*this)[f].SetG(CMap[f*3+1]);
(*this)[f].SetB(CMap[f*3+2]);
}
}
return(true);
}
void Palette::SetPalSize(int NumOfCols)
{
TheColours.resize(NumOfCols);
}
bool Palette::IsIntersecting(Palette const & ComPal) const
{
int MinColours=min(TheColours.size(),ComPal.TheColours.size());
if (MinColours)
{
for (int f=0;f<MinColours;f++)
{
if (!(TheColours[f] ==ComPal.TheColours[f]))
return(false);
}
}
return(true);
}
/*----------------------------------------------------------------------
Colour Class Stuff
---------------------------------------------------------------------- */
Colour::Colour(int nR,int nG,int nB)
{
R=nR;
G=nG;
B=nB;
}
bool Colour::operator==(Colour const &Col) const
{
return((R==Col.R) && (G==Col.G) && (B==Col.B));
}
bool Colour::operator!=(Colour const &Col) const
{
return(!(*this==Col));
}
void Colour::CopyCol(Colour const &Col)
{
R=Col.R;
G=Col.G;
B=Col.B;
}
int Colour::DistanceUnroot(Colour const &Col) const
{
int Dist;
int RDif=R-Col.R;
int GDif=G-Col.G;
int BDif=B-Col.B;
Dist=RDif*RDif+GDif*GDif+BDif*BDif;
return(Dist);
}
float Colour::Distance(Colour const &Col) const
{
float Dist;
float RDif=R-Col.R;
float GDif=G-Col.G;
float BDif=B-Col.B;
Dist=sqrt(RDif*RDif+GDif*GDif+BDif*BDif);
return(Dist);
}
int * Palette::MakeRemapTable(Palette const & P) const
{
int * RetTab;
if (!(RetTab=new int[P.GetNumOfCols()]))
Error(ERM_OUTOFMEM);
int NumOfFCols=P.GetNumOfCols();
int NumOfGCols=GetNumOfCols();
for (int f=1;f<NumOfFCols;f++)
{
Colour const * ThisCol;
ThisCol=&P[f];
int MinIndex=-1;
int MinDist=-1;
for (int g=1;g<NumOfGCols && MinDist;g++)
{
int Distance=(*this)[g].DistanceUnroot(*ThisCol);
if ((MinIndex==-1) || (Distance < MinDist))
{
MinIndex=g;
MinDist=Distance;
}
}
if (MinIndex < 0)
RetTab[f]=f;
else
RetTab[f]=MinIndex;
}
RetTab[0]=0;
return(RetTab);
}
/*===========================================================================
end */

125
Utils/Libs/GLib/Pal.hpp Normal file
View File

@ -0,0 +1,125 @@
/*=========================================================================
PAL.CPP
Author: Gary Liddon @ Fareham
Created:
Project:
Purpose:
Copyright (c) 1997 G R Liddon
===========================================================================*/
#ifndef __PAL_HPP__
#define __PAL_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* STL
--- */
#include <vector>
/* Glib
---- */
#include "gobject.hpp"
#include "gtypes.h"
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class GLIB_API Colour : public GObject
{
public:
Colour(int nR=0,int nG=0,int nB=0);
Colour(Colour const & Col) {CopyCol(Col);}
void operator=(Colour const &Col) {CopyCol(Col);}
int GetR(void) const {return (R);}
int GetG(void) const {return (G);}
int GetB(void) const {return (B);}
void SetR(int n){R=n;}
void SetG(int n){G=n;}
void SetB(int n){B=n;}
void SetRGB(int nr,int ng,int nb)
{
SetR(nr);
SetG(ng);
SetB(nb);
}
float Distance(Colour const &Col) const;
int DistanceUnroot(Colour const &Col) const;
bool operator==(Colour const &Col) const;
bool operator<(Colour const &Col) const;
bool operator!=(Colour const &Col) const;
protected:
void CopyCol(Colour const &);
int R;
int G;
int B;
};
class GLIB_API Palette : public GObject
{
public:
Palette(void);
Palette(Palette const &);
~Palette(void);
void operator=(Palette const &Fr);
bool operator==(Palette const &Fr) const;
bool operator<(Palette const &Fr) const;
int GetNumOfCols(void) const {return TheColours.size();}
int * MakeRemapTable(Palette const & P) const;
Colour const & operator[](int) const;
Colour & operator[](int);
u8 * MakeDpPal(void) const;
bool FromLbm(char const * Name);
void SetPalSize(int NumOfCols);
bool IsIntersecting(Palette const & ComPal) const;
protected:
void CopyPal(Palette const &Fr);
typedef std::vector <Colour> ColVec;
typedef ColVec::iterator ColVecIt;
ColVec TheColours;
Colour DummyCol;
};
/*---------------------------------------------------------------------- */
#endif /* __PAL_HPP__ */
/*===========================================================================
end */

4952
Utils/Libs/GLib/REGEX.C Normal file

File diff suppressed because it is too large Load Diff

493
Utils/Libs/GLib/REGEX.H Normal file
View File

@ -0,0 +1,493 @@
/* Definitions for data structures and routines for the regular
expression library, version 0.12.
Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#define __STDC__ 1
#define STDC_HEADERS 1
#define REGEX_MALLOC
#ifndef __REGEXP_LIBRARY_H__
#define __REGEXP_LIBRARY_H__
/* POSIX says that <sys/types.h> must be included (by the caller) before
<regex.h>. */
#ifdef VMS
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
should be there. */
#include <stddef.h>
#endif
/* The following bits are used to determine the regexp syntax we
recognize. The set/not-set meanings are chosen so that Emacs syntax
remains the value 0. The bits are given in alphabetical order, and
the definitions shifted by one from the previous bit; thus, when we
add or remove a bit, only one other definition need change. */
typedef unsigned reg_syntax_t;
/* If this bit is not set, then \ inside a bracket expression is literal.
If set, then such a \ quotes the following character. */
#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
/* If this bit is not set, then + and ? are operators, and \+ and \? are
literals.
If set, then \+ and \? are operators and + and ? are literals. */
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
/* If this bit is set, then character classes are supported. They are:
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
If not set, then character classes are not supported. */
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
If this bit is not set, then it depends:
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
We already implemented a previous draft which made those constructs
invalid, though, so we haven't changed the code back. */
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
/* If this bit is set, then special characters are always special
regardless of where they are in the pattern.
If this bit is not set, then special characters are special only in
some contexts; otherwise they are ordinary. Specifically,
* + ? and intervals are only special when not after the beginning,
open-group, or alternation operator. */
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
immediately after an alternation or begin-group operator. */
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
/* If this bit is set, then . matches newline.
If not set, then it doesn't. */
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
/* If this bit is set, then . doesn't match NUL.
If not set, then it does. */
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
/* If this bit is set, nonmatching lists [^...] do not match newline.
If not set, they do. */
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
/* If this bit is set, either \{...\} or {...} defines an
interval, depending on RE_NO_BK_BRACES.
If not set, \{, \}, {, and } are literals. */
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
/* If this bit is set, +, ? and | aren't recognized as operators.
If not set, they are. */
#define RE_LIMITED_OPS (RE_INTERVALS << 1)
/* If this bit is set, newline is an alternation operator.
If not set, newline is literal. */
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
are literals.
If not set, then `\{...\}' defines an interval. */
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
/* If this bit is set, (...) defines a group, and \( and \) are literals.
If not set, \(...\) defines a group, and ( and ) are literals. */
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
/* If this bit is set, then \<digit> matches <digit>.
If not set, then \<digit> is a back-reference. */
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
/* If this bit is set, then | is an alternation operator, and \| is literal.
If not set, then \| is an alternation operator, and | is literal. */
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
/* If this bit is set, then an ending range point collating higher
than the starting range point, as in [z-a], is invalid.
If not set, then when ending range point collates higher than the
starting range point, the range is ignored. */
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
/* If this bit is set, then an unmatched ) is ordinary.
If not set, then an unmatched ) is invalid. */
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
/* This global variable defines the particular regexp syntax to use (for
some interfaces). When a regexp is compiled, the syntax used is
stored in the pattern buffer, so changing this does not affect
already-compiled regexps. */
extern reg_syntax_t re_syntax_options;
/* Define combinations of the above bits for the standard possibilities.
(The [[[ comments delimit what gets put into the Texinfo file, so
don't delete them!) */
/* [[[begin syntaxes]]] */
#define RE_SYNTAX_EMACS 0
#define RE_SYNTAX_AWK \
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
| RE_UNMATCHED_RIGHT_PAREN_ORD)
#define RE_SYNTAX_POSIX_AWK \
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
#define RE_SYNTAX_GREP \
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
| RE_NEWLINE_ALT)
#define RE_SYNTAX_EGREP \
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \
| RE_NO_BK_VBAR)
#define RE_SYNTAX_POSIX_EGREP \
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
/* Syntax bits common to both basic and extended POSIX regex syntax. */
#define _RE_SYNTAX_POSIX_COMMON \
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
#define RE_SYNTAX_POSIX_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
isn't minimal, since other operators, such as \`, aren't disabled. */
#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
#define RE_SYNTAX_POSIX_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \
| RE_UNMATCHED_RIGHT_PAREN_ORD)
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
/* [[[end syntaxes]]] */
/* Maximum number of duplicates an interval can allow. Some systems
(erroneously) define this in other header files, but we want our
value, so remove any previous define. */
#ifdef RE_DUP_MAX
#undef RE_DUP_MAX
#endif
#define RE_DUP_MAX ((1 << 15) - 1)
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
/* If this bit is set, then use extended regular expression syntax.
If not set, then use basic regular expression syntax. */
#define REG_EXTENDED 1
/* If this bit is set, then ignore case when matching.
If not set, then case is significant. */
#define REG_ICASE (REG_EXTENDED << 1)
/* If this bit is set, then anchors do not match at newline
characters in the string.
If not set, then anchors do match at newlines. */
#define REG_NEWLINE (REG_ICASE << 1)
/* If this bit is set, then report only success or fail in regexec.
If not set, then returns differ between not matching and errors. */
#define REG_NOSUB (REG_NEWLINE << 1)
/* POSIX `eflags' bits (i.e., information for regexec). */
/* If this bit is set, then the beginning-of-line operator doesn't match
the beginning of the string (presumably because it's not the
beginning of a line).
If not set, then the beginning-of-line operator does match the
beginning of the string. */
#define REG_NOTBOL 1
/* Like REG_NOTBOL, except for the end-of-line. */
#define REG_NOTEOL (1 << 1)
/* If any error codes are removed, changed, or added, update the
`re_error_msg' table in regex.c. */
typedef enum
{
REG_NOERROR = 0, /* Success. */
REG_NOMATCH, /* Didn't find a match (for regexec). */
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
REG_BADPAT, /* Invalid pattern. */
REG_ECOLLATE, /* Not implemented. */
REG_ECTYPE, /* Invalid character class name. */
REG_EESCAPE, /* Trailing backslash. */
REG_ESUBREG, /* Invalid back reference. */
REG_EBRACK, /* Unmatched left bracket. */
REG_EPAREN, /* Parenthesis imbalance. */
REG_EBRACE, /* Unmatched \{. */
REG_BADBR, /* Invalid contents of \{\}. */
REG_ERANGE, /* Invalid range end. */
REG_ESPACE, /* Ran out of memory. */
REG_BADRPT, /* No preceding re for repetition op. */
/* Error codes we've added. */
REG_EEND, /* Premature end. */
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
} reg_errcode_t;
/* This data structure represents a compiled pattern. Before calling
the pattern compiler, the fields `buffer', `allocated', `fastmap',
`translate', and `no_sub' can be set. After the pattern has been
compiled, the `re_nsub' field is available. All other fields are
private to the regex routines. */
struct re_pattern_buffer
{
/* [[[begin pattern_buffer]]] */
/* Space that holds the compiled pattern. It is declared as
`unsigned char *' because its elements are
sometimes used as array indexes. */
unsigned char *buffer;
/* Number of bytes to which `buffer' points. */
unsigned long allocated;
/* Number of bytes actually used in `buffer'. */
unsigned long used;
/* Syntax setting with which the pattern was compiled. */
reg_syntax_t syntax;
/* Pointer to a fastmap, if any, otherwise zero. re_search uses
the fastmap, if there is one, to skip over impossible
starting points for matches. */
char *fastmap;
/* Either a translate table to apply to all characters before
comparing them, or zero for no translation. The translation
is applied to a pattern when it is compiled and to a string
when it is matched. */
char *translate;
/* Number of subexpressions found by the compiler. */
size_t re_nsub;
/* Zero if this pattern cannot match the empty string, one else.
Well, in truth it's used only in `re_search_2', to see
whether or not we should use the fastmap, so we don't set
this absolutely perfectly; see `re_compile_fastmap' (the
`duplicate' case). */
unsigned can_be_null : 1;
/* If REGS_UNALLOCATED, allocate space in the `regs' structure
for `max (RE_NREGS, re_nsub + 1)' groups.
If REGS_REALLOCATE, reallocate space if necessary.
If REGS_FIXED, use what's there. */
#define REGS_UNALLOCATED 0
#define REGS_REALLOCATE 1
#define REGS_FIXED 2
unsigned regs_allocated : 2;
/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
unsigned fastmap_accurate : 1;
/* If set, `re_match_2' does not return information about
subexpressions. */
unsigned no_sub : 1;
/* If set, a beginning-of-line anchor doesn't match at the
beginning of the string. */
unsigned not_bol : 1;
/* Similarly for an end-of-line anchor. */
unsigned not_eol : 1;
/* If true, an anchor at a newline matches. */
unsigned newline_anchor : 1;
/* [[[end pattern_buffer]]] */
};
typedef struct re_pattern_buffer regex_t;
/* search.c (search_buffer) in Emacs needs this one opcode value. It is
defined both in `regex.c' and here. */
#define RE_EXACTN_VALUE 1
/* Type for byte offsets within the string. POSIX mandates this. */
typedef int regoff_t;
/* This is the structure we store register match data in. See
regex.texinfo for a full description of what registers match. */
struct re_registers
{
unsigned num_regs;
regoff_t *start;
regoff_t *end;
};
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
`re_match_2' returns information about at least this many registers
the first time a `regs' structure is passed. */
#ifndef RE_NREGS
#define RE_NREGS 30
#endif
/* POSIX specification for registers. Aside from the different names than
`re_registers', POSIX uses an array of structures, instead of a
structure of arrays. */
typedef struct
{
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
} regmatch_t;
/* Declarations for routines. */
/* To avoid duplicating every routine declaration -- once with a
prototype (if we are ANSI), and once without (if we aren't) -- we
use the following macro to declare argument types. This
unfortunately clutters up the declarations a bit, but I think it's
worth it. */
#if __STDC__
#define _RE_ARGS(args) args
#else /* not __STDC__ */
#define _RE_ARGS(args) ()
#endif /* not __STDC__ */
/* Sets the current default syntax to SYNTAX, and return the old syntax.
You can also simply assign to the `re_syntax_options' variable. */
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
/* Compile the regular expression PATTERN, with length LENGTH
and syntax given by the global `re_syntax_options', into the buffer
BUFFER. Return NULL if successful, and an error string if not. */
extern const char *re_compile_pattern
_RE_ARGS ((const char *pattern, int length,
struct re_pattern_buffer *buffer));
/* Compile a fastmap for the compiled pattern in BUFFER; used to
accelerate searches. Return 0 if successful and -2 if was an
internal error. */
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
/* Search in the string STRING (with length LENGTH) for the pattern
compiled into BUFFER. Start searching at position START, for RANGE
characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
extern int re_search
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, int range, struct re_registers *regs));
/* Like `re_search', but search in the concatenation of STRING1 and
STRING2. Also, stop searching at index START + STOP. */
extern int re_search_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2,
int start, int range, struct re_registers *regs, int stop));
/* Like `re_search', but return how many characters in STRING the regexp
in BUFFER matched, starting at position START. */
extern int re_match
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, struct re_registers *regs));
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
extern int re_match_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2,
int start, struct re_registers *regs, int stop));
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
ENDS. Subsequent matches using BUFFER and REGS will use this memory
for recording register information. STARTS and ENDS must be
allocated with malloc, and must each be at least `NUM_REGS * sizeof
(regoff_t)' bytes long.
If NUM_REGS == 0, then subsequent matches should allocate their own
register data.
Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */
extern void re_set_registers
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
unsigned num_regs, regoff_t *starts, regoff_t *ends));
/* 4.2 bsd compatibility. */
extern char *re_comp _RE_ARGS ((const char *));
extern int re_exec _RE_ARGS ((const char *));
/* POSIX compatibility. */
extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
extern int regexec
_RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags));
extern size_t regerror
_RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
size_t errbuf_size));
extern void regfree _RE_ARGS ((regex_t *preg));
#endif /* not __REGEXP_LIBRARY_H__ */
/*
Local variables:
make-backup-files: t
version-control: t
trim-versions-without-asking: nil
End:
*/

View File

@ -0,0 +1,146 @@
/*************************************************
* Perl-Compatible Regular Expressions *
*************************************************/
/* This file is automatically written by the makechartables auxiliary
program. If you edit it by hand, you might like to edit the Makefile to
prevent its ever being regenerated.
This file is #included in the compilation of pcre.c to build the default
character tables which are used when no tables are passed to the compile
function. */
static unsigned char pcre_default_tables[] = {
/* This table is a lower casing table. */
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63,
64, 97, 98, 99,100,101,102,103,
104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,
120,121,122, 91, 92, 93, 94, 95,
96, 97, 98, 99,100,101,102,103,
104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,
120,121,122,123,124,125,126,127,
128,129,130,131,132,133,134,135,
136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,
152,153,154,155,156,157,158,159,
160,161,162,163,164,165,166,167,
168,169,170,171,172,173,174,175,
176,177,178,179,180,181,182,183,
184,185,186,187,188,189,190,191,
192,193,194,195,196,197,198,199,
200,201,202,203,204,205,206,207,
208,209,210,211,212,213,214,215,
216,217,218,219,220,221,222,223,
224,225,226,227,228,229,230,231,
232,233,234,235,236,237,238,239,
240,241,242,243,244,245,246,247,
248,249,250,251,252,253,254,255,
/* This table is a case flipping table. */
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63,
64, 97, 98, 99,100,101,102,103,
104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,
120,121,122, 91, 92, 93, 94, 95,
96, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90,123,124,125,126,127,
128,129,130,131,132,133,134,135,
136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,
152,153,154,155,156,157,158,159,
160,161,162,163,164,165,166,167,
168,169,170,171,172,173,174,175,
176,177,178,179,180,181,182,183,
184,185,186,187,188,189,190,191,
192,193,194,195,196,197,198,199,
200,201,202,203,204,205,206,207,
208,209,210,211,212,213,214,215,
216,217,218,219,220,221,222,223,
224,225,226,227,228,229,230,231,
232,233,234,235,236,237,238,239,
240,241,242,243,244,245,246,247,
248,249,250,251,252,253,254,255,
/* This table contains bit maps for digits, 'word' chars, and white
space. Each map is 32 bytes long and the bits run from the least
significant end of each byte. */
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,
/* This table identifies various classes of character by individual bits:
0x01 white space character
0x02 letter
0x04 decimal digit
0x08 hexadecimal digit
0x10 alphanumeric or '_'
0x80 regular expression metacharacter or binary zero
*/
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */
0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00, /* 8- 15 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16- 23 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */
0x01,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /* - ' */
0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x00, /* ( - / */
0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /* 0 - 7 */
0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x80, /* 8 - ? */
0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */
0x12,0x12,0x12,0x80,0x00,0x00,0x80,0x10, /* X - _ */
0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */
0x12,0x12,0x12,0x80,0x80,0x00,0x00,0x00, /* x -127 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
/* End of chartables.c */

2652
Utils/Libs/GLib/gal.c Normal file

File diff suppressed because it is too large Load Diff

210
Utils/Libs/GLib/gal.h Normal file
View File

@ -0,0 +1,210 @@
/* ==========================================================================
File: GAL.H
Notes: Memory allocation \ deallocation module header file
Author: Gary Liddon
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
=========================================================================== */
#ifndef __GAL_H__
#define __GAL_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
#define NULL_HANDLE -1
#define PHANTOM_MEM -1
/* ---------------------------------------------------------------------------
Typedefs
-------- */
typedef S32 MHANDLE;
typedef int MTYPE;
typedef void (*GAL_FILTER)(U32 MemType,U32 Size,const char *Name);
/* ---------------------------------------------------------------------------
Enums
----- */
enum
{
GAL_PHANTOM_MEM=0,
GAL_FIRST_FREE_MEM_TYPE,
GAL_HIGH = 1<<15,
GAL_FLAGS = GAL_HIGH
};
typedef enum GAL_ERROR_CODE
{
ERR_GAL_NO_ERROR = 0,
ERR_RUN_OUT_OF_MEM_HDRS,
ERR_GAL_MEM_TYPE_EXISTS,
ERR_GAL_MEM_TYPE_OVERLAP,
ERR_GAL_INVALID_MEM_TYPE,
ERR_GAL_INVALID_MEM_HANDLE,
ERR_GAL_MEM_ALREADY_UNLOCKED,
ERR_GAL_MEM_BLOCK_COLLISION,
ERR_GAL_MEM_AREA_NOT_COVERED,
ERR_GAL_NO_MEM_MOVE,
ERR_GAL_NOT_ENOUGH_MEM,
NUM_OF_ERROR_MESSAGES
}GAL_ERROR_CODE;
typedef enum GAL_VERB_LEV
{
GAL_SILENT=0,
GAL_AVERAGE,
GAL_NOISY
} GAL_VERB_LEV;
/* ---------------------------------------------------------------------------
Structures
---------- */
/* Pre declaration of Header each block of free / used memory has
-------------------------------------------------------------- */
struct MEM_HDR;
/* Memory Initialisation module Structure
Must be placed in RAM
-------------------------------------- */
typedef struct MEM_INIT_INFO
{
void * Mem; /* Start of memory region */
U32 Size; /* Size of memory region */
U32 Type; /* Type of memory region */
char * TypeString; /* Debugging string */
U16 Alignment; /* Alignment required */
void (*MemMove)(void *Dest,void *Source,U32 size); /* Memory move vector */
/* Used by System, Leave uninitialised */
struct MEM_INIT_INFO * NextInitBlock;
U16 Flags;
struct MEM_HDR * Empty; /* Pointer to free MEM_HDRs of this mem type */
struct MEM_HDR * Used; /* Pointer to used MEM_HDRs of this mem type */
} MEM_INIT_INFO;
/* Structure used by GAL_AllocMultiStruct
-------------------------------------- */
typedef struct GAL_STRUCT
{
int OriginalSize;
UINT Offset;
} GAL_STRUCT;
/* ---------------------------------------------------------------------------
Supported Functions
------------------- */
#ifdef __cplusplus
extern "C" {
#endif
/* Initialisation Functions
------------------------ */
void GAL_InitModule(void);
/* Mem allocing / deallocing functions
----------------------------------- */
GLIB_API MHANDLE GAL_Alloc(U32 Size,U32 Type,const char *Name);
GLIB_API MHANDLE GAL_AllocAt(U32 Size,void *Addr,U32 Type,const char *Name);
GLIB_API BOOL GAL_Free(MHANDLE Handle);
GLIB_API void * GAL_Lock(MHANDLE Handle);
GLIB_API BOOL GAL_Unlock(MHANDLE Handle);
/*
Purpose: Split a Block into two. If Split point outside
block to be split then this will return an error.
Split is rounded rounded up to be on mem type alignment
boundary
Returns: Handle of second block else
NULL_HANDLE if unsucessful
*/
GLIB_API MHANDLE GAL_SplitBlock(MHANDLE CurBlock,U32 Split);
GLIB_API BOOL GAL_SetMemName(MHANDLE Hnd,const char *Text);
GLIB_API MHANDLE GAL_AllocMultiStruct(GAL_STRUCT * G,U32 Type,const char *Name);
GLIB_API UINT GAL_ProcessMultiStruct(GAL_STRUCT * G,U32 Type);
GLIB_API UINT GAL_GetMemSize(MHANDLE hnd);
/* Mem type Functions
------------------ */
GLIB_API BOOL GAL_DefragMem(U32 type);
GLIB_API BOOL GAL_AddMemType(MEM_INIT_INFO *M);
GLIB_API U32 GAL_TotalMem(U32 Type);
GLIB_API void * GAL_MemBase(U32 Type);
GLIB_API U32 GAL_GetFreeMem(U32 Type);
GLIB_API U32 GAL_GetUsedMem(U32 Type);
GLIB_API U32 GAL_LargestFreeBlock(U32 Type);
GLIB_API S32 GAL_AlignSizeToType(U32 Size,U32 MemType);
GLIB_API u32 GAL_GetAlignment(u32 MemType);
/* Error Functions
--------------- */
GLIB_API GAL_ERROR_CODE GAL_GetLastErrorCode(void);
GLIB_API char * GAL_GetLastErrorText(void);
GLIB_API char * GAL_GetErrorText(GAL_ERROR_CODE Err);
GLIB_API void GAL_MemDump(U32 Type);
GLIB_API void GAL_HaltOnError(void);
GLIB_API void GAL_ReturnOnError(void);
/* Debug amd diagnostic functions
------------------------------ */
GLIB_API s32 GAL_GetSize(MHANDLE hnd);
/* Debug amd diagnostic functions
------------------------------ */
GLIB_API BOOL GAL_CheckMem(U32 Type);
GLIB_API GAL_FILTER GAL_SetAllocFilter(GAL_FILTER NewFilter);
GLIB_API void GAL_IterateUsedMem(U32 MemType,void (*Func)(MHANDLE hnd,void *Addr,U32 Size,const char *Name,int Users,int TimeStamp));
GLIB_API void GAL_IterateEmptyMem(U32 MemType,void (*Func)(void *Addr,U32 Size,const char *Name));
GLIB_API int GAL_HowManyUsedRegions(U32 Type);
GLIB_API int GAL_HowManyEmptyRegions(U32 Type);
GLIB_API int GAL_GetTimeStamp(void);
GLIB_API void GAL_IncTimeStamp(void);
GLIB_API void GAL_SetTimeStamp(int Time);
GLIB_API void GAL_SetErrorChecking(BOOL OnOff);
GLIB_API void GAL_SetVerbosity(GAL_VERB_LEV G);
GLIB_API int GAL_GetNumFreeHeaders(void);
GLIB_API u32 GAL_GetLastTypeAlloced(void);
GLIB_API BOOL GAL_SortUsedRegionsBySize(U32 Type);
GLIB_API BOOL GAL_SortUsedRegionsByAddress(U32 MemType);
/* ---------------------------------------------------------------------------
API'd but As Yet Unsupported
---------------------------- */
GLIB_API BOOL GAL_Resize(MHANDLE Handle);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

112
Utils/Libs/GLib/gdebug.h Normal file
View File

@ -0,0 +1,112 @@
/* ===========================================================================
File: GDEBUG.H
Notes: API for machine independant debugging
Author: Gary Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 - 1997 Gary Liddon
All rights reserved.
============================================================================ */
#ifndef __GDEBUG_H__
#define __GDEBUG_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
/* Standard Lib
------------ */
#include "stdarg.h"
/* Glib Includes
------------- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Typedefs
-------- */
#ifdef __GL_DEBUG__
#define ASSERT(p) ( (p) ? (void)0 : (void) DBG_Error(#p,__FILE__,__LINE__) )
#else
#define ASSERT(p) ( (p) ? (void)0 : (void) DBG_Error(NULL,__FILE__,__LINE__) )
#endif
#ifdef __GL_DEBUG__
#define DBG_MSG0(a) DBG_SendMessage(a)
#define DBG_MSG1(a,b) DBG_SendMessage(a,b)
#define DBG_MSG2(a,b,c) DBG_SendMessage(a,b,c)
#define DBG_MSG3(a,b,c,d) DBG_SendMessage(a,b,c,d)
#define DBG_MSG4(a,b,c,d,e) DBG_SendMessage(a,b,c,d,e)
#else
#define DBG_MSG0(a)
#define DBG_MSG1(a,b)
#define DBG_MSG2(a,b,c)
#define DBG_MSG3(a,b,c,d)
#define DBG_MSG4(a,b,c,d,e)
#endif
/* ---------------------------------------------------------------------------
Enums
----- */
/* ---------------------------------------------------------------------------
Id for each file
---------------- */
/* ---------------------------------------------------------------------------
Externs
------- */
/* ---------------------------------------------------------------------------
Structures
---------- */
/* ---------------------------------------------------------------------------
Supported Functions
------------------- */
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API BOOL DBG_OpenModule(void);
GLIB_API void DBG_Halt(void);
GLIB_API void DBG_PollHost(void);
GLIB_API void DBG_SendMessage(char *e,...);
GLIB_API void DBG_SendErrorMessage(char *e,...);
GLIB_API void DBG_SetMessageHandler(void (*Func)(char *e,va_list argptr));
GLIB_API void DBG_SetErrorMessageHandler(void (*Func)(char *e,va_list argptr));
GLIB_API void DBG_Error(char *Text,char *File,int Line);
GLIB_API void DBG_SetErrorFunc(void (*EFunc)(char *Text,char *File,int Line));
GLIB_API void DBG_SetPollRoutine(void (*Func)(void));
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

46
Utils/Libs/GLib/gmain.c Normal file
View File

@ -0,0 +1,46 @@
/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
File: GMAIN.C
Notes: Main!
Author: G Robert Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 DCI Ltd All rights reserved.
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Glib Includes
ÄÄÄÄÄÄÄÄÄÄÄÄÄ */
#include "gmain.h"
#include "gal.h"
#include "gsys.h"
#include "tick.h"
#include "gutils.h"
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function Prototypes
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Main
ÄÄÄÄ */
void main(void)
{
GSYS_InitMachine();
GAL_InitModule();
TICK_InitModule();
GU_InitModule();
AppMain();
while (1)
{
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Ends
ÄÄÄÄ */

59
Utils/Libs/GLib/gmain.h Normal file
View File

@ -0,0 +1,59 @@
/* ===========================================================================
File: GMAIN.C
Notes: Glib Main
Author: Gary Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 - 1997 Gary Liddon
All rights reserved.
============================================================================ */
#ifndef __GMAIN_H__
#define __GMAIN_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Typedefs
-------- */
/* ---------------------------------------------------------------------------
Enums
----- */
/* ---------------------------------------------------------------------------
Externs
------- */
/* ---------------------------------------------------------------------------
Structures
---------- */
/* ---------------------------------------------------------------------------
Supported Functions
------------------- */
#ifdef __cplusplus
extern "C" {
#endif
void AppMain(void);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

83
Utils/Libs/GLib/gsys.h Normal file
View File

@ -0,0 +1,83 @@
/* ==========================================================================
File: GSYS.H
Notes: Machine Independant API to target for low level system info
and manipulation
Author: Gary Liddon
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
=========================================================================== */
#ifndef __GSYS_H__
#define __GSYS_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Typedefs
-------- */
/* ---------------------------------------------------------------------------
Enums
----- */
/* ---------------------------------------------------------------------------
Externs
------- */
/* ---------------------------------------------------------------------------
Structures
---------- */
typedef struct MEM_INFO
{
void * Addr;
U32 Size;
} MEM_INFO;
/* ---------------------------------------------------------------------------
Supported Functions
------------------- */
#ifdef __cplusplus
extern "C" {
#endif
/* System Initialisation stuff
--------------------------- */
GLIB_API BOOL GSYS_InitMachine(void);
/* Stack handling functions
------------------------ */
GLIB_API void GSYS_SetStackAndJump(void *Stack,void(*Func)(void *),void *Param);
GLIB_API void GSYS_MarkStack(void * Stack, U32 StackSize);
GLIB_API BOOL GSYS_IsStackCorrupted(void * Stack, U32 StackSize);
GLIB_API BOOL GSYS_CheckPtr(void *Ptr);
GLIB_API BOOL GSYS_IsStackOutOfBounds(void* Stack, U32 StackSize);
/* Machine Info Functions
---------------------- */
GLIB_API const MEM_INFO * GSYS_GetWorkMemInfo(void);
#ifdef __cplusplus
};
#endif
/* Global Vars
----------- */
GLIB_API extern UINT GSYS_MemStart;
GLIB_API extern UINT GSYS_MemEnd;
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

225
Utils/Libs/GLib/gtimer.c Normal file
View File

@ -0,0 +1,225 @@
/* ===========================================================================
File: GTIMER.C
Notes: Timing Stuff
Author: G Robert Liddon @ 73b
Copyright (C) 1996 DCI Ltd All rights reserved.
============================================================================ */
/* ---------------------------------------------------------------------------
Standard Lib Includes
--------------------- */
/* Standard Lib
------------ */
/* Glib
---- */
#include "gal.h"
/* Headers
------- */
#include "gtimer.h"
#include "gtimsys.h"
/* ---------------------------------------------------------------------------
Defines and Enums
----------------- */
/* ---------------------------------------------------------------------------
Structs
------- */
/* ---------------------------------------------------------------------------
Vars
---- */
MHANDLE hndClocks;
CLOCK * Clocks;
int ClocksOut;
int ClocksInAll;
U32 TimeForAFrame;
U32 ReadTime;
/* ---------------------------------------------------------------------------
Function Prototypes
------------------- */
static void StartClock(CLOCK * C,U32 Id);
static void StopClock(CLOCK * C);
static void ReadTestFunc(void);
static U32 GetTimer(void)
{
return((GTIMSYS_GetTimer()*0x10000)/TimeForAFrame);
}
/* ---------------------------------------------------------------------------
Function: BOOL GTIM_Open(int MaxClocks,U32 RamId);
Purpose: Creates the timer moduler
Params: MaxClocks = Max amount of clocks you can have
Returns: FALSE if an error
--------------------------------------------------------------------------- */
BOOL GTIM_Open(int MaxClocks,U32 RamId)
{
hndClocks=GAL_Alloc(sizeof(CLOCK)*MaxClocks,RamId,NULL);
if (hndClocks != NULL_HANDLE)
{
Clocks=GAL_Lock(hndClocks);
if (Clocks)
{
ClocksInAll=MaxClocks;
TimeForAFrame=GTIMSYS_InitTimer();
GTIM_ClearClocks();
ReadTime=GTIM_TimeFunction(ReadTestFunc,5000);
return(TRUE);
}
}
return(FALSE);
}
/* ---------------------------------------------------------------------------
Function: void GTIM_ClearClocks(void)
Purpose: Reset all clocks
--------------------------------------------------------------------------- */
void GTIM_ClearClocks(void)
{
ClocksOut=0;
GTIMSYS_ResetTimer();
}
/* ---------------------------------------------------------------------------
Function: GTHANDLE GTIM_StartClock(U32 Id)
Purpose: Start a clock
Params: Id for a clock
Returns: Handle used to stop the clock
--------------------------------------------------------------------------- */
GTHANDLE GTIM_StartClock(U32 Id)
{
S32 RetHandle;
if (ClocksOut==ClocksInAll)
RetHandle=NULL_GTHANDLE;
else
{
RetHandle=ClocksOut;
ClocksOut++;
StartClock(&Clocks[RetHandle],Id);
}
return(RetHandle);
}
/* ---------------------------------------------------------------------------
Function: void GTIM_StopClock(GTHANDLE Hnd)
Purpose: Stop a clock
Params: Id for a clock to stop
--------------------------------------------------------------------------- */
U32 GTIM_StopClock(GTHANDLE Hnd)
{
CLOCK * C;
C=&Clocks[Hnd];
StopClock(C);
return(C->StopTime-C->StartTime);
}
/* ---------------------------------------------------------------------------
Function: void GTIM_IterateClocks(void (*Func)(U32 Start,U32 End,U32 Id)
Purpose: Callback through all the current clocks
Params: Id for a clock to stop
--------------------------------------------------------------------------- */
void GTIM_IterateClocks(void (*Func)(U32 Start,U32 End,U32 Id))
{
int f;
CLOCK * C;
for (f=0,C=Clocks;f<ClocksOut;f++,C++)
Func(C->StartTime,C->StopTime,C->Id);
}
/* ---------------------------------------------------------------------------
Function: U32 GTIM_TimeFunction(void (*Func)(void),int Tries)
Purpose: Test this functions speed
Params: Func -> Function to test
Tries = Number of tries to average it out against
Returns: Time taken
--------------------------------------------------------------------------- */
U32 GTIM_TimeFunction(void (*Func)(void),int Tries)
{
U32 Time0;
U32 Time1;
int f;
Time0=GetTimer();
for (f=0;f<Tries;f++)
Func();
Time1=GetTimer();
return ((Time1-Time0)/Tries);
}
/* ---------------------------------------------------------------------------
Helpy routines
--------------------------------------------------------------------------- */
static void StartClock(CLOCK * C,U32 Id)
{
int RealTime;
RealTime=GetTimer();
C->StartTime=RealTime;
C->Id=Id;
C->Running=TRUE;
}
static void StopClock(CLOCK * C)
{
int RealTime;
RealTime=GetTimer();
C->StopTime=RealTime;
C->Running=FALSE;
}
static void ReadTestFunc(void)
{
GTHANDLE GtHnd0;
GtHnd0=GTIM_StartClock(0);
GTIM_StopClock(GtHnd0);
}
/* ---------------------------------------------------------------------------
ends */

76
Utils/Libs/GLib/gtimer.h Normal file
View File

@ -0,0 +1,76 @@
/* ===========================================================================
File: GTIMER.C
Notes: PSX stuff for timing things
Author: Gary Liddon
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
============================================================================ */
#ifndef __GTIMER_H__
#define __GTIMER_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
/* Glib
---- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Typedefs
-------- */
/* ---------------------------------------------------------------------------
Enums
----- */
/* ---------------------------------------------------------------------------
Structures
---------- */
typedef S32 GTHANDLE;
typedef struct CLOCK
{
U32 StartTime;
U32 StopTime;
U32 Id;
BOOL Running;
} CLOCK;
#define NULL_GTHANDLE -1
/* ---------------------------------------------------------------------------
Supported Functions
------------------- */
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API BOOL GTIM_Open(int MaxClocks,U32 RamId);
GLIB_API void GTIM_ClearClocks(void);
GLIB_API GTHANDLE GTIM_StartClock(U32 Id);
GLIB_API U32 GTIM_StopClock(GTHANDLE Hnd);
GLIB_API void GTIM_StopAllClocks(void);
GLIB_API void GTIM_IterateClocks(void (*Func)(U32 Start,U32 End,U32 Id));
GLIB_API U32 GTIM_TimeFunction(void (*Func)(void),int Tries);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

57
Utils/Libs/GLib/gtimsys.h Normal file
View File

@ -0,0 +1,57 @@
/* ヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘヘ
File: GTIMSYS.C
Notes: Timing system stuff needed by gtim
Author: G Robert Liddon @ 73b
Copyright (C) 1996 DCI Ltd All rights reserved.
*/
#ifndef __GTIMSYS_H__
#define __GTIMSYS_H__
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
Includes
*/
/* Glib
*/
#include "gtypes.h"
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
Defines
*/
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
Typedefs
*/
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
Enums
*/
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
Structures
*/
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
Supported Functions
*/
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API U32 GTIMSYS_InitTimer(void);
GLIB_API void GTIMSYS_ResetTimer(void);
GLIB_API U32 GTIMSYS_GetTimer(void);
#ifdef __cplusplus
}
#endif
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト */
#endif
/* トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
ends */

154
Utils/Libs/GLib/gtypes.h Normal file
View File

@ -0,0 +1,154 @@
/* ==========================================================================
File: GTYPES.H
Notes: Standard Non Machine dependant data types used by LIBGAZ
Author: Gary Liddon @ 73b
Created: Saturday 16th March 1996
Copyright (C) 1996 - 1997 Gary Liddon
All rights reserved.
=========================================================================== */
#ifndef __GTYPES_H__
#define __GTYPES_H__
/* ---------------------------------------------------------------------------
Includes
-------- */
#include "mtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif /* __cplusplus */
#endif /* NULL */
#ifndef NOP
#define NOP ((void)0)
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
/* ---------------------------------------------------------------------------
Typedefs
-------- */
#ifndef __GLIB_uint__
#define __GLIB_uint__
typedef unsigned int uint;
#endif
#ifndef __GLIB_uchar__
#define __GLIB_uchar__
typedef unsigned char uchar;
#endif
#ifndef __GLIB_ushort__
#define __GLIB_ushort__
typedef unsigned short ushort;
#endif
#ifndef __GLIB_ulong__
#define __GLIB_ulong__
typedef unsigned long ulong;
#endif
#ifndef __GLIB_UBYTE__
#define __GLIB_UBYTE__
typedef u8 UBYTE;
#endif
#ifndef __GLIB_UWORD__
#define __GLIB_UWORD__
typedef u16 UWORD;
#endif
typedef uint UINT;
typedef uchar UCHAR;
typedef ushort USHORT;
typedef ulong ULONG;
#ifdef __GLIB_BOOLAsInt__
typedef int BOOL;
#else
typedef u8 BOOL;
#endif
/* Lower case versions are defined in mtypes.h */
typedef s8 S8; /* signed 8-bit */
typedef s16 S16; /* signed 16-bit */
typedef s32 S32; /* signed 32-bit */
typedef u8 U8; /* unsigned 8-bit */
typedef u16 U16; /* unsigned 16-bit */
typedef u32 U32; /* unsigned 32-bit */
/* More alternative names */
typedef s8 int8;
typedef u8 uint8;
typedef u8 byte;
typedef s16 int16;
typedef u16 uint16;
typedef u16 word;
typedef s32 int32;
typedef u32 uint32;
typedef u32 dword;
/* 64 bit names
------------ */
#ifndef __GLIB_No64__
typedef s64 S64;
typedef u64 U64;
typedef s64 int64;
typedef u64 uint64;
typedef u64 qword;
#endif
/* GLIB Api Defintion
------------------ */
#ifndef GLIB_API
#define GLIB_API
#endif
/* ---------------------------------------------------------------------------
Globals
------- */
/* --------------------------------------------------------------------------- */
#endif /* __GTYPES_H__ */
/* ---------------------------------------------------------------------------
ends */

132
Utils/Libs/GLib/gutils.c Normal file
View File

@ -0,0 +1,132 @@
/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
File: GUTILS.C
Notes: Machine indepnant util code
Author: G Robert Liddon @ 73b
Project: NBA Hang Time PSX
Copyright (C) 1996 DCI Ltd All rights reserved.
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Includes
ÄÄÄÄÄÄÄÄ */
/* Glib
ÄÄÄÄ */
#include "gsys.h"
#include "gdebug.h"
/* Game
ÄÄÄÄ */
#include "gutils.h"
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function Prototypes
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Vars
ÄÄÄÄ */
U32 RndTabs[6];
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Tables
ÄÄÄÄÄÄ */
U32 DefaultRnd[6]=
{
0xabcd1234,
0xffde1534,
0xffde1534,
0x001a1010,
0xf61a1890,
0x00000002,
};
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Init the general utilities module
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL GU_InitModule(void)
{
GU_SetRndSeed(DefaultRnd);
return(TRUE);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Init the general utilities module
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void GU_SetRndSeed(U32 *Tab)
{
int f;
for (f=0;f<6;f++)
RndTabs[f]=Tab[f];
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Get a random 32 bit unsigned number
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
U32 GU_GetRnd(void)
{
U32 RetVal;
RetVal=RndTabs[1]+RndTabs[4];
if (RetVal< RndTabs[1] && RetVal < RndTabs[4])
RetVal++;
RetVal++;
RndTabs[0]=RetVal;
RndTabs[5]=RndTabs[4];
RndTabs[4]=RndTabs[3];
RndTabs[3]=RndTabs[2];
RndTabs[2]=RndTabs[1];
RndTabs[1]=RndTabs[0];
return(RndTabs[0]);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: S32 GU_GetSRnd(void)
Notes: Get a signed random number
Returns: Signed Number
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
S32 GU_GetSRnd(void)
{
return((S32)GU_GetRnd());
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: U32 GU_GetRndRange(UINT Range)
Notes: Returns a number between 0 and Range-1
Params: Range -> Max number returned -1
Returns: unsigned number
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
U32 GU_GetRndRange(UINT Range)
{
return(GU_GetRnd()%Range);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: UINT GU_AlignVal(UINT w,UINT round)
Notes: Align a value to a boundary (7 round to boundaries of 4 = 8)
Params: w = Value to align
round = Boundaries to align it to
Returns: Aligned number
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
UINT GU_AlignVal(UINT w,UINT round)
{
w += round - 1;
return (w - w % round);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
ends */

63
Utils/Libs/GLib/gutils.h Normal file
View File

@ -0,0 +1,63 @@
/* ==========================================================================
File: GUTILS.C
Notes: General miscellaneous utilities
Author: Gary Liddon
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
=========================================================================== */
#ifndef __GUTILS_H
#define __GUTILS_H
/* ---------------------------------------------------------------------------
Includes
-------- */
/* Glib
---- */
#include "gtypes.h"
/* Includes
-------- */
/* ---------------------------------------------------------------------------
Defines, enums & Typedefs
------------------------- */
#define STRUCT_OFFSET(type,member) ((int)(&(((type *)0)->member)));
/* ---------------------------------------------------------------------------
Structure Definitions
--------------------- */
/* ---------------------------------------------------------------------------
Globals
------- */
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API BOOL GU_InitModule(void);
/* Random number stuff
------------------- */
GLIB_API void GU_SetRndSeed(U32 *Tab);
GLIB_API U32 GU_GetRnd(void);
GLIB_API S32 GU_GetSRnd(void);
GLIB_API U32 GU_GetRndRange(UINT Range); /* 0- Range-1 */
GLIB_API UINT GU_AlignVal(UINT w,UINT round);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

334
Utils/Libs/GLib/internal.h Normal file
View File

@ -0,0 +1,334 @@
/*************************************************
* Perl-Compatible Regular Expressions *
*************************************************/
#define PCRE_VERSION "2.02 14-Jan-1999"
/* This is a library of functions to support regular expressions whose syntax
and semantics are as close as possible to those of the Perl 5 language. See
the file Tech.Notes for some information on the internals.
Written by: Philip Hazel <ph10@cam.ac.uk>
Copyright (c) 1997-1999 University of Cambridge
-----------------------------------------------------------------------------
Permission is granted to anyone to use this software for any purpose on any
computer system, and to redistribute it freely, subject to the following
restrictions:
1. This software 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.
2. The origin of this software must not be misrepresented, either by
explicit claim or by omission.
3. Altered versions must be plainly marked as such, and must not be
misrepresented as being the original software.
-----------------------------------------------------------------------------
*/
/* This header contains definitions that are shared between the different
modules, but which are not relevant to the outside. */
/* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
define a macro for memmove() if USE_BCOPY is defined. */
#ifdef USE_BCOPY
#undef memmove /* some systems may have a macro */
#define memmove(a, b, c) bcopy(b, a, c)
#endif
/* Standard C headers plus the external interface definition */
#include <ctype.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pcre.h"
/* In case there is no definition of offsetof() provided - though any proper
Standard C system should have one. */
#ifndef offsetof
#define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
#endif
/* These are the public options that can change during matching. */
#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
/* Private options flags start at the most significant end of the two bytes.
The public options defined in pcre.h start at the least significant end. Make
sure they don't overlap! */
#define PCRE_FIRSTSET 0x8000 /* first_char is set */
#define PCRE_STARTLINE 0x4000 /* start after \n for multiline */
#define PCRE_INGROUP 0x2000 /* compiling inside a group */
/* Options for the "extra" block produced by pcre_study(). */
#define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */
/* Masks for identifying the public options which are permitted at compile
time, run time or study time, respectively. */
#define PUBLIC_OPTIONS \
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY)
#define PUBLIC_EXEC_OPTIONS (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL)
#define PUBLIC_STUDY_OPTIONS 0 /* None defined */
/* Magic number to provide a small check against being handed junk. */
#define MAGIC_NUMBER 0x50435245 /* 'PCRE' */
/* Miscellaneous definitions */
typedef int BOOL;
#define FALSE 0
#define TRUE 1
/* These are escaped items that aren't just an encoding of a particular data
value such as \n. They must have non-zero values, as check_escape() returns
their negation. Also, they must appear in the same order as in the opcode
definitions below, up to ESC_z. The final one must be ESC_REF as subsequent
values are used for \1, \2, \3, etc. There is a test in the code for an escape
greater than ESC_b and less than ESC_X to detect the types that may be
repeated. If any new escapes are put in-between that don't consume a character,
that code will have to change. */
enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w,
ESC_Z, ESC_z, ESC_REF };
/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
OP_EOD must correspond in order to the list of escapes immediately above. */
enum {
OP_END, /* End of pattern */
/* Values corresponding to backslashed metacharacters */
OP_SOD, /* Start of data: \A */
OP_NOT_WORD_BOUNDARY, /* \B */
OP_WORD_BOUNDARY, /* \b */
OP_NOT_DIGIT, /* \D */
OP_DIGIT, /* \d */
OP_NOT_WHITESPACE, /* \S */
OP_WHITESPACE, /* \s */
OP_NOT_WORDCHAR, /* \W */
OP_WORDCHAR, /* \w */
OP_EODN, /* End of data or \n at end of data: \Z. */
OP_EOD, /* End of data: \z */
OP_OPT, /* Set runtime options */
OP_CIRC, /* Start of line - varies with multiline switch */
OP_DOLL, /* End of line - varies with multiline switch */
OP_ANY, /* Match any character */
OP_CHARS, /* Match string of characters */
OP_NOT, /* Match anything but the following char */
OP_STAR, /* The maximizing and minimizing versions of */
OP_MINSTAR, /* all these opcodes must come in pairs, with */
OP_PLUS, /* the minimizing one second. */
OP_MINPLUS, /* This first set applies to single characters */
OP_QUERY,
OP_MINQUERY,
OP_UPTO, /* From 0 to n matches */
OP_MINUPTO,
OP_EXACT, /* Exactly n matches */
OP_NOTSTAR, /* The maximizing and minimizing versions of */
OP_NOTMINSTAR, /* all these opcodes must come in pairs, with */
OP_NOTPLUS, /* the minimizing one second. */
OP_NOTMINPLUS, /* This first set applies to "not" single characters */
OP_NOTQUERY,
OP_NOTMINQUERY,
OP_NOTUPTO, /* From 0 to n matches */
OP_NOTMINUPTO,
OP_NOTEXACT, /* Exactly n matches */
OP_TYPESTAR, /* The maximizing and minimizing versions of */
OP_TYPEMINSTAR, /* all these opcodes must come in pairs, with */
OP_TYPEPLUS, /* the minimizing one second. These codes must */
OP_TYPEMINPLUS, /* be in exactly the same order as those above. */
OP_TYPEQUERY, /* This set applies to character types such as \d */
OP_TYPEMINQUERY,
OP_TYPEUPTO, /* From 0 to n matches */
OP_TYPEMINUPTO,
OP_TYPEEXACT, /* Exactly n matches */
OP_CRSTAR, /* The maximizing and minimizing versions of */
OP_CRMINSTAR, /* all these opcodes must come in pairs, with */
OP_CRPLUS, /* the minimizing one second. These codes must */
OP_CRMINPLUS, /* be in exactly the same order as those above. */
OP_CRQUERY, /* These are for character classes and back refs */
OP_CRMINQUERY,
OP_CRRANGE, /* These are different to the three seta above. */
OP_CRMINRANGE,
OP_CLASS, /* Match a character class */
OP_REF, /* Match a back reference */
OP_ALT, /* Start of alternation */
OP_KET, /* End of group that doesn't have an unbounded repeat */
OP_KETRMAX, /* These two must remain together and in this */
OP_KETRMIN, /* order. They are for groups the repeat for ever. */
/* The assertions must come before ONCE and COND */
OP_ASSERT, /* Positive lookahead */
OP_ASSERT_NOT, /* Negative lookahead */
OP_ASSERTBACK, /* Positive lookbehind */
OP_ASSERTBACK_NOT, /* Negative lookbehind */
OP_REVERSE, /* Move pointer back - used in lookbehind assertions */
/* ONCE and COND must come after the assertions, with ONCE first, as there's
a test for >= ONCE for a subpattern that isn't an assertion. */
OP_ONCE, /* Once matched, don't back up into the subpattern */
OP_COND, /* Conditional group */
OP_CREF, /* Used to hold an extraction string number */
OP_BRAZERO, /* These two must remain together and in this */
OP_BRAMINZERO, /* order. */
OP_BRA /* This and greater values are used for brackets that
extract substrings. */
};
/* The highest extraction number. This is limited by the number of opcodes
left after OP_BRA, i.e. 255 - OP_BRA. We actually set it somewhat lower. */
#define EXTRACT_MAX 99
/* The texts of compile-time error messages are defined as macros here so that
they can be accessed by the POSIX wrapper and converted into error codes. Yes,
I could have used error codes in the first place, but didn't feel like changing
just to accommodate the POSIX wrapper. */
#define ERR1 "\\ at end of pattern"
#define ERR2 "\\c at end of pattern"
#define ERR3 "unrecognized character follows \\"
#define ERR4 "numbers out of order in {} quantifier"
#define ERR5 "number too big in {} quantifier"
#define ERR6 "missing terminating ] for character class"
#define ERR7 "invalid escape sequence in character class"
#define ERR8 "range out of order in character class"
#define ERR9 "nothing to repeat"
#define ERR10 "operand of unlimited repeat could match the empty string"
#define ERR11 "internal error: unexpected repeat"
#define ERR12 "unrecognized character after (?"
#define ERR13 "too many capturing parenthesized sub-patterns"
#define ERR14 "missing )"
#define ERR15 "back reference to non-existent subpattern"
#define ERR16 "erroffset passed as NULL"
#define ERR17 "unknown option bit(s) set"
#define ERR18 "missing ) after comment"
#define ERR19 "too many sets of parentheses"
#define ERR20 "regular expression too large"
#define ERR21 "failed to get memory"
#define ERR22 "unmatched parentheses"
#define ERR23 "internal error: code overflow"
#define ERR24 "unrecognized character after (?<"
#define ERR25 "lookbehind assertion is not fixed length"
#define ERR26 "malformed number after (?("
#define ERR27 "conditional group contains more than two branches"
#define ERR28 "assertion expected after (?("
/* All character handling must be done as unsigned characters. Otherwise there
are problems with top-bit-set characters and functions such as isspace().
However, we leave the interface to the outside world as char *, because that
should make things easier for callers. We define a short type for unsigned char
to save lots of typing. I tried "uchar", but it causes problems on Digital
Unix, where it is defined in sys/types, so use "uschar" instead. */
typedef unsigned char uschar;
/* The real format of the start of the pcre block; the actual code vector
runs on as long as necessary after the end. */
typedef struct real_pcre {
unsigned int magic_number;
const unsigned char *tables;
unsigned short int options;
unsigned char top_bracket;
unsigned char top_backref;
unsigned char first_char;
unsigned char code[1];
} real_pcre;
/* The real format of the extra block returned by pcre_study(). */
typedef struct real_pcre_extra {
unsigned char options;
unsigned char start_bits[32];
} real_pcre_extra;
/* Structure for passing "static" information around between the functions
doing the compiling, so that they are thread-safe. */
typedef struct compile_data {
const uschar *lcc; /* Points to lower casing table */
const uschar *fcc; /* Points to case-flippint table */
const uschar *cbits; /* Points to character type table */
const uschar *ctypes; /* Points to table of type maps */
} compile_data;
/* Structure for passing "static" information around between the functions
doing the matching, so that they are thread-safe. */
typedef struct match_data {
int errorcode; /* As it says */
int *offset_vector; /* Offset vector */
int offset_end; /* One past the end */
int offset_max; /* The maximum usable for return data */
const uschar *lcc; /* Points to lower casing table */
const uschar *ctypes; /* Points to table of type maps */
BOOL offset_overflow; /* Set if too many extractions */
BOOL notbol; /* NOTBOL flag */
BOOL noteol; /* NOTEOL flag */
BOOL endonly; /* Dollar not before final \n */
const uschar *start_subject; /* Start of the subject string */
const uschar *end_subject; /* End of the subject string */
const uschar *end_match_ptr; /* Subject position at end match */
int end_offset_top; /* Highwater mark at end of match */
} match_data;
/* Bit definitions for entries in the pcre_ctypes table. */
#define ctype_space 0x01
#define ctype_letter 0x02
#define ctype_digit 0x04
#define ctype_xdigit 0x08
#define ctype_word 0x10 /* alphameric or '_' */
#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
of bits for a class map. */
#define cbit_digit 0 /* for \d */
#define cbit_word 32 /* for \w */
#define cbit_space 64 /* for \s */
#define cbit_length 96 /* Length of the cbits table */
/* Offsets of the various tables from the base tables pointer, and
total length. */
#define lcc_offset 0
#define fcc_offset 256
#define cbits_offset 512
#define ctypes_offset (cbits_offset + cbit_length)
#define tables_length (ctypes_offset + 256)
/* End of internal.h */

52
Utils/Libs/GLib/ll.c Normal file
View File

@ -0,0 +1,52 @@
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
File: LL.C
Notes: General Link List Handling Code
Author: G Robert Liddon @ Croydon
Created: Wednesday 6th October 1994
Copyright (C) 1994 G Robert Liddon
All rights reserved.
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Includes
ÄÄÄÄÄÄÄÄ */
#include "ll.h"
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Defines
ÄÄÄÄÄÄÄ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Detach from a list
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void LL_DetachFromList(LinkList **Head,LinkList *ThisObj)
{
if (ThisObj->Prev)
ThisObj->Prev->Next=ThisObj->Next;
else
*Head=ThisObj->Next;
if (ThisObj->Next)
ThisObj->Next->Prev=ThisObj->Prev;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Add To A List
ÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void LL_AddToList(LinkList **Head,LinkList *ThisObj)
{
ThisObj->Prev=NULL;
if ((ThisObj->Next=*Head))
ThisObj->Next->Prev=ThisObj;
*Head=ThisObj;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
ends
ÄÄÄÄ */

49
Utils/Libs/GLib/ll.h Normal file
View File

@ -0,0 +1,49 @@
/* ===========================================================================
File: LL.C
Notes: General Link List Handling Code
Author: G Robert Liddon @ Croydon
Created: Wednesday 6th October 1994
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
=========================================================================== */
#ifndef __LL_H
#define __LL_H
/* ---------------------------------------------------------------------------
Includes
-------- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Structures
---------- */
typedef struct LinkList
{
struct LinkList *Next;
struct LinkList *Prev;
} LinkList;
/* ---------------------------------------------------------------------------
Globals
------- */
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API void LL_DetachFromList(LinkList **Head,LinkList *ThisObj);
GLIB_API void LL_AddToList(LinkList **Head,LinkList *ThisObj);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

View File

@ -0,0 +1,109 @@
/*************************************************
* Perl-Compatible Regular Expressions *
*************************************************/
/*
PCRE is a library of functions to support regular expressions whose syntax
and semantics are as close as possible to those of the Perl 5 language.
Written by: Philip Hazel <ph10@cam.ac.uk>
Copyright (c) 1997-1999 University of Cambridge
-----------------------------------------------------------------------------
Permission is granted to anyone to use this software for any purpose on any
computer system, and to redistribute it freely, subject to the following
restrictions:
1. This software 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.
2. The origin of this software must not be misrepresented, either by
explicit claim or by omission.
3. Altered versions must be plainly marked as such, and must not be
misrepresented as being the original software.
-----------------------------------------------------------------------------
See the file Tech.Notes for some information on the internals.
*/
/* This file is compiled on its own as part of the PCRE library. However,
it is also included in the compilation of dftables.c, in which case the macro
DFTABLES is defined. */
#ifndef DFTABLES
#include "internal.h"
#endif
/*************************************************
* Create PCRE character tables *
*************************************************/
/* This function builds a set of character tables for use by PCRE and returns
a pointer to them. They are build using the ctype functions, and consequently
their contents will depend upon the current locale setting. When compiled as
part of the library, the store is obtained via pcre_malloc(), but when compiled
inside dftables, use malloc().
Arguments: none
Returns: pointer to the contiguous block of data
*/
unsigned const char *
pcre_maketables(void)
{
unsigned char *yield, *p;
int i;
#ifndef DFTABLES
yield = (pcre_malloc)(tables_length);
#else
yield = malloc(tables_length);
#endif
if (yield == NULL) return NULL;
p = yield;
/* First comes the lower casing table */
for (i = 0; i < 256; i++) *p++ = tolower(i);
/* Next the case-flipping table */
for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i);
/* Then the character class tables */
memset(p, 0, cbit_length);
for (i = 0; i < 256; i++)
{
if (isdigit(i)) p[cbit_digit + i/8] |= 1 << (i&7);
if (isalnum(i) || i == '_')
p[cbit_word + i/8] |= 1 << (i&7);
if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7);
}
p += cbit_length;
/* Finally, the character type table */
for (i = 0; i < 256; i++)
{
int x = 0;
if (isspace(i)) x += ctype_space;
if (isalpha(i)) x += ctype_letter;
if (isdigit(i)) x += ctype_digit;
if (isxdigit(i)) x += ctype_xdigit;
if (isalnum(i) || i == '_') x += ctype_word;
if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta;
*p++ = x;
}
return yield;
}
/* End of maketables.c */

800
Utils/Libs/GLib/objs.c Normal file
View File

@ -0,0 +1,800 @@
/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
File: OBJS.C
Notes: Genric Object Server
Author: G Robert Liddon @ The Park
Created: Wednesday 5th April, 1995
Copyright (C) 1995 G Robert Liddon
All rights reserved.
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Includes
ÄÄÄÄÄÄÄÄ */
/* Glib
ÄÄÄÄ */
#include "objs.h"
#include "gal.h"
#include "gdebug.h"
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function Prototypes
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_DetachOLFromList(OBJ_LIST **Head,OBJ_LIST *ThisObj);
static void OBJS_AddOLToList(OBJ_LIST **Head,OBJ_LIST *ThisObj);
static void OBJS_DetachFromList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj);
static void OBJS_AddToList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj);
static void SortList(OBJ_LIST *OL);
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Vars
ÄÄÄÄ */
int ObjsAlloced; /* Number of currently active objs */
OBJ_LIST * ListOfObjLists; /* Head of the list of print Qs */
BOOL AddVels; /* Should vels be auto added or not */
U32 MemId;
void (*ProcessEpilog)(void); /* Called after processobj */
void (*ProcessProlog)(void); /* Called after processobj */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_OpenModule(U32 MemType)
Purpose: Initialise the object module for use.
Params: MyMaxObjs = Max objs to alloc for
MemType = GAL memtype to alloc in
Returns: TRUE if opened succesfuly
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_OpenModule(U32 MemType)
{
MemId=MemType;
ObjsAlloced=0;
ListOfObjLists=NULL;
AddVels=TRUE;
ProcessEpilog=NULL;
ProcessProlog=NULL;
return TRUE;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: BOOL OBJS_CloseModule(void)
Purpose: Closes the active obj module
Returns: TRUE if closed succesfuly
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_CloseModule(void)
{
OBJS_DestroyAllObjs();
return TRUE;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_AddDisplayList(OBJ_LIST *OL)
Purpose: Add a display list
Params: OL -> Object List to add
Returns: -> Created object if succesfull
NULL if not
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_AddDisplayList(OBJ_LIST *OL)
{
OBJS_AddOLToList(&ListOfObjLists,OL);
OL->Head=NULL;
OL->Visible=TRUE;
OL->SortCompare=NULL;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: OBJ_STRUCT *OBJS_MakeObj(const OBJ_TYPE_INFO *OTI,OBJ_LIST *OL,void *Ptr)
Purpose: Make an object
Params: OTI -> Obj type info
OL -> Object List to add to
Ptr -> Instance specefic info
Returns: -> Created object if succesfull
NULL if not
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
OBJ_STRUCT *OBJS_CreateObjMulti(const OBJ_TYPE_INFO *OTI,OBJ_LIST *OL,GAL_STRUCT * G,void *Ptr)
{
UINT TotalMem;
TotalMem=GAL_ProcessMultiStruct(G,MemId);
return(OBJS_CreateObj(OTI,OL,(int)TotalMem,Ptr));
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: OBJ_STRUCT *OBJS_MakeObj(const OBJ_TYPE_INFO *OTI,OBJ_LIST *OL,void *Ptr)
Purpose: Make an object
Params: OTI -> Obj type info
OL -> Object List to add to
Ptr -> Instance specefic info
Returns: -> Created object if succesfull
NULL if not
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
OBJ_STRUCT *OBJS_CreateObj(const OBJ_TYPE_INFO *OTI,OBJ_LIST *OL,int DataSize,void *Ptr)
{
MHANDLE ObjHandle;
int SizeOfObjstruct;
int SizeOfData;
OBJ_STRUCT * ThisObj;
SizeOfObjstruct=GAL_AlignSizeToType(sizeof(OBJ_STRUCT),MemId);
if (SizeOfObjstruct==-1)
return(NULL);
SizeOfData=GAL_AlignSizeToType((U32)DataSize,MemId);
if (SizeOfData==-1)
return(NULL);
ObjHandle=GAL_Alloc((U32)(SizeOfObjstruct+SizeOfData),MemId,"OBJ");
if (ObjHandle==NULL_HANDLE)
return(NULL);
ThisObj=GAL_Lock(ObjHandle);
if (ThisObj)
{
OBJS_AddToList(&OL->Head,ThisObj);
ThisObj->MemHandle=ObjHandle;
ThisObj->Data=(void *)((U32)ThisObj + SizeOfObjstruct);
ThisObj->OTI=OTI;
ThisObj->OL=OL;
ThisObj->ID=0;
ThisObj->XVel=0;
ThisObj->YVel=0;
ThisObj->ZVel=0;
if (ThisObj->OTI->Constructor)
ThisObj->OTI->Constructor(ThisObj,Ptr);
ObjsAlloced++;
}
return ThisObj;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_ProcessObjsEpilogue(void (*Func)(void))
Purpose: Add a call back that's executed after OBJS_ProcessObjs
Params: Func -> Function
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_ProcessObjsEpilogue(void (*Func)(void))
{
ProcessEpilog=Func;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_ProcessObjsPrologue(void (*Func)(void))
Purpose: Add a call back that's executed before OBJS_ProcessObjs
Params: Func -> Function
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_ProcessObjsPrologue(void (*Func)(void))
{
ProcessProlog=Func;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_DetachFromList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj)
Purpose: Take an object from an obj list
Params: Head -> Head ptr of list
ThisObj -> Obj to add
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
static void OBJS_DetachFromList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj)
{
if (ThisObj->Prev)
ThisObj->Prev->Next=ThisObj->Next;
else
*Head=ThisObj->Next;
if (ThisObj->Next)
ThisObj->Next->Prev=ThisObj->Prev;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_AddToList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj)
Purpose: Add an object to a obj list
Params: Head -> Head ptr of list
ThisObj -> Obj to add
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
static void OBJS_AddToList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj)
{
ThisObj->Prev=NULL;
if ((ThisObj->Next=*Head))
ThisObj->Next->Prev=ThisObj;
*Head=ThisObj;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_DetachFromList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj)
Purpose: Take an object from an obj list
Params: Head -> Head ptr of list
ThisObj -> Obj to add
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_DetachOLFromList(OBJ_LIST **Head,OBJ_LIST *ThisObj)
{
if (ThisObj->Prev)
ThisObj->Prev->Next=ThisObj->Next;
else
*Head=ThisObj->Next;
if (ThisObj->Next)
ThisObj->Next->Prev=ThisObj->Prev;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_AddToList(OBJ_STRUCT **Head,OBJ_STRUCT *ThisObj)
Purpose: Add an object to a obj list
Params: Head -> Head ptr of list
ThisObj -> Obj to add
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
static void OBJS_AddOLToList(OBJ_LIST **Head,OBJ_LIST *ThisObj)
{
ThisObj->Prev=NULL;
if ((ThisObj->Next=*Head))
ThisObj->Next->Prev=ThisObj;
*Head=ThisObj;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Change this Object's Print List
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_ChangeDisplayList(OBJ_STRUCT *O,OBJ_LIST *NewList)
{
if (NewList != O->OL)
{
OBJS_DetachFromList(&O->OL->Head,O);
OBJS_AddToList(&NewList->Head,O);
O->OL=NewList;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_ProcessObjs(void)
Purpose: Print the display lists
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_ProcessObjs(void)
{
OBJ_LIST *ThisList;
if (ProcessProlog)
ProcessProlog();
ThisList=ListOfObjLists;
while (ThisList)
{
if (ThisList->Visible)
{
{
OBJ_STRUCT *ObjList;
SortList(ThisList);
ObjList=ThisList->Head;
while (ObjList)
{
if (AddVels)
{
ObjList->XPos+=ObjList->XVel;
ObjList->YPos+=ObjList->YVel;
ObjList->ZPos+=ObjList->ZVel;
}
if (ObjList->OTI->Printer)
ObjList->OTI->Printer(ObjList,ThisList);
ObjList=ObjList->Next;
}
}
}
ThisList=ThisList->Next;
}
if (ProcessEpilog)
ProcessEpilog();
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_ProcessObjs(void)
Purpose: Print the display lists
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_ObjsVelAddOnly(void)
{
OBJ_LIST *ThisList;
ThisList=ListOfObjLists;
while (ThisList)
{
if (ThisList->Visible)
{
{
OBJ_STRUCT *ObjList;
SortList(ThisList);
ObjList=ThisList->Head;
while (ObjList)
{
if (AddVels)
{
ObjList->XPos+=ObjList->XVel;
ObjList->YPos+=ObjList->YVel;
ObjList->ZPos+=ObjList->ZVel;
}
ObjList=ObjList->Next;
}
}
}
ThisList=ThisList->Next;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_DestroyAllObjs(void)
Purpose: Delete all objects in all lists
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_DestroyAllObjs(void)
{
OBJ_LIST *ThisList;
ThisList=ListOfObjLists;
while (ThisList)
{
OBJS_DestroyListObjs(ThisList);
ThisList=ThisList->Next;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_DestroyListObjs(OBJ_LIST *OL)
Purpose: Destroy all the objs in a list if list is killable
Params: OL -> List
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_DestroyListObjs(OBJ_LIST *OL)
{
if (OL->Killable)
{
OBJ_STRUCT *O;
O=OL->Head;
while (O)
O=OBJS_DestroyObj(O);
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_DestroyAllObjsOfAType(U32 Type,U32 AndMask)
Purpose: Go through all display lists and destroy objs
of a certain type.
if (O->ID&AndMask)==Type then obj is destroyed
Params: Type = Type of objs to destroy
AndMask = And maks
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_DestroyAllObjsOfAType(U32 Type,U32 AndMask)
{
OBJ_LIST *ThisList;
ThisList=ListOfObjLists;
while (ThisList)
{
OBJS_DestroyListObjsOfAType(ThisList,Type,AndMask);
ThisList=ThisList->Next;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_DestroyListObjsOfAType(OBJ_LIST *OL,U32 Type,U32 AndMask)
Purpose: Go through a single display list and destroy objs
of a certain type.
if (O->ID&AndMask)==Type then obj is destroyed
Params: Type = Type of objs to destroy
AndMask = And maks
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_DestroyListObjsOfAType(OBJ_LIST *OL,U32 Type,U32 AndMask)
{
OBJ_STRUCT *O;
O=OL->Head;
while (O)
{
OBJ_STRUCT * NextO;
NextO=O->Next;
if (((O->ID)&AndMask)==Type)
OBJS_DestroyObj(O);
O=NextO;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: OBJ_STRUCT *OBJS_DestroyObj(OBJ_STRUCT *O)
Purpose: Destroy an object
Params: O -> Obj to destroy
Returns: -> to what was next in list
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
OBJ_STRUCT *OBJS_DestroyObj(OBJ_STRUCT *O)
{
MHANDLE ObjHandle;
OBJ_STRUCT * RetObj;
BOOL GalRet;
ObjHandle=O->MemHandle;
RetObj=O->Next;
if (O->OTI->Destructor)
O->OTI->Destructor(O);
OBJS_DetachFromList(&O->OL->Head,O);
O->Next=NULL; /* Handy for debugging */
O->Prev=NULL;
GalRet=GAL_Free(ObjHandle);
ASSERT(GalRet);
ObjsAlloced--;
return RetObj;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_IterateAllObjs(U32 Type,U32 AndMask,void (*CallBack)(OBJ_STRUCT *O))
Purpose: Go through all display lists and do a callback for objs
of a certain type.
if (O->ID&AndMask)==Type then obj is callbacked
Params: Type = Type of objs to callback
AndMask = And maks
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_IterateAllObjs(U32 Type,U32 AndMask,void (*CallBack)(OBJ_STRUCT *O))
{
OBJ_LIST *ThisList;
ThisList=ListOfObjLists;
while (ThisList)
{
OBJS_IterateListObjs(ThisList,Type,AndMask,CallBack);
ThisList=ThisList->Next;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_IterateListObjs(OBJ_LIST *OL,U32 Type,U32 AndMask,void (*CallBack)(OBJ_STRUCT *O))
Purpose: Go through a single display list and do a callback for objs
of a certain type.
if (O->ID&AndMask)==Type then obj is callbacked
Params: Type = Type of objs to callback
AndMask = And maks
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_IterateListObjs(OBJ_LIST *OL,U32 Type,U32 AndMask,void (*CallBack)(OBJ_STRUCT *O))
{
OBJ_STRUCT *O;
O=OL->Head;
while (O)
{
OBJ_STRUCT * NextO;
NextO=O->Next;
if (((O->ID)&AndMask)==Type)
CallBack(O);
O=NextO;
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Set the World's XY
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_SetListXY(OBJ_LIST *OL,S32 X,S32 Y)
{
OBJS_SetListX(OL,X);
OBJS_SetListY(OL,Y);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Set the World's X
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_SetListX(OBJ_LIST *OL,S32 X)
{
OL->X=X;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Set the World's X
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_SetListY(OBJ_LIST *OL,S32 Y)
{
OL->Y=Y;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Make a Priority level of sprites undestroyable
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_MakeListImmortal(OBJ_LIST *OL)
{
OL->Killable=FALSE;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Make a Priority level of sprites Destroyable
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_MakeListMortal(OBJ_LIST *OL)
{
OL->Killable=TRUE;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void MKOBJS_NoVels(void)
Purpose: Say no vels to be addes
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_NoAddVels(void)
{
BOOL OldVels;
OldVels=AddVels;
AddVels=FALSE;
return(OldVels);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void MKOBJS_AddVels(void)
Purpose: Say vels to be addes
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_AddVels(void)
{
BOOL OldVels;
OldVels=AddVels;
AddVels=TRUE;
return(OldVels);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_MakeListInvisible(OBJ_LIST *OL)
Purpose: Mark this list as invisble
Params: OL - > List to mark
Returns: Previous visible / invisible state of list
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_MakeListInvisible(OBJ_LIST *OL)
{
BOOL OldState;
OldState=OL->Visible;
OL->Visible=FALSE;
return(OldState);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_MakeListInvisible(OBJ_LIST *OL)
Purpose: Mark this list as visble
Params: OL - > List to mark
Returns: Previous visible / invisible state of list
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_MakeListVisible(OBJ_LIST *OL)
{
BOOL OldState;
OldState=OL->Visible;
OL->Visible=TRUE;
return(OldState);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Make a Priority level of sprites Invisible
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ*/
BOOL OBJS_GetVelState(void)
{
return AddVels;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: BOOL OBJS_SetVelState(BOOL NewState)
Purpose: Set wether to add vels
Params: Newstate =
Returns: Previous addvel state of list
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
BOOL OBJS_SetVelState(BOOL NewState)
{
BOOL OldState;
OldState=AddVels;
AddVels=NewState;
return(OldState);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: void OBJS_SetSortCompare(OBJ_LIST *OL,void (*CompRout)(OBJ_STRUCT *O1,OBJ_STRUCT *O1))
Purpose: Set the call back used in the sort routine
Params: OL -> List to set sort routine for
CompRout -> Function to do the compare
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void OBJS_SetSortCompare(OBJ_LIST *OL,BOOL (*CompRout)(OBJ_STRUCT *O1,OBJ_STRUCT *O2))
{
OL->SortCompare=CompRout;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: int OBJS_GetWidth(OBJ_STRUCT *O)
Purpose: Get an objs width
Params: O -> Obj 2 get width off
Returns: Width, zero if no width routine
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
int OBJS_GetWidth(OBJ_STRUCT *O)
{
if (O->OTI->GetWidth)
return(O->OTI->GetWidth(O));
else
return(0);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: int OBJS_GetWidth(OBJ_STRUCT *O)
Purpose: Get an objs width
Params: O -> Obj 2 get width off
Returns: Width, zero if no width routine
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
int OBJS_GetHeight(OBJ_STRUCT *O)
{
if (O->OTI->GetHeight)
return(O->OTI->GetHeight(O));
else
return(0);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: int OBJS_GetXOff(OBJ_STRUCT *O)
Purpose: Get an objs X offset
Params: O -> Obj 2 get width off
Returns: Width, zero if no width routine
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
int OBJS_GetXOff(OBJ_STRUCT *O)
{
if (O->OTI->GetXOff)
return(O->OTI->GetXOff(O));
else
return(0);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: int OBJS_GetYOff(OBJ_STRUCT *O)
Purpose: Get an objs X offset
Params: O -> Obj 2 get width off
Returns: Width, zero if no width routine
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
int OBJS_GetYOff(OBJ_STRUCT *O)
{
if (O->OTI->GetYOff)
return(O->OTI->GetYOff(O));
else
return(0);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: int OBJS_GetYOff(OBJ_STRUCT *O)
Purpose: Get an objs X offset
Params: O -> Obj 2 get width off
Returns: Width, zero if no width routine
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
int OBJS_GetPal(OBJ_STRUCT *O)
{
if (O->OTI->GetPal)
return(O->OTI->GetPal(O));
else
return(0);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: static void SortList(OBJ_LIST *OL)
Purpose: Sort this list
Params: OL -> List to sort
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
static void SortList(OBJ_LIST *OL)
{
if (OL->SortCompare && OL->Head && OL->Head->Next)
{
BOOL DidSwap;
do
{
OBJ_STRUCT * O;
OBJ_STRUCT * NO;
O=OL->Head;
DidSwap=FALSE;
do
{
NO=O->Next;
if (OL->SortCompare(O,NO))
{
O->Next=NO->Next;
NO->Next=O;
NO->Prev=O->Prev;
O->Prev=NO;
if (NO->Prev)
NO->Prev->Next=NO;
else
OL->Head=NO;
if (O->Next)
O->Next->Prev=O;
DidSwap=TRUE;
}
else
O=O->Next;
}
while (O->Next);
}
while(DidSwap);
}
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Function: int OBJS_GetObjsAlloced(void)
Purpose: Tell us how many objects are out
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
int OBJS_GetObjsAlloced(void)
{
return(ObjsAlloced);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
ends */

157
Utils/Libs/GLib/objs.h Normal file
View File

@ -0,0 +1,157 @@
/* ===========================================================================
File: OBJS.H
Notes: Genric Object Server
Author: G Robert Liddon @ The Park
Created: Wednesday 5th April, 1995
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
============================================================================ */
#ifndef __GAZ_OBJS_H
#define __GAZ_OBJS_H
/* ---------------------------------------------------------------------------
Includes
-------- */
/* Glib
---- */
#include "gtypes.h"
#include "gal.h"
/* ---------------------------------------------------------------------------
Typedefs, Defines & Structs
--------------------------- */
struct OBJ_LIST;
struct OBJ_STRUCT;
/* Information about a type of object
---------------------------------- */
typedef struct OBJ_TYPE_INFO
{
void (*Constructor)(struct OBJ_STRUCT *O,void *Ptr); /* Object constructor routine */
void (*Destructor)(struct OBJ_STRUCT *O); /* Object destructor routine */
void (*Printer)(struct OBJ_STRUCT *O,struct OBJ_LIST *OL); /* Individual object printer */
int (*GetWidth)(struct OBJ_STRUCT *O); /* Get this obj width */
int (*GetHeight)(struct OBJ_STRUCT *O); /* Get this obj height */
int (*GetXOff)(struct OBJ_STRUCT *O); /* Get this obj x */
int (*GetYOff)(struct OBJ_STRUCT *O); /* Get this obj y */
int (*GetPal)(struct OBJ_STRUCT *O); /* Get this obj pal */
} OBJ_TYPE_INFO;
/* A List of objects
----------------- */
typedef struct OBJ_LIST
{
U32 PrintDepth;
BOOL Visible;
BOOL Killable;
char * ListName;
struct OBJ_LIST *Prev;
struct OBJ_LIST *Next;
S32 X,Y,Z;
struct OBJ_STRUCT *Head;
BOOL (*SortCompare)(struct OBJ_STRUCT *O1,struct OBJ_STRUCT *O2);
} OBJ_LIST;
/* An Object itself
---------------- */
typedef struct OBJ_STRUCT
{
struct OBJ_STRUCT *Next;
struct OBJ_STRUCT *Prev;
U32 ID;
S32 XPos,YPos,ZPos;
S32 XVel,YVel,ZVel;
const OBJ_TYPE_INFO * OTI; /* Object type info */
OBJ_LIST * OL; /* Obj list we're currently in */
void * Data;
MHANDLE MemHandle;
} OBJ_STRUCT;
/* ---------------------------------------------------------------------------
Globals Functions
----------------- */
#ifdef __cplusplus
extern "C" {
#endif
/* Module Management
----------------- */
GLIB_API BOOL OBJS_OpenModule(U32 MemType);
GLIB_API BOOL OBJS_CloseModule(void);
GLIB_API void OBJS_ProcessObjs(void);
GLIB_API void OBJS_ProcessObjsPrologue(void (*Func)(void));
GLIB_API void OBJS_ProcessObjsEpilogue(void (*Func)(void));
GLIB_API void OBJS_AddDisplayList(OBJ_LIST *OL);
GLIB_API BOOL OBJS_AddVels(void);
GLIB_API BOOL OBJS_NoAddVels(void);
GLIB_API BOOL OBJS_GetVelState(void);
GLIB_API BOOL OBJS_SetVelState(BOOL NewState);
/* Object Management
----------------- */
GLIB_API OBJ_STRUCT * OBJS_CreateObj(const OBJ_TYPE_INFO *OTI,OBJ_LIST *OL,int DataSize,void *Ptr);
GLIB_API OBJ_STRUCT * OBJS_CreateObjMulti(const OBJ_TYPE_INFO *OTI,OBJ_LIST *OL,GAL_STRUCT * G,void *Ptr);
GLIB_API void OBJS_ChangeDisplayList(OBJ_STRUCT *O,OBJ_LIST *NewList);
GLIB_API OBJ_STRUCT * OBJS_DestroyObj(OBJ_STRUCT *O);
GLIB_API void OBJS_DestroyAllObjs(void);
GLIB_API void OBJS_DestroyListObjs(OBJ_LIST *OL);
GLIB_API void OBJS_DestroyAllObjsOfAType(U32 Type,U32 AndMask);
GLIB_API void OBJS_DestroyListObjsOfAType(OBJ_LIST *OL,U32 Type,U32 AndMask);
GLIB_API void OBJS_IterateAllObjs(U32 Type,U32 AndMask,void (*CallBack)(OBJ_STRUCT *O));
GLIB_API void OBJS_IterateListObjs(OBJ_LIST *OL,U32 Type,U32 AndMask,void (*CallBack)(OBJ_STRUCT *O));
/* List Management
--------------- */
GLIB_API void OBJS_SetListXY(OBJ_LIST *OL,S32 X,S32 Y);
GLIB_API void OBJS_SetListX(OBJ_LIST *OL,S32 X);
GLIB_API void OBJS_SetListY(OBJ_LIST *OL,S32 Y);
GLIB_API void OBJS_SetListZ(OBJ_LIST *OL,S32 Z);
GLIB_API void OBJS_MakeListImmortal(OBJ_LIST *OL);
GLIB_API void OBJS_MakeListMortal(OBJ_LIST *OL);
GLIB_API BOOL OBJS_MakeListInvisible(OBJ_LIST *OL);
GLIB_API BOOL OBJS_MakeListVisible(OBJ_LIST *OL);
GLIB_API void OBJS_SetSortCompare(OBJ_LIST *OL,BOOL (*CompRout)(OBJ_STRUCT *O1,OBJ_STRUCT *O2));
GLIB_API int OBJS_GetHeight(OBJ_STRUCT *O);
GLIB_API int OBJS_GetWidth(OBJ_STRUCT *O);
GLIB_API int OBJS_GetPal(OBJ_STRUCT *O);
GLIB_API int OBJS_GetYOff(OBJ_STRUCT *O);
GLIB_API int OBJS_GetXOff(OBJ_STRUCT *O);
GLIB_API int OBJS_GetObjsAlloced(void);
GLIB_API void OBJS_ObjsVelAddOnly(void);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif

4175
Utils/Libs/GLib/pcre.c Normal file

File diff suppressed because it is too large Load Diff

70
Utils/Libs/GLib/pcre.h Normal file
View File

@ -0,0 +1,70 @@
/*************************************************
* Perl-Compatible Regular Expressions *
*************************************************/
/* Copyright (c) 1997-1999 University of Cambridge */
#ifndef _PCRE_H
#define _PCRE_H
/* Have to include stdlib.h in order to ensure that size_t is defined;
it is needed here for malloc. */
#include <sys/types.h>
#include <stdlib.h>
/* Allow for C++ users */
#ifdef __cplusplus
extern "C" {
#endif
/* Options */
#define PCRE_CASELESS 0x0001
#define PCRE_MULTILINE 0x0002
#define PCRE_DOTALL 0x0004
#define PCRE_EXTENDED 0x0008
#define PCRE_ANCHORED 0x0010
#define PCRE_DOLLAR_ENDONLY 0x0020
#define PCRE_EXTRA 0x0040
#define PCRE_NOTBOL 0x0080
#define PCRE_NOTEOL 0x0100
#define PCRE_UNGREEDY 0x0200
/* Exec-time error codes */
#define PCRE_ERROR_NOMATCH (-1)
#define PCRE_ERROR_NULL (-2)
#define PCRE_ERROR_BADOPTION (-3)
#define PCRE_ERROR_BADMAGIC (-4)
#define PCRE_ERROR_UNKNOWN_NODE (-5)
#define PCRE_ERROR_NOMEMORY (-6)
/* Types */
typedef void pcre;
typedef void pcre_extra;
/* Store get and free functions. These can be set to alternative malloc/free
functions if required. */
extern void *(*pcre_malloc)(size_t);
extern void (*pcre_free)(void *);
/* Functions */
extern pcre *pcre_compile(const char *, int, const char **, int *,
const unsigned char *);
extern int pcre_exec(const pcre *, const pcre_extra *, const char *,
int, int, int *, int);
extern unsigned const char *pcre_maketables(void);
extern int pcre_info(const pcre *, int *, int *);
extern pcre_extra *pcre_study(const pcre *, int, const char **);
extern const char *pcre_version(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* End of pcre.h */

393
Utils/Libs/GLib/study.c Normal file
View File

@ -0,0 +1,393 @@
/*************************************************
* Perl-Compatible Regular Expressions *
*************************************************/
/*
This is a library of functions to support regular expressions whose syntax
and semantics are as close as possible to those of the Perl 5 language. See
the file Tech.Notes for some information on the internals.
Written by: Philip Hazel <ph10@cam.ac.uk>
Copyright (c) 1997-1999 University of Cambridge
-----------------------------------------------------------------------------
Permission is granted to anyone to use this software for any purpose on any
computer system, and to redistribute it freely, subject to the following
restrictions:
1. This software 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.
2. The origin of this software must not be misrepresented, either by
explicit claim or by omission.
3. Altered versions must be plainly marked as such, and must not be
misrepresented as being the original software.
-----------------------------------------------------------------------------
*/
/* Include the internals header, which itself includes Standard C headers plus
the external pcre header. */
#include "internal.h"
/*************************************************
* Set a bit and maybe its alternate case *
*************************************************/
/* Given a character, set its bit in the table, and also the bit for the other
version of a letter if we are caseless.
Arguments:
start_bits points to the bit map
c is the character
caseless the caseless flag
cd the block with char table pointers
Returns: nothing
*/
static void
set_bit(uschar *start_bits, int c, BOOL caseless, compile_data *cd)
{
start_bits[c/8] |= (1 << (c&7));
if (caseless && (cd->ctypes[c] & ctype_letter) != 0)
start_bits[cd->fcc[c]/8] |= (1 << (cd->fcc[c]&7));
}
/*************************************************
* Create bitmap of starting chars *
*************************************************/
/* This function scans a compiled unanchored expression and attempts to build a
bitmap of the set of initial characters. If it can't, it returns FALSE. As time
goes by, we may be able to get more clever at doing this.
Arguments:
code points to an expression
start_bits points to a 32-byte table, initialized to 0
caseless the current state of the caseless flag
cd the block with char table pointers
Returns: TRUE if table built, FALSE otherwise
*/
static BOOL
set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless,
compile_data *cd)
{
register int c;
/* This next statement and the later reference to dummy are here in order to
trick the optimizer of the IBM C compiler for OS/2 into generating correct
code. Apparently IBM isn't going to fix the problem, and we would rather not
disable optimization (in this module it actually makes a big difference, and
the pcre module can use all the optimization it can get). */
volatile int dummy;
do
{
const uschar *tcode = code + 3;
BOOL try_next = TRUE;
while (try_next)
{
try_next = FALSE;
/* If a branch starts with a bracket or a positive lookahead assertion,
recurse to set bits from within them. That's all for this branch. */
if ((int)*tcode >= OP_BRA || *tcode == OP_ASSERT)
{
if (!set_start_bits(tcode, start_bits, caseless, cd))
return FALSE;
}
else switch(*tcode)
{
default:
return FALSE;
/* Skip over lookbehind and negative lookahead assertions */
case OP_ASSERT_NOT:
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
try_next = TRUE;
do tcode += (tcode[1] << 8) + tcode[2]; while (*tcode == OP_ALT);
tcode += 3;
break;
/* Skip over an option setting, changing the caseless flag */
case OP_OPT:
caseless = (tcode[1] & PCRE_CASELESS) != 0;
tcode += 2;
try_next = TRUE;
break;
/* BRAZERO does the bracket, but carries on. */
case OP_BRAZERO:
case OP_BRAMINZERO:
if (!set_start_bits(++tcode, start_bits, caseless, cd))
return FALSE;
dummy = 1;
do tcode += (tcode[1] << 8) + tcode[2]; while (*tcode == OP_ALT);
tcode += 3;
try_next = TRUE;
break;
/* Single-char * or ? sets the bit and tries the next item */
case OP_STAR:
case OP_MINSTAR:
case OP_QUERY:
case OP_MINQUERY:
set_bit(start_bits, tcode[1], caseless, cd);
tcode += 2;
try_next = TRUE;
break;
/* Single-char upto sets the bit and tries the next */
case OP_UPTO:
case OP_MINUPTO:
set_bit(start_bits, tcode[3], caseless, cd);
tcode += 4;
try_next = TRUE;
break;
/* At least one single char sets the bit and stops */
case OP_EXACT: /* Fall through */
tcode++;
case OP_CHARS: /* Fall through */
tcode++;
case OP_PLUS:
case OP_MINPLUS:
set_bit(start_bits, tcode[1], caseless, cd);
break;
/* Single character type sets the bits and stops */
case OP_NOT_DIGIT:
for (c = 0; c < 32; c++)
start_bits[c] |= ~cd->cbits[c+cbit_digit];
break;
case OP_DIGIT:
for (c = 0; c < 32; c++)
start_bits[c] |= cd->cbits[c+cbit_digit];
break;
case OP_NOT_WHITESPACE:
for (c = 0; c < 32; c++)
start_bits[c] |= ~cd->cbits[c+cbit_space];
break;
case OP_WHITESPACE:
for (c = 0; c < 32; c++)
start_bits[c] |= cd->cbits[c+cbit_space];
break;
case OP_NOT_WORDCHAR:
for (c = 0; c < 32; c++)
start_bits[c] |= ~(cd->cbits[c] | cd->cbits[c+cbit_word]);
break;
case OP_WORDCHAR:
for (c = 0; c < 32; c++)
start_bits[c] |= (cd->cbits[c] | cd->cbits[c+cbit_word]);
break;
/* One or more character type fudges the pointer and restarts, knowing
it will hit a single character type and stop there. */
case OP_TYPEPLUS:
case OP_TYPEMINPLUS:
tcode++;
try_next = TRUE;
break;
case OP_TYPEEXACT:
tcode += 3;
try_next = TRUE;
break;
/* Zero or more repeats of character types set the bits and then
try again. */
case OP_TYPEUPTO:
case OP_TYPEMINUPTO:
tcode += 2; /* Fall through */
case OP_TYPESTAR:
case OP_TYPEMINSTAR:
case OP_TYPEQUERY:
case OP_TYPEMINQUERY:
switch(tcode[1])
{
case OP_NOT_DIGIT:
for (c = 0; c < 32; c++)
start_bits[c] |= ~cd->cbits[c+cbit_digit];
break;
case OP_DIGIT:
for (c = 0; c < 32; c++)
start_bits[c] |= cd->cbits[c+cbit_digit];
break;
case OP_NOT_WHITESPACE:
for (c = 0; c < 32; c++)
start_bits[c] |= ~cd->cbits[c+cbit_space];
break;
case OP_WHITESPACE:
for (c = 0; c < 32; c++)
start_bits[c] |= cd->cbits[c+cbit_space];
break;
case OP_NOT_WORDCHAR:
for (c = 0; c < 32; c++)
start_bits[c] |= ~(cd->cbits[c] | cd->cbits[c+cbit_word]);
break;
case OP_WORDCHAR:
for (c = 0; c < 32; c++)
start_bits[c] |= (cd->cbits[c] | cd->cbits[c+cbit_word]);
break;
}
tcode += 2;
try_next = TRUE;
break;
/* Character class: set the bits and either carry on or not,
according to the repeat count. */
case OP_CLASS:
{
tcode++;
for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];
tcode += 32;
switch (*tcode)
{
case OP_CRSTAR:
case OP_CRMINSTAR:
case OP_CRQUERY:
case OP_CRMINQUERY:
tcode++;
try_next = TRUE;
break;
case OP_CRRANGE:
case OP_CRMINRANGE:
if (((tcode[1] << 8) + tcode[2]) == 0)
{
tcode += 5;
try_next = TRUE;
}
break;
}
}
break; /* End of class handling */
} /* End of switch */
} /* End of try_next loop */
code += (code[1] << 8) + code[2]; /* Advance to next branch */
}
while (*code == OP_ALT);
return TRUE;
}
/*************************************************
* Study a compiled expression *
*************************************************/
/* This function is handed a compiled expression that it must study to produce
information that will speed up the matching. It returns a pcre_extra block
which then gets handed back to pcre_exec().
Arguments:
re points to the compiled expression
options contains option bits
errorptr points to where to place error messages;
set NULL unless error
Returns: pointer to a pcre_extra block,
NULL on error or if no optimization possible
*/
pcre_extra *
pcre_study(const pcre *external_re, int options, const char **errorptr)
{
uschar start_bits[32];
real_pcre_extra *extra;
const real_pcre *re = (const real_pcre *)external_re;
compile_data compile_block;
*errorptr = NULL;
if (re == NULL || re->magic_number != MAGIC_NUMBER)
{
*errorptr = "argument is not a compiled regular expression";
return NULL;
}
if ((options & ~PUBLIC_STUDY_OPTIONS) != 0)
{
*errorptr = "unknown or incorrect option bit(s) set";
return NULL;
}
/* For an anchored pattern, or an unchored pattern that has a first char, or a
multiline pattern that matches only at "line starts", no further processing at
present. */
if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)
return NULL;
/* Set the character tables in the block which is passed around */
compile_block.lcc = re->tables + lcc_offset;
compile_block.fcc = re->tables + fcc_offset;
compile_block.cbits = re->tables + cbits_offset;
compile_block.ctypes = re->tables + ctypes_offset;
/* See if we can find a fixed set of initial characters for the pattern. */
memset(start_bits, 0, 32 * sizeof(uschar));
if (!set_start_bits(re->code, start_bits, (re->options & PCRE_CASELESS) != 0,
&compile_block)) return NULL;
/* Get an "extra" block and put the information therein. */
extra = (real_pcre_extra *)(pcre_malloc)(sizeof(real_pcre_extra));
if (extra == NULL)
{
*errorptr = "failed to get memory";
return NULL;
}
extra->options = PCRE_STUDY_MAPPED;
memcpy(extra->start_bits, start_bits, sizeof(start_bits));
return (pcre_extra *)extra;
}
/* End of study.c */

860
Utils/Libs/GLib/tasker.c Normal file
View File

@ -0,0 +1,860 @@
/* ===========================================================================
File: TASKER.C
Notes: Cooperative multitasking
Author: G Robert Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 DCI Ltd All rights reserved.
============================================================================ */
/* ---------------------------------------------------------------------------
Standard Lib Includes
--------------------- */
/* ---------------------------------------------------------------------------
Glib Includes
------------- */
#include "tasker.h"
#include "gsys.h"
#include "gdebug.h"
#include "gtimsys.h"
/* ---------------------------------------------------------------------------
My Includes
----------- */
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Function Prototypes
------------------- */
static void ReturnToSchedulerIfCurrentTask(TASK *T);
static void ExecuteTask(TASK *T);
static void AddToList(TASK **Head,TASK *ThisObj);
static void DetachFromList(TASK **Head,TASK *ThisObj);
static void LoTskKill(TASK *T);
static void DoEpi(TASK * T);
static void DoPro(TASK * T);
static void ExtraMarkStack(u32 * Stack,int SizeLongs);
static int CheckExtraStack(u32 * Stack,int LongsToCheck);
/* ---------------------------------------------------------------------------
Defines
------- */
#define NUM_OF_TASKS 100
#define DEFAULT_XTRA_PRO_STACK_LONGS 1024
/* ---------------------------------------------------------------------------
Variables
--------- */
static TASK * ActiveTasks;
static TASK * CurrentTask;
static TASK * T;
static U32 MemTypeForTasker;
static jmp_buf SchEnv; /* The Scheduler's enviroment */
static U32 ExecId;
static U32 ExecMask;
static int TasksActive;
/* Vars for epi pro stuff
---------------------- */
static TSK_CBACK EpiFunc; /* Func to call before execing task of correct class */
static TSK_CBACK ProFunc; /* Func to call after execing task of correct class */
static U32 EpiProId;
static U32 EpiProMask;
static DOTSK_CBACK DoTasksPrologue;
static DOTSK_CBACK DoTasksEpilogue;
/* Vars for Xtra Stack Protection
------------------------------ */
static TSK_CBACK StackFloodCallback;
static BOOL ExtraStackProtection;
static int ExtraStackSizeLongs;
/* ---------------------------------------------------------------------------
Function: static void DoEpi(TASK * T)
Purpose: Do epilogue route if appropriate
--------------------------------------------------------------------------- */
static void DoEpi(TASK * T)
{
if (EpiFunc)
if ((T->Id&EpiProMask)==EpiProId)
EpiFunc(T);
}
/* ---------------------------------------------------------------------------
Function: static void DoPro(TASK * T)
Purpose: Do prologue route if appropriate
--------------------------------------------------------------------------- */
static void DoPro(TASK * T)
{
if (ProFunc)
if ((T->Id&EpiProMask)==EpiProId)
ProFunc(T);
}
/* ---------------------------------------------------------------------------
Function: BOOL TSK_OpenModule(U32 MemType)
Purpose: Init the tasker module
Params: MemType = Mem tasker uses for workspace
Returns: FALSE if an error
--------------------------------------------------------------------------- */
BOOL TSK_OpenModule(U32 MemType)
{
TasksActive=0;
ActiveTasks=NULL;
MemTypeForTasker=MemType;
CurrentTask=NULL;
TSK_ClearExecFilter();
TSK_ClearEpiProFilter();
TSK_SetDoTasksEpilogue(NULL);
TSK_SetDoTasksPrologue(NULL);
TSK_SetExtraStackProtection(FALSE);
TSK_SetStackFloodCallback(NULL);
TSK_SetExtraStackSize(DEFAULT_XTRA_PRO_STACK_LONGS*sizeof(u32));
return TRUE;
}
/* ---------------------------------------------------------------------------
Function: TASK * TSK_AddTask(U32 Id,void (*Main)(TASK *T))
Purpose: Add a task to the list of those to do
Returns: -> to task to run
NULL if no tasks available
--------------------------------------------------------------------------- */
TASK * TSK_AddTask(U32 Id,void (*Main)(TASK *T),int StackSize,int DataSize)
{
TASK * RetTask;
MHANDLE hndTask;
GAL_STRUCT G[4];
G[0].OriginalSize=sizeof(TASK);
G[1].OriginalSize=DataSize;
if (ExtraStackProtection)
G[2].OriginalSize=StackSize+ExtraStackSizeLongs*sizeof(u32);
else
G[2].OriginalSize=StackSize;
G[3].OriginalSize=-1;
hndTask=GAL_AllocMultiStruct(G,MemTypeForTasker,"TASK");
if (hndTask==NULL_HANDLE)
return(NULL);
RetTask=GAL_Lock(hndTask);
if (RetTask)
{
RetTask->Id = Id;
RetTask->fToInit=1;
RetTask->fToDie=0;
RetTask->fKillable=1;
RetTask->fActive=1;
RetTask->Main=Main;
RetTask->hndTask=hndTask;
RetTask->Stack=(void *)(((U32) RetTask)+G[2].Offset);
RetTask->StackSize=G[3].Offset-G[2].Offset;
if (DataSize)
RetTask->Data=(void *)(((U32) RetTask)+G[1].Offset);
else
RetTask->Data=NULL;
RetTask->SleepTime=1;
RetTask->fXtraStack=ExtraStackProtection;
RetTask->XtraLongs=ExtraStackSizeLongs;
if (RetTask->fXtraStack)
ExtraMarkStack(RetTask->Stack,RetTask->StackSize/sizeof(u32));
else
GSYS_MarkStack(RetTask->Stack,RetTask->StackSize);
/* if a task running then add as next in list or at beggining */
if (CurrentTask)
{
AddToList(&CurrentTask->Next,RetTask);
RetTask->Prev=CurrentTask;
}
else
AddToList(&ActiveTasks,RetTask);
TasksActive++;
}
return RetTask;
}
/* ---------------------------------------------------------------------------
Function: void TSK_DoTasks(void)
Purpose: Run All the tasks
--------------------------------------------------------------------------- */
void TSK_DoTasks(void)
{
T=ActiveTasks;
if (DoTasksPrologue)
DoTasksPrologue();
while (T)
{
if (T->fActive && (T->Id&ExecMask)==ExecId)
{
T->SleepTime--;
if (!T->SleepTime)
{
if (!setjmp(SchEnv))
{
/* See if this task needs initing or not */
CurrentTask=T;
DoPro(T);
if (T->fToInit)
{
T->fToInit=0;
GSYS_SetStackAndJump((void *)((U32)T->Stack+T->StackSize-sizeof(void *)*4),(void *)ExecuteTask,T);
}
else
longjmp(T->TskEnv,1);
}
else
{
/* Back from the previous task */
TASK * NextT;
NextT=T->Next;
/* Top this task if it was intended to die */
if (T->fToDie)
LoTskKill(T);
T=NextT;
}
}
else
T=T->Next;
}
else
T=T->Next;
}
if (DoTasksEpilogue)
DoTasksEpilogue();
CurrentTask=NULL;
}
/* ---------------------------------------------------------------------------
Function: void TSK_Sleep(int Frames)
Purpose: This Task to sleep for an amount of frames
Params: T -> Task
Frames = num of frames to sleep
--------------------------------------------------------------------------- */
void TSK_Sleep(int Frames)
{
TASK * T;
T=CurrentTask;
ASSERT(T);
if (TSK_IsStackCorrupted(T))
{
if (StackFloodCallback)
StackFloodCallback(T);
else
ASSERT(!"TSK STACK CORRUPTION");
}
// ASSERT(!GSYS_IsStackOutOfBounds(T->Stack,T->StackSize));
DoEpi(T);
if (!setjmp(T->TskEnv))
{
/* Saving enviro so go back to scheduler */
T->SleepTime=Frames;
ReturnToSchedulerIfCurrentTask(CurrentTask);
}
}
/* ---------------------------------------------------------------------------
Function: static void ReturnToScheduler(TASK *T)
Purpose: Return to scheduler
Params: T -> Current Task
--------------------------------------------------------------------------- */
static void ReturnToSchedulerIfCurrentTask(TASK *T)
{
if (TSK_IsStackCorrupted(T))
{
if (StackFloodCallback)
StackFloodCallback(T);
else
ASSERT(!"TSK STACK CORRUPTION");
}
longjmp(SchEnv,1);
}
/* ---------------------------------------------------------------------------
Function: void TSK_Die(void)
Purpose: Kill off current task
--------------------------------------------------------------------------- */
void TSK_Die(void)
{
if (CurrentTask)
TSK_Kill(CurrentTask);
}
/* ---------------------------------------------------------------------------
Function: void TSK_Kill(TASK *T)
Purpose: Kill off a task
If this is the current task then return to scheduler
Params: T -> Task to kill
--------------------------------------------------------------------------- */
void TSK_Kill(TASK *T)
{
if (T==CurrentTask && CurrentTask)
{
T->fToDie=TRUE;
ReturnToSchedulerIfCurrentTask(T);
}
else
LoTskKill(T);
}
/* ---------------------------------------------------------------------------
Function: TASK * TSK_GetFirstActive(void);
Purpose: Get the first in the chain of active tasks
Params: T -> Task block to check
Returns: True if it is
--------------------------------------------------------------------------- */
TASK * TSK_GetFirstActive(void)
{
return(ActiveTasks);
}
/* ---------------------------------------------------------------------------
Function: BOOL TSK_IsStackCorrupted(TASK *T)
Purpose: Check to see if this task's stack has flooded
Params: T -> Task block to check
Returns: True if it is
--------------------------------------------------------------------------- */
BOOL TSK_IsStackCorrupted(TASK *T)
{
if (T->fXtraStack)
{
int LongsOk;
LongsOk=CheckExtraStack(T->Stack,T->StackSize/4);
T->MaxStackSizeBytes=(u16)T->StackSize-(LongsOk*sizeof(u32));
return (LongsOk < T->XtraLongs);
}
else
return(GSYS_IsStackCorrupted(T->Stack,T->StackSize));
}
/* ---------------------------------------------------------------------------
Function: void TSK_JumpAndResetStack(void (*RunFunc)(TASK *))
Purpose: Current running task stack is reset and jumped off to
another routine
Params: T -> Task block to check
Returns: True if it is
--------------------------------------------------------------------------- */
void TSK_JumpAndResetStack(void (*RunFunc)(TASK *))
{
TASK * T;
T=CurrentTask;
if (T)
{
T->Main=RunFunc;
GSYS_SetStackAndJump((void *)((U32)T->Stack+T->StackSize-sizeof(void *)*4),(void *)ExecuteTask,T);
}
}
/* ---------------------------------------------------------------------------
Function: void TSK_SetStackAndJump(void (*RunFunc)(TASK *))
Purpose: Current running task
Params: T -> Task block to repoint
Returns: True if it is
--------------------------------------------------------------------------- */
void TSK_RepointProc(TASK *T,void (*Func)(TASK *T))
{
/* If the current task is this task then just jump there else mark as
needing initing and -> start to new func */
if (T==CurrentTask)
TSK_JumpAndResetStack(Func);
else
{
T->fToInit=1;
T->Main=Func;
}
}
/* ---------------------------------------------------------------------------
Function: TASK * TSK_GetCurrentTask(void);
Purpose: Get the current executing task
Returns: -> Current execiting task block
--------------------------------------------------------------------------- */
TASK * TSK_GetCurrentTask(void)
{
return(CurrentTask);
}
/* ---------------------------------------------------------------------------
Function: BOOL TSK_IsCurrentTask(TASK *T)
Purpose: Is this task the currently executing one?
Returns: TRUE or FALSE
--------------------------------------------------------------------------- */
BOOL TSK_IsCurrentTask(TASK *T)
{
return(T==CurrentTask);
}
/* ---------------------------------------------------------------------------
Function: TASK *TSK_Exist(TASK *T,U32 Id,U32 Mask)
Purpose: Is this task the currently executing one?
Params: T -> Calling task
Returns: -> first task found
--------------------------------------------------------------------------- */
TASK *TSK_Exist(TASK *T,U32 Id,U32 Mask)
{
TASK * ptrTask;
TASK * RetTask;
ptrTask=ActiveTasks;
RetTask=NULL;
while (ptrTask && !RetTask)
{
if ((ptrTask != T) && (ptrTask->Id&Mask)==Id)
RetTask=ptrTask;
else
ptrTask=ptrTask->Next;
}
return(RetTask);
}
/* ---------------------------------------------------------------------------
Function: void TSK_SetExecFilter(U32 Id,U32 Mask)
Purpose: Set a filter for tasks that are executed
If ((Task.Id&Mask) == Id) then task is run
Params:
U32 = Id;
Mask = Task class mask
--------------------------------------------------------------------------- */
void TSK_SetExecFilter(U32 Id,U32 Mask)
{
ExecId=Id;
ExecMask=Mask;
}
/* ---------------------------------------------------------------------------
Function: void TSK_ClearExecFilter(void)
Purpose: Clears the exec filter, everything is run
--------------------------------------------------------------------------- */
void TSK_ClearExecFilter(void)
{
TSK_SetExecFilter(0,0);
}
/* ---------------------------------------------------------------------------
Function: int TSK_KillTasks(TASK * CallingT,U32 Id,U32 Mask)
Purpose: Mass task killer. Whacks through task list looking for victims.
If (T->fKillable && (Task.Id&Mask) == Id) then kill it.
Params: CallingT -> Calling task
U32 = Id;
Mask = Task class mask
Returns: # of Tasks Killed
--------------------------------------------------------------------------- */
int TSK_KillTasks(TASK * CallingT,U32 Id,U32 Mask)
{
int TasksKilled;
TASK * T;
BOOL WasCurrentTaskKilled;
TasksKilled=0;
WasCurrentTaskKilled=FALSE;
T=ActiveTasks;
while (T)
{
TASK * NextT;
NextT=T->Next;
if (T != CallingT)
{
if (T->fKillable && (T->Id&Mask)==Id)
{
if (T==CurrentTask)
WasCurrentTaskKilled=TRUE;
else
LoTskKill(T);
TasksKilled++;
}
}
T=NextT;
}
/* If Current task was killed then we go on to next task */
if (WasCurrentTaskKilled)
{
CurrentTask->fToDie=TRUE;
ReturnToSchedulerIfCurrentTask(CurrentTask);
}
return(TasksKilled);
}
/* ---------------------------------------------------------------------------
Function: void TSK_IterateTasks(U32 Id,U32 Mask,void (*CallBack)(TASK *T))
Purpose: Go through task list and do a callback for all tasks which match.
If (Task->Id&Mask)==Id then callback function is invoked.
Params: Id = Task Id to match
Mask = Task class mask
--------------------------------------------------------------------------- */
void TSK_IterateTasks(U32 Id,U32 Mask,void (*CallBack)(TASK *T))
{
TASK * T;
T=ActiveTasks;
while (T)
{
TASK * NextT;
NextT=T->Next;
if ((T->Id&Mask)==Id)
CallBack(T);
T=NextT;
}
}
/* ---------------------------------------------------------------------------
Function: void TSK_MakeTaskInactive(TASK *T)
Purpose: Make a task temporarily inactive.
Params: T -> Task to knock out
--------------------------------------------------------------------------- */
void TSK_MakeTaskInactive(TASK *T)
{
T->fActive=0;
}
/* ---------------------------------------------------------------------------
Function: void TSK_MakeTaskActive(TASK *T)
Purpose: Make a task active again.
Params: T -> Task to reactivate
--------------------------------------------------------------------------- */
void TSK_MakeTaskActive(TASK *T)
{
T->fActive=1;
}
/* ---------------------------------------------------------------------------
Function: void TSK_MakeTaskImmortal(TASK *T)
Purpose: Make a task impervious to mass killings.
Note that task can still be killed explicitly with TSK_Kill.
Params: T -> Task to protect
--------------------------------------------------------------------------- */
void TSK_MakeTaskImmortal(TASK *T)
{
T->fKillable=0;
}
/* ---------------------------------------------------------------------------
Function: void TSK_MakeTaskMortal(TASK *T)
Purpose: Make a task vulnerable to mass killings.
Params: T -> Task to expose
--------------------------------------------------------------------------- */
void TSK_MakeTaskMortal(TASK *T)
{
T->fKillable=1;
}
/* ---------------------------------------------------------------------------
Function: BOOL TSK_IsTaskActive(TASK *T)
Purpose: Check if a task is active
Params: T -> Task to eheck
Returns: 0=Inactive, 1=Active
--------------------------------------------------------------------------- */
BOOL TSK_IsTaskActive(TASK *T)
{
return (T->fActive);
}
/* ---------------------------------------------------------------------------
Function: BOOL TSK_IsTaskMortal(TASK *T)
Purpose: Check if a task is easy to kill.
Params: T -> Task to check
Returns: 0=Immortal, 1=Mortal
--------------------------------------------------------------------------- */
BOOL TSK_IsTaskMortal(TASK *T)
{
return (T->fKillable);
}
/* ---------------------------------------------------------------------------
Function: void DetachFromList(TASK **Head,TASK *ThisObj)
Purpose: Take an object from an obj list
Params: Head -> Head ptr of list
ThisObj -> Obj to add
--------------------------------------------------------------------------- */
static void DetachFromList(TASK **Head,TASK *ThisObj)
{
if (ThisObj->Prev)
ThisObj->Prev->Next=ThisObj->Next;
else
*Head=ThisObj->Next;
if (ThisObj->Next)
ThisObj->Next->Prev=ThisObj->Prev;
}
/* ---------------------------------------------------------------------------
Function: void AddToList(TASK **Head,TASK *ThisObj)
Purpose: Add an object to a obj list
Params: Head -> Head ptr of list
ThisObj -> Obj to add
--------------------------------------------------------------------------- */
static void AddToList(TASK **Head,TASK *ThisObj)
{
ThisObj->Prev=NULL;
if ((ThisObj->Next=*Head))
ThisObj->Next->Prev=ThisObj;
*Head=ThisObj;
}
/* ---------------------------------------------------------------------------
Function: static void LoTskKill(TASK *T)
Purpose: Low level killing of task helper routine
Params: T -> Task to kill
--------------------------------------------------------------------------- */
static void LoTskKill(TASK *T)
{
BOOL GalRet;
/* Take out of list of active tasks */
DetachFromList(&ActiveTasks,T);
/* Dealloc the task block */
GalRet=GAL_Free(T->hndTask);
TasksActive--;
ASSERT(GalRet);
}
/* ---------------------------------------------------------------------------
Function: static void ExecuteTask(TASK *T)
Purpose: Low level task executor, protects from tasks that return
without a TSK_Kill
Params: T -> Task to execute
--------------------------------------------------------------------------- */
static void ExecuteTask(TASK *T)
{
T->Main(T);
DoEpi(T);
T->fToDie=TRUE;
ReturnToSchedulerIfCurrentTask(T);
}
/* ---------------------------------------------------------------------------
Epilogue / Prologue Function stuff
--------------------------------------------------------------------------- */
DOTSK_CBACK TSK_SetDoTasksPrologue(DOTSK_CBACK Func)
{
DOTSK_CBACK Old;
Old=DoTasksPrologue;
DoTasksPrologue=Func;
return(Old);
}
DOTSK_CBACK TSK_SetDoTasksEpilogue(DOTSK_CBACK Func)
{
DOTSK_CBACK Old;
Old=DoTasksEpilogue;
DoTasksEpilogue=Func;
return(Old);
}
TSK_CBACK TSK_SetTaskPrologue(TSK_CBACK Pro)
{
TSK_CBACK Old;
Old=ProFunc;
ProFunc=Pro;
return(Old);
}
TSK_CBACK TSK_SetTaskEpilogue(TSK_CBACK Epi)
{
TSK_CBACK Old;
Old=EpiFunc;
EpiFunc=Epi;
return(Old);
}
void TSK_SetEpiProFilter(U32 Id,U32 Mask)
{
EpiProId=Id;
EpiProMask=Id;
}
void TSK_ClearEpiProFilter(void)
{
TSK_SetEpiProFilter(1,0);
TSK_SetTaskEpilogue(NULL);
TSK_SetTaskPrologue(NULL);
}
/* ---------------------------------------------------------------------------
Function: void TSK_SetExtraStackProtection(BOOL OnOff)
Purpose: Say if we want the slow, memory heavy xtra stack protection
--------------------------------------------------------------------------- */
void TSK_SetExtraStackProtection(BOOL OnOff)
{
ExtraStackProtection=OnOff;
}
/* ---------------------------------------------------------------------------
Function: TSK_CBACK TSK_SetStackFloodCallback(TSK_CBACK Func);
Purpose: This gets called if stack is detected as broken
--------------------------------------------------------------------------- */
TSK_CBACK TSK_SetStackFloodCallback(TSK_CBACK Func)
{
TSK_CBACK OldFunc;
OldFunc=StackFloodCallback;
StackFloodCallback=Func;
return(OldFunc);
}
/* ---------------------------------------------------------------------------
Function: int TSK_SetExtraStackSize(int Size)
Purpose: Set the xtra stack size for safety
--------------------------------------------------------------------------- */
int TSK_SetExtraStackSize(int Size)
{
int OldSize=ExtraStackSizeLongs*sizeof(u32);
ExtraStackSizeLongs=Size/4;
return(OldSize);
}
void ExtraMarkStack(u32 * Stack,int SizeLongs)
{
int f;
for (f=0;f<SizeLongs;f++)
Stack[f]=f;
}
int CheckExtraStack(u32 * Stack,int LongsToCheck)
{
u32 f;
for (f=0;f<(u32) LongsToCheck;f++)
{
if (Stack[f] != f)
return(f);
}
return(f);
}
/* ---------------------------------------------------------------------------
ends */

132
Utils/Libs/GLib/tasker.h Normal file
View File

@ -0,0 +1,132 @@
/* ===========================================================================
File: TASKER.H
Notes: Cooperative multitasking Header file
Author: Gary Liddon @ 73b
Created: Wednesday 27th March 1996
Copyright (C) 1996 - 1997 Gary Liddon
All rights reserved.
============================================================================ */
#ifndef __TASKER_HPP_
#define __TASKER_HPP_
/* ---------------------------------------------------------------------------
Standard Lib Includes
--------------------- */
#include <setjmp.h>
/* ---------------------------------------------------------------------------
Glib Includes
------------- */
#include "gtypes.h"
#include "gal.h"
/* ---------------------------------------------------------------------------
Structure Definitions
--------------------- */
typedef struct TASK
{
struct TASK *Next;
struct TASK *Prev;
U32 Id;
U32 SleepTime;
U32 fToInit:1, /* Has this task been inited */
fToDie:1, /* Does this task deserve to die! */
fKillable:1, /* Can this task be killed */
fActive:1, /* Is this task active or what */
fXtraStack:1;
void * Stack;
U32 StackSize;
void * Data;
jmp_buf TskEnv;
void (*Main)(struct TASK *T);
MHANDLE hndTask;
u16 XtraLongs;
u16 MaxStackSizeBytes;
} TASK;
/* ---------------------------------------------------------------------------
Function Prototypes
------------------- */
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API BOOL TSK_OpenModule(U32 MemType);
GLIB_API void TSK_DoTasks(void);
/* Task management
--------------- */
GLIB_API TASK * TSK_AddTask(U32 Id,void (*Main)(TASK *T),int StackSize,int DataSize);
GLIB_API void TSK_RepointProc(TASK *T,void (*Func)(TASK *T));
GLIB_API void TSK_Kill(TASK *T);
GLIB_API int TSK_KillTasks(TASK * CallingT,U32 Id,U32 Mask);
GLIB_API void TSK_Sleep(int Frames);
GLIB_API void TSK_Die(void);
GLIB_API void TSK_JumpAndResetStack(void (*RunFunc)(TASK *));
GLIB_API void TSK_ClearExecFilter(void);
GLIB_API void TSK_SetExecFilter(U32 Id,U32 Mask);
GLIB_API void TSK_IterateTasks(U32 Id,U32 Mask,void (*CallBack)(TASK *T));
GLIB_API void TSK_MakeTaskInactive(TASK *T);
GLIB_API void TSK_MakeTaskActive(TASK *T);
GLIB_API void TSK_MakeTaskImmortal(TASK *T);
GLIB_API void TSK_MakeTaskMortal(TASK *T);
/* Info and reporting
------------------ */
GLIB_API TASK * TSK_Exist(TASK *T,U32 Id,U32 Mask);
GLIB_API TASK * TSK_GetCurrentTask(void);
GLIB_API BOOL TSK_IsCurrentTask(TASK *T);
GLIB_API TASK * TSK_GetFirstActive(void);
GLIB_API BOOL TSK_IsStackCorrupted(TASK *T);
GLIB_API BOOL TSK_IsTaskActive(TASK *T);
GLIB_API BOOL TSK_IsTaskMortal(TASK *T);
/* Debug Stuff
----------- */
typedef void (*TSK_CBACK)(TASK *T);
typedef void (*DOTSK_CBACK)(void);
GLIB_API DOTSK_CBACK TSK_SetDoTasksEpilogue(DOTSK_CBACK Func);
GLIB_API DOTSK_CBACK TSK_SetDoTasksPrologue(DOTSK_CBACK Func);
GLIB_API TSK_CBACK TSK_SetTaskPrologue(TSK_CBACK Pro);
GLIB_API TSK_CBACK TSK_SetTaskEpilogue(TSK_CBACK Epi);
GLIB_API void TSK_SetEpiProFilter(U32 Id,U32 Mask);
GLIB_API void TSK_ClearEpiProFilter(void);
GLIB_API void TSK_SetExtraStackProtection(BOOL OnOff);
GLIB_API TSK_CBACK TSK_SetStackFloodCallback(TSK_CBACK Func);
GLIB_API int TSK_SetExtraStackSize(int Size);
#ifdef __cplusplus
};
#endif
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

82
Utils/Libs/GLib/tick.c Normal file
View File

@ -0,0 +1,82 @@
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
File: TICK.C
Notes: Game Frame Clock stuff
Author: G Robert Liddon @ Croydon
Created: Monday 2nd October 1995
Copyright (C) 1994/1995 G Robert Liddon
All rights reserved.
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Glib Includes
ÄÄÄÄÄÄÄÄÄÄÄÄÄ */
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Includes
ÄÄÄÄÄÄÄÄ */
#include "tick.h"
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Vars
ÄÄÄÄ */
U32 GazTick;
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Intialise the module
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void TICK_InitModule(void)
{
TICK_Set(0);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Set the current tick value
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
void TICK_Set(U32 Val)
{
GazTick=Val;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Set the current tick value
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
U32 TICK_Get(void)
{
return(GazTick);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Update Tick
ÄÄÄÄÄÄÄÄÄÄÄ */
void TICK_Update(void)
{
GazTick++;
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Get the frames passed since last tick
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ */
U32 TICK_GetAge(U32 OldTick)
{
return(TICK_Get()-OldTick);
}
const char * TICK_GetDateString(void)
{
return(__DATE__);
}
const char * TICK_GetTimeString(void)
{
return(__TIME__);
}
/* ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
ends */

59
Utils/Libs/GLib/tick.h Normal file
View File

@ -0,0 +1,59 @@
/* ===========================================================================
File: TICK.C
Notes: Game Frame Clock stuff
Author: G Robert Liddon @ Croydon
Created: Monday 2nd October 1995
Copyright (C) 1995 - 1997 Gary Liddon
All rights reserved.
=========================================================================== */
#ifndef __TICK_H
#define __TICK_H
/* ---------------------------------------------------------------------------
Glib Includes
------------- */
#include "gtypes.h"
/* ---------------------------------------------------------------------------
Defines
------- */
/* ---------------------------------------------------------------------------
Structures
---------- */
/* ---------------------------------------------------------------------------
Global Routines
--------------- */
#ifdef __cplusplus
extern "C" {
#endif
GLIB_API void TICK_InitModule(void);
GLIB_API void TICK_Set(U32 Val);
GLIB_API U32 TICK_Get(void);
GLIB_API void TICK_Update(void);
GLIB_API U32 TICK_GetAge(U32 OldTick);
GLIB_API const char * TICK_GetTimeString(void);
GLIB_API const char * TICK_GetDateString(void);
#ifdef __cplusplus
};
#endif
/* ---------------------------------------------------------------------------
Global Vars
----------- */
/* --------------------------------------------------------------------------- */
#endif
/* ---------------------------------------------------------------------------
ends */

467
Utils/Libs/GLib/tquant.cpp Normal file
View File

@ -0,0 +1,467 @@
/**********************************************************************
C Implementation of Wu's Color Quantizer (v. 2)
(see Graphics Gems vol. II, pp. 126-133)
Author: Wu
Dept. of Computer Science
Univ. of Western Ontario
London, Ontario N6A 5B7
wu@csd.uwo.ca
Algorithm: Greedy orthogonal bipartition of RGB space for variance
minimization aided by inclusion-exclusion tricks.
For speed no nearest neighbor search is done. Slightly
better performance can be expected by more sophisticated
but more expensive versions.
The author thanks Tom Lane at Tom_Lane@G.GP.CS.CMU.EDU for much of
additional documentation and a cure to a previous bug.
Free to distribute, comments and suggestions are appreciated.
**********************************************************************/
#include "Tquant.h"
#include "gobject.hpp"
#define MAXCOLOR 256
#define RED 2
#define GREEN 1
#define BLUE 0
struct box {
int r0; /* min value, exclusive */
int r1; /* max value, inclusive */
int g0;
int g1;
int b0;
int b1;
int vol;
};
/* Histogram is in elements 1..HISTSIZE along each axis,
* element 0 is for base or marginal value
* NB: these must start out 0!
*/
float gm2[33][33][33];
long int wt[33][33][33], mr[33][33][33], mg[33][33][33], mb[33][33][33];
unsigned char *Ir, *Ig, *Ib;
//int size; /*image size*/
//int K; /*color look-up table size*/
unsigned short int *Qadd;
void ClearTables(void);
void ClearTables(void)
{
for (int x=0;x<33;x++)
for (int y=0;y<33;y++)
for (int z=0;z<33;z++)
{
gm2[x][y][z]=0;
wt[x][y][z]=0;
mr[x][y][z]=0;
mg[x][y][z]=0;
mb[x][y][z]=0;
}
}
/* build 3-D color histogram of counts, r/g/b, c^2 */
void Hist3d(long int* vwt, long int *vmr, long int *vmg, long int *vmb, float *m2, int size)
{
register int ind, r, g, b;
int inr, ing, inb, table[256];
register long int i;
for(i=0; i<256; ++i) table[i]=i*i;
Qadd = (unsigned short int *)malloc(sizeof(short int)*size);
if (Qadd==NULL)
GObject::Error(ERM_OUTOFMEM);
for(i=0; i<size; ++i)
{
r = Ir[i]; g = Ig[i]; b = Ib[i];
inr=(r>>3)+1;
ing=(g>>3)+1;
inb=(b>>3)+1;
Qadd[i]=ind=(inr<<10)+(inr<<6)+inr+(ing<<5)+ing+inb;
/*[inr][ing][inb]*/
++vwt[ind];
vmr[ind] += r;
vmg[ind] += g;
vmb[ind] += b;
m2[ind] += (float)(table[r]+table[g]+table[b]);
}
}
/* At conclusion of the histogram step, we can interpret
* wt[r][g][b] = sum over voxel of P(c)
* mr[r][g][b] = sum over voxel of r*P(c) , similarly for mg, mb
* m2[r][g][b] = sum over voxel of c^2*P(c)
* Actually each of these should be divided by 'size' to give the usual
* interpretation of P() as ranging from 0 to 1, but we needn't do that here.
*/
/* We now convert histogram into moments so that we can rapidly calculate
* the sums of the above quantities over any desired box.
*/
/* compute cumulative moments. */
void M3d(long int *vwt, long int *vmr, long int *vmg, long int *vmb, float *m2)
{
register unsigned short int ind1, ind2;
register unsigned char i, r, g, b;
long int line, line_r, line_g, line_b;
long int area[33], area_r[33], area_g[33], area_b[33];
float line2, area2[33];
for(r=1; r<=32; ++r)
{
for(i=0; i<=32; ++i)
{
area[i]=area_r[i]=area_g[i]=area_b[i]=0;
area2[i]=0.f;
}
for(g=1; g<=32; ++g)
{
line = line_r = line_g = line_b = 0;
line2 = 0.f;
for(b=1; b<=32; ++b)
{
ind1 = (r<<10) + (r<<6) + r + (g<<5) + g + b; /* [r][g][b] */
line += vwt[ind1];
line_r += vmr[ind1];
line_g += vmg[ind1];
line_b += vmb[ind1];
line2 += m2[ind1];
area[b] += line;
area_r[b] += line_r;
area_g[b] += line_g;
area_b[b] += line_b;
area2[b] += line2;
ind2 = ind1 - 1089; /* [r-1][g][b] */
vwt[ind1] = vwt[ind2] + area[b];
vmr[ind1] = vmr[ind2] + area_r[b];
vmg[ind1] = vmg[ind2] + area_g[b];
vmb[ind1] = vmb[ind2] + area_b[b];
m2[ind1] = m2[ind2] + area2[b];
}
}
}
}
/* Compute sum over a box of any given statistic */
long int Vol(box *cube, long int *mmt)
{
return( mmt[((cube->r1)*33*33)+((cube->g1)*33)+(cube->b1)]
-mmt[((cube->r1)*33*33)+((cube->g1)*33)+(cube->b0)]
-mmt[((cube->r1)*33*33)+((cube->g0)*33)+(cube->b1)]
+mmt[((cube->r1)*33*33)+((cube->g0)*33)+(cube->b0)]
-mmt[((cube->r0)*33*33)+((cube->g1)*33)+(cube->b1)]
+mmt[((cube->r0)*33*33)+((cube->g1)*33)+(cube->b0)]
+mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b1)]
-mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b0)] );
}
/* The next two routines allow a slightly more efficient calculation
* of Vol() for a proposed subbox of a given box. The sum of Top()
* and Bottom() is the Vol() of a subbox split in the given direction
* and with the specified new upper bound.
*/
/* Compute part of Vol(cube, mmt) that doesn't depend on r1, g1, or b1 */
/* (depending on dir) */
long int Bottom(box *cube, unsigned char dir, long int *mmt)
{
switch(dir){
case RED:
return( -mmt[((cube->r0)*33*33)+((cube->g1)*33)+(cube->b1)]
+mmt[((cube->r0)*33*33)+((cube->g1)*33)+(cube->b0)]
+mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b1)]
-mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b0)] );
break;
case GREEN:
return( -mmt[((cube->r1)*33*33)+((cube->g0)*33)+(cube->b1)]
+mmt[((cube->r1)*33*33)+((cube->g0)*33)+(cube->b0)]
+mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b1)]
-mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b0)] );
break;
case BLUE:
return( -mmt[((cube->r1)*33*33)+((cube->g1)*33)+(cube->b0)]
+mmt[((cube->r1)*33*33)+((cube->g0)*33)+(cube->b0)]
+mmt[((cube->r0)*33*33)+((cube->g1)*33)+(cube->b0)]
-mmt[((cube->r0)*33*33)+((cube->g0)*33)+(cube->b0)] );
break;
default:
return NULL;
}
}
/* Compute remainder of Vol(cube, mmt), substituting pos for */
/* r1, g1, or b1 (depending on dir) */
long int Top(box *cube, unsigned char dir, int pos, long int *mmt)
{
switch(dir){
case RED:
return( mmt[(pos*33*33)+(cube->g1*33)+cube->b1]
-mmt[(pos*33*33)+(cube->g1*33)+cube->b0]
-mmt[(pos*33*33)+(cube->g0*33)+cube->b1]
+mmt[(pos*33*33)+(cube->g0*33)+cube->b0] );
break;
case GREEN:
return( mmt[((cube->r1)*33*33)+(pos*33)+cube->b1]
-mmt[((cube->r1)*33*33)+(pos*33)+cube->b0]
-mmt[((cube->r0)*33*33)+(pos*33)+cube->b1]
+mmt[((cube->r0)*33*33)+(pos*33)+cube->b0] );
break;
case BLUE:
return( mmt[(cube->r1*33*33)+(cube->g1*33)+pos]
-mmt[(cube->r1*33*33)+(cube->g0*33)+pos]
-mmt[(cube->r0*33*33)+(cube->g1*33)+pos]
+mmt[(cube->r0*33*33)+(cube->g0*33)+pos] );
break;
default:
return NULL;
}
}
/* Compute the weighted variance of a box */
/* NB: as with the raw statistics, this is really the variance * size */
float Var(box *cube)
{
float dr, dg, db, xx;
dr = (float)Vol(cube, &mr[0][0][0]);
dg = (float)Vol(cube, &mg[0][0][0]);
db = (float)Vol(cube, &mb[0][0][0]);
xx = gm2[cube->r1][cube->g1][cube->b1]
-gm2[cube->r1][cube->g1][cube->b0]
-gm2[cube->r1][cube->g0][cube->b1]
+gm2[cube->r1][cube->g0][cube->b0]
-gm2[cube->r0][cube->g1][cube->b1]
+gm2[cube->r0][cube->g1][cube->b0]
+gm2[cube->r0][cube->g0][cube->b1]
-gm2[cube->r0][cube->g0][cube->b0];
return( xx - (dr*dr+dg*dg+db*db)/(float)Vol(cube,&wt[0][0][0]) );
}
/* We want to minimize the sum of the variances of two subboxes.
* The sum(c^2) terms can be ignored since their sum over both subboxes
* is the same (the sum for the whole box) no matter where we split.
* The remaining terms have a minus sign in the variance formula,
* so we drop the minus sign and MAXIMIZE the sum of the two terms.
*/
float Maximize(box *cube, unsigned char dir, int first, int last, int *cut,long int whole_r, long int whole_g, long int whole_b, long int whole_w)
{
register long int half_r, half_g, half_b, half_w;
long int base_r, base_g, base_b, base_w;
register int i;
register float temp, max;
base_r = Bottom(cube, dir, &mr[0][0][0]);
base_g = Bottom(cube, dir, &mg[0][0][0]);
base_b = Bottom(cube, dir, &mb[0][0][0]);
base_w = Bottom(cube, dir, &wt[0][0][0]);
max = 0.0;
*cut = -1;
for(i=first; i<last; ++i)
{
half_r = base_r + Top(cube, dir, i, &mr[0][0][0]);
half_g = base_g + Top(cube, dir, i, &mg[0][0][0]);
half_b = base_b + Top(cube, dir, i, &mb[0][0][0]);
half_w = base_w + Top(cube, dir, i, &wt[0][0][0]);
/* now half_x is sum over lower half of box, if split at i */
if (half_w == 0) { /* subbox could be empty of pixels! */
continue; /* never split into an empty box */
} else
temp = ((float)half_r*half_r + (float)half_g*half_g +
(float)half_b*half_b)/half_w;
half_r = whole_r - half_r;
half_g = whole_g - half_g;
half_b = whole_b - half_b;
half_w = whole_w - half_w;
if (half_w == 0) { /* subbox could be empty of pixels! */
continue; /* never split into an empty box */
} else
temp += ((float)half_r*half_r + (float)half_g*half_g +
(float)half_b*half_b)/half_w;
if (temp > max) {max=temp; *cut=i;}
}
return(max);
}
int Cut(box *set1, box *set2)
{
unsigned char dir;
int cutr, cutg, cutb;
float maxr, maxg, maxb;
long int whole_r, whole_g, whole_b, whole_w;
whole_r = Vol(set1, &mr[0][0][0]);
whole_g = Vol(set1, &mg[0][0][0]);
whole_b = Vol(set1, &mb[0][0][0]);
whole_w = Vol(set1, &wt[0][0][0]);
maxr = Maximize(set1, RED, set1->r0+1, set1->r1, &cutr,
whole_r, whole_g, whole_b, whole_w);
maxg = Maximize(set1, GREEN, set1->g0+1, set1->g1, &cutg,
whole_r, whole_g, whole_b, whole_w);
maxb = Maximize(set1, BLUE, set1->b0+1, set1->b1, &cutb,
whole_r, whole_g, whole_b, whole_w);
if( (maxr>=maxg)&&(maxr>=maxb) )
{
dir = RED;
if (cutr < 0) return 0; /* can't split the box */
}else
if( (maxg>=maxr)&&(maxg>=maxb) )
dir = GREEN;
else
dir = BLUE;
set2->r1 = set1->r1;
set2->g1 = set1->g1;
set2->b1 = set1->b1;
switch (dir){
case RED:
set2->r0 = set1->r1 = cutr;
set2->g0 = set1->g0;
set2->b0 = set1->b0;
break;
case GREEN:
set2->g0 = set1->g1 = cutg;
set2->r0 = set1->r0;
set2->b0 = set1->b0;
break;
case BLUE:
set2->b0 = set1->b1 = cutb;
set2->r0 = set1->r0;
set2->g0 = set1->g0;
break;
}
set1->vol=(set1->r1-set1->r0)*(set1->g1-set1->g0)*(set1->b1-set1->b0);
set2->vol=(set2->r1-set2->r0)*(set2->g1-set2->g0)*(set2->b1-set2->b0);
return 1;
}
void Mark(box *cube, int label, unsigned char *tag)
{
register int r, g, b;
for(r=cube->r0+1; r<=cube->r1; ++r)
for(g=cube->g0+1; g<=cube->g1; ++g)
for(b=cube->b0+1; b<=cube->b1; ++b)
tag[(r<<10) + (r<<6) + r + (g<<5) + g + b] = label;
}
void tquant(BYTE* Src, BYTE* Dst, BYTE* Pal, int K, int size)
{
struct box cube[MAXCOLOR];
unsigned char *tag;
unsigned char lut_r[MAXCOLOR], lut_g[MAXCOLOR], lut_b[MAXCOLOR];
int next;
register long int i, weight;
register int k;
float vv[MAXCOLOR], temp;
ClearTables();
/* input R,G,B components into Ir, Ig, Ib;
set size to width*height */
// screen_debug_msg("Reducing to %d cols",K);
Ir=(BYTE*)malloc(size);
Ig=(BYTE*)malloc(size);
Ib=(BYTE*)malloc(size);
/* Split in data into RGB buffers */
for(i=0;i<size;i++)
{
Ir[i]=*Src++;
Ig[i]=*Src++;
Ib[i]=*Src++;
}
Hist3d(&wt[0][0][0], &mr[0][0][0], &mg[0][0][0], &mb[0][0][0], &gm2[0][0][0], size);
free(Ig); free(Ib); free(Ir);
M3d(&wt[0][0][0], &mr[0][0][0], &mg[0][0][0], &mb[0][0][0], &gm2[0][0][0]);
cube[0].r0 = cube[0].g0 = cube[0].b0 = 0;
cube[0].r1 = cube[0].g1 = cube[0].b1 = 32;
next = 0;
for(i=1; i<K; ++i)
{
if (Cut(&cube[next], &cube[i])) {
/* volume test ensures we won't try to cut one-cell box */
vv[next] = (cube[next].vol>1) ? Var(&cube[next]) : 0.f;
vv[i] = (cube[i].vol>1) ? Var(&cube[i]) : 0.f;
} else {
vv[next] = 0.0; /* don't try to split this box again */
i--; /* didn't create box i */
}
next = 0; temp = vv[0];
for(k=1; k<=i; ++k)
if (vv[k] > temp) {
temp = vv[k]; next = k;
}
if (temp <= 0.0) {
K = i+1;
break;
}
}
/* the space for array gm2 can be freed now */
tag = (unsigned char *)malloc(33*33*33);
if (tag==NULL)
GObject::Error(ERM_OUTOFMEM);
for(k=0; k<K; ++k){
Mark(&cube[k], k, tag);
weight = Vol(&cube[k], &wt[0][0][0]);
if (weight) {
lut_r[k] = (unsigned char)(Vol(&cube[k], &mr[0][0][0]) / weight);
lut_g[k] = (unsigned char)(Vol(&cube[k], &mg[0][0][0]) / weight);
lut_b[k] = (unsigned char)(Vol(&cube[k], &mb[0][0][0]) / weight);
}
else{
lut_r[k] = lut_g[k] = lut_b[k] = 0;
}
}
for(i=0; i<size; ++i) Qadd[i] = tag[Qadd[i]];
/* output lut_r, lut_g, lut_b as color look-up table contents,
Qadd as the quantized image (array of table addresses). */
for(i=0; i<size; ++i) *Dst++ = (unsigned char)Qadd[i];
free(Qadd);
for(i=0;i<K;i++)
{
*Pal++=lut_r[i];
*Pal++=lut_g[i];
*Pal++=lut_b[i];
}
free(tag);
}

10
Utils/Libs/GLib/tquant.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __TQUANT_H__
#define __TQUANT_H__
#include "windows.h"
#include "gtypes.h"
void GLIB_API tquant(BYTE* Src, BYTE* Dst, BYTE* Pal, int K, int size);
#endif