Add rayman2 source files
This commit is contained in:
199
Rayman_X/cpa/tempgrp/ldt/Inc/DynArray.h
Normal file
199
Rayman_X/cpa/tempgrp/ldt/Inc/DynArray.h
Normal file
@@ -0,0 +1,199 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : DynArray.h
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: dynamic pointer array with sorting capabilities
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __DMS_DYN_ARRAY__
|
||||
#define __DMS_DYN_ARRAY__
|
||||
|
||||
/*
|
||||
* To export code.
|
||||
*/
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else /* CPA_WANTS_IMPORT */
|
||||
#define CPA_EXPORT
|
||||
#endif /* CPA_WANTS_IMPORT */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
TYPES
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct LDT_tdst_DSArray_ LDT_tdst_DSArray;
|
||||
|
||||
struct LDT_tdst_DSArray_
|
||||
{
|
||||
void** pData; /*the array of pointers*/
|
||||
int nSize; /*the size of the array*/
|
||||
int nMaxSize; /*the allocated size*/
|
||||
int nGrowBy;
|
||||
int nSortKey; /*the key to sort the array by*/
|
||||
int (* pfnCompare)(const void**, const void** ); /*the comparison function*/
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
FUNCTIONS
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/*creation, initialization, deletion
|
||||
--------------------------------------*/
|
||||
|
||||
CPA_EXPORT LDT_tdst_DSArray* LDT_DSAr_new(); /* creates a new array */
|
||||
CPA_EXPORT int LDT_DSAr_Init( LDT_tdst_DSArray* ); /* initializes an array */
|
||||
CPA_EXPORT void LDT_DSAr_delete( LDT_tdst_DSArray* ); /* deletes an existing array*/
|
||||
|
||||
CPA_EXPORT void LDT_DSAr_SetGranularity(LDT_tdst_DSArray*, int);
|
||||
CPA_EXPORT void LDT_DSAr_SetSortMethod(LDT_tdst_DSArray*, int (*)(const void**, const void** ));
|
||||
|
||||
/* standard pointer array functionality
|
||||
-----------------------------------------*/
|
||||
|
||||
/* Attributes */
|
||||
|
||||
CPA_EXPORT int LDT_DSAr_GetSize( LDT_tdst_DSArray* );
|
||||
CPA_EXPORT int LDT_DSAr_GetUpperBound( LDT_tdst_DSArray* );
|
||||
CPA_EXPORT int LDT_DSAr_SetSize( LDT_tdst_DSArray*, int nNewSize );
|
||||
|
||||
/* Operations */
|
||||
|
||||
/* Clean up */
|
||||
|
||||
CPA_EXPORT void LDT_DSAr_FreeExtra( LDT_tdst_DSArray* );
|
||||
CPA_EXPORT void LDT_DSAr_RemoveAll( LDT_tdst_DSArray* );
|
||||
|
||||
/* Accessing elements */
|
||||
|
||||
CPA_EXPORT void* LDT_DSAr_GetAt(LDT_tdst_DSArray*, int nIndex);
|
||||
CPA_EXPORT void LDT_DSAr_SetAt(LDT_tdst_DSArray*, int nIndex, void* newElement);
|
||||
CPA_EXPORT void** LDT_DSAr_ElementAt(LDT_tdst_DSArray*, int nIndex);
|
||||
|
||||
/* Potentially growing the array */
|
||||
|
||||
CPA_EXPORT int LDT_DSAr_Add(LDT_tdst_DSArray*, void* newElement);
|
||||
|
||||
/* Operations that move elements around */
|
||||
|
||||
CPA_EXPORT int LDT_DSAr_InsertAt(LDT_tdst_DSArray*, int nIndex, void* newElement );
|
||||
CPA_EXPORT void* LDT_DSAr_RemoveAt(LDT_tdst_DSArray*, int nIndex );
|
||||
CPA_EXPORT int LDT_DSAr_InsertArrayAt(LDT_tdst_DSArray*, int nStartIndex, LDT_tdst_DSArray* pNewArray);
|
||||
|
||||
/* sorting facilities
|
||||
------------------------*/
|
||||
|
||||
/* Sorting elements */
|
||||
|
||||
CPA_EXPORT void LDT_DSAr_QSort( LDT_tdst_DSArray* );
|
||||
|
||||
/* Adding elements */
|
||||
|
||||
CPA_EXPORT int LDT_DSAr_SAdd( LDT_tdst_DSArray*, void* newElement, int AdmitDuplicates, int* position );
|
||||
|
||||
/* Searching elements */
|
||||
CPA_EXPORT int LDT_DSAr_Index( LDT_tdst_DSArray*, void* newElement, int *p_iidx );
|
||||
CPA_EXPORT int LDT_DSAr_UpperBound( LDT_tdst_DSArray*, int idx);
|
||||
CPA_EXPORT int LDT_DSAr_LowerBound( LDT_tdst_DSArray*, int idx);
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
INLINE FUNCTIONS IMPLEMENTATION
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : sets the array's granularity
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline void LDT_DSAr_SetGranularity(LDT_tdst_DSArray* pst_Ar, int _nGrowBy )
|
||||
{
|
||||
pst_Ar->nGrowBy = ( 0>_nGrowBy? 0: _nGrowBy );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : sets the array's sort method. If NULL, the array's sort functions
|
||||
are not effective.
|
||||
WARNING : The sort method must be set prior to the use of any sort-related
|
||||
functions.
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline void LDT_DSAr_SetSortMethod(LDT_tdst_DSArray* pst_Ar,
|
||||
int (*_pfnCompare)(const void**, const void** ))
|
||||
{
|
||||
pst_Ar->pfnCompare = _pfnCompare;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : gets the array's number of elements
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline int LDT_DSAr_GetSize( LDT_tdst_DSArray* pst_Ar )
|
||||
{
|
||||
return pst_Ar->nSize;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : gets the array's upper bound (maximum index)
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline int LDT_DSAr_GetUpperBound( LDT_tdst_DSArray* pst_Ar )
|
||||
{
|
||||
return pst_Ar->nSize-1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : sets the array's size. - returns 1 if successful, 0 on error;
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline void LDT_DSAr_RemoveAll( LDT_tdst_DSArray* pst_Ar )
|
||||
{
|
||||
LDT_DSAr_SetSize( pst_Ar, 0 ); /* clean-up */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Gets the value of an array element. returns NULL on error
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline void* LDT_DSAr_GetAt(LDT_tdst_DSArray* pst_Ar, int nIndex)
|
||||
{
|
||||
if(nIndex < 0 || nIndex >= pst_Ar->nSize) return NULL;
|
||||
return pst_Ar->pData[nIndex];
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Sets an array element. If the index is out of bounds, nothing happens
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline void LDT_DSAr_SetAt(LDT_tdst_DSArray* pst_Ar, int nIndex, void* newElement)
|
||||
{
|
||||
if(nIndex < 0 || nIndex >= pst_Ar->nSize) return;
|
||||
pst_Ar->pData[nIndex] = newElement;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Gets an array element. returns NULL on error
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
__inline void** LDT_DSAr_ElementAt(LDT_tdst_DSArray* pst_Ar, int nIndex)
|
||||
{
|
||||
if(nIndex < 0 || nIndex >= pst_Ar->nSize) return NULL;
|
||||
return pst_Ar->pData + nIndex;
|
||||
}
|
||||
|
||||
#endif/*__DMS_DYN_ARRAY__*/
|
75
Rayman_X/cpa/tempgrp/ldt/Inc/ErrLDT.h
Normal file
75
Rayman_X/cpa/tempgrp/ldt/Inc/ErrLDT.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Management of the Module : LDT
|
||||
//
|
||||
// File Name : ErrLDT.h
|
||||
// Date :
|
||||
// Author : CPA_Ed_1 team
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// abbreviation of the module-name. Used in macro is 'LDT'
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __ERRLDT_H__
|
||||
#define __ERRLDT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define C_szLDTVersion "LDT V1.0.0" /* The format is LDT Va.b.c with LDT is the Tag of the module */
|
||||
#define C_szLDTFullName "LDT Module"/* the complete and clear name of the module */
|
||||
#define C_szLDTDate __DATE__ /*The format is "Mmm dd yyyy".You can use __DATE__ but be careful that you have the control of the compilation*/
|
||||
|
||||
/* For DLLs who are using this module : */
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define CPA_EXPORT
|
||||
#endif
|
||||
|
||||
|
||||
#include "ERM.h"
|
||||
|
||||
//------------------
|
||||
// Global Variables
|
||||
//------------------
|
||||
#undef __ERRLDT_EXTERN
|
||||
#ifndef __DeclareGlobalVariableErrLDT_h__
|
||||
#define __ERRLDT_EXTERN extern /*external declaration*/
|
||||
#else //__DeclareGlobalVariableErrLDT_h__
|
||||
#define __ERRLDT_EXTERN /*replace by nothing : we have to declare*/
|
||||
#endif //__DeclareGlobalVariableErrLDT_h__
|
||||
|
||||
__ERRLDT_EXTERN CPA_EXPORT unsigned char g_ucLDTModuleId /*number of identification of the Erm module*/
|
||||
#if defined(__DeclareGlobalVariableErrLDT_h__) && !defined(CPA_WANTS_IMPORT)
|
||||
= C_ucModuleNotInitialized
|
||||
#endif //__DeclareGlobalVariableErrLDT_h__&& CPA_WANTS_IMPORT
|
||||
;
|
||||
|
||||
#ifdef __ERROR_STRINGS__
|
||||
|
||||
__ERRLDT_EXTERN CPA_EXPORT char * g_a_szLDTInformationModule []
|
||||
#if defined(__DeclareGlobalVariableErrLDT_h__) && !defined(CPA_WANTS_IMPORT)
|
||||
= {C_szLDTVersion, C_szLDTFullName, C_szLDTDate}
|
||||
#endif /*__DeclareGlobalVariableErrLDT_h__ && CPA_WANTS_IMPORT*/
|
||||
;
|
||||
|
||||
__ERRLDT_EXTERN CPA_EXPORT struct tdstErrorMsg_ g_a_stLDTTabErr [] /* Mandatory syntax 'g_a_st'+[Abbreviation of ModuleName]+'TabErr'*/
|
||||
#if defined(__DeclareGlobalVariableErrLDT_h__) && !defined(CPA_WANTS_IMPORT)
|
||||
= {0, NULL}; /*The Erm module need this variable even if it's equal to NULL*/
|
||||
#endif //__DeclareGlobalVariableErrLgh_h__ && CPA_WANTS_IMPORT
|
||||
;
|
||||
|
||||
#endif //__ERROR_STRINGS__
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif //__ERRLDT_H__
|
27
Rayman_X/cpa/tempgrp/ldt/Inc/Error.h
Normal file
27
Rayman_X/cpa/tempgrp/ldt/Inc/Error.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Error.h
|
||||
CREATED : 98/09/02
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: LDT Error management
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_ERROR__
|
||||
#define __LDT_ERROR__
|
||||
|
||||
#include "Link.h"
|
||||
|
||||
#define LDT_MAX_ERROR_DESCRIPTION 4000 /* maximum number of characters for error description */
|
||||
|
||||
extern char LDT_ErrDesc[LDT_MAX_ERROR_DESCRIPTION +1];
|
||||
|
||||
void SignalError(int level, LDT_tdst_Link * pLink, int errorcode, char* szErrDesc, char* szSourceFile, int line);
|
||||
void InitErrFile();
|
||||
void CLoseErrFile();
|
||||
|
||||
#ifdef LDT_ERROR_TREATMENT
|
||||
#define ERRoR(level, link, code, Desc) SignalError(level, link, code, Desc, __FILE__, __LINE__)
|
||||
#else
|
||||
#define ERRoR(level, link, code, Desc)
|
||||
#endif
|
||||
|
||||
#endif
|
42
Rayman_X/cpa/tempgrp/ldt/Inc/File.h
Normal file
42
Rayman_X/cpa/tempgrp/ldt/Inc/File.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
**************************************************************************************************
|
||||
* CPA_Ed_1 team *
|
||||
* File Management *
|
||||
**************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __LDT_FILE_H__
|
||||
#define __LDT_FILE_H__
|
||||
|
||||
#ifdef LDT_USE_SINGLE_FILE_BUFFER
|
||||
|
||||
extern char* GBuff;
|
||||
extern unsigned long GBuffSize;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* struct like a FILE , but for file in memory*/
|
||||
typedef struct LDT_tdst_MemFile_ LDT_tdst_MemFile;
|
||||
|
||||
struct LDT_tdst_MemFile_ {
|
||||
char *pName; /* Name of the file */
|
||||
char *pBuffer; /* Pointer of the file in memory */
|
||||
unsigned long Pos; /* Current Pos of the file in memory*/
|
||||
size_t Size; /* Size of the file in memory*/
|
||||
int sPathLength; /* Length of additional path */
|
||||
};
|
||||
|
||||
/* methods */
|
||||
|
||||
long f_OpenMem(LDT_tdst_MemFile **_pInfoMemFile,char* _Name);
|
||||
long f_CloseMem(LDT_tdst_MemFile *_pInfoMemFile);
|
||||
|
||||
long f_TellMem(LDT_tdst_MemFile *_pInfoMemFile );
|
||||
long f_SeekMem(LDT_tdst_MemFile *_pInfoMemFile ,long _Offset,int _Origin);
|
||||
|
||||
long f_ReadMem(char * _PointerDest,size_t _Size,LDT_tdst_MemFile *_pInfoMemFile ) ;
|
||||
|
||||
#endif /*__LDT_FILE_H__*/
|
||||
|
||||
|
74
Rayman_X/cpa/tempgrp/ldt/Inc/Hash.h
Normal file
74
Rayman_X/cpa/tempgrp/ldt/Inc/Hash.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Hash.h
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: variable size hash table
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_HASH__
|
||||
#define __LDT_HASH__
|
||||
|
||||
#include "DynArray.h"
|
||||
|
||||
/*
|
||||
* To export code.
|
||||
*/
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else /* CPA_WANTS_IMPORT */
|
||||
#define CPA_EXPORT
|
||||
#endif /* CPA_WANTS_IMPORT */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
TYPES
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct LDT_tdst_DSHash_ LDT_tdst_DSHash;
|
||||
|
||||
struct LDT_tdst_DSHash_
|
||||
{
|
||||
int (* pfnDispersion ) (void*); /* the dispersion function */
|
||||
void (* pfnDelete ) (void*); /* the element deletion function */
|
||||
LDT_tdst_DSArray* pData; /* the vector */
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
FUNCTIONS
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/*creation, initialization, deletion
|
||||
--------------------------------------*/
|
||||
|
||||
CPA_EXPORT LDT_tdst_DSHash* LDT_DSHs_new(int (* _pfnDispersion ) (void*),
|
||||
int (* _pfnCompare) (const void**, const void** ),
|
||||
void (* _pfnDelete) (void*) ); /* creates a new hash */
|
||||
CPA_EXPORT int LDT_DSHs_Init(LDT_tdst_DSHash*,
|
||||
int (* _pfnDispersion ) (void*),
|
||||
int (* _pfnCompare)(const void**, const void** ),
|
||||
void (* _pfnDelete) (void*) ); /* initializes an existing hash */
|
||||
|
||||
CPA_EXPORT void LDT_DSHs_delete( LDT_tdst_DSHash*, int ); /* deletes an existing array*/
|
||||
|
||||
CPA_EXPORT void LDT_DSHs_SetGranularity( LDT_tdst_DSHash*, int); /* sets the dynamic aray elements granularity */
|
||||
|
||||
|
||||
/* Clean up
|
||||
-------------*/
|
||||
|
||||
CPA_EXPORT void LDT_DSHs_FreeExtra( LDT_tdst_DSHash* ); /* frees the unused memory */
|
||||
CPA_EXPORT void LDT_DSHs_RemoveAll( LDT_tdst_DSHash*, int ); /* removes all elements */
|
||||
CPA_EXPORT void LDT_DSHs_Close( LDT_tdst_DSHash*, int ); /* clears the hash memory */
|
||||
|
||||
|
||||
/* Accessing elements
|
||||
-----------------------*/
|
||||
|
||||
CPA_EXPORT void* LDT_DSHs_GetEqOf( LDT_tdst_DSHash*, void* ); /* gets the hash element matching the parameter*/
|
||||
CPA_EXPORT void* LDT_DSHs_RemoveEqOf( LDT_tdst_DSHash*, void* ); /* removes the hash element matching the parameter*/
|
||||
CPA_EXPORT void* LDT_DSHs_Insert( LDT_tdst_DSHash*, void*, int ); /* inserts the element in the hash table*/
|
||||
|
||||
#endif
|
||||
|
228
Rayman_X/cpa/tempgrp/ldt/Inc/Interface.h
Normal file
228
Rayman_X/cpa/tempgrp/ldt/Inc/Interface.h
Normal file
@@ -0,0 +1,228 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Interface.h
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: user end functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_INTERFACE__
|
||||
#define __LDT_INTERFACE__
|
||||
|
||||
#include "hash.h" /* to export the dynamic array and the hash */
|
||||
|
||||
/*
|
||||
* To export code.
|
||||
*/
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else /* CPA_WANTS_IMPORT */
|
||||
#define CPA_EXPORT
|
||||
#endif /* CPA_WANTS_IMPORT */
|
||||
|
||||
|
||||
/* Constants
|
||||
--------------*/
|
||||
|
||||
#define LDT_REG_SECTION 0 /* registers section callbacks */
|
||||
#define LDT_REG_FILE 1 /* registers file callbacks */
|
||||
|
||||
/* Types */
|
||||
|
||||
/* result of parsing a line */
|
||||
|
||||
typedef enum eParseResult_
|
||||
{
|
||||
ParseResult_EOF,
|
||||
ParseResult_Directive,
|
||||
ParseResult_BeginSection,
|
||||
ParseResult_EndSection,
|
||||
ParseResult_Entry,
|
||||
ParseResult_Error
|
||||
} LDT_tdeParseResult;
|
||||
|
||||
typedef void * HREF;
|
||||
|
||||
/*
|
||||
________________________________________________________________________________________________
|
||||
Exported structures
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* link flags */
|
||||
#define LDT_LF_ALLOCATED 0x00010000
|
||||
#define LDT_LF_LOADED 0x00020000
|
||||
#define LDT_LF_ALLFILE 0x00040000
|
||||
#define LDT_LF_FILE 0x00080000
|
||||
#define LDT_LF_VOLATILE 0x00100000
|
||||
|
||||
|
||||
/* the callback registration */
|
||||
typedef struct LDT_tdst_CallbackEntry_ LDT_tdst_CallbackEntry;
|
||||
|
||||
/* the section link */
|
||||
typedef struct LDT_tdst_Link_ LDT_tdst_Link;
|
||||
|
||||
struct LDT_tdst_CallbackEntry_
|
||||
{
|
||||
char* szType; /* the section type */
|
||||
int (*Create) ( LDT_tdst_Link* ); /* the creation function */
|
||||
int ( *Load ) ( LDT_tdst_Link* ); /* the loading function */
|
||||
};
|
||||
|
||||
#pragma pack ( push, default_packing )
|
||||
#pragma pack ( 1 )
|
||||
|
||||
struct LDT_tdst_Link_
|
||||
{
|
||||
char* szFile; /* the file containing the section - stored in a string table */
|
||||
char* szParent; /* the section parent */
|
||||
char* szName; /* the section name */
|
||||
|
||||
LDT_tdst_CallbackEntry* Type;
|
||||
|
||||
unsigned long dwFlags; /* flags */
|
||||
|
||||
void* pObject; /* the allocated memory structure or NULL */
|
||||
LDT_tdst_Link* pParent; /* the section that requested the loading */
|
||||
|
||||
unsigned short wUnsolvedRefs; /* number of references to postprocess */
|
||||
};
|
||||
|
||||
#pragma pack ( pop, default_packing )
|
||||
|
||||
/*
|
||||
________________________________________________________________________________________________
|
||||
Exported methods
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
/* Initialization/Closing functions
|
||||
-------------------------------------*/
|
||||
|
||||
CPA_EXPORT int LDT_Initialize();
|
||||
CPA_EXPORT int LDT_Close();
|
||||
CPA_EXPORT void LDT_CleanUpRegistrations();
|
||||
|
||||
|
||||
/* Linking persistence management functions
|
||||
------------------------------------------*/
|
||||
CPA_EXPORT void LDT_SetLinkingPersistence (unsigned short Level);
|
||||
CPA_EXPORT void LDT_Forget(unsigned short Level);
|
||||
|
||||
/* Reference solving function
|
||||
-------------------------------------*/
|
||||
|
||||
CPA_EXPORT int LDT_Flush();
|
||||
CPA_EXPORT int LDT_FlushAndForget(unsigned short Level);
|
||||
|
||||
/* Loading functions
|
||||
-------------------------------------*/
|
||||
|
||||
CPA_EXPORT void* LDT_LoadSection( char* );
|
||||
CPA_EXPORT void* LDT_LoadSectionAt( char*, void* );
|
||||
CPA_EXPORT LDT_tdst_Link* LDT_GetLink( char *szSection );
|
||||
|
||||
/* In-callback link manipulation functions
|
||||
-------------------------------------*/
|
||||
|
||||
CPA_EXPORT void LDT_SetVolatileSubsection( LDT_tdst_Link* );
|
||||
|
||||
/* In-callback parsing functions
|
||||
-------------------------------------*/
|
||||
|
||||
CPA_EXPORT void LDT_SkipSection();
|
||||
CPA_EXPORT char *LDT_szGetParam( int i );
|
||||
CPA_EXPORT LDT_tdeParseResult LDT_GetNextEntry();
|
||||
CPA_EXPORT char *LDT_szGetSectionName();
|
||||
CPA_EXPORT char *LDT_szGetSectionType();
|
||||
CPA_EXPORT char *LDT_szGetEntryName();
|
||||
CPA_EXPORT int LDT_iGetNbParams();
|
||||
CPA_EXPORT void LDT_SplitSectionName( char *szSection, char *szFile, char *szParent, char *szType, char *szId );
|
||||
CPA_EXPORT int LDT_ComputeSectionName( LDT_tdst_Link *, char * );
|
||||
|
||||
/* reference delaying methods */
|
||||
|
||||
CPA_EXPORT HREF LDT_CreateRefsTable( );
|
||||
CPA_EXPORT void LDT_AddToRefsTable( HREF hRef, LDT_tdst_Link *pObj, int iType, short xCount, ... );
|
||||
CPA_EXPORT int LDT_GetRefFromTable( HREF hRef, LDT_tdst_Link **pObj, LDT_tdst_Link **pGetFrom, int *iType, short *xCount, long **pVal );
|
||||
CPA_EXPORT void LDT_FreeRefValues( long *p );
|
||||
CPA_EXPORT HREF LDT_RegisterSolver( void(* Solve)(HREF), int iPri );
|
||||
|
||||
/* File values methods */
|
||||
|
||||
CPA_EXPORT unsigned long LDT_GetFileLong( int i );
|
||||
CPA_EXPORT double LDT_GetFileDouble( int i );
|
||||
CPA_EXPORT void LDT_SetFileLong( int i, unsigned long ul );
|
||||
CPA_EXPORT void LDT_SetFileDouble( int i, double d );
|
||||
|
||||
CPA_EXPORT unsigned long LDT_GetTempLong( int i );
|
||||
CPA_EXPORT void LDT_SetTempLong( int i, unsigned long ul );
|
||||
|
||||
/* Default Callbacks
|
||||
-----------------------*/
|
||||
|
||||
CPA_EXPORT int LDT_Default_NULL_Create( LDT_tdst_Link* );
|
||||
CPA_EXPORT int LDT_Default_Load( LDT_tdst_Link* );
|
||||
|
||||
|
||||
/* Type Registration functions
|
||||
---------------------------------*/
|
||||
|
||||
CPA_EXPORT int LDT_RegisterType( char* szType, int (*) ( LDT_tdst_Link* ), int (*) ( LDT_tdst_Link* ), int);
|
||||
CPA_EXPORT LDT_tdst_CallbackEntry* LDT_IsTypeRegistered( char* szType, int );
|
||||
CPA_EXPORT int LDT_UnregisterType( char* szType, int );
|
||||
|
||||
/* Path Registration functions
|
||||
---------------------------------*/
|
||||
CPA_EXPORT int LDT_AddBaseDirectory( char* szBasePath );
|
||||
CPA_EXPORT int LDT_RegisterPath( char* szPath, char* szFileTypes );
|
||||
/* CPA_EXPORT void LDT_DeletePath( char* szPath ); */
|
||||
/* CPA_EXPORT void LDT_EraseRegisteredPaths(); */
|
||||
|
||||
|
||||
/* File finding function
|
||||
---------------------------------*/
|
||||
CPA_EXPORT int LDT_SearchFile( char* szFile, char* Buffer );
|
||||
|
||||
/* Link-Value association functions
|
||||
---------------------------------*/
|
||||
CPA_EXPORT void LDT_SetLinkValue( LDT_tdst_Link*, unsigned long );
|
||||
CPA_EXPORT unsigned long LDT_GetLinkValue( LDT_tdst_Link* );
|
||||
CPA_EXPORT unsigned long LDT_RemoveLinkValue( LDT_tdst_Link* pLink );
|
||||
|
||||
|
||||
/* Access to the referenced files history list
|
||||
I HATE to do this, but it sewems that the material editor is in desperate need of such a list.
|
||||
------------------------------------------------------------------------------------------------*/
|
||||
CPA_EXPORT int LDT_GetReferencedFilesNumber();
|
||||
CPA_EXPORT const char* LDT_GetReferencedFile(int idx);
|
||||
|
||||
/*
|
||||
________________________________________________________________________________________________
|
||||
Exported macros
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
|
||||
/* In-callback memory allocation/deallocation macros
|
||||
------------------------------------------------------*/
|
||||
|
||||
#ifdef LDT_USE_MMG
|
||||
|
||||
#include "Mem.h"
|
||||
|
||||
#define LDT_M_malloc LDT_malloc_Mmg
|
||||
#define LDT_M_free LDT_free_Mmg
|
||||
#define LDT_M_realloc LDT_realloc_Mmg
|
||||
|
||||
#else
|
||||
|
||||
#define LDT_M_malloc malloc
|
||||
#define LDT_M_free free
|
||||
#define LDT_M_realloc realloc
|
||||
|
||||
#endif /* LDT_USE_MMG */
|
||||
|
||||
|
||||
#endif
|
||||
|
120
Rayman_X/cpa/tempgrp/ldt/Inc/Link.h
Normal file
120
Rayman_X/cpa/tempgrp/ldt/Inc/Link.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Link.h
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: linktable/position structures & functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_LINK__
|
||||
#define __LDT_LINK__
|
||||
|
||||
#include "Hash.h"
|
||||
#include "Interface.h"
|
||||
#include "File.h"
|
||||
|
||||
/* Structures
|
||||
----------------*/
|
||||
|
||||
/* section position inside the containing file */
|
||||
typedef struct LDT_tdst_Position_ LDT_tdst_Position;
|
||||
|
||||
struct LDT_tdst_Position_
|
||||
{
|
||||
char* szName; /* the section name */
|
||||
char* szParent; /* the section parent */
|
||||
LDT_tdst_CallbackEntry* Type; /* the type of the section */
|
||||
|
||||
unsigned short uwFlags; /* flags */
|
||||
|
||||
unsigned long dwPos; /* the offset inside the file */
|
||||
unsigned long nLine; /* the text line */
|
||||
int iLevel; /*the level in file*/
|
||||
};
|
||||
|
||||
/* Reference Collection for a File */
|
||||
|
||||
typedef struct LDT_tdst_Refs_ LDT_tdst_Refs;
|
||||
|
||||
struct LDT_tdst_Refs_
|
||||
{
|
||||
char* szFile; /* the file */
|
||||
LDT_tdst_DSArray Links; /* the references */
|
||||
LDT_tdst_Refs* p_NextReferencedFile;/* the next file */
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
LDT_tdst_MemFile* pFile; /* the opened file */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* Link associated value */
|
||||
typedef struct LDT_tdst_LinkValue_ LDT_tdst_LinkValue;
|
||||
|
||||
struct LDT_tdst_LinkValue_
|
||||
{
|
||||
LDT_tdst_Link* pLink;
|
||||
unsigned long value;
|
||||
};
|
||||
|
||||
/* Globals
|
||||
-------------*/
|
||||
|
||||
extern LDT_tdst_DSHash g_HashLinks; /* the linktable */
|
||||
extern LDT_tdst_DSArray g_ArRefs; /* thereferences, grouped by file */
|
||||
extern LDT_tdst_DSArray g_ArFilenames; /* thefilename strings */
|
||||
|
||||
extern char LDT_EMPTY_STR[1];
|
||||
|
||||
extern LDT_tdst_Refs* g_pFileToProcess; /* the file to load */
|
||||
extern LDT_tdst_Refs* g_pLastFileQueued; /* the last fiel referenced */
|
||||
#ifdef LDT_MULTITHREADED
|
||||
extern LDT_tdst_Refs* g_pFileToRead; /* the file to read */
|
||||
#endif
|
||||
|
||||
/* Functions
|
||||
--------------*/
|
||||
|
||||
/* Link - related */
|
||||
|
||||
int LDT_Link_Dispersion( LDT_tdst_Link*);
|
||||
int LDT_Compare_Links(const void**, const void** );
|
||||
int LDT_Compare_LinkValues(const void**, const void** );
|
||||
|
||||
LDT_tdst_Link* LDT_CreateLinkFromReference( char* szSection );
|
||||
|
||||
LDT_tdst_Link* LDT_Create_Link( char* szName, /* the section name */
|
||||
char* szParent, /* the section parent */
|
||||
char* szFile, /* the file containing the section - stored in a string table */
|
||||
LDT_tdst_CallbackEntry* Type,
|
||||
unsigned long dwFlags, /* flags */
|
||||
void* pObject, /* the allocated memory structure or NULL */
|
||||
LDT_tdst_Link* pParent); /* the section that requested the loading */
|
||||
|
||||
void LDT_Delete_Link( LDT_tdst_Link *);
|
||||
|
||||
/* Position - related */
|
||||
|
||||
int LDT_Compare_Positions(const void**, const void** );
|
||||
|
||||
LDT_tdst_Position *LDT_Create_Position( char *szName,
|
||||
char *szParent,
|
||||
LDT_tdst_CallbackEntry* Type,
|
||||
unsigned short uwFlags,
|
||||
unsigned long ulPos,
|
||||
unsigned long nLine,
|
||||
int iLevel );
|
||||
void LDT_Delete_Position( LDT_tdst_Position *pos );
|
||||
|
||||
/* String - related */
|
||||
|
||||
int LDT_Compare_Strings(const void**, const void** );
|
||||
|
||||
|
||||
/* Reference - related */
|
||||
|
||||
void AddReference( LDT_tdst_Link* );
|
||||
|
||||
int LDT_Compare_Refs(const void**, const void** );
|
||||
|
||||
|
||||
#endif
|
35
Rayman_X/cpa/tempgrp/ldt/Inc/Mem.h
Normal file
35
Rayman_X/cpa/tempgrp/ldt/Inc/Mem.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
* LDT_Mem.h
|
||||
* CPA_Ed_1 team
|
||||
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LDT_MEM__
|
||||
#define __LDT_MEM__
|
||||
/*
|
||||
* To export code.
|
||||
*/
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else /* CPA_WANTS_IMPORT */
|
||||
#define CPA_EXPORT
|
||||
#endif /* CPA_WANTS_IMPORT */
|
||||
|
||||
|
||||
CPA_EXPORT void* LDT_malloc_Mmg(size_t _size);
|
||||
CPA_EXPORT void* LDT_realloc_Mmg(void * _PointerSrc, size_t _Size);
|
||||
CPA_EXPORT void LDT_free_Mmg(void *_Pointer);
|
||||
|
||||
void LDT_fn_v_Mem_InitModule(void);
|
||||
void LDT_fn_v_Mem_CloseModule(void);
|
||||
void LDT_fn_v_Mem_InitWithMemLevel(unsigned long *);
|
||||
|
||||
#endif /* __LDT_MEM__ */
|
||||
|
||||
|
||||
|
63
Rayman_X/cpa/tempgrp/ldt/Inc/MmgLDT.h
Normal file
63
Rayman_X/cpa/tempgrp/ldt/Inc/MmgLDT.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Memory Management of the Module : LDT
|
||||
//
|
||||
// File Name : MmgLDT.h
|
||||
// Date :
|
||||
// Author : CPA_Ed_1 team
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
#ifndef __MmgLDT_H__
|
||||
#define __MmgLDT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* For DLLs who are using this module : */
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define CPA_EXPORT
|
||||
#endif
|
||||
|
||||
|
||||
#include "MMG.h"
|
||||
|
||||
typedef enum e_ucLDTStaticBlocks_
|
||||
{
|
||||
E_ucLDTMemoryBlock0 = 0,
|
||||
E_ucLDTMemoryBlock1 = 1,
|
||||
E_ucLDTMemoryBlock2 = 2,
|
||||
E_ucLDTMemoryBlock3 = 3,
|
||||
E_ucLDTMemoryBlock4 = 4,
|
||||
E_ucLDTMemoryBlock5 = 5,
|
||||
E_ucLDTMemoryBlock6 = 6,
|
||||
E_ucLDTMemoryBlock7 = 7,
|
||||
E_ucLDTMemoryBlock8 = 8,
|
||||
E_ucLDTMaxBlocksNb // maximum number of static block, You have to follow this syntax 'E_uc+ Abbreviation Module +MaxBlocksNb'
|
||||
} e_ucLDTStaticBlocks;
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __DeclareGlobalVariableMmgLDT_h__
|
||||
#define EXTERN /*nothing*/
|
||||
#else // no __DeclareGlobalVariableMmgLDT_h__
|
||||
#define EXTERN extern
|
||||
#endif //__DeclareGlobalVariableMmgLDT_h__
|
||||
|
||||
EXTERN CPA_EXPORT struct tdstBlockInfo_ g_a_stLDTBlocksInfo[E_ucLDTMaxBlocksNb];
|
||||
|
||||
#ifdef __DYNAMIC_MALLOC_ALLOWED__
|
||||
#ifdef __DEBUG_MALLOC_MODE__
|
||||
EXTERN CPA_EXPORT struct tdstDynInfo_ g_stLDTDynInfo;
|
||||
#endif //__DEBUG_MALLOC_MODE__
|
||||
#endif //__DYNAMIC_MALLOC_ALLOWED__
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif //__MmgLDT_H__
|
91
Rayman_X/cpa/tempgrp/ldt/Inc/Parser.h
Normal file
91
Rayman_X/cpa/tempgrp/ldt/Inc/Parser.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Parser.c
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
CONTENTS: parsing structures, variables & functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef __LDT_PARSER_H
|
||||
#define __LDT_PARSER_H
|
||||
|
||||
|
||||
#include "File.h"
|
||||
#include "DynArray.h"
|
||||
#include "Link.h"
|
||||
|
||||
extern char g_szType[512];
|
||||
extern char g_szName[512];
|
||||
extern char g_szParent[512];
|
||||
extern char g_szId[512];
|
||||
|
||||
extern LDT_tdst_Link* g_CrtSection;
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
extern CRITICAL_SECTION GReadExclusion;
|
||||
extern HANDLE GReadCount;
|
||||
extern HANDLE GReadLimit;
|
||||
extern HANDLE GFileLimit;
|
||||
|
||||
#define LDT_READ_COUNT "LDT_Rd_S"
|
||||
#define LDT_READ_LIMIT "LDT_Rd_L"
|
||||
#define MAX_FILE_NO 6
|
||||
|
||||
#endif
|
||||
|
||||
/* Constants */
|
||||
|
||||
/* directive flags */
|
||||
#define LDT_uw_Anl_Normal 0x0000 /* Normal analyse */
|
||||
#define LDT_uw_Anl_Comments 0x0001 /* It's a comment, don't care */
|
||||
#define LDT_uw_Anl_ForceAnalyse 0x0002 /* To force analyse of section */
|
||||
#define LDT_uw_Anl_NotSaveSection 0x0004 /* To not save section in memory */
|
||||
#define LDT_uw_Anl_WarnIfNotHere 0x0008 /* No error if section does not exist */
|
||||
|
||||
/* Types */
|
||||
|
||||
/* a file encapsulation for parsing */
|
||||
|
||||
typedef struct LDT_tdst_FileDesc_ LDT_tdst_FileDesc;
|
||||
|
||||
|
||||
struct LDT_tdst_FileDesc_
|
||||
{
|
||||
LDT_tdst_MemFile* _pInfoMemFile; /* the file handle */
|
||||
|
||||
char* szFile; /* the file name */
|
||||
LDT_tdst_DSArray arContents; /* the file parsed contents */
|
||||
|
||||
int iLevel; /* the (sub)section level */
|
||||
int iLineNumber; /* the current line */
|
||||
|
||||
int iLastIndex; /* for parsing purposes */
|
||||
char chLastChar; /* same */
|
||||
|
||||
short sLengthDiff; /* length of additional path */
|
||||
|
||||
unsigned short uwFlags; /* various directive flags */
|
||||
unsigned long ulValues[64]; /* file long values */
|
||||
double dValues[8]; /* file double values */
|
||||
unsigned short uwLoadType;
|
||||
};
|
||||
|
||||
extern LDT_tdst_FileDesc* g_FileDesc;
|
||||
extern LDT_tdst_Link *pParent[100];
|
||||
extern LDT_tdst_FileDesc TheFileDesc;
|
||||
|
||||
/* Functions */
|
||||
|
||||
LDT_tdeParseResult fn_e_ParseLine(int bSeek );
|
||||
|
||||
LDT_tdeParseResult LDT_GetNextEntry( );
|
||||
|
||||
int Solve( LDT_tdst_Refs *refs );
|
||||
|
||||
void InitParser( void );
|
||||
|
||||
//void LDT_SkipSection( );
|
||||
|
||||
LDT_tdst_MemFile* AccessFile( char* szFile );
|
||||
|
||||
#endif
|
41
Rayman_X/cpa/tempgrp/ldt/Inc/REFS.H
Normal file
41
Rayman_X/cpa/tempgrp/ldt/Inc/REFS.H
Normal file
@@ -0,0 +1,41 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : DynArray.h
|
||||
CREATED : 98/06/11
|
||||
AUTHOR : Mircea Petrescu
|
||||
CONTENTS: management of unsolved references
|
||||
( for get x from reference operations )
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_Refs__
|
||||
#define __LDT_Refs__
|
||||
|
||||
/* Types */
|
||||
|
||||
typedef struct tdst_Ref_ tdst_Ref;
|
||||
|
||||
/* the packing of a reference */
|
||||
struct tdst_Ref_
|
||||
{
|
||||
LDT_tdst_Link *pObject;
|
||||
LDT_tdst_Link *pGetFrom;
|
||||
int iType;
|
||||
short xCount;
|
||||
long *pVal;
|
||||
};
|
||||
|
||||
/* handle to a reference list */
|
||||
typedef void * HREF;
|
||||
|
||||
typedef struct tdst_Solver_ tdst_Solver;
|
||||
|
||||
struct tdst_Solver_
|
||||
{
|
||||
void (*Solve)( HREF );
|
||||
HREF hRef;
|
||||
int iPriority;
|
||||
};
|
||||
|
||||
int SortSolvers( const void **A, const void **B );
|
||||
|
||||
#endif
|
||||
|
38
Rayman_X/cpa/tempgrp/ldt/Inc/REGISTER.BAK
Normal file
38
Rayman_X/cpa/tempgrp/ldt/Inc/REGISTER.BAK
Normal file
@@ -0,0 +1,38 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Register.h
|
||||
CREATED : 19/05/97
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: callback registering structures & functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_REGISTER__
|
||||
#define __LDT_REGISTER__
|
||||
|
||||
#include "Link.h"
|
||||
#include "Parser.h"
|
||||
#include "DynArray.h"
|
||||
|
||||
|
||||
/* Constants
|
||||
--------------*/
|
||||
|
||||
#define LDT_REG_SECTION 0 /* registers section callbacks */
|
||||
#define LDT_REG_FILE 1 /* registers file callbacks */
|
||||
|
||||
|
||||
/* Globals
|
||||
-------------*/
|
||||
|
||||
extern tdst_DSArray g_ArSectionCallbacks; /* the section callbacks */
|
||||
extern tdst_DSArray g_ArFileCallbacks; /* the file callbacks */
|
||||
|
||||
|
||||
/* Functions
|
||||
-------------*/
|
||||
|
||||
int LDT_Compare_CallbackEntries(const void**, const void** );
|
||||
LDT_tdst_CallbackEntry* GetType( char* szType, int Mode);
|
||||
|
||||
|
||||
#endif
|
||||
|
52
Rayman_X/cpa/tempgrp/ldt/Inc/REGISTER.H
Normal file
52
Rayman_X/cpa/tempgrp/ldt/Inc/REGISTER.H
Normal file
@@ -0,0 +1,52 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Register.h
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: callback registering structures & functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_REGISTER__
|
||||
#define __LDT_REGISTER__
|
||||
|
||||
#include "Link.h"
|
||||
#include "Parser.h"
|
||||
#include "DynArray.h"
|
||||
|
||||
|
||||
/* Constants
|
||||
--------------*/
|
||||
|
||||
#define LDT_REG_SECTION 0 /* registers section callbacks */
|
||||
#define LDT_REG_FILE 1 /* registers file callbacks */
|
||||
|
||||
|
||||
/* Globals
|
||||
-------------*/
|
||||
|
||||
extern LDT_tdst_DSArray g_ArSectionCallbacks; /* the section callbacks */
|
||||
extern LDT_tdst_DSArray g_ArFileCallbacks; /* the file callbacks */
|
||||
extern LDT_tdst_DSArray g_ArSolvers; /* the post-process solvers */
|
||||
extern LDT_tdst_DSArray g_ArPaths; /* the paths */
|
||||
extern LDT_tdst_DSArray g_ArPathStrings; /* the path strings */
|
||||
extern LDT_tdst_DSArray g_ArBaseDirectories; /* the base paths */
|
||||
|
||||
|
||||
/* Functions
|
||||
-------------*/
|
||||
|
||||
int LDT_Compare_CallbackEntries(const void**, const void** );
|
||||
LDT_tdst_CallbackEntry* GetType( char* szType, int Mode);
|
||||
|
||||
/* Types
|
||||
----------*/
|
||||
|
||||
typedef struct LDT_tdst_TypePaths_ LDT_tdst_TypePaths;
|
||||
|
||||
struct LDT_tdst_TypePaths_
|
||||
{
|
||||
char* szExtension;
|
||||
LDT_tdst_DSArray arPaths;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
230
Rayman_X/cpa/tempgrp/ldt/Inc/StdInc.h
Normal file
230
Rayman_X/cpa/tempgrp/ldt/Inc/StdInc.h
Normal file
@@ -0,0 +1,230 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : StdInc.h
|
||||
CREATED : 98/05/11
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: standard includes - header to precompile
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __LDT_STDINC__
|
||||
#define __LDT_STDINC__
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
/* PROJECT-CONFIGURING DEFINES */
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
/*=============================COMPATIBILITY==================================*/
|
||||
#define LDT_SCR /* define this to enable LDT/SCR interfacing facilities */
|
||||
|
||||
/*=================================DISK=======================================*/
|
||||
#define LDT_MULTITHREADED
|
||||
/* define this if you want to use LDT in a multithreading environment */
|
||||
#define LDT_USE_SINGLE_FILE_BUFFER /* WORKS ONLY IN THE SINGLETHREADED MODE */
|
||||
/* define this if you want to use a persistent and unique file buffer */
|
||||
|
||||
|
||||
/*=============================PERFORMANCE====================================*/
|
||||
#define LDT_LOG_STATISTICS
|
||||
/* define this if you want LDT to print an information log file at the
|
||||
end of the execution */
|
||||
#define LDT_LOG_MEMORY /* WORKS ONLY IN THE SINGLETHREADED MODE */
|
||||
/* define this if you want LDT to generate memory usage information */
|
||||
|
||||
/*================================ERRoR=======================================*/
|
||||
#define LDT_LOG_ERRORS /* log warnings/errors */
|
||||
#define LDT_DISPLAY_ERRORS /* display error messages */
|
||||
//#define LDT_DISPLAY_WARNINGS /* display warning messages */
|
||||
#define LDT_WARNING_LEVEL 3 /* the warning level:
|
||||
0 - no warnings (DEFAULT)
|
||||
1 - level 1 warnings
|
||||
2 - level 2 & 1 warnings
|
||||
3 - levels 1, 2 & 3
|
||||
4 - all warnings */
|
||||
#define LDT_ERROR_LEVEL 0 /* the error level:
|
||||
0 - errors only for level 0 (DEFAULT)
|
||||
1 - level 1 warnings are treated as errors
|
||||
2 - level 2 & 1 warnings are treated as errors
|
||||
3 - level 1, 2 & 3 are treated as errors
|
||||
4 - all warnings are treated as errors */
|
||||
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
/* DO NOT EDIT THE FILE BEYOND THIS POINT ! */
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
|
||||
|
||||
#ifdef U64
|
||||
#undef LDT_MULTITHREADED
|
||||
#undef LDT_LOG_STATISTICS
|
||||
#undef LDT_LOG_MEMORY
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LDT_DISPLAY_WARNINGS
|
||||
#define LDT_DISPLAY_ERRORS
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_ERRORS
|
||||
#define LDT_ERROR_TREATMENT
|
||||
#endif
|
||||
|
||||
#ifdef LDT_DISPLAY_ERRORS
|
||||
#define LDT_ERROR_TREATMENT
|
||||
#endif
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
#undef LDT_USE_SINGLE_FILE_BUFFER
|
||||
#undef LDT_LOG_MEMORY
|
||||
#define LDT_USE_WIN
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_MEMORY
|
||||
#define LDT_LOG_STATISTICS
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
#define LDT_USE_WIN
|
||||
#endif
|
||||
|
||||
#ifdef LDT_USE_WIN
|
||||
|
||||
#pragma warning(disable: 4115)
|
||||
#pragma warning(disable: 4201)
|
||||
#pragma warning(disable: 4214)
|
||||
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
|
||||
#else
|
||||
|
||||
//typedef unsigned long DWORD;
|
||||
typedef int BOOL;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
|
||||
/* Log/stat stuff
|
||||
-------------------*/
|
||||
extern unsigned TimerStartCount;
|
||||
extern unsigned TimerStopCount;
|
||||
|
||||
extern LONGLONG Frequency;
|
||||
extern LONGLONG TimingOverhead;
|
||||
extern LONGLONG StartOverhead;
|
||||
extern LONGLONG StopOverhead;
|
||||
|
||||
typedef struct TimerStruct_ TimerStruct;
|
||||
|
||||
struct TimerStruct_
|
||||
{
|
||||
LONGLONG TimeCounter;
|
||||
LONGLONG LastValue;
|
||||
unsigned LastStartCount;
|
||||
unsigned LastStopCount;
|
||||
};
|
||||
|
||||
void InitializeTimingEnvironment();
|
||||
|
||||
void InitTimer(TimerStruct*);
|
||||
void StartTimer(TimerStruct*);
|
||||
void StopTimer(TimerStruct*);
|
||||
double ReadTimer(TimerStruct*);
|
||||
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
COMPILER-DEPENDENT DEFINES
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
|
||||
#define __inline
|
||||
|
||||
#endif /* __WATCOMC__ */
|
||||
|
||||
#ifdef _MSC_VER /* Visulal C/C++ compiler */
|
||||
|
||||
#pragma warning(disable: 4514) /* Warning: unreferenced inline/local function has been removed */
|
||||
|
||||
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
STANDARD INCLUDES
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef U64
|
||||
|
||||
#define LDT_USE_MMG /* on ultra 64, use the memory manager*/
|
||||
#include <ultra.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <search.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <io.h>
|
||||
|
||||
#endif /* U64 */
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
MEMORY ALLOCATION TYPE
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef LDT_USE_MMG
|
||||
|
||||
#define malloc LDT_malloc_Mmg
|
||||
#define realloc LDT_realloc_Mmg
|
||||
#define free LDT_free_Mmg
|
||||
|
||||
#include "Mem.h"
|
||||
|
||||
#endif /* LDT_USE_MMG */
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DEFINES
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* Code exportation */
|
||||
#undef CPA_EXPORT
|
||||
#if defined(CPA_WANTS_IMPORT)
|
||||
#define CPA_EXPORT __declspec(dllimport)
|
||||
#elif defined(CPA_WANTS_EXPORT)
|
||||
#define CPA_EXPORT __declspec(dllexport)
|
||||
#else /* CPA_WANTS_IMPORT */
|
||||
#define CPA_EXPORT
|
||||
#endif /* CPA_WANTS_IMPORT */
|
||||
|
||||
|
||||
#ifdef LDT_LOG_MEMORY
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
extern unsigned long g_allocsize;
|
||||
extern unsigned long g_Maxallocsize;
|
||||
extern unsigned long g_size;
|
||||
extern void* g_palloc;
|
||||
|
||||
extern unsigned long g_allocCount;
|
||||
extern unsigned long g_reallocCount;
|
||||
extern unsigned long g_freeCount;
|
||||
|
||||
#define malloc(x) ( g_size = x, g_allocsize += g_size, g_allocCount++, g_Maxallocsize = max(g_Maxallocsize, g_allocsize), malloc(g_size))
|
||||
#define realloc( y, x) (g_palloc = y, g_size = x, g_reallocCount++, g_allocsize += g_size - (g_palloc?_msize(g_palloc):0), g_Maxallocsize = max(g_Maxallocsize, g_allocsize), realloc( g_palloc, g_size ))
|
||||
#define free( y ) (g_palloc = y, g_freeCount++, g_size =(g_palloc?_msize(g_palloc):0), g_allocsize -= g_size, free(g_palloc))
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __LDT_STDINC__ */
|
67
Rayman_X/cpa/tempgrp/ldt/Inc/Types.h
Normal file
67
Rayman_X/cpa/tempgrp/ldt/Inc/Types.h
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
/*
|
||||
**************************************************************************************************
|
||||
* CPA_Ed_1 team *
|
||||
* general types *
|
||||
**************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __LDT_TYPE_H__
|
||||
#define __LDT_TYPE_H__
|
||||
|
||||
|
||||
|
||||
#include "StdInc.h"
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
Define for types
|
||||
-----------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------
|
||||
Define for error types
|
||||
-----------------------------------------------------------*/
|
||||
/*
|
||||
* Enum that describes the list of all errors Id.
|
||||
*/
|
||||
typedef enum LDT_tde_Err_Identification_
|
||||
{
|
||||
LDT_EI_Err_InvalidAddress = 0xffffffff,
|
||||
LDT_EI_Err_None = 0,
|
||||
LDT_EI_Err_Malloc,
|
||||
LDT_EI_Err_OpenFile,
|
||||
LDT_EI_Err_OpenWrite,
|
||||
LDT_EI_Err_CloseFile,
|
||||
LDT_EI_Err_ReadFile,
|
||||
LDT_EI_Err_SeekFile,
|
||||
LDT_EI_Err_MemMove,
|
||||
LDT_EI_Err_NotEnoughDataForMove,
|
||||
LDT_EI_Err_AllreadyClose,
|
||||
LDT_EI_Err_SeekInMem,
|
||||
LDT_EI_Err_NotEnoughPlaceForWrite,
|
||||
LDT_EI_Err_EndOfFile,
|
||||
LDT_EI_Err_AtemptTOWriteInReadFile,
|
||||
LDT_EI_Err_DuplicateRegister,
|
||||
LDT_EI_Err_RegisterWorkspaceNULL,
|
||||
LDT_EI_Err_NotRegistered,
|
||||
|
||||
LDT_EI_Err_AddressConflict,
|
||||
LDT_EI_Err_InexistentLink
|
||||
|
||||
} LDT_tde_Err_Identification;
|
||||
|
||||
typedef enum LDT_D_tType_
|
||||
{
|
||||
ReadType,
|
||||
WriteType
|
||||
} LDT_D_tType;
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
Define for types
|
||||
-----------------------------------------------------------*/
|
||||
|
||||
#endif /*__LDT_TYPE_H__*/
|
248
Rayman_X/cpa/tempgrp/ldt/Ldt.dsp
Normal file
248
Rayman_X/cpa/tempgrp/ldt/Ldt.dsp
Normal file
@@ -0,0 +1,248 @@
|
||||
# Microsoft Developer Studio Project File - Name="Ldt" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=Ldt - Win32 MMG Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Ldt.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Ldt.mak" CFG="Ldt - Win32 MMG Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Ldt - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "Ldt - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "Ldt - Win32 MMG Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "Ldt - Win32 MMG Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""$/cpa/tempgrp/ldt", QQQAAAAA"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
|
||||
!IF "$(CFG)" == "Ldt - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Temp\Release"
|
||||
# PROP Intermediate_Dir "Temp\Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W4 /GX /O2 /I ".\inc" /I "x:\cpa\public" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "CPA_WANTS_EXPORT" /YX"StdInc.h" /FD /c
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\..\Lib\Ldt_vr.lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "Ldt - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Temp\Debug"
|
||||
# PROP Intermediate_Dir "Temp\Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W4 /GX /Zi /Od /I ".\inc" /I "x:\cpa\public" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "CPA_WANTS_EXPORT" /FR /YX"StdInc.h" /FD /c
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\..\Lib\Ldt_vd.lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "Ldt - Win32 MMG Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Ldt___Wi"
|
||||
# PROP BASE Intermediate_Dir "Ldt___Wi"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Temp\Ldt___Wi"
|
||||
# PROP Intermediate_Dir "Temp\Ldt___Wi"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W4 /GX /Z7 /Od /I ".\inc" /I "x:\cpa\public" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX"StdInc.h" /FD /c
|
||||
# ADD CPP /nologo /MD /W4 /GX /Z7 /Od /I ".\inc" /I "x:\cpa\public" /D "_DEBUG" /D "LDT_USE_MMG" /D "WIN32" /D "_WINDOWS" /D "CPA_WANTS_EXPORT" /FR /YX"StdInc.h" /FD /c
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo /out:"..\..\Lib\Ldt_vd.lib"
|
||||
# ADD LIB32 /nologo /out:"..\..\Lib\Ldt_MMG_vd.lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "Ldt - Win32 MMG Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Ldt___W0"
|
||||
# PROP BASE Intermediate_Dir "Ldt___W0"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Temp\Ldt___W0"
|
||||
# PROP Intermediate_Dir "Temp\Ldt___W0"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W4 /GX /O2 /I ".\inc" /I "x:\cpa\public" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX"StdInc.h" /FD /c
|
||||
# ADD CPP /nologo /MD /W4 /GX /O2 /I ".\inc" /I "x:\cpa\public" /D "NDEBUG" /D "LDT_USE_MMG" /D "WIN32" /D "_WINDOWS" /D "CPA_WANTS_EXPORT" /YX"StdInc.h" /FD /c
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo /out:"..\..\Lib\Ldt_vr.lib"
|
||||
# ADD LIB32 /nologo /out:"..\..\Lib\Ldt_MMG_vr.lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Ldt - Win32 Release"
|
||||
# Name "Ldt - Win32 Debug"
|
||||
# Name "Ldt - Win32 MMG Debug"
|
||||
# Name "Ldt - Win32 MMG Release"
|
||||
# Begin Group "Sources"
|
||||
|
||||
# PROP Default_Filter "*.c"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\DynArray.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Error.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\File.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Hash.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Interface.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Link.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Mem.c
|
||||
|
||||
!IF "$(CFG)" == "Ldt - Win32 Release"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "Ldt - Win32 Debug"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "Ldt - Win32 MMG Debug"
|
||||
|
||||
# PROP BASE Exclude_From_Build 1
|
||||
# ADD CPP /w /W0
|
||||
|
||||
!ELSEIF "$(CFG)" == "Ldt - Win32 MMG Release"
|
||||
|
||||
# PROP BASE Exclude_From_Build 1
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Parser.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\refs.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Src\Register.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Headers"
|
||||
|
||||
# PROP Default_Filter "*.h"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\DynArray.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\ErrLDT.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Error.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\File.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Hash.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Interface.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Link.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Mem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\MmgLDT.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Parser.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\refs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Register.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\StdInc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Inc\Types.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
248
Rayman_X/cpa/tempgrp/ldt/Ldt.dsw
Normal file
248
Rayman_X/cpa/tempgrp/ldt/Ldt.dsw
Normal file
@@ -0,0 +1,248 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 5.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "GLIGLOU"=..\..\..\cpa\tempgrp\gliglou\multidrv\gliglou.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "GMT"=..\..\..\cpa\tempgrp\gmt\gmt.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "GamLib"=..\..\..\cpa\tempgrp\gam\makelib\gamlib.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Geo"=..\..\..\cpa\tempgrp\geo\geo.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "IPO"=..\..\..\cpa\tempgrp\ipo\ipo.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "IPT"=..\..\..\cpa\tempgrp\ipt\ipt.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "ISI"=..\..\..\cpa\tempgrp\isi\isi.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Ldt"=.\Ldt.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "MEC"=..\..\..\cpa\tempgrp\mec\mec.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Main"=..\..\..\cpa\main\make\main.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Ldt
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "PO"=..\..\..\cpa\tempgrp\po\po.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "RND"=..\..\..\cpa\tempgrp\rnd\rnd.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "SCT"=..\..\..\cpa\tempgrp\sct\sct.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "SIF"=..\..\..\cpa\tempgrp\sif\sif.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "SNA"=..\..\..\cpa\tempgrp\sna\sna.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "SPO"=..\..\..\cpa\tempgrp\spo\spo.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Static Library for DLL"=..\..\..\cpa\tempgrp\snd\make\dll\static\snddllv.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Vig"=..\..\..\cpa\tempgrp\vig\vig.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "ai"=..\..\..\cpa\tempgrp\ai\ai.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
374
Rayman_X/cpa/tempgrp/ldt/Src/DynArray.c
Normal file
374
Rayman_X/cpa/tempgrp/ldt/Src/DynArray.c
Normal file
@@ -0,0 +1,374 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : DynArray.c
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: dynamic pointer array with sorting capabilities
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "DynArray.h"
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Creaton of a default array (allocation + default initialization)
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_DSArray* LDT_DSAr_new()
|
||||
{
|
||||
LDT_tdst_DSArray* pst_NewArray = malloc( sizeof(LDT_tdst_DSArray) ); /* allocate */
|
||||
LDT_DSAr_Init( pst_NewArray );
|
||||
return pst_NewArray;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : default initialization of an array - returns 1 if successful,
|
||||
0 on error;
|
||||
WARNING : This function should be called only once and prior to the use of
|
||||
any other array functions.
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_Init( LDT_tdst_DSArray* pst_Ar)
|
||||
{
|
||||
if( !pst_Ar ) return 0; /* NULL argument */
|
||||
memset( pst_Ar, 0, sizeof( LDT_tdst_DSArray ) );
|
||||
return 1; /* success */
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : deletes an existing array
|
||||
WARNING : this should only be called for dinamically allocated arrays.
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSAr_delete( LDT_tdst_DSArray* pst_Ar )
|
||||
{
|
||||
if( !pst_Ar ) return;
|
||||
LDT_DSAr_RemoveAll( pst_Ar );
|
||||
free( pst_Ar );
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : sets the array's size. - returns 1 if successful, 0 on error;
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_SetSize( LDT_tdst_DSArray* pst_Ar, int nNewSize )
|
||||
{
|
||||
void** pNewData;
|
||||
|
||||
if(nNewSize < 0) return 0; /* wrong size input */
|
||||
|
||||
if (nNewSize == 0)
|
||||
{
|
||||
/* shrink to nothing */
|
||||
if(pst_Ar->pData)
|
||||
{
|
||||
free( pst_Ar->pData );
|
||||
pst_Ar->pData = NULL;
|
||||
}
|
||||
pst_Ar->nSize = pst_Ar->nMaxSize = 0;
|
||||
}
|
||||
else if (pst_Ar->pData == NULL)
|
||||
{
|
||||
int nNewMax = nNewSize;
|
||||
if( nNewSize < pst_Ar->nGrowBy ) nNewMax = pst_Ar->nGrowBy;
|
||||
/* create one with exact size */
|
||||
pst_Ar->pData = malloc( nNewMax * sizeof(void*) );
|
||||
if(!pst_Ar->pData ) return 0; /* allocation failed */
|
||||
memset( pst_Ar->pData, 0, nNewMax * sizeof(void*) ); /* zero fill */
|
||||
pst_Ar->nSize = nNewSize;
|
||||
pst_Ar->nMaxSize = nNewMax;
|
||||
}
|
||||
else if (nNewSize <= pst_Ar->nMaxSize)
|
||||
{
|
||||
/* it fits */
|
||||
if (nNewSize > pst_Ar->nSize)
|
||||
/* initialize the new elements */
|
||||
memset( &pst_Ar->pData[pst_Ar->nSize], 0,
|
||||
(nNewSize-pst_Ar->nSize) * sizeof(void*));
|
||||
pst_Ar->nSize = nNewSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise grow array */
|
||||
int nNewMax;
|
||||
if (nNewSize < pst_Ar->nMaxSize + pst_Ar->nGrowBy)
|
||||
nNewMax = pst_Ar->nMaxSize + pst_Ar->nGrowBy; /* granularity */
|
||||
else
|
||||
nNewMax = nNewSize; /* no slush */
|
||||
|
||||
pNewData = realloc( pst_Ar->pData, nNewMax * sizeof(void*) );
|
||||
if( !pNewData ) return 0; /* reallocation failed */
|
||||
|
||||
/* construct remaining elements */
|
||||
memset( &pNewData[pst_Ar->nSize], 0,
|
||||
(nNewSize-pst_Ar->nSize) * sizeof(void*));
|
||||
|
||||
pst_Ar->pData = pNewData;
|
||||
pst_Ar->nSize = nNewSize;
|
||||
pst_Ar->nMaxSize = nNewMax;
|
||||
}
|
||||
return 1; /* success */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : frees unused memory
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSAr_FreeExtra( LDT_tdst_DSArray* pst_Ar)
|
||||
{
|
||||
void** pNewData;
|
||||
if (pst_Ar->nSize != pst_Ar->nMaxSize)
|
||||
{
|
||||
/* shrink to desired size */
|
||||
if( pst_Ar->nSize )
|
||||
{
|
||||
pNewData = realloc( pst_Ar->pData, pst_Ar->nSize * sizeof(void*) );
|
||||
if( pNewData )
|
||||
{
|
||||
pst_Ar->pData = pNewData;
|
||||
pst_Ar->nMaxSize = pst_Ar->nSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
LDT_DSAr_SetSize( pst_Ar, 0 ); /* clean-up */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Appends an array element. returns the index of the appended
|
||||
element, or -1 on error
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_Add( LDT_tdst_DSArray* pst_Ar, void* newElement)
|
||||
{
|
||||
if(!LDT_DSAr_SetSize( pst_Ar, pst_Ar->nSize+1 )) return -1;
|
||||
pst_Ar->pData[pst_Ar->nSize-1] = newElement;
|
||||
return pst_Ar->nSize-1;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Inserts a new array element. Returns 1 on success, 0 on failure
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_InsertAt(LDT_tdst_DSArray* pst_Ar, int nIndex, void* newElement )
|
||||
{
|
||||
if(nIndex < 0) return 0;
|
||||
|
||||
if (nIndex >= pst_Ar->nSize)
|
||||
{
|
||||
/* adding after the end of the array */
|
||||
/* grow so nIndex is valid */
|
||||
if(!LDT_DSAr_SetSize( pst_Ar, nIndex + 1)) return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* inserting in the middle of the array */
|
||||
/* grow the array to new size */
|
||||
if(!LDT_DSAr_SetSize( pst_Ar, pst_Ar->nSize + 1)) return 0;
|
||||
/* shift old data up to fill gap */
|
||||
memmove(pst_Ar->pData+nIndex+1, pst_Ar->pData+nIndex,
|
||||
( pst_Ar->nSize - nIndex - 1 ) * sizeof(void*));
|
||||
}
|
||||
/* insert new value in the gap */
|
||||
pst_Ar->pData[nIndex] = newElement;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : removes an array element. Returns the element on success, NULL on failure
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void* LDT_DSAr_RemoveAt(LDT_tdst_DSArray* pst_Ar, int nIndex )
|
||||
{
|
||||
int nMoveCount;
|
||||
void * pRemoved;
|
||||
if(nIndex < 0 || nIndex >= pst_Ar->nSize ) return NULL;
|
||||
|
||||
pRemoved = pst_Ar->pData[nIndex]; /* the removed element */
|
||||
|
||||
nMoveCount = pst_Ar->nSize - nIndex - 1;
|
||||
memcpy(pst_Ar->pData+nIndex, pst_Ar->pData+nIndex+1, nMoveCount*sizeof(void*));
|
||||
pst_Ar->nSize--;
|
||||
return pRemoved;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Inserts the elements of another array. Returns 1 on success,
|
||||
0 on failure.
|
||||
CREATED : 97/12/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_InsertArrayAt(LDT_tdst_DSArray* pst_Ar, int nIndex, LDT_tdst_DSArray* pNewArray)
|
||||
{
|
||||
int nCount, nOldSize;
|
||||
if(pNewArray == NULL || nIndex < 0) return 0;
|
||||
nCount = pNewArray->nSize;
|
||||
if (nCount > 0)
|
||||
{
|
||||
if (nIndex >= pst_Ar->nSize)
|
||||
{
|
||||
/* adding after the end of the array */
|
||||
/* grow so nIndex is valid */
|
||||
if(!LDT_DSAr_SetSize(pst_Ar, nIndex + nCount)) return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* inserting in the middle of the array */
|
||||
nOldSize = pst_Ar->nSize;
|
||||
/* grow it to new size */
|
||||
if(!LDT_DSAr_SetSize( pst_Ar, nOldSize + nCount)) return 0;
|
||||
/* shift old data up to fill gap */
|
||||
memmove(pst_Ar->pData+nIndex+nCount, pst_Ar->pData+nIndex,
|
||||
(nOldSize-nIndex) * sizeof(void*));
|
||||
}
|
||||
memcpy( pst_Ar->pData + nIndex, pNewArray->pData, nCount * sizeof(void*));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Sorts the array, using the comparison function
|
||||
CREATED : 97/12/03
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSAr_QSort( LDT_tdst_DSArray* pst_Ar )
|
||||
{
|
||||
if( pst_Ar->pfnCompare)
|
||||
qsort( &pst_Ar->pData[0], pst_Ar->nSize, sizeof(void*),
|
||||
(int (*)(const void *,const void *)) pst_Ar->pfnCompare );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Adds an element in the array, in sorted position.
|
||||
Returns the index of the added element, -1 on failure
|
||||
On failure,if the <<position>> parameter is not NULL, it will
|
||||
contain the index at which the element(or an equivalent) was found.
|
||||
CREATED : 97/12/03
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_SAdd( LDT_tdst_DSArray* pst_Ar, void* newElement, int AdmitDuplicates, int* position )
|
||||
{
|
||||
int iidx, idx = LDT_DSAr_Index( pst_Ar, newElement, &iidx );
|
||||
if(position) *position = idx;
|
||||
if(idx>=0 && ( !AdmitDuplicates || (newElement == pst_Ar->pData[idx]) ))
|
||||
return -1;
|
||||
else return ( LDT_DSAr_InsertAt(pst_Ar, iidx, newElement )? iidx: -1 );
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : gets the index of a certain element. -1 if the element
|
||||
(or an equivalent) is not found
|
||||
CREATED : 97/12/03
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_Index( LDT_tdst_DSArray* pst_Ar, void* newElement, int *p_iidx )
|
||||
{
|
||||
int hidx = pst_Ar->nSize-1, lidx = 0, cidx; /* , i, plus, minus; */
|
||||
|
||||
assert(pst_Ar->pfnCompare); /* the comparison function must exist*/
|
||||
|
||||
if(p_iidx) *p_iidx = 0;
|
||||
if(!newElement) return -1;
|
||||
if(hidx<0) return hidx;
|
||||
while(hidx > lidx)
|
||||
switch(pst_Ar->pfnCompare(&newElement,pst_Ar->pData+(cidx = (hidx+lidx)/2)))
|
||||
{
|
||||
case 0: hidx = lidx = cidx; break;
|
||||
case -1: hidx = cidx; break;
|
||||
default: lidx = cidx+1; break;
|
||||
}
|
||||
if(p_iidx) *p_iidx = lidx+1;
|
||||
switch(pst_Ar->pfnCompare( &newElement, pst_Ar->pData+lidx ))
|
||||
{
|
||||
case 0:
|
||||
/* for( i = 0, plus = pst_Ar->nSize-1-lidx, minus = lidx; plus>=0 || minus>=0; i++ )
|
||||
{
|
||||
if( plus>=i &&
|
||||
(plus = pst_Ar->pfnCompare(&newElement,pst_Ar->pData+lidx+1)?-1:plus)>=0 &&
|
||||
newElement == pst_Ar->pData[lidx+i])
|
||||
{
|
||||
lidx += i;
|
||||
break;
|
||||
}
|
||||
if( minus>=i &&
|
||||
(minus = pst_Ar->pfnCompare(&newElement,pst_Ar->pData+lidx-1 )?-1:minus)>=0 &&
|
||||
newElement == pst_Ar->pData[lidx+i])
|
||||
{
|
||||
lidx -= i;
|
||||
break;
|
||||
}
|
||||
} */
|
||||
if(p_iidx) *p_iidx = lidx+1;
|
||||
return lidx;
|
||||
case -1:
|
||||
if(p_iidx) (*p_iidx)--;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : gets the starting of an equivalence interval that includes the
|
||||
<<idx>> index
|
||||
CREATED : 97/12/03
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_UpperBound( LDT_tdst_DSArray* pst_Ar, int idx)
|
||||
{
|
||||
void** pCrt;
|
||||
int Midx = pst_Ar->nSize-1, lidx, hidx, cidx; /* the upper limit */
|
||||
if(idx<0 || idx>=Midx ) return Midx; /* the item is out of bounds or the last in the array */
|
||||
pCrt = pst_Ar->pData + (lidx = hidx = idx); /* this is the target */
|
||||
/* if the last element of the array is <=> with the target, return its index (no use for further search)*/
|
||||
if( !pst_Ar->pfnCompare( pCrt, pst_Ar->pData + Midx ) ) return Midx;
|
||||
/* find the interval bound */
|
||||
for(hidx ++; !pst_Ar->pfnCompare( pCrt,pst_Ar->pData + hidx );
|
||||
lidx = hidx, cidx = idx+(hidx-idx)*2, hidx = ( cidx<Midx? cidx: Midx ));
|
||||
hidx--;
|
||||
while(hidx > lidx)
|
||||
switch(pst_Ar->pfnCompare( pCrt, pst_Ar->pData +( cidx = (hidx+lidx+1)/2) ))
|
||||
{
|
||||
case -1: hidx = cidx-1; break;
|
||||
default: lidx = cidx; break;
|
||||
}
|
||||
return lidx;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : gets the beginning of an equivalence interval that includes the
|
||||
<<idx>> index
|
||||
CREATED : 97/12/03
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSAr_LowerBound( LDT_tdst_DSArray* pst_Ar, int idx)
|
||||
{
|
||||
int lidx, hidx, cidx;
|
||||
void** pCrt;
|
||||
if(idx<=0 || idx>pst_Ar->nSize-1 ) return 0; /* the item is out of bounds or the last in the array */
|
||||
pCrt = pst_Ar->pData + (lidx = hidx = idx); /* this is the target */
|
||||
/* if the first element of the array is <=> with the target, return its index (no use for further search) */
|
||||
if(!pst_Ar->pfnCompare( pCrt, pst_Ar->pData )) return 0;
|
||||
/* find the interval bound */
|
||||
for(lidx--; !pst_Ar->pfnCompare( pCrt, pst_Ar->pData + lidx );
|
||||
hidx = lidx, cidx = idx-(idx-lidx)*2, lidx = (cidx>lidx? cidx: lidx) );
|
||||
lidx++;
|
||||
while(hidx > lidx)
|
||||
switch(pst_Ar->pfnCompare( pCrt, pst_Ar->pData + (cidx = (hidx+lidx)/2) ) )
|
||||
{
|
||||
case 0: case -1: hidx = cidx; break;
|
||||
default: lidx = cidx+1; break;
|
||||
}
|
||||
return lidx;
|
||||
}
|
102
Rayman_X/cpa/tempgrp/ldt/Src/Error.c
Normal file
102
Rayman_X/cpa/tempgrp/ldt/Src/Error.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Error.c
|
||||
CREATED : 98/09/02
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: LDT Error management
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Error.h"
|
||||
#include "Parser.h"
|
||||
|
||||
char LDT_ErrDesc[LDT_MAX_ERROR_DESCRIPTION +1];
|
||||
FILE* pErrFile = NULL;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : initializes the error log file.
|
||||
CREATED : 98/09/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void InitErrFile()
|
||||
{
|
||||
static int count = 0;
|
||||
pErrFile = fopen("LDT_ERR.log", count?"a+":"w");
|
||||
count++;
|
||||
if(pErrFile)
|
||||
{
|
||||
time_t strTime;
|
||||
struct tm *newtime;
|
||||
time( &strTime );
|
||||
newtime = localtime( &strTime );
|
||||
fprintf(pErrFile, "LDT error log session %u >>> %s \n", count, asctime( newtime ));
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Closes the eror log file
|
||||
CREATED : 98/09/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void CLoseErrFile()
|
||||
{
|
||||
if(pErrFile)
|
||||
{
|
||||
fprintf(pErrFile, "\n\n\n");
|
||||
fclose(pErrFile);
|
||||
}
|
||||
pErrFile = NULL;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Error treatment
|
||||
CREATED : 98/09/02
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void SignalError(int level, LDT_tdst_Link * pLink, int errorcode, char* szErrDesc, char* szSourceFile, int line)
|
||||
{
|
||||
char* buff = LDT_ErrDesc;
|
||||
if(level > LDT_WARNING_LEVEL && level > LDT_ERROR_LEVEL) return;
|
||||
|
||||
buff += sprintf( buff,"\n%s\t(Level %u)\n" ,level>LDT_ERROR_LEVEL?"WARNING":"ERROR", level);
|
||||
buff += sprintf( buff,"\nCODE :\t\t%i (%s)", errorcode, errorcode?"USER":"SYSTEM");
|
||||
if(szErrDesc)
|
||||
buff += sprintf( buff,"\nDESCRIPTION:\t%s\n", szErrDesc);
|
||||
buff += sprintf( buff,"LOCATION:\t");
|
||||
if(pLink)
|
||||
{
|
||||
buff += sprintf( buff,"(%s) ", (pLink->dwFlags & LDT_LF_FILE)?"FILE":"SECTION");
|
||||
LDT_ComputeSectionName( pLink, buff);
|
||||
buff+= strlen(buff);
|
||||
}
|
||||
else
|
||||
if( g_FileDesc )
|
||||
buff += sprintf( buff, "(FILE) %s", g_FileDesc->_pInfoMemFile->pName );
|
||||
else
|
||||
buff += sprintf( buff, "No information available" );
|
||||
|
||||
buff += sprintf( buff,"\nSOURCE FILE:\t %s\nLINE:\t\t %u\n",szSourceFile, line);
|
||||
|
||||
#ifdef LDT_LOG_ERRORS
|
||||
if(pErrFile )
|
||||
{
|
||||
fprintf(pErrFile, LDT_ErrDesc );
|
||||
fprintf(pErrFile, "\n");
|
||||
}
|
||||
#endif
|
||||
#ifdef LDT_DISPLAY_ERRORS
|
||||
#ifndef LDT_DISPLAY_WARNINGS
|
||||
if(level > LDT_ERROR_LEVEL) return;
|
||||
#endif
|
||||
sprintf( buff,"\nPress 'Abort' to exit the application, 'Retry' to debug or 'Ignore' to continue.");
|
||||
switch( MessageBox(NULL, LDT_ErrDesc, "LDT MESSAGE", MB_ABORTRETRYIGNORE |MB_TASKMODAL |MB_TOPMOST |
|
||||
(level > LDT_ERROR_LEVEL?MB_ICONWARNING|MB_DEFBUTTON3:MB_ICONERROR|MB_DEFBUTTON2)))
|
||||
{
|
||||
case IDABORT: exit(errorcode); /* quit the application */
|
||||
case IDRETRY: /* debug */
|
||||
__asm
|
||||
{
|
||||
int 3h
|
||||
};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
297
Rayman_X/cpa/tempgrp/ldt/Src/File.c
Normal file
297
Rayman_X/cpa/tempgrp/ldt/Src/File.c
Normal file
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
**************************************************************************************************
|
||||
* CPA_Ed_1 team *
|
||||
* File Management *
|
||||
**************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "Stdinc.h"
|
||||
|
||||
|
||||
#include "File.h"
|
||||
#include "Types.h"
|
||||
|
||||
|
||||
#ifdef LDT_USE_SINGLE_FILE_BUFFER
|
||||
|
||||
char* GBuff = NULL;
|
||||
unsigned long GBuffSize = 0;
|
||||
#define GBuffMargin (1024*50) /* 50k above the file size */
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* OPEN a file for reading
|
||||
* --------------------------------------------------------------
|
||||
* _pInfoMemFile : the value returned
|
||||
* _Name : Name of the file.
|
||||
* Return : Error code(zero for none)
|
||||
* --------------------------------------------------------------
|
||||
* Conditions : If the file does not exist or cannot be found, the fopen call fails.
|
||||
* --------------------------------------------------------------
|
||||
* Comments : If succes, the pointer value not NULL
|
||||
* A null pointer value indicates an error.
|
||||
* If some errors occur, then all space are free
|
||||
*/
|
||||
//#define OVERLAPPED_
|
||||
#ifdef OVERLAPPED_
|
||||
#define OVERLAPPED_NO_BUFFERING
|
||||
long f_OpenMem(LDT_tdst_MemFile **_pInfoMemFile,char* _Name)
|
||||
{
|
||||
long Err = LDT_EI_Err_None;
|
||||
|
||||
*_pInfoMemFile= (LDT_tdst_MemFile *)malloc(sizeof(LDT_tdst_MemFile));
|
||||
|
||||
if(*_pInfoMemFile)
|
||||
{
|
||||
HANDLE File;
|
||||
|
||||
(*_pInfoMemFile)->sPathLength = 0;
|
||||
(*_pInfoMemFile)->pName= (char *)malloc(( strlen(_Name)+1 ));
|
||||
strcpy((*_pInfoMemFile)->pName , _Name);
|
||||
(*_pInfoMemFile)->pBuffer = NULL;
|
||||
|
||||
#ifdef OVERLAPPED_NO_BUFFERING
|
||||
File = CreateFile( _Name, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED|FILE_FLAG_NO_BUFFERING, NULL);
|
||||
#else
|
||||
File = CreateFile( _Name, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
#endif
|
||||
if(File != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
(*_pInfoMemFile)->Size = GetFileSize( File, NULL);
|
||||
if((*_pInfoMemFile)->Size)
|
||||
{
|
||||
DWORD BoundSize, VolumeSectorsize, SectorsPerCluster, NumberOfFreeClusters, TotalNumberOfClusters ;
|
||||
char Drive[4] = "C:\\";
|
||||
if(_Name[1] == ':') Drive[0] = _Name[0];
|
||||
GetDiskFreeSpace(_Name[1] == ':'? Drive: NULL, &SectorsPerCluster, &VolumeSectorsize, &NumberOfFreeClusters, &TotalNumberOfClusters );
|
||||
|
||||
#ifdef OVERLAPPED_NO_BUFFERING
|
||||
BoundSize = (*_pInfoMemFile)->Size + 5 + VolumeSectorsize;
|
||||
BoundSize -= BoundSize%VolumeSectorsize;
|
||||
(*_pInfoMemFile)->pBuffer= (char*)VirtualAlloc( NULL, BoundSize, MEM_COMMIT, PAGE_READWRITE );
|
||||
#else
|
||||
BoundSize = (*_pInfoMemFile)->Size + 5;
|
||||
(*_pInfoMemFile)->pBuffer= (char*)malloc( BoundSize );
|
||||
#endif
|
||||
if((*_pInfoMemFile)->pBuffer)
|
||||
{
|
||||
OVERLAPPED overlapped;
|
||||
overlapped.Offset = overlapped.OffsetHigh = 0;
|
||||
overlapped.hEvent = CreateEvent( NULL, FALSE, FALSE, NULL);
|
||||
ReadFile( File, (*_pInfoMemFile)->pBuffer, BoundSize, NULL, &overlapped);
|
||||
WaitForSingleObject( overlapped.hEvent, INFINITE);
|
||||
CloseHandle(overlapped.hEvent);
|
||||
|
||||
(*_pInfoMemFile)->Pos = 0;
|
||||
strcpy((*_pInfoMemFile)->pBuffer+(*_pInfoMemFile)->Size , "\n\"\n\n");
|
||||
}
|
||||
else Err = LDT_EI_Err_Malloc;
|
||||
}
|
||||
else Err = LDT_EI_Err_SeekFile;
|
||||
CloseHandle(File);
|
||||
}
|
||||
else Err = LDT_EI_Err_OpenFile;
|
||||
}
|
||||
else Err = LDT_EI_Err_Malloc;
|
||||
|
||||
if( Err != LDT_EI_Err_None && *_pInfoMemFile )
|
||||
{
|
||||
free((*_pInfoMemFile)->pName);
|
||||
#ifndef LDT_USE_SINGLE_FILE_BUFFER
|
||||
if((*_pInfoMemFile)->pBuffer) free((*_pInfoMemFile)->pBuffer);
|
||||
#endif
|
||||
|
||||
free((*_pInfoMemFile));
|
||||
*_pInfoMemFile = NULL;
|
||||
}
|
||||
return Err;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
long f_OpenMem(LDT_tdst_MemFile **_pInfoMemFile,char* _Name)
|
||||
{
|
||||
long Err = LDT_EI_Err_None;
|
||||
FILE *pFile; /* Pointer of the file */
|
||||
|
||||
*_pInfoMemFile= (LDT_tdst_MemFile *)malloc(sizeof(LDT_tdst_MemFile));
|
||||
|
||||
if(*_pInfoMemFile)
|
||||
{
|
||||
(*_pInfoMemFile)->sPathLength = 0;
|
||||
(*_pInfoMemFile)->pName= (char *)malloc(( strlen(_Name)+1 ));
|
||||
strcpy((*_pInfoMemFile)->pName , _Name);
|
||||
|
||||
(*_pInfoMemFile)->pBuffer = NULL;
|
||||
pFile = fopen(_Name, "rb");
|
||||
if(pFile)
|
||||
{
|
||||
(*_pInfoMemFile)->Size = _filelength (_fileno(pFile));
|
||||
if((*_pInfoMemFile)->Size)
|
||||
{
|
||||
#ifdef LDT_USE_SINGLE_FILE_BUFFER
|
||||
if(GBuffSize < (*_pInfoMemFile)->Size)
|
||||
{
|
||||
if(GBuff) free(GBuff);
|
||||
GBuff = malloc( GBuffSize = (*_pInfoMemFile)->Size + 5 + GBuffMargin);
|
||||
}
|
||||
(*_pInfoMemFile)->pBuffer = GBuff;
|
||||
#else
|
||||
(*_pInfoMemFile)->pBuffer= (char*) malloc(((*_pInfoMemFile)->Size + 5 ));
|
||||
#endif
|
||||
if((*_pInfoMemFile)->pBuffer)
|
||||
{
|
||||
if(fread((*_pInfoMemFile)->pBuffer,(*_pInfoMemFile)->Size,1,pFile))
|
||||
{
|
||||
(*_pInfoMemFile)->Pos = 0;
|
||||
strcpy((*_pInfoMemFile)->pBuffer+(*_pInfoMemFile)->Size , "\n\"\n\n");
|
||||
}
|
||||
else Err = LDT_EI_Err_ReadFile;
|
||||
}
|
||||
else Err = LDT_EI_Err_Malloc;
|
||||
}
|
||||
else Err = LDT_EI_Err_SeekFile;
|
||||
fclose(pFile);
|
||||
}
|
||||
else Err = LDT_EI_Err_OpenFile;
|
||||
}
|
||||
else Err = LDT_EI_Err_Malloc;
|
||||
|
||||
if( Err != LDT_EI_Err_None && *_pInfoMemFile )
|
||||
{
|
||||
free((*_pInfoMemFile)->pName);
|
||||
|
||||
#ifndef LDT_USE_SINGLE_FILE_BUFFER
|
||||
if((*_pInfoMemFile)->pBuffer) free((*_pInfoMemFile)->pBuffer);
|
||||
#endif
|
||||
|
||||
free((*_pInfoMemFile));
|
||||
*_pInfoMemFile = NULL;
|
||||
}
|
||||
return Err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* READ a piece of file from memory
|
||||
* --------------------------------------------------------------
|
||||
* _PointerDest : Address of the destination
|
||||
* _Size : size of data to move (in bytes)
|
||||
* _pInfoMemFile : Source file address in memory
|
||||
* Return : error code if <0 or the Size of data moved(for none error)
|
||||
* --------------------------------------------------------------
|
||||
* Conditions :
|
||||
* --------------------------------------------------------------
|
||||
* Comments : If succes, the return value are the Size of data moved
|
||||
* A value<0 indicate an error
|
||||
*/
|
||||
long f_ReadMem(char * _PointerDest,size_t _Size,LDT_tdst_MemFile *_pInfoMemFile )
|
||||
{
|
||||
long Err;
|
||||
|
||||
/*if( (_pInfoMemFile->Pos < _pInfoMemFile->Size) && */
|
||||
if (_pInfoMemFile->Size -_pInfoMemFile->Pos >= _Size)
|
||||
{
|
||||
if(_PointerDest == memmove(_PointerDest,_pInfoMemFile->pBuffer+_pInfoMemFile->Pos,_Size))
|
||||
{
|
||||
_pInfoMemFile->Pos += _Size;
|
||||
return _Size;
|
||||
}
|
||||
else
|
||||
Err = -LDT_EI_Err_MemMove;
|
||||
}
|
||||
else
|
||||
Err = -LDT_EI_Err_NotEnoughDataForMove;
|
||||
|
||||
return Err;
|
||||
}
|
||||
|
||||
/*
|
||||
* CLOSE a file (in memory and stream)
|
||||
* --------------------------------------------------------------
|
||||
* _pInfoMemFile : Source file address in memory
|
||||
* Return : error code
|
||||
* --------------------------------------------------------------
|
||||
* Conditions : close an open stream
|
||||
* --------------------------------------------------------------
|
||||
* Comments : fclose returns 0 if the stream is successfully closed
|
||||
* return EOF to indicate an error..
|
||||
* Return value must be int
|
||||
*/
|
||||
long f_CloseMem(LDT_tdst_MemFile *_pInfoMemFile)
|
||||
{
|
||||
#ifdef LDT_MULTITHREADED
|
||||
#ifdef OVERLAPPED_NO_BUFFERING
|
||||
VirtualFree( _pInfoMemFile->pBuffer, 0, MEM_RELEASE);
|
||||
#else
|
||||
free( _pInfoMemFile->pBuffer );
|
||||
#endif
|
||||
#else
|
||||
#ifndef LDT_USE_SINGLE_FILE_BUFFER
|
||||
free(_pInfoMemFile->pBuffer);
|
||||
#endif
|
||||
#endif
|
||||
free(_pInfoMemFile->pName);
|
||||
free(_pInfoMemFile);
|
||||
return LDT_EI_Err_None;
|
||||
}
|
||||
|
||||
/*
|
||||
* SEEK a file in memory to a given position.
|
||||
* --------------------------------------------------------------
|
||||
* _File : File to seek.
|
||||
* _Offset : Offset to seek.
|
||||
* _Origin : SEEK_SET or SEEK_END.
|
||||
* Return : error code
|
||||
* --------------------------------------------------------------
|
||||
* Conditions : The argument origin must be one of the following constant:
|
||||
* -SEEK_CUR Current position of file pointer
|
||||
* -SEEK_END End of file
|
||||
* -SEEK_SET Beginning of file
|
||||
* --------------------------------------------------------------
|
||||
* Comments : If successful, fseek returns 0
|
||||
* Return value must be long
|
||||
*/
|
||||
long f_SeekMem(LDT_tdst_MemFile *_pInfoMemFile ,long _Offset,int _Origin)
|
||||
{
|
||||
long Err;
|
||||
|
||||
|
||||
Err = LDT_EI_Err_None;
|
||||
switch (_Origin)
|
||||
{
|
||||
case SEEK_SET:
|
||||
if(_Offset>=0 && _pInfoMemFile->Size >= (size_t)_Offset)
|
||||
_pInfoMemFile->Pos = _Offset;
|
||||
else
|
||||
Err = LDT_EI_Err_SeekInMem;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
if(_Offset>0 && ((_pInfoMemFile->Size-_pInfoMemFile->Pos) >= (size_t)_Offset) )
|
||||
_pInfoMemFile->Pos += _Offset;
|
||||
else if( _Offset<0 && (_pInfoMemFile->Pos >= (size_t)(-_Offset)))
|
||||
_pInfoMemFile->Pos += _Offset;
|
||||
else
|
||||
Err = LDT_EI_Err_SeekInMem;
|
||||
break;
|
||||
case SEEK_END:
|
||||
if(_Offset <= 0 && (_pInfoMemFile->Size >= (size_t)(-_Offset)))
|
||||
_pInfoMemFile->Pos = _Offset+_pInfoMemFile->Size;
|
||||
else
|
||||
Err = LDT_EI_Err_SeekInMem;
|
||||
break;
|
||||
default:
|
||||
Err = LDT_EI_Err_SeekInMem;
|
||||
}
|
||||
|
||||
return Err;
|
||||
}
|
||||
|
||||
|
||||
long f_TellMem(LDT_tdst_MemFile *_pInfoMemFile )
|
||||
{
|
||||
return _pInfoMemFile->Pos;
|
||||
}
|
217
Rayman_X/cpa/tempgrp/ldt/Src/Hash.c
Normal file
217
Rayman_X/cpa/tempgrp/ldt/Src/Hash.c
Normal file
@@ -0,0 +1,217 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Hash.c
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: variable size hash table implementation
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Hash.h"
|
||||
|
||||
|
||||
|
||||
/*creation, initialization, deletion
|
||||
--------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a new hash
|
||||
INPUT : A) the dispersion function, with the following characteristics:
|
||||
- input : pointer to a hash element, or NULL;
|
||||
- output: > if input is NULL, the maximum index possible + 1
|
||||
> else, the hash index.
|
||||
B) the comparison function - similar with the one used for the LDT_tdst_DSArray
|
||||
C) the element deletion function - used to delete the elements
|
||||
OUTPUT : the newly created hash or NULL
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_DSHash* LDT_DSHs_new(int (* _pfnDispersion ) (void*),
|
||||
int (* _pfnCompare)(const void**, const void** ),
|
||||
void (* _pfnDelete) (void*) )
|
||||
{
|
||||
LDT_tdst_DSHash* pObj = (LDT_tdst_DSHash*) malloc( sizeof(LDT_tdst_DSHash) );
|
||||
if( LDT_DSHs_Init( pObj, _pfnDispersion, _pfnCompare, _pfnDelete) )
|
||||
return pObj; /* success */
|
||||
free( pObj );
|
||||
return NULL; /* failure */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : initializes an existing hash
|
||||
INPUT : see above
|
||||
OUTPUT : nonzero if successful
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_DSHs_Init(LDT_tdst_DSHash* pObj,
|
||||
int (* _pfnDispersion ) (void*),
|
||||
int (* _pfnCompare)(const void**, const void** ),
|
||||
void (* _pfnDelete) (void*) )
|
||||
{
|
||||
int HashDimension;
|
||||
|
||||
if(!pObj || !_pfnDispersion || !_pfnCompare || !_pfnDelete ) return 0; /* invalid input */
|
||||
|
||||
HashDimension = _pfnDispersion(NULL);
|
||||
if( !HashDimension ) return 0; /* bad dispersion function */
|
||||
|
||||
pObj->pfnDelete = _pfnDelete; /* set the deletion function */
|
||||
pObj->pfnDispersion = _pfnDispersion; /* set the dispersion function */
|
||||
pObj->pData = (LDT_tdst_DSArray*) malloc( HashDimension * sizeof(LDT_tdst_DSArray) ); /* allocate the needed memory */
|
||||
for(HashDimension --; HashDimension>=0; HashDimension--)
|
||||
{
|
||||
LDT_DSAr_Init( pObj->pData + HashDimension ); /* initialize the dynamic arrays */
|
||||
LDT_DSAr_SetSortMethod( pObj->pData + HashDimension, _pfnCompare );
|
||||
}
|
||||
return 1; /* success */
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : deletes an existing array
|
||||
INPUT : - the object
|
||||
- an integer: DelElements; if non-zero, all elements are freed
|
||||
(the pfnDelete is called for each element)
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSHs_delete( LDT_tdst_DSHash* pObj, int DelElements)
|
||||
{
|
||||
if( pObj )
|
||||
{
|
||||
LDT_DSHs_Close( pObj, DelElements ); /* clean-up */
|
||||
free( pObj ); /* deletion */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : sets the dynamic aray elements granularity
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSHs_SetGranularity( LDT_tdst_DSHash* pObj, int _nGrowBy)
|
||||
{
|
||||
int HashDimension = pObj->pfnDispersion( NULL ) - 1 ;
|
||||
for( ; HashDimension>=0; HashDimension--)
|
||||
LDT_DSAr_SetGranularity( pObj->pData + HashDimension, _nGrowBy ); /* set the granularity for each array */
|
||||
}
|
||||
|
||||
|
||||
/* Clean up
|
||||
-------------*/
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : frees the unused memory
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSHs_FreeExtra( LDT_tdst_DSHash* pObj )
|
||||
{
|
||||
int HashDimension = pObj->pfnDispersion( NULL ) - 1 ;
|
||||
for( ; HashDimension>=0; HashDimension--)
|
||||
LDT_DSAr_FreeExtra( pObj->pData + HashDimension );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : clears the hash, removing all the elements
|
||||
INPUT : - the object
|
||||
- an integer: DelElements; if non-zero, all elements are freed
|
||||
(the pfnDelete is called for each element)
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSHs_RemoveAll( LDT_tdst_DSHash* pObj, int DelElements)
|
||||
{
|
||||
LDT_tdst_DSArray* pCrtAr;
|
||||
void** pData;
|
||||
void (* Delete ) (void*) = pObj->pfnDelete;
|
||||
int i;
|
||||
int HashDimension = pObj->pfnDispersion( NULL ) - 1 ;
|
||||
for( ; HashDimension>=0; HashDimension--)
|
||||
{
|
||||
pCrtAr = pObj->pData + HashDimension;
|
||||
if(DelElements)
|
||||
for(i = LDT_DSAr_GetUpperBound( pCrtAr ), pData = pCrtAr->pData; i>=0; i--)
|
||||
Delete( pData[i]);
|
||||
LDT_DSAr_RemoveAll( pCrtAr );
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : clears the hash memory
|
||||
INPUT : - the object
|
||||
- an integer: DelElements; if non-zero, all elements are freed
|
||||
(the pfnDelete is called for each element)
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_DSHs_Close( LDT_tdst_DSHash* pObj, int DelElements )
|
||||
{
|
||||
LDT_DSHs_RemoveAll( pObj, DelElements );
|
||||
free( pObj->pData );
|
||||
pObj->pData = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Accessing elements
|
||||
-----------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : gets the hash element matching the parameter
|
||||
OUTPUT : the equivalent element in the hash, or NULL if none found
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void* LDT_DSHs_GetEqOf( LDT_tdst_DSHash* pHash, void* pTgt)
|
||||
{
|
||||
LDT_tdst_DSArray* pArr;
|
||||
if( !pTgt ) return NULL;
|
||||
pArr = pHash->pData + pHash->pfnDispersion( pTgt ); /* get the array */
|
||||
return LDT_DSAr_GetAt( pArr, LDT_DSAr_Index( pArr, pTgt, NULL )); /* get the element */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : removes the hash element matching the parameter
|
||||
OUTPUT : the equivalent element removed, or NULL if none found
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void* LDT_DSHs_RemoveEqOf( LDT_tdst_DSHash* pHash, void* pTgt )
|
||||
{
|
||||
LDT_tdst_DSArray* pArr;
|
||||
if( !pTgt ) return NULL;
|
||||
pArr = pHash->pData + pHash->pfnDispersion( pTgt ); /* get the array */
|
||||
return LDT_DSAr_RemoveAt( pArr, LDT_DSAr_Index( pArr, pTgt, NULL ));/* remove the element */
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : inserts the element in the hash table
|
||||
INPUT : the hash;
|
||||
the element to insert;
|
||||
an integer specifying the action to perform if an equivalent element is found in the hash:
|
||||
0 -> no action
|
||||
1 -> delete the element if it is not needed (an equivalent is found)
|
||||
OUTPUT : the element in the hash: the inserted element or the found equivalent.
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void* LDT_DSHs_Insert( LDT_tdst_DSHash* pHash, void* pTgt, int del)
|
||||
{
|
||||
int position;
|
||||
LDT_tdst_DSArray* pArr;
|
||||
if( !pTgt ) return NULL;
|
||||
pArr = pHash->pData + pHash->pfnDispersion( pTgt ); /* get the array */
|
||||
if(LDT_DSAr_SAdd( pArr, pTgt, 0, &position ) < 0) /* try to insert the element */
|
||||
{
|
||||
/* insertion failed */
|
||||
void* existing = LDT_DSAr_GetAt( pArr, position);
|
||||
if( del && (existing != pTgt) )
|
||||
pHash->pfnDelete (pTgt); /* delete the non-inserted element */
|
||||
return existing;
|
||||
}
|
||||
return pTgt;
|
||||
}
|
932
Rayman_X/cpa/tempgrp/ldt/Src/Interface.c
Normal file
932
Rayman_X/cpa/tempgrp/ldt/Src/Interface.c
Normal file
@@ -0,0 +1,932 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Interface.c
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: user end functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Interface.h"
|
||||
|
||||
#include "Register.h"
|
||||
#include "Parser.h"
|
||||
#include "Refs.h"
|
||||
#include "Error.h"
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
int LogFileOpened = 0;
|
||||
|
||||
TimerStruct TotalFlushtime = {0};
|
||||
TimerStruct Totalsolvetime = {0};
|
||||
TimerStruct Totalreadtime = {0};
|
||||
TimerStruct TotalPostprtime = {0};
|
||||
unsigned TotalFileCount = 0, TotalNumLinks = 0;
|
||||
double TotalFileSize = 0.;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_MEMORY
|
||||
|
||||
unsigned long g_allocsize = 0;
|
||||
unsigned long g_Maxallocsize = 0;
|
||||
unsigned long g_size;
|
||||
|
||||
void* g_palloc;
|
||||
|
||||
unsigned long g_allocCount = 0;
|
||||
unsigned long g_reallocCount = 0;
|
||||
unsigned long g_freeCount = 0;
|
||||
|
||||
#endif
|
||||
|
||||
int g_nInitialized = 0;
|
||||
extern int g_isFileNameValid = 1;
|
||||
|
||||
LDT_tdst_Link *g_pGetFrom = NULL;
|
||||
unsigned short g_usLinkingPerstincence;
|
||||
|
||||
/* Link-Value association array
|
||||
----------------------------------*/
|
||||
|
||||
LDT_tdst_DSArray g_arLinkAssocTable;
|
||||
|
||||
|
||||
|
||||
/* Initialization/Closing functions
|
||||
-------------------------------------*/
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : initialization method can be called any number of times.
|
||||
The method must be called before using the other module functions !!!!!!
|
||||
OUTPUT : 0 if the module was already initialized, 1 otherwise
|
||||
CREATED : 98/10/07
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Initialize()
|
||||
{
|
||||
if( g_nInitialized ) return 0;
|
||||
#ifdef LDT_USE_MMG /* initialization of the memory module */
|
||||
LDT_fn_v_Mem_InitModule();
|
||||
#endif /* LDT_USE_MMG */
|
||||
|
||||
#ifdef LDT_LOG_MEMORY
|
||||
g_allocsize = 0;
|
||||
g_Maxallocsize = 0;
|
||||
g_allocCount = 0;
|
||||
g_reallocCount = 0;
|
||||
g_freeCount = 0;
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
TotalFileCount = 0;
|
||||
TotalFileSize = 0.;
|
||||
TotalNumLinks = 0;
|
||||
TotalFlushtime.TimeCounter = 0;
|
||||
Totalsolvetime.TimeCounter = 0;
|
||||
Totalreadtime.TimeCounter = 0;
|
||||
TotalPostprtime.TimeCounter = 0;
|
||||
{
|
||||
FILE* file = fopen("LDT.log", LogFileOpened++?"a+":"w");
|
||||
time_t strTime;
|
||||
struct tm *newtime;
|
||||
time( &strTime );
|
||||
newtime = localtime( &strTime );
|
||||
fprintf(file, "===================================================================\n" );
|
||||
fprintf(file, "LDT module initialized: %s", asctime( newtime ) );
|
||||
fprintf(file, "===================================================================\n" );
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
g_usLinkingPerstincence = 0; /* maximum linking perstincence */
|
||||
/* initialize the section type registration table */
|
||||
LDT_DSAr_Init( &g_ArSectionCallbacks );
|
||||
LDT_DSAr_SetSortMethod( &g_ArSectionCallbacks, LDT_Compare_CallbackEntries);
|
||||
LDT_DSAr_SetGranularity( &g_ArSectionCallbacks, 25 );
|
||||
|
||||
/* initialize the file type registration table */
|
||||
LDT_DSAr_Init( &g_ArFileCallbacks );
|
||||
LDT_DSAr_SetSortMethod( &g_ArFileCallbacks, LDT_Compare_CallbackEntries);
|
||||
LDT_DSAr_SetGranularity( &g_ArFileCallbacks, 25 );
|
||||
|
||||
/* initialize the paths array */
|
||||
LDT_DSAr_Init( &g_ArBaseDirectories );
|
||||
|
||||
/* initialize the paths array */
|
||||
LDT_DSAr_Init( &g_ArPaths );
|
||||
LDT_DSAr_SetSortMethod( &g_ArPaths, LDT_Compare_CallbackEntries);
|
||||
LDT_DSAr_SetGranularity( &g_ArPaths, 25 );
|
||||
|
||||
/* initialize the path strings array */
|
||||
LDT_DSAr_Init( &g_ArPathStrings );
|
||||
LDT_DSAr_SetSortMethod( &g_ArPathStrings, LDT_Compare_Strings);
|
||||
LDT_DSAr_SetGranularity( &g_ArPathStrings, 25 );
|
||||
|
||||
/* initialize the post-process registration table */
|
||||
LDT_DSAr_Init( &g_ArSolvers );
|
||||
LDT_DSAr_SetSortMethod( &g_ArSolvers, SortSolvers );
|
||||
LDT_DSAr_SetGranularity( &g_ArSolvers, 25 );
|
||||
|
||||
/* contents initialization */
|
||||
LDT_DSAr_Init( &TheFileDesc.arContents );
|
||||
LDT_DSAr_SetSortMethod( &TheFileDesc.arContents, LDT_Compare_Positions );
|
||||
LDT_DSAr_SetGranularity( &TheFileDesc.arContents, 100 );
|
||||
/* contents initialization */
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
InitializeTimingEnvironment();
|
||||
#endif
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
InitializeCriticalSection( &GReadExclusion );
|
||||
#endif
|
||||
/* initialize the parser */
|
||||
InitParser();
|
||||
|
||||
/* first instance activated */
|
||||
#ifdef LDT_LOG_ERRORS
|
||||
InitErrFile();
|
||||
#endif
|
||||
|
||||
/* initialize the link/value table */
|
||||
LDT_DSAr_Init( &g_arLinkAssocTable );
|
||||
LDT_DSAr_SetSortMethod( &g_arLinkAssocTable, LDT_Compare_LinkValues);
|
||||
LDT_DSAr_SetGranularity( &g_arLinkAssocTable, 100 );
|
||||
|
||||
/* initialize the string array */
|
||||
LDT_DSAr_Init( &g_ArFilenames );
|
||||
LDT_DSAr_SetSortMethod( &g_ArFilenames, LDT_Compare_Strings);
|
||||
LDT_DSAr_SetGranularity( &g_ArFilenames, 100 );
|
||||
|
||||
/* initialize the reference table */
|
||||
LDT_DSAr_Init( &g_ArRefs );
|
||||
LDT_DSAr_SetSortMethod( &g_ArRefs, LDT_Compare_Refs);
|
||||
LDT_DSAr_SetGranularity( &g_ArRefs, 100 );
|
||||
|
||||
/* initialize the link table */
|
||||
LDT_DSHs_Init(&g_HashLinks,
|
||||
(int(*)(void*))LDT_Link_Dispersion,
|
||||
LDT_Compare_Links,
|
||||
(void(*)(void*))LDT_Delete_Link);
|
||||
LDT_DSHs_SetGranularity( &g_HashLinks, 100 );
|
||||
return (g_nInitialized = 1); /* the module was initialized */
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Closing method can be called any number of times.
|
||||
OUTPUT : 0 if the module was already closed, 1 otherwise
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Close()
|
||||
{
|
||||
if(!g_nInitialized) return 0;
|
||||
/*_____________________________________________________________________________*/
|
||||
|
||||
LDT_FlushAndForget(0); /* load the unresolved refs and delete the internal linktable */
|
||||
LDT_CleanUpRegistrations(); /* delete the registered stuff */
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
/* close the link table (deleting the existing links) */
|
||||
LDT_DSHs_Close( &g_HashLinks, 1);
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
DeleteCriticalSection( &GReadExclusion );
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_ERRORS
|
||||
CLoseErrFile();
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
{
|
||||
TimerStruct TempTimer;
|
||||
FILE* file = fopen("LDT.log", LogFileOpened++?"a+":"w");
|
||||
time_t strTime;
|
||||
struct tm *newtime;
|
||||
time( &strTime );
|
||||
newtime = localtime( &strTime );
|
||||
fprintf(file, "===================================================================\n" );
|
||||
fprintf(file, "Totals:\n\n" );
|
||||
|
||||
fprintf(file, "Flush Time:\t\t%.3f\n", ReadTimer(&TotalFlushtime) );
|
||||
fprintf(file, "Read Time:\t\t%.3f\n", ReadTimer(&Totalreadtime) );
|
||||
#ifdef LDT_MULTITHREADED
|
||||
fprintf(file, "Process Time:\t\t%.3f\n", ReadTimer(&Totalsolvetime) );
|
||||
#else
|
||||
TempTimer.TimeCounter = Totalsolvetime.TimeCounter - Totalreadtime.TimeCounter;
|
||||
fprintf(file, "Process Time:\t\t%.3f\n", ReadTimer(&TempTimer));
|
||||
#endif
|
||||
fprintf(file, "Postprocess Time:\t%.3f\n", ReadTimer(&TotalPostprtime) );
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
{
|
||||
TempTimer.TimeCounter = TotalPostprtime.TimeCounter + Totalsolvetime.TimeCounter + Totalreadtime.TimeCounter;
|
||||
fprintf(file, "\nMultithreaded disk read performance:\n");
|
||||
fprintf(file, "Useful Time:\t\t%.3f\n", ReadTimer(&TempTimer));
|
||||
fprintf(file, "Absloute Time Gain:\t%.3f\n", ReadTimer(&TempTimer) - ReadTimer(&TotalFlushtime));
|
||||
TempTimer.TimeCounter -= TotalFlushtime.TimeCounter;
|
||||
fprintf(file, "Disk Read Savings: \t%.1f%%\n", (ReadTimer(&TempTimer))*100/ReadTimer(&Totalreadtime));
|
||||
}
|
||||
#endif
|
||||
|
||||
fprintf(file, "\nSections:\t\t%u", TotalNumLinks );
|
||||
fprintf(file, "\nFiles:\t\t\t%u", TotalFileCount );
|
||||
fprintf(file, "\nRead:\t\t\t%.3f MB\n\n", TotalFileSize/1024/1024 );
|
||||
|
||||
#ifdef LDT_LOG_MEMORY
|
||||
fprintf(file, "\nMaximum Memory Used:\t%.3f MB\n", ((double)g_Maxallocsize)/1024/1024 );
|
||||
fprintf(file, "\nMalloc Count:\t\t%u\n", g_allocCount );
|
||||
fprintf(file, "Free Count:\t\t%u\n", g_freeCount );
|
||||
fprintf(file, "Realloc Count:\t\t%u\n", g_reallocCount );
|
||||
fprintf(file, "Memory Leaks:\t\t%.3f KB\n", ((double)g_allocsize)/1024 );
|
||||
fprintf(file, "\nWarning, time estimation is affected by the memory measurements. \n\n");
|
||||
#endif
|
||||
|
||||
fprintf(file, "LDT module closed: %s", asctime( newtime ) );
|
||||
fprintf(file, "===================================================================\n" );
|
||||
fprintf(file, "\n\n\n");
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LDT_USE_MMG /* release the memory module */
|
||||
LDT_fn_v_Mem_CloseModule();
|
||||
#endif /* DMS_USE_MMG */
|
||||
|
||||
g_nInitialized = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : unregisters all registered types, paths and solvers - memory clean-up
|
||||
CREATED : 98/09/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_CleanUpRegistrations()
|
||||
{
|
||||
int i, j;
|
||||
// if(InstanceCount)
|
||||
// {
|
||||
// ERRoR(0, NULL, 0, "All types and paths registrations are deleted during a loading session");
|
||||
// return;
|
||||
// }
|
||||
if( g_nInitialized == 0 ) return;
|
||||
/* close the section type registration table */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArSectionCallbacks); i>=0; i--)
|
||||
{
|
||||
free(((LDT_tdst_CallbackEntry*)g_ArSectionCallbacks.pData[i])->szType);
|
||||
free( g_ArSectionCallbacks.pData[i]);
|
||||
}
|
||||
LDT_DSAr_RemoveAll( &g_ArSectionCallbacks );
|
||||
|
||||
/* close the file type registration table */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArFileCallbacks); i>=0; i--)
|
||||
{
|
||||
free(((LDT_tdst_CallbackEntry*)g_ArFileCallbacks.pData[i])->szType);
|
||||
free( g_ArFileCallbacks.pData[i]);
|
||||
}
|
||||
LDT_DSAr_RemoveAll( &g_ArFileCallbacks );
|
||||
|
||||
/* close the post-process registration table */
|
||||
{
|
||||
LDT_tdst_DSArray* pRef;
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArSolvers); i>=0; i--)
|
||||
{
|
||||
pRef = (LDT_tdst_DSArray*)((tdst_Solver*)g_ArSolvers.pData[i])->hRef;
|
||||
if(pRef)
|
||||
for( j = LDT_DSAr_GetUpperBound(pRef); j>=0; j--)
|
||||
free( pRef->pData[j]);
|
||||
LDT_DSAr_delete( pRef );
|
||||
free( g_ArSolvers.pData[i]);
|
||||
}
|
||||
}
|
||||
LDT_DSAr_RemoveAll( &g_ArSolvers );
|
||||
|
||||
/* close the base paths table */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArBaseDirectories); i>=0; i--)
|
||||
free(g_ArBaseDirectories.pData[i]);
|
||||
LDT_DSAr_RemoveAll(&g_ArBaseDirectories);
|
||||
|
||||
/* close the path table */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArPaths); i>=0; i--)
|
||||
{
|
||||
LDT_DSAr_RemoveAll(&((LDT_tdst_TypePaths*)g_ArPaths.pData[i])->arPaths);
|
||||
free( ((LDT_tdst_TypePaths*)g_ArPaths.pData[i])->szExtension );
|
||||
free(g_ArPaths.pData[i]);
|
||||
}
|
||||
LDT_DSAr_RemoveAll(&g_ArPaths);
|
||||
|
||||
/* close the path strings table */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArPathStrings); i>=0; i--)
|
||||
free(g_ArPathStrings.pData[i]);
|
||||
LDT_DSAr_RemoveAll(&g_ArPathStrings);
|
||||
|
||||
}
|
||||
|
||||
/* Link-Value association functions
|
||||
-------------------------------------*/
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : associates an userd-supplied value to a link
|
||||
CREATED : 98/08/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void LDT_SetLinkValue( LDT_tdst_Link* pLink, unsigned long value )
|
||||
{
|
||||
int idx, iidx;
|
||||
idx = LDT_DSAr_Index( &g_arLinkAssocTable, (LDT_tdst_LinkValue*)&pLink, &iidx );
|
||||
if( idx<0 )
|
||||
{ /* the link is not present in the table */
|
||||
LDT_tdst_LinkValue* pNewAssoc = malloc(sizeof(LDT_tdst_LinkValue));
|
||||
pNewAssoc->pLink = pLink;
|
||||
pNewAssoc->value = value;
|
||||
LDT_DSAr_InsertAt( &g_arLinkAssocTable, iidx, pNewAssoc );
|
||||
}
|
||||
else
|
||||
{
|
||||
((LDT_tdst_LinkValue*)g_arLinkAssocTable.pData[idx])->value = value; /* link already present -> change the associated value */
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 3 || LDT_ERROR_LEVEL >= 3)
|
||||
ERRoR(3, pLink, 0, "Link associated value already present. The old value was overwritten.");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : retrieves the user-supplied value associated to the link
|
||||
CREATED : 98/08/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
unsigned long LDT_GetLinkValue( LDT_tdst_Link* pLink )
|
||||
{
|
||||
int idx = LDT_DSAr_Index( &g_arLinkAssocTable, (LDT_tdst_LinkValue*)&pLink, NULL );
|
||||
if(idx < 0)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 3 || LDT_ERROR_LEVEL >= 3)
|
||||
ERRoR(3, pLink, 0, "No associated value available for this link.");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
return ((LDT_tdst_LinkValue*)LDT_DSAr_GetAt( &g_arLinkAssocTable, idx ))->value;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : retrieves and removes the user-supplied value associated to the link
|
||||
CREATED : 98/09/31
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
unsigned long LDT_RemoveLinkValue( LDT_tdst_Link* pLink )
|
||||
{
|
||||
LDT_tdst_LinkValue* pAssoc;
|
||||
unsigned long value;
|
||||
int idx = LDT_DSAr_Index( &g_arLinkAssocTable, (LDT_tdst_LinkValue*)&pLink, NULL );
|
||||
if(idx < 0)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 3 || LDT_ERROR_LEVEL >= 3)
|
||||
ERRoR(3, pLink, 0, "No associated value available for this link.");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
pAssoc = (LDT_tdst_LinkValue*)LDT_DSAr_RemoveAt( &g_arLinkAssocTable, idx );
|
||||
value = pAssoc->value;
|
||||
free(pAssoc);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Loading functions
|
||||
-------------------------------------*/
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Find a link
|
||||
OUTPUT : The pointer to link ( NULL if not found )
|
||||
-1 on error;
|
||||
CREATED : 98/08/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_Link* LDT_GetLink( char *szSection )
|
||||
{
|
||||
LDT_tdst_Link *pLink, *pRetVal;
|
||||
if( szSection==NULL)
|
||||
return NULL;
|
||||
pLink=LDT_CreateLinkFromReference( szSection );
|
||||
pRetVal=LDT_DSHs_GetEqOf(&g_HashLinks, (void *)pLink);
|
||||
LDT_Delete_Link( pLink );
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 2 || LDT_ERROR_LEVEL >= 2)
|
||||
if(!pRetVal)
|
||||
ERRoR(2, NULL, 0, "No link matches this description.");
|
||||
#endif
|
||||
return pRetVal;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Load a section
|
||||
OUTPUT : The allocated object(can be NULL)
|
||||
-1 on error;
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void* LDT_LoadSection( char* szSection )
|
||||
{
|
||||
int errcode, level;
|
||||
LDT_tdst_Link *Link = NULL;
|
||||
g_pGetFrom=NULL; /* MP-for refs */
|
||||
if(szSection) /* loading request */
|
||||
{
|
||||
Link = LDT_CreateLinkFromReference( szSection );/* normal call */
|
||||
if( !Link ) return (void*)-1; /* error */
|
||||
Link = LDT_DSHs_Insert( &g_HashLinks, Link, 1);
|
||||
g_pGetFrom=Link; /* MP-for refs */
|
||||
if( Link->dwFlags & LDT_LF_ALLOCATED )
|
||||
return Link->pObject; /* the link was already processed */
|
||||
g_isFileNameValid = 0;
|
||||
errcode = Link->Type->Create( Link ); /* create the object */
|
||||
g_isFileNameValid = 1;
|
||||
if(errcode)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, Link, errcode, "Unable to create associated object.");
|
||||
#endif
|
||||
return (void*)-1;
|
||||
}
|
||||
Link->dwFlags |= LDT_LF_ALLOCATED; /* set the corresponding flag */
|
||||
AddReference( Link ); /* append the reference */
|
||||
return Link->pObject;
|
||||
}
|
||||
if( g_FileDesc ) /* sub-section loading */
|
||||
{
|
||||
void* pObject;
|
||||
LDT_tdst_CallbackEntry* Type = GetType( g_szType, LDT_REG_SECTION );
|
||||
Link=LDT_Create_Link( g_szId, g_szParent, g_FileDesc->szFile, Type, g_usLinkingPerstincence, NULL, pParent[g_FileDesc->iLevel-1] );
|
||||
Link=(LDT_tdst_Link *)LDT_DSHs_Insert( &g_HashLinks, (void *)Link, 1 );
|
||||
|
||||
pParent[ g_FileDesc->iLevel ]=Link;
|
||||
g_CrtSection=Link;
|
||||
|
||||
if( Link->dwFlags&LDT_LF_LOADED )
|
||||
{
|
||||
pObject = Link->pObject; /* the link was already processed */
|
||||
LDT_SkipSection();
|
||||
if( Link->dwFlags & LDT_LF_VOLATILE)
|
||||
free ( LDT_DSHs_RemoveEqOf( &g_HashLinks, Link)); /* remove volatile subsection*/
|
||||
return pObject;
|
||||
}
|
||||
if( (Link->dwFlags & LDT_LF_ALLOCATED) == 0 )
|
||||
{
|
||||
errcode = Type->Create( Link );
|
||||
if(errcode )
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, Link, errcode, "Unable to create associated object.");
|
||||
#endif
|
||||
return (void*)-1;
|
||||
}
|
||||
Link->dwFlags |= LDT_LF_ALLOCATED; /* the link was allocated */
|
||||
}
|
||||
level = g_FileDesc->iLevel - 1;
|
||||
errcode = Type->Load( Link );
|
||||
pObject = Link->pObject;
|
||||
if(errcode)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, Link, errcode, "Unable to load section. User error triggered in callback.");
|
||||
#endif
|
||||
pObject = (void*)-1;
|
||||
}
|
||||
else if(level != g_FileDesc->iLevel)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, Link, 0, "Erroneous load callback. Failure to reach the section end mark! (premature return or subsections not treated)");
|
||||
#endif
|
||||
pObject = (void*)-1;
|
||||
}
|
||||
Link->dwFlags |= LDT_LF_LOADED; /* the link was loaded */
|
||||
if( Link->dwFlags & LDT_LF_VOLATILE)
|
||||
LDT_Delete_Link( LDT_DSHs_RemoveEqOf( &g_HashLinks, Link)); /* remove volatile subsection*/
|
||||
return pObject;
|
||||
}
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, NULL, 0, "Cannot Load Subsection. Called from outside any \"Load\" callback.");
|
||||
#endif
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Load a section
|
||||
OUTPUT : pointer to the allocated object
|
||||
( can be different from the received parameter -
|
||||
if the section was previously allocated)
|
||||
-1 on error;
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void* LDT_LoadSectionAt( char* szSection, void* pSection )
|
||||
{
|
||||
int errcode, level;
|
||||
LDT_tdst_Link *Link = NULL;
|
||||
g_pGetFrom=NULL; /* MP-for refs */
|
||||
if(szSection) /* loading request */
|
||||
{
|
||||
Link = LDT_CreateLinkFromReference( szSection );/* normal call */
|
||||
if( !Link ) return (void*)-1; /* error */
|
||||
Link = LDT_DSHs_Insert( &g_HashLinks, Link, 1);
|
||||
g_pGetFrom=Link; /* MP-for refs */
|
||||
if( Link->dwFlags & LDT_LF_ALLOCATED )
|
||||
return Link->pObject; /* the link was already processed */
|
||||
Link->pObject = pSection; /* copy the object */
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 2 || LDT_ERROR_LEVEL >= 2)
|
||||
if(!pSection)
|
||||
ERRoR(2, Link, 0, "Associated object is set to NULL.");
|
||||
#endif
|
||||
Link->dwFlags |= LDT_LF_ALLOCATED; /* set the corresponding flag */
|
||||
AddReference( Link ); /* append the reference */
|
||||
return Link->pObject;
|
||||
}
|
||||
if( g_FileDesc ) /* sub-section loading */
|
||||
{
|
||||
void* pObject;
|
||||
LDT_tdst_CallbackEntry* Type = GetType( g_szType, LDT_REG_SECTION );
|
||||
Link=LDT_Create_Link( g_szId, g_szParent, g_FileDesc->szFile, Type, g_usLinkingPerstincence, NULL, pParent[g_FileDesc->iLevel-1] );
|
||||
Link=(LDT_tdst_Link *)LDT_DSHs_Insert( &g_HashLinks, (void *)Link, 1 );
|
||||
|
||||
pParent[ g_FileDesc->iLevel ]=Link;
|
||||
g_CrtSection=Link;
|
||||
|
||||
if( Link->dwFlags&LDT_LF_LOADED )
|
||||
{
|
||||
pObject = Link->pObject; /* the link was already processed */
|
||||
LDT_SkipSection();
|
||||
if( Link->dwFlags & LDT_LF_VOLATILE)
|
||||
free ( LDT_DSHs_RemoveEqOf( &g_HashLinks, Link)); /* remove volatile subsection*/
|
||||
return pObject;
|
||||
}
|
||||
if( (Link->dwFlags & LDT_LF_ALLOCATED) == 0 )
|
||||
{
|
||||
Link->pObject = pSection; /* copy the object */
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 2 || LDT_ERROR_LEVEL >= 2)
|
||||
if(!pSection)
|
||||
ERRoR(2, Link, 0, "Associated object is set to NULL.");
|
||||
#endif
|
||||
Link->dwFlags |= LDT_LF_ALLOCATED; /* the link was allocated */
|
||||
}
|
||||
level = g_FileDesc->iLevel - 1;
|
||||
errcode = Type->Load( Link );
|
||||
pObject = Link->pObject;
|
||||
if(errcode)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, Link, errcode, "Unable to load section. User error triggered in callback.");
|
||||
#endif
|
||||
pObject = (void*)-1;
|
||||
}
|
||||
else if(level != g_FileDesc->iLevel)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, Link, 0, "Erroneous load callback. Failure to reach the section end mark! (premature return or subsections not treated)");
|
||||
#endif
|
||||
pObject = (void*)-1;
|
||||
}
|
||||
Link->dwFlags |= LDT_LF_LOADED; /* the link was loaded */
|
||||
if( Link->dwFlags & LDT_LF_VOLATILE)
|
||||
LDT_Delete_Link( LDT_DSHs_RemoveEqOf( &g_HashLinks, Link)); /* remove volatile subsection*/
|
||||
return pObject;
|
||||
}
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, NULL, 0, "Cannot Load Subsection. Called from outside any \"Load\" callback.");
|
||||
#endif
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
|
||||
HANDLE GReadCount; /* the number of files read from disk */
|
||||
HANDLE GReadLimit; /* the number of available files */
|
||||
HANDLE GFileLimit = NULL; /* the maximum number of files read in advance */
|
||||
|
||||
#pragma warning(disable: 4100)
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : File Reading thread method
|
||||
CREATED : 98/07/07
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
//unsigned int __stdcall DiskRead( void * p);
|
||||
|
||||
unsigned int __stdcall DiskRead( void * p)
|
||||
{
|
||||
LDT_tdst_Refs * pRefs;
|
||||
LDT_tdst_MemFile* pFile;
|
||||
|
||||
unsigned int uiPos=0;
|
||||
static char buffer[256];
|
||||
int ok=1;
|
||||
// SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE );
|
||||
|
||||
for(;;)
|
||||
{
|
||||
WaitForSingleObject( GReadLimit, INFINITE); /* wait to have the number of opened files less than the max allowed */
|
||||
WaitForSingleObject( GFileLimit, INFINITE); /* wait to have at least one file available for reading */
|
||||
EnterCriticalSection( &GReadExclusion );
|
||||
if((pRefs = g_pFileToRead)==NULL)
|
||||
{
|
||||
LeaveCriticalSection( &GReadExclusion );
|
||||
break;
|
||||
}
|
||||
g_pFileToRead = pRefs->p_NextReferencedFile;
|
||||
LeaveCriticalSection( &GReadExclusion );
|
||||
|
||||
// SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
||||
pFile = AccessFile( pRefs->szFile ); /* open the file */
|
||||
// SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE );
|
||||
|
||||
pRefs->pFile = pFile;
|
||||
ReleaseSemaphore( GReadCount, 1, NULL); /* the file was opened */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma warning(default: 4100)
|
||||
#endif
|
||||
|
||||
void LDT_SetLinkingPersistence (unsigned short Level)
|
||||
{
|
||||
if( g_ArRefs.nSize )
|
||||
LDT_Flush();
|
||||
g_usLinkingPerstincence = Level;
|
||||
}
|
||||
|
||||
void LDT_Forget(unsigned short Level)
|
||||
{
|
||||
int i, gap, maxValue, HashDimension;
|
||||
LDT_tdst_DSArray* pCrtAr;
|
||||
void** pData;
|
||||
|
||||
LDT_DSAr_RemoveAll( &g_ArRefs ); /* the reference table is empty at this point - no other closing procedure necessary*/
|
||||
LDT_DSAr_RemoveAll( &TheFileDesc.arContents);
|
||||
|
||||
#ifdef LDT_USE_SINGLE_FILE_BUFFER
|
||||
if(GBuff) free(GBuff);
|
||||
GBuff = NULL;
|
||||
GBuffSize = 0;
|
||||
#endif
|
||||
|
||||
if(Level)
|
||||
{ /* Partial clean-up. Not reccomended due to low speed performance */
|
||||
/* delete the invalid associations from the link/value table */
|
||||
for( i = gap = 0, maxValue = LDT_DSAr_GetSize(&g_arLinkAssocTable), pData = g_arLinkAssocTable.pData; i<maxValue; i++)
|
||||
{
|
||||
if(((short)(((LDT_tdst_LinkValue*)pData[i])->pLink->dwFlags)) >= Level )
|
||||
{
|
||||
free( pData[i]);
|
||||
gap++;
|
||||
}
|
||||
else
|
||||
pData[i-gap] = pData[i];
|
||||
}
|
||||
LDT_DSAr_SetSize(&g_arLinkAssocTable, maxValue - gap); /* adjust the size of the array */
|
||||
|
||||
/* delete the not needed links from the links hash table */
|
||||
for(HashDimension = g_HashLinks.pfnDispersion( NULL ) - 1 ; HashDimension>=0; HashDimension--)
|
||||
{
|
||||
pCrtAr = g_HashLinks.pData + HashDimension;
|
||||
pData = pCrtAr->pData;
|
||||
for( i = gap = 0, maxValue = LDT_DSAr_GetSize(pCrtAr); i<maxValue; i++)
|
||||
{
|
||||
if(((short)(((LDT_tdst_Link*)pData[i])->dwFlags)) >= Level )
|
||||
{
|
||||
g_HashLinks.pfnDelete( pData[i]);
|
||||
gap++;
|
||||
}
|
||||
else
|
||||
pData[i-gap] = pData[i];
|
||||
}
|
||||
LDT_DSAr_SetSize(pCrtAr, maxValue - gap); /* adjust the size of the array */
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* Total clean-up. The normal operation */
|
||||
/*------------------------------- delete the existing links and the related data ----------------------*/
|
||||
|
||||
/* close the link/value table(deleting all stored associations) */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_arLinkAssocTable), pData = g_arLinkAssocTable.pData; i>=0; i--)
|
||||
free( pData[i]);
|
||||
LDT_DSAr_RemoveAll( &g_arLinkAssocTable );
|
||||
/* close the string array (deleting all stored strings) */
|
||||
for( i = LDT_DSAr_GetUpperBound(&g_ArFilenames), pData = g_ArFilenames.pData; i>=0; i--)
|
||||
free( pData[i]);
|
||||
LDT_DSAr_RemoveAll( &g_ArFilenames );
|
||||
|
||||
LDT_DSHs_RemoveAll( &g_HashLinks, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Reference solving function - performs loading & deletes the linktable afterwards
|
||||
OUTPUT : zero on error, nonzero if successful;
|
||||
CREATED : 98/05/24
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_FlushAndForget(unsigned short Level)
|
||||
{
|
||||
int ERR = LDT_Flush();
|
||||
LDT_Forget( Level );
|
||||
return ERR;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Reference solving function - performs the loading
|
||||
OUTPUT : zero on error, nonzero if successful;
|
||||
CREATED : 98/05/24
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
extern unsigned char* g_ulPos;
|
||||
|
||||
int LDT_Flush()
|
||||
{
|
||||
static int FlushLaunched = 0;
|
||||
int OK = 1, i;
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
unsigned CurrentLinks = 0;
|
||||
TimerStruct FlushTime = TotalFlushtime;
|
||||
TimerStruct SolveTime = Totalsolvetime;
|
||||
TimerStruct Readtime = Totalreadtime;
|
||||
TimerStruct Postprtime = TotalPostprtime ;
|
||||
unsigned FileCount = TotalFileCount;
|
||||
double FileSize = TotalFileSize;
|
||||
|
||||
{ /* count the number of links */
|
||||
int HashDimension = g_HashLinks.pfnDispersion( NULL ) - 1 ;
|
||||
for( ; HashDimension>=0; HashDimension--)
|
||||
CurrentLinks += LDT_DSAr_GetSize( g_HashLinks.pData + HashDimension );
|
||||
}
|
||||
#endif
|
||||
|
||||
if(FlushLaunched)
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, NULL, 0, "Recursive call to LDT_Flush() not allowed. Call aborted. ");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
FlushLaunched = 1; /* sentinel */
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
StartTimer(&TotalFlushtime);
|
||||
#endif
|
||||
|
||||
do
|
||||
{
|
||||
if(g_pFileToProcess)
|
||||
{
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
|
||||
unsigned thrdaddr; /* the read thread */
|
||||
HANDLE Hthrd; /* the read thread */
|
||||
|
||||
GReadCount = CreateSemaphore( NULL, 0, LONG_MAX, NULL ); /* the number of files read from disk */
|
||||
GFileLimit = CreateSemaphore( NULL, g_ArRefs.nSize, LONG_MAX, NULL ); /* the number of available files */
|
||||
GReadLimit = CreateSemaphore( NULL, MAX_FILE_NO, LONG_MAX, NULL ); /* the maximum number of files read in advance */
|
||||
|
||||
InitializeCriticalSection( &GReadExclusion );
|
||||
Hthrd = (void*)_beginthreadex(NULL, 0, DiskRead, NULL, 0, &thrdaddr); /* start the thread that reads files from disk */
|
||||
#endif
|
||||
|
||||
/* processing */
|
||||
for(;g_pFileToProcess;)
|
||||
{
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
WaitForSingleObject( GReadCount, INFINITE);
|
||||
// SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST );
|
||||
#endif
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
StartTimer(&Totalsolvetime);
|
||||
#endif
|
||||
|
||||
if( Solve(g_pFileToProcess) ) /* the effective loading */
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 2 || LDT_ERROR_LEVEL >= 2)
|
||||
ERRoR(2, NULL, 0, "Unable to satisfy all loading requests for the previous file.");
|
||||
#endif
|
||||
OK = 0; /* Error encountered */
|
||||
}
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
StopTimer(&Totalsolvetime);
|
||||
#endif
|
||||
|
||||
LDT_DSAr_RemoveAll(&g_pFileToProcess->Links);
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
// SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL );
|
||||
ReleaseSemaphore( GReadLimit, 1, NULL); /* signal that the file was processed */
|
||||
#endif
|
||||
{
|
||||
LDT_tdst_Refs * pRefs = g_pFileToProcess;
|
||||
g_pFileToProcess = g_pFileToProcess->p_NextReferencedFile;
|
||||
free( LDT_DSAr_RemoveAt( &g_ArRefs, LDT_DSAr_Index(&g_ArRefs, pRefs, NULL) ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
ReleaseSemaphore( GReadLimit, 1, NULL ); /* allow the file reading thread to advance */
|
||||
ReleaseSemaphore( GFileLimit, 1, NULL ); /* allow the file reading thread to advance */
|
||||
WaitForSingleObject( Hthrd, INFINITE );
|
||||
CloseHandle( Hthrd );
|
||||
CloseHandle( GReadCount );
|
||||
CloseHandle( GFileLimit );
|
||||
CloseHandle( GReadLimit );
|
||||
|
||||
GFileLimit = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
StartTimer(&TotalPostprtime);
|
||||
#endif
|
||||
/* post-process */
|
||||
for( i=0; i<g_ArSolvers.nSize; i++ )
|
||||
{
|
||||
tdst_Solver *pSolver=(tdst_Solver *)LDT_DSAr_GetAt( &g_ArSolvers, i );
|
||||
pSolver->Solve( pSolver->hRef );
|
||||
}
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
StopTimer(&TotalPostprtime);
|
||||
#endif
|
||||
}
|
||||
while(g_pFileToProcess);
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
StopTimer(&TotalFlushtime);
|
||||
|
||||
{ /* count the number of links */
|
||||
TimerStruct TempTimer;
|
||||
FILE* file = fopen("LDT.log", LogFileOpened++?"a+":"w");
|
||||
time_t strTime;
|
||||
struct tm *newtime;
|
||||
|
||||
unsigned NumLinks = 0;
|
||||
int HashDimension = g_HashLinks.pfnDispersion( NULL ) - 1 ;
|
||||
for( ; HashDimension>=0; HashDimension--)
|
||||
NumLinks += LDT_DSAr_GetSize( g_HashLinks.pData + HashDimension );
|
||||
TotalNumLinks += NumLinks - CurrentLinks;
|
||||
|
||||
FlushTime.TimeCounter = TotalFlushtime.TimeCounter - FlushTime.TimeCounter;
|
||||
SolveTime.TimeCounter = Totalsolvetime.TimeCounter - SolveTime.TimeCounter;
|
||||
Readtime.TimeCounter = Totalreadtime.TimeCounter - Readtime.TimeCounter;
|
||||
Postprtime.TimeCounter = TotalPostprtime.TimeCounter - Postprtime.TimeCounter;
|
||||
FileCount = TotalFileCount - FileCount;
|
||||
FileSize = TotalFileSize - FileSize;
|
||||
|
||||
time( &strTime );
|
||||
newtime = localtime( &strTime );
|
||||
fprintf(file, "-------------------------------------------\n" );
|
||||
fprintf(file, "Flush Stats:\n\n" );
|
||||
|
||||
fprintf(file, "Flush Time:\t\t%.3f\n", ReadTimer(&FlushTime) );
|
||||
fprintf(file, "Read Time:\t\t%.3f\n", ReadTimer(&Readtime) );
|
||||
#ifdef LDT_MULTITHREADED
|
||||
fprintf(file, "Process Time:\t\t%.3f\n", ReadTimer(&SolveTime) );
|
||||
#else
|
||||
TempTimer.TimeCounter = SolveTime.TimeCounter - Readtime.TimeCounter;
|
||||
fprintf(file, "Process Time:\t\t%.3f\n", ReadTimer(&TempTimer));
|
||||
#endif
|
||||
fprintf(file, "Postprocess Time:\t%.3f\n", ReadTimer(&Postprtime) );
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
{
|
||||
TempTimer.TimeCounter = Postprtime.TimeCounter + SolveTime.TimeCounter + Readtime.TimeCounter;
|
||||
fprintf(file, "\nMultithreaded disk read performance:\n");
|
||||
fprintf(file, "Useful Time:\t\t%.3f\n", ReadTimer(&TempTimer));
|
||||
fprintf(file, "Absloute Time Gain:\t%.3f\n", ReadTimer(&TempTimer) - ReadTimer(&FlushTime));
|
||||
TempTimer.TimeCounter -= FlushTime.TimeCounter;
|
||||
fprintf(file, "Disk Read Savings: \t%.1f%%\n", (ReadTimer(&TempTimer))*100/ReadTimer(&Readtime));
|
||||
}
|
||||
#endif
|
||||
|
||||
fprintf(file, "\nSections:\t\t%u", NumLinks - CurrentLinks );
|
||||
fprintf(file, "\nFiles:\t\t\t%u", FileCount );
|
||||
fprintf(file, "\nRead:\t\t\t%.3f MB\n\n", FileSize/1024/1024 );
|
||||
|
||||
fprintf(file, "-------------------------------------------\n" );
|
||||
fprintf(file, "\n\n\n");
|
||||
fclose(file);
|
||||
|
||||
}
|
||||
#endif /* LDT_LOG_STATISTICS */
|
||||
|
||||
FlushLaunched = 0; /* sentinel removal */
|
||||
return OK; /* return the error code */
|
||||
}
|
||||
|
||||
|
||||
/* In-callback link manipulation functions
|
||||
-------------------------------------*/
|
||||
|
||||
void LDT_SetVolatileSubsection( LDT_tdst_Link* Link)
|
||||
{
|
||||
Link->dwFlags |= LDT_LF_VOLATILE;
|
||||
}
|
356
Rayman_X/cpa/tempgrp/ldt/Src/LINK.BAK
Normal file
356
Rayman_X/cpa/tempgrp/ldt/Src/LINK.BAK
Normal file
@@ -0,0 +1,356 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Link.c
|
||||
CREATED : 19/05/97
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: linktable/position functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Register.h"
|
||||
#include "Parser.h"
|
||||
|
||||
/* Globals
|
||||
-------------*/
|
||||
|
||||
tdst_DSHash g_HashLinks; /* the linktable */
|
||||
tdst_DSArray g_ArRefs; /* thereferences, grouped by file */
|
||||
tdst_DSArray g_ArFilenames; /* thefilename strings */
|
||||
|
||||
int InstanceCount = 0; /* init counter */
|
||||
|
||||
char LDT_EMPTY_STR[1] = {0};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : computes the dispersion value for a link
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Link_Dispersion( LDT_tdst_Link* pObj )
|
||||
{
|
||||
char* szName;
|
||||
unsigned char pHashVal = 0;
|
||||
if( !pObj ) return 256;
|
||||
szName = (pObj->dwFlags & LDT_LF_FILE)? pObj->szFile: pObj->szName;
|
||||
while(*szName) pHashVal = (unsigned char) ( (pHashVal<<5) + pHashVal + *szName++);
|
||||
return pHashVal;
|
||||
/*/
|
||||
unsigned long pHashVal = 0;
|
||||
if( !pObj ) return 65536;
|
||||
szName = (pObj->dwFlags & LDT_LF_FILE)? pObj->szFile: pObj->szName;
|
||||
while(*szName) pHashVal = ((pHashVal<<7) + pHashVal + *szName++);
|
||||
return (unsigned short)pHashVal;*/
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two links
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Links(const void** _pA, const void** _pB)
|
||||
{
|
||||
LDT_tdst_Link* A = (LDT_tdst_Link*) *_pA;
|
||||
LDT_tdst_Link* B = (LDT_tdst_Link*) *_pB;
|
||||
|
||||
int Result = A->szFile - B->szFile;
|
||||
if(Result == 0)
|
||||
{
|
||||
Result = A->Type - B->Type;
|
||||
if(Result == 0)
|
||||
{
|
||||
Result = strcmp( A->szParent, B->szParent);
|
||||
if(Result == 0)
|
||||
Result = strcmp( A->szName, B->szName );
|
||||
}
|
||||
}
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a link record, given its description
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_Link* LDT_CreateLinkFromReference( char* szSection ) /* the section description */
|
||||
{
|
||||
unsigned long dwFlags = 0;
|
||||
LDT_tdst_CallbackEntry* Type;
|
||||
|
||||
LDT_tdst_Link* Link = NULL;
|
||||
char *szType, *szParent = NULL, *szName = NULL, *szFile = NULL;
|
||||
|
||||
/* convert the input string to lower case */
|
||||
char *sz=szSection;
|
||||
for( ; *sz; sz++ )
|
||||
if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
*sz+='a'-'A';
|
||||
|
||||
|
||||
szParent = strchr( szSection, '^'); /* get the parent description */
|
||||
szType = strrchr( szSection, '^'); /* get the section type name */
|
||||
|
||||
/* get the section type */
|
||||
if(!szType)
|
||||
{
|
||||
/* the reference is to a file */
|
||||
dwFlags = LDT_LF_FILE;
|
||||
if((szType = strrchr( szSection, '.' )) != NULL)
|
||||
szType++;
|
||||
Type = GetType( szType, LDT_REG_FILE );
|
||||
szType = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the reference is to a section */
|
||||
szName = strrchr(szType, ':'); /* get the section name */
|
||||
if(szName) *szName++ = 0;
|
||||
*szType = 0;
|
||||
Type = GetType( szType+1, LDT_REG_SECTION);
|
||||
if( szType == szParent ) szParent = NULL;
|
||||
else *szParent++ = 0;
|
||||
}
|
||||
|
||||
/* get the name of the file (in which the section is located) */
|
||||
if( *szSection == '*')/* the current file */
|
||||
{
|
||||
if( g_FileDesc ) szFile = g_FileDesc->szFile; /* we are inside a file, all correct */
|
||||
}
|
||||
else
|
||||
{ /* an absolute path */
|
||||
int iidx, idx = DSAr_Index( &g_ArFilenames, szSection, &iidx );
|
||||
if(idx>=0) szFile = g_ArFilenames.pData[idx]; /* we have it in the string table */
|
||||
else
|
||||
{ /* the filename is not present in the string table - it is added now */
|
||||
strcpy( szFile = (char*) malloc( strlen(szSection) + 1 ), szSection);
|
||||
DSAr_InsertAt(&g_ArFilenames, iidx, szFile );
|
||||
}
|
||||
}
|
||||
|
||||
if( szFile )
|
||||
{
|
||||
/* we have a valid section description */
|
||||
Link= (LDT_tdst_Link *) malloc( sizeof( LDT_tdst_Link ) );
|
||||
if( szName && *szName)
|
||||
{
|
||||
Link->szName=(char*) malloc( strlen( szName ) +1 );
|
||||
strcpy( Link->szName, szName );
|
||||
}
|
||||
else Link->szName=LDT_EMPTY_STR;
|
||||
if( szParent )
|
||||
{
|
||||
Link->szParent=(char*) malloc( strlen( szParent) +1 );
|
||||
strcpy( Link->szParent, szParent );
|
||||
}
|
||||
else Link->szParent=LDT_EMPTY_STR;
|
||||
|
||||
Link->szFile = szFile;
|
||||
Link->Type = Type;
|
||||
Link->dwFlags = dwFlags;
|
||||
Link->pObject = NULL;
|
||||
Link->pParent = g_CrtSection;
|
||||
}
|
||||
|
||||
if( szType) *( szType ) = '^';
|
||||
if( szName ) *( szName-1 ) = ':';
|
||||
if( szParent) *( szParent -1 ) = '^';
|
||||
return Link;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a link record
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_Link* LDT_Create_Link( char* szName, /* the section name */
|
||||
char* szParent, /* the section parent */
|
||||
char* szFile, /* the file containing the section - stored in a string table */
|
||||
LDT_tdst_CallbackEntry* Type,
|
||||
unsigned long dwFlags, /* flags */
|
||||
void* pObject, /* the allocated memory structure or NULL */
|
||||
LDT_tdst_Link* pParent) /* the section that requested the loading */
|
||||
{
|
||||
LDT_tdst_Link *Link;
|
||||
if (!Type) return NULL;
|
||||
|
||||
Link = (LDT_tdst_Link *) malloc( sizeof( LDT_tdst_Link ) );
|
||||
if( szName && *szName )
|
||||
{
|
||||
Link->szName=(char*) malloc( strlen( szName ) +1 );
|
||||
strcpy( Link->szName, szName );
|
||||
}
|
||||
else Link->szName=LDT_EMPTY_STR;
|
||||
if( szParent && *szParent )
|
||||
{
|
||||
Link->szParent=(char*) malloc( strlen( szParent) +1 );
|
||||
strcpy( Link->szParent, szParent );
|
||||
}
|
||||
else Link->szParent=LDT_EMPTY_STR;
|
||||
|
||||
Link->szFile = szFile;
|
||||
Link->Type = Type;
|
||||
Link->dwFlags = dwFlags;
|
||||
Link->pObject = pObject;
|
||||
Link->pParent = pParent;
|
||||
|
||||
return Link;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : destroys a link record
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void LDT_Delete_Link( LDT_tdst_Link *Link )
|
||||
{
|
||||
if( Link->szName != LDT_EMPTY_STR ) free( Link->szName );
|
||||
if( Link->szParent != LDT_EMPTY_STR ) free( Link->szParent );
|
||||
free(Link);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : deletes an existing array
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Positions(const void** _pA, const void** _pB)
|
||||
{
|
||||
LDT_tdst_Position* A = (LDT_tdst_Position*) *_pA;
|
||||
LDT_tdst_Position* B = (LDT_tdst_Position*) *_pB;
|
||||
int Result = strcmp( A->szName, B->szName );
|
||||
if(Result == 0)
|
||||
{
|
||||
Result = A->Type - B->Type ;
|
||||
if(Result == 0)
|
||||
Result = strcmp( A->szParent, B->szParent);
|
||||
}
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a section position record
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Mircea Petrescu
|
||||
MODIFIED: Catalin Cocos 98/05/22
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
LDT_tdst_Position *LDT_Create_Position( char *szName,
|
||||
char *szParent,
|
||||
LDT_tdst_CallbackEntry* Type,
|
||||
unsigned short uwFlags,
|
||||
unsigned long ulPos,
|
||||
unsigned long nLine,
|
||||
int iLevel
|
||||
)
|
||||
{
|
||||
LDT_tdst_Position *pos= (LDT_tdst_Position *) malloc( sizeof( LDT_tdst_Position ) );
|
||||
if( szName )
|
||||
{
|
||||
pos->szName=(char*) malloc( strlen( szName ) +1 );
|
||||
strcpy( pos->szName, szName );
|
||||
}
|
||||
else pos->szName=LDT_EMPTY_STR;
|
||||
if( szParent )
|
||||
{
|
||||
pos->szParent=(char*) malloc( strlen( szParent) +1 );
|
||||
strcpy( pos->szParent, szParent );
|
||||
}
|
||||
else pos->szParent=LDT_EMPTY_STR;
|
||||
|
||||
pos->Type = Type;
|
||||
pos->uwFlags=uwFlags;
|
||||
pos->dwPos=ulPos;
|
||||
pos->nLine = nLine;
|
||||
pos->iLevel=iLevel;
|
||||
return pos;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : destroys a section position record
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void LDT_Delete_Position( LDT_tdst_Position *pos )
|
||||
{
|
||||
if( pos->szName != LDT_EMPTY_STR ) free( pos->szName );
|
||||
if( pos->szParent != LDT_EMPTY_STR ) free( pos->szParent );
|
||||
free( pos );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two names
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Strings(const void** _pA, const void** _pB)
|
||||
{
|
||||
int Result = strcmp( (char*)(*_pA), (char*)(*_pB) );
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/* Reference - related */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Adds a reference in the reference structure
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void AddReference( LDT_tdst_Link* pLink )
|
||||
{
|
||||
int idx, position;
|
||||
tdst_DSArray* pRefs;
|
||||
idx = DSAr_Index( &g_ArRefs, (LDT_tdst_Refs*) pLink, &position );
|
||||
if( idx<0 )
|
||||
{
|
||||
LDT_tdst_Refs* pNewRef = (LDT_tdst_Refs*) malloc( sizeof(LDT_tdst_Refs));
|
||||
pNewRef->szFile = pLink->szFile;
|
||||
pRefs = &(pNewRef->Links);
|
||||
DSAr_Init( pRefs );
|
||||
DSAr_SetSortMethod( pRefs, LDT_Compare_Links );
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
pNewRef->pFile = NULL;
|
||||
EnterCriticalSection( &GReadExclusion );
|
||||
#endif
|
||||
DSAr_InsertAt( &g_ArRefs, idx = position, pNewRef );
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
ReleaseSemaphore( GFileLimit, 1, NULL ); /* a new file is available for reading */
|
||||
LeaveCriticalSection( &GReadExclusion );
|
||||
#endif
|
||||
}
|
||||
pRefs = &( ((LDT_tdst_Refs*)g_ArRefs.pData[idx])->Links); /* the reference collection */
|
||||
if( pLink->dwFlags & LDT_LF_FILE )
|
||||
{
|
||||
/* the whole file is to be added */
|
||||
DSAr_RemoveAll( pRefs ); /* remove all the existing references */
|
||||
DSAr_Add( pRefs, pLink ); /* add the unique reference to the file */
|
||||
}
|
||||
else
|
||||
{
|
||||
if(DSAr_GetSize( pRefs ) && (((LDT_tdst_Link*)pRefs->pData[0])->dwFlags & LDT_LF_FILE ) )
|
||||
return;
|
||||
DSAr_SAdd( pRefs, pLink, 0, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two refs
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Refs(const void** _pA, const void** _pB)
|
||||
{
|
||||
int Result = ((LDT_tdst_Refs*)*_pA)->szFile - ((LDT_tdst_Refs*)*_pB)->szFile;
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
407
Rayman_X/cpa/tempgrp/ldt/Src/LINK.C
Normal file
407
Rayman_X/cpa/tempgrp/ldt/Src/LINK.C
Normal file
@@ -0,0 +1,407 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Link.c
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: linktable/position functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Register.h"
|
||||
#include "Parser.h"
|
||||
#include "Error.h"
|
||||
|
||||
/* Globals
|
||||
-------------*/
|
||||
|
||||
LDT_tdst_DSHash g_HashLinks; /* the linktable */
|
||||
LDT_tdst_DSArray g_ArRefs; /* the references, grouped by file */
|
||||
LDT_tdst_DSArray g_ArFilenames; /* the filename strings */
|
||||
LDT_tdst_Refs* g_pFileToProcess = NULL; /* the file to load */
|
||||
LDT_tdst_Refs* g_pLastFileQueued = NULL; /* the last fiel referenced */
|
||||
#ifdef LDT_MULTITHREADED
|
||||
LDT_tdst_Refs* g_pFileToRead = NULL; /* the file to read */
|
||||
#endif
|
||||
|
||||
extern unsigned short g_usLinkingPerstincence;
|
||||
|
||||
char LDT_EMPTY_STR[1] = {0};
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : methods to allow external access to the list of filenames
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_GetReferencedFilesNumber()
|
||||
{
|
||||
return g_ArFilenames.nSize;
|
||||
}
|
||||
|
||||
const char* LDT_GetReferencedFile(int idx)
|
||||
{
|
||||
return (const char*) LDT_DSAr_GetAt(&g_ArFilenames, idx);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : computes the dispersion value for a link
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
#pragma warning ( disable: 4244)
|
||||
int LDT_Link_Dispersion( LDT_tdst_Link* pObj )
|
||||
{
|
||||
char* szName;
|
||||
unsigned char pHashVal = 0;
|
||||
if( !pObj ) return 256;
|
||||
szName = (pObj->dwFlags & LDT_LF_FILE)? pObj->szFile: pObj->szName;
|
||||
// while(*szName) pHashVal = (unsigned char) ( (pHashVal<<5) + pHashVal + *szName++);
|
||||
/* hash computing is CASE INSENSITIVE */
|
||||
while(*szName)
|
||||
pHashVal += (unsigned char) ( (pHashVal<<5) | 0xDF&*szName++);
|
||||
return pHashVal;
|
||||
}
|
||||
#pragma warning ( default: 4244)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two links
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Links(const void** _pA, const void** _pB)
|
||||
{
|
||||
LDT_tdst_Link* A = (LDT_tdst_Link*) *_pA;
|
||||
LDT_tdst_Link* B = (LDT_tdst_Link*) *_pB;
|
||||
|
||||
int Result = A->szFile - B->szFile;
|
||||
if(Result == 0)
|
||||
{
|
||||
Result = A->Type - B->Type;
|
||||
if(Result == 0)
|
||||
{
|
||||
Result = stricmp( A->szParent, B->szParent);
|
||||
if(Result == 0)
|
||||
Result = stricmp( A->szName, B->szName );
|
||||
}
|
||||
}
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two links
|
||||
CREATED : 98/08/27
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_LinkValues(const void** _pA, const void** _pB)
|
||||
{
|
||||
long Result = ((LDT_tdst_LinkValue*)*_pA)->pLink - ((LDT_tdst_LinkValue*)*_pB)->pLink;
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a link record, given its description
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_Link* LDT_CreateLinkFromReference( char* szSection ) /* the section description */
|
||||
{
|
||||
unsigned long dwFlags = g_usLinkingPerstincence;
|
||||
LDT_tdst_CallbackEntry* Type;
|
||||
|
||||
LDT_tdst_Link* Link = NULL;
|
||||
char *szType, *szParent = NULL, *szName = NULL, *szFile = NULL;
|
||||
|
||||
/* cut the ':^' from the section desc.*/
|
||||
char *sz=szSection;
|
||||
int delta = 0;
|
||||
for( ; *sz; sz++ )
|
||||
if( *sz == ':' && (sz[1] == '^' || !sz[1]))
|
||||
delta--;
|
||||
else sz[delta]=*sz;
|
||||
|
||||
sz[delta]=0;
|
||||
|
||||
szParent = strchr( szSection, '^'); /* get the parent description */
|
||||
szType = strrchr( szSection, '^'); /* get the section type name */
|
||||
|
||||
/* get the section type */
|
||||
if(!szType)
|
||||
{
|
||||
/* the reference is to a file */
|
||||
dwFlags |= LDT_LF_FILE;
|
||||
if((szType = strrchr( szSection, '.' )) != NULL)
|
||||
szType++;
|
||||
Type = GetType( szType, LDT_REG_FILE );
|
||||
szType = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the reference is to a section */
|
||||
szName = strrchr(szType, ':'); /* get the section name */
|
||||
if(szName) *szName++ = 0;
|
||||
*szType = 0;
|
||||
Type = GetType( szType+1, LDT_REG_SECTION);
|
||||
if( szType == szParent ) szParent = NULL;
|
||||
else *szParent++ = 0;
|
||||
}
|
||||
|
||||
/* get the name of the file (in which the section is located) */
|
||||
if( *szSection == '*')/* the current file */
|
||||
{
|
||||
if( g_FileDesc ) szFile = g_FileDesc->szFile; /* we are inside a file, all correct */
|
||||
}
|
||||
else
|
||||
{ /* an absolute path */
|
||||
int iidx, idx = LDT_DSAr_Index( &g_ArFilenames, szSection, &iidx );
|
||||
if(idx>=0) szFile = g_ArFilenames.pData[idx]; /* we have it in the string table */
|
||||
else
|
||||
{ /* the filename is not present in the string table - it is added now */
|
||||
strcpy( szFile = (char*) malloc( strlen(szSection) + 1 ), szSection);
|
||||
LDT_DSAr_InsertAt(&g_ArFilenames, iidx, szFile );
|
||||
}
|
||||
}
|
||||
|
||||
if( szFile )
|
||||
{
|
||||
/* we have a valid section description */
|
||||
Link= (LDT_tdst_Link *) malloc( sizeof( LDT_tdst_Link ) );
|
||||
if( szName && *szName)
|
||||
{
|
||||
Link->szName=(char*) malloc( strlen( szName ) +1 );
|
||||
strcpy( Link->szName, szName );
|
||||
}
|
||||
else Link->szName=LDT_EMPTY_STR;
|
||||
if( szParent )
|
||||
{
|
||||
Link->szParent=(char*) malloc( strlen( szParent) +1 );
|
||||
strcpy( Link->szParent, szParent );
|
||||
}
|
||||
else Link->szParent=LDT_EMPTY_STR;
|
||||
|
||||
Link->szFile = szFile;
|
||||
Link->Type = Type;
|
||||
Link->dwFlags = dwFlags;
|
||||
Link->pObject = NULL;
|
||||
Link->pParent = g_CrtSection;
|
||||
Link->wUnsolvedRefs = 0; /* MP - postprocess */
|
||||
}
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
else
|
||||
ERRoR(0, NULL, 0, "Unable to create Link. Invalid Link Description");
|
||||
#endif
|
||||
|
||||
if( szType) *( szType ) = '^';
|
||||
if( szName ) *( szName-1 ) = ':';
|
||||
if( szParent) *( szParent -1 ) = '^';
|
||||
return Link;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a link record
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_Link* LDT_Create_Link( char* szName, /* the section name */
|
||||
char* szParent, /* the section parent */
|
||||
char* szFile, /* the file containing the section - stored in a string table */
|
||||
LDT_tdst_CallbackEntry* Type,
|
||||
unsigned long dwFlags, /* flags */
|
||||
void* pObject, /* the allocated memory structure or NULL */
|
||||
LDT_tdst_Link* pParent) /* the section that requested the loading */
|
||||
{
|
||||
LDT_tdst_Link *Link;
|
||||
if (!Type) return NULL;
|
||||
|
||||
Link = (LDT_tdst_Link *) malloc( sizeof( LDT_tdst_Link ) );
|
||||
if( szName && *szName )
|
||||
{
|
||||
Link->szName=(char*) malloc( strlen( szName ) +1 );
|
||||
strcpy( Link->szName, szName );
|
||||
}
|
||||
else Link->szName=LDT_EMPTY_STR;
|
||||
if( szParent && *szParent )
|
||||
{
|
||||
Link->szParent=(char*) malloc( strlen( szParent) +1 );
|
||||
strcpy( Link->szParent, szParent );
|
||||
}
|
||||
else Link->szParent=LDT_EMPTY_STR;
|
||||
|
||||
Link->szFile = szFile;
|
||||
Link->Type = Type;
|
||||
Link->dwFlags = dwFlags;
|
||||
Link->pObject = pObject;
|
||||
Link->pParent = pParent;
|
||||
Link->wUnsolvedRefs = 0; /* MP - postprocess */
|
||||
|
||||
return Link;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : destroys a link record
|
||||
CREATED : 98/05/21
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void LDT_Delete_Link( LDT_tdst_Link *Link )
|
||||
{
|
||||
if( Link->szName != LDT_EMPTY_STR ) free( Link->szName );
|
||||
if( Link->szParent != LDT_EMPTY_STR ) free( Link->szParent );
|
||||
free(Link);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : deletes an existing array
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Positions(const void** _pA, const void** _pB)
|
||||
{
|
||||
LDT_tdst_Position* A = (LDT_tdst_Position*) *_pA;
|
||||
LDT_tdst_Position* B = (LDT_tdst_Position*) *_pB;
|
||||
int Result = A->Type - B->Type ;
|
||||
if(Result == 0)
|
||||
{
|
||||
Result = stricmp( A->szParent, B->szParent);
|
||||
if(Result == 0)
|
||||
Result = stricmp( A->szName, B->szName );
|
||||
}
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : creates a section position record
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Mircea Petrescu
|
||||
MODIFIED: Catalin Cocos 98/05/22
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
LDT_tdst_Position *LDT_Create_Position( char *szName,
|
||||
char *szParent,
|
||||
LDT_tdst_CallbackEntry* Type,
|
||||
unsigned short uwFlags,
|
||||
unsigned long ulPos,
|
||||
unsigned long nLine,
|
||||
int iLevel
|
||||
)
|
||||
{
|
||||
LDT_tdst_Position *pos= (LDT_tdst_Position *) malloc( sizeof( LDT_tdst_Position ) );
|
||||
if( szName )
|
||||
{
|
||||
pos->szName=(char*) malloc( strlen( szName ) +1 );
|
||||
strcpy( pos->szName, szName );
|
||||
}
|
||||
else pos->szName=LDT_EMPTY_STR;
|
||||
if( szParent )
|
||||
{
|
||||
pos->szParent=(char*) malloc( strlen( szParent) +1 );
|
||||
strcpy( pos->szParent, szParent );
|
||||
}
|
||||
else pos->szParent=LDT_EMPTY_STR;
|
||||
|
||||
pos->Type = Type;
|
||||
pos->uwFlags=uwFlags;
|
||||
pos->dwPos=ulPos;
|
||||
pos->nLine = nLine;
|
||||
pos->iLevel=iLevel;
|
||||
return pos;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : destroys a section position record
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void LDT_Delete_Position( LDT_tdst_Position *pos )
|
||||
{
|
||||
if( pos->szName != LDT_EMPTY_STR ) free( pos->szName );
|
||||
if( pos->szParent != LDT_EMPTY_STR ) free( pos->szParent );
|
||||
free( pos );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two names
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Strings(const void** _pA, const void** _pB)
|
||||
{
|
||||
int Result = stricmp( (char*)(*_pA), (char*)(*_pB) );
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
/* Reference - related */
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Adds a reference in the reference structure
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
void AddReference( LDT_tdst_Link* pLink )
|
||||
{
|
||||
int idx, position;
|
||||
LDT_tdst_DSArray* pRefs;
|
||||
idx = LDT_DSAr_Index( &g_ArRefs, (LDT_tdst_Refs*) pLink, &position );
|
||||
if( idx<0 )
|
||||
{
|
||||
LDT_tdst_Refs* pNewRef = (LDT_tdst_Refs*) malloc( sizeof(LDT_tdst_Refs));
|
||||
pNewRef->p_NextReferencedFile = NULL; /* this is the last file referenced */
|
||||
pNewRef->szFile = pLink->szFile;
|
||||
pRefs = &(pNewRef->Links);
|
||||
LDT_DSAr_Init( pRefs );
|
||||
LDT_DSAr_SetSortMethod( pRefs, LDT_Compare_Links );
|
||||
LDT_DSAr_SetGranularity( pRefs, 50 );
|
||||
|
||||
LDT_DSAr_InsertAt( &g_ArRefs, idx = position, pNewRef );
|
||||
|
||||
if(g_pFileToProcess) g_pLastFileQueued->p_NextReferencedFile = pNewRef; /* insert the reference in the list of files to load... */
|
||||
else g_pFileToProcess = pNewRef;
|
||||
g_pLastFileQueued = pNewRef;
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
EnterCriticalSection( &GReadExclusion );
|
||||
if(!g_pFileToRead)
|
||||
g_pFileToRead = pNewRef;
|
||||
LeaveCriticalSection( &GReadExclusion );
|
||||
pNewRef->pFile = NULL;
|
||||
if(GFileLimit)
|
||||
ReleaseSemaphore( GFileLimit, 1, NULL ); /* a new file is available for reading */
|
||||
#endif
|
||||
}
|
||||
pRefs = &( ((LDT_tdst_Refs*)g_ArRefs.pData[idx])->Links); /* the reference collection */
|
||||
if( pLink->dwFlags & LDT_LF_FILE )
|
||||
{
|
||||
/* the whole file is to be added */
|
||||
LDT_DSAr_RemoveAll( pRefs ); /* remove all the existing references */
|
||||
LDT_DSAr_Add( pRefs, pLink ); /* add the unique reference to the file */
|
||||
}
|
||||
else
|
||||
{
|
||||
if(LDT_DSAr_GetSize( pRefs ) && (((LDT_tdst_Link*)pRefs->pData[0])->dwFlags & LDT_LF_FILE ) )
|
||||
return;
|
||||
LDT_DSAr_SAdd( pRefs, pLink, 0, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : Compares two refs
|
||||
CREATED : 98/05/22
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_Refs(const void** _pA, const void** _pB)
|
||||
{
|
||||
int Result = ((LDT_tdst_Refs*)*_pA)->szFile - ((LDT_tdst_Refs*)*_pB)->szFile;
|
||||
if( Result<0 ) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
136
Rayman_X/cpa/tempgrp/ldt/Src/Mem.c
Normal file
136
Rayman_X/cpa/tempgrp/ldt/Src/Mem.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
* Mem.c
|
||||
* Managment of memory.
|
||||
* CPA_Ed_1 team
|
||||
*
|
||||
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
*/
|
||||
|
||||
/*
|
||||
*=================================================================================================
|
||||
* Includes.
|
||||
*=================================================================================================
|
||||
*/
|
||||
|
||||
/* conditional compilation */
|
||||
|
||||
#ifdef LDT_USE_MMG
|
||||
|
||||
#include "StdInc.h"
|
||||
|
||||
|
||||
#if !defined(U64)
|
||||
|
||||
#define __DeclareGlobalVariableMmgLDT_h__
|
||||
#define __DeclareGlobalVariableErrLDT_h__
|
||||
|
||||
#include "Mem.h"
|
||||
|
||||
#include "ErrLDT.h" /* ERM */
|
||||
#include "MmgLDT.h" /* MMG */
|
||||
|
||||
#undef __DeclareGlobalVariableMmgLDT_h__
|
||||
#undef __DeclareGlobalVariableErrLDT_h__
|
||||
|
||||
#endif /* U64 */
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
* malloc
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void* LDT_malloc_Mmg(size_t _size)
|
||||
{
|
||||
void* _Pointer;
|
||||
Mmg_M_SetModeAlloc4Ch(LDT, E_ucDynamic, C_ucMmgDefaultChannel);
|
||||
_Pointer = Mmg_fn_p_vAlloc4Ch(_size, C_ucMmgDefaultChannel);
|
||||
if(Erm_M_uwCheckError(Mmg, C_ucErmDefaultChannel))
|
||||
Erm_M_ClearLastError(C_ucErmDefaultChannel);
|
||||
if(_Pointer == NULL){};
|
||||
return _Pointer;
|
||||
}
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
* realloc
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void *LDT_realloc_Mmg(void * _PointerSrc, size_t _Size)
|
||||
{
|
||||
|
||||
Mmg_M_SetModeAlloc4Ch(LDT, E_ucDynamic, C_ucMmgDefaultChannel);
|
||||
_PointerSrc = Mmg_fn_p_vRealloc4Ch(_PointerSrc, _Size , C_ucMmgDefaultChannel);
|
||||
if(Erm_M_uwCheckError(Mmg, C_ucErmDefaultChannel))
|
||||
Erm_M_ClearLastError(C_ucErmDefaultChannel);
|
||||
if(_PointerSrc == NULL) { };
|
||||
return _PointerSrc;
|
||||
}
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
* free
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void LDT_free_Mmg(void *_Pointer)
|
||||
{
|
||||
if(_Pointer)
|
||||
{
|
||||
Mmg_M_SetModeAlloc4Ch(LDT, E_ucDynamic, C_ucMmgDefaultChannel);
|
||||
if(Erm_M_uwCheckError(Mmg, C_ucErmDefaultChannel))
|
||||
Erm_M_ClearLastError(C_ucErmDefaultChannel);
|
||||
Mmg_fn_vFree4Ch(_Pointer, C_ucMmgDefaultChannel);
|
||||
_Pointer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
* Init of memory managment.
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
void LDT_fn_v_Mem_InitModule(void)
|
||||
{
|
||||
static char s_cFirstInit = 1;
|
||||
|
||||
/* Must init only one time error module (in case of multiple script init/close) */
|
||||
if(s_cFirstInit == 1)
|
||||
{
|
||||
Erm_M_InitErrMsg(LDT);
|
||||
s_cFirstInit = 0;
|
||||
}
|
||||
Mmg_M_InitMmg(LDT);
|
||||
}
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
* Close.
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
void LDT_fn_v_Mem_CloseModule(void)
|
||||
{
|
||||
Mmg_fn_v_StopMmg(Erm_M_ucGiveModuleId(LDT));
|
||||
}
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
* Init of memory managment.
|
||||
* Use of MMG and ERM modules.
|
||||
* _p_ulMemorySize : Address of unsigned long size for blocs. Size if 0 for a dynamic malloc.
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
void LDT_fn_v_Mem_InitWithMemLevel(unsigned long *_p_ulMemorySize)
|
||||
{
|
||||
unsigned char ucIndex;
|
||||
|
||||
for(ucIndex = 0; ucIndex < E_ucLDTMaxBlocksNb; ucIndex++)
|
||||
{
|
||||
Mmg_M_InitBlockV5_1_0(LDT, ucIndex, *_p_ulMemorySize,200000);
|
||||
_p_ulMemorySize++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LDT_USE_MMG */
|
813
Rayman_X/cpa/tempgrp/ldt/Src/PARSER.BAK
Normal file
813
Rayman_X/cpa/tempgrp/ldt/Src/PARSER.BAK
Normal file
@@ -0,0 +1,813 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Parser.c
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
CONTENTS: parsing structures, variables & functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "File.h"
|
||||
#include "DynArray.h"
|
||||
#include "Parser.h"
|
||||
#include "Register.h"
|
||||
#include "Link.h"
|
||||
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
CRITICAL_SECTION GReadExclusion;
|
||||
#endif
|
||||
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
/* Valid characters in a word */
|
||||
|
||||
char tbl[256];
|
||||
|
||||
/* variables used for in place break into words */
|
||||
|
||||
char g_lastChar=0;
|
||||
int g_lastIndex=-1;
|
||||
int parseLen[256], parseCount;
|
||||
unsigned char* parsePos[256];
|
||||
|
||||
/* for in-place word break */
|
||||
unsigned char* g_ulPos=0;
|
||||
|
||||
|
||||
unsigned long g_ulBeginLineMark; /* last begin of line found */
|
||||
|
||||
/* variables for building a complete section name (in case of subsections) */
|
||||
|
||||
char g_szType[512]="";
|
||||
char g_szName[512]="";
|
||||
char g_szParent[512]="";
|
||||
char g_szId[512]="";
|
||||
|
||||
LDT_tdst_FileDesc TheFileDesc, *g_FileDesc=NULL;
|
||||
|
||||
LDT_tdst_Link *g_CrtSection=NULL;
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : initializes character classes for parsing
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void InitParser( void )
|
||||
{
|
||||
char sztmp[]=":^!%&*+-<=>?_|~\\QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890";
|
||||
int i;
|
||||
|
||||
for( i=0; i<128; i++ )
|
||||
tbl[i]= (char)(( strchr( sztmp, (char)i )!=NULL )?1:0 );
|
||||
for( i=128; i<255; i++ )
|
||||
tbl[i]= 1;
|
||||
tbl[255]=0;
|
||||
|
||||
|
||||
tbl[(unsigned char )'\"']=2;
|
||||
tbl[(unsigned char )'[']=3;
|
||||
tbl[(unsigned char )']']=4;
|
||||
tbl[(unsigned char )'$']=5;
|
||||
tbl[(unsigned char )'{']=6;
|
||||
tbl[(unsigned char )'}']=7;
|
||||
tbl[(unsigned char )';']=8;
|
||||
tbl[(unsigned char )'\n']=9;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : access function for word #i in current line
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
MODIFIED: Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
char *LDT_szGetParam( int i )
|
||||
{
|
||||
if( (i<0) || (i>parseCount) )
|
||||
return NULL;
|
||||
|
||||
if( g_FileDesc->iLastIndex!=-1 )
|
||||
*g_ulPos=g_FileDesc->chLastChar;
|
||||
|
||||
g_ulPos = parsePos[i]+parseLen[i];
|
||||
g_FileDesc->chLastChar = *g_ulPos;
|
||||
*g_ulPos = 0;
|
||||
|
||||
g_FileDesc->iLastIndex = i;
|
||||
|
||||
return (char *) parsePos[i];
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : actualize section name and level in file @ begin section
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void BeginSection( void )
|
||||
{
|
||||
char *szName=LDT_szGetParam( 0 );
|
||||
char *szId;
|
||||
|
||||
if( g_szParent[0]!=0 )
|
||||
strcat( g_szParent, "^" );
|
||||
strcat( g_szParent, g_szName );
|
||||
|
||||
strcpy( g_szName, szName );
|
||||
|
||||
szId=strchr( g_szName, ':' );
|
||||
if( szId )
|
||||
{
|
||||
strcpy( g_szId, szId+1 );
|
||||
*szId=0;
|
||||
strcpy( g_szType, g_szName );
|
||||
*szId=':';
|
||||
}
|
||||
else
|
||||
{
|
||||
g_szId[0]=0;
|
||||
strcpy( g_szType, szName );
|
||||
}
|
||||
|
||||
|
||||
if( !(g_FileDesc->uwLoadType) )
|
||||
/* construct file contents in case not loading all file */
|
||||
{
|
||||
DSAr_Add( &g_FileDesc->arContents,
|
||||
(void *) LDT_Create_Position( g_szId, g_szParent, GetType( g_szType, LDT_REG_SECTION ),
|
||||
g_FileDesc->uwFlags, g_ulBeginLineMark, g_FileDesc->iLineNumber,
|
||||
g_FileDesc->iLevel )
|
||||
);
|
||||
}
|
||||
|
||||
g_FileDesc->iLevel++;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : actualize section name and level in file @ end section
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void EndSection( void )
|
||||
{
|
||||
char *szTmp, *szTmp1;
|
||||
int erase=0;
|
||||
g_FileDesc->iLevel--;
|
||||
szTmp=strrchr( g_szParent, '^' ); /* get last child in parent xxx:xx^xxx:xx^XXX:XX */
|
||||
if( szTmp ) /* if we have a child ( parent is not xxx:xx )*/
|
||||
{
|
||||
*szTmp=0; /* cut it from parent */
|
||||
szTmp++;
|
||||
}
|
||||
else {
|
||||
szTmp=g_szParent; /* only one section name */
|
||||
erase=1; /* so erase it after we extract child */
|
||||
}
|
||||
strcpy( g_szName, szTmp ); /* CC - moved this line here !!! the copy is always needed /// paste it to current section name */
|
||||
|
||||
szTmp1=strchr( szTmp, ':' ); /* current name in szTmp */
|
||||
if( szTmp1 )
|
||||
{
|
||||
strcpy( g_szId, szTmp1+1 ); /* split it in Type:Id */
|
||||
*szTmp1=0;
|
||||
}
|
||||
else g_szId[0]=0;
|
||||
|
||||
strcpy( g_szType, szTmp );
|
||||
|
||||
if( erase )
|
||||
g_szParent[0]=0;
|
||||
|
||||
if( g_FileDesc->iLevel==0 ) /* adjust for file level */
|
||||
{
|
||||
g_szName[0]=0;
|
||||
g_szParent[0]=0;
|
||||
g_CrtSection=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : split a line in the component words
|
||||
CREATED : 98/06/29
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int bConvertToLowerCase=0;
|
||||
|
||||
|
||||
void GetWords( LDT_tdst_MemFile* pMemFile, unsigned char* buffer, int bSeek )
|
||||
{
|
||||
int i = 0;
|
||||
if( bSeek )
|
||||
{
|
||||
while( buffer[i] != '\n' ) i++;
|
||||
pMemFile->Pos = buffer +i +1 - (unsigned char *)pMemFile->pBuffer;
|
||||
return;
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
while( tbl[buffer[i]] == 0 ) i++;
|
||||
|
||||
switch( tbl[buffer[i]] )
|
||||
{
|
||||
case 2: /* a string */
|
||||
i++;
|
||||
parsePos[parseCount]= buffer + i;
|
||||
while( buffer[i] != '\"') i++;
|
||||
parseLen[parseCount] = buffer +i -parsePos[parseCount];
|
||||
parseCount++;
|
||||
i++;
|
||||
break;
|
||||
case 3: /* a format specifier -- ignore */
|
||||
while( buffer[i] != ']' && buffer[i] != '\n' ) i++;
|
||||
if(buffer[i] == ']') i++;
|
||||
break;
|
||||
case 8: /* comment - skip the rest of the line */
|
||||
while( buffer[i] != '\n') i++;
|
||||
case 9: /* end of line */
|
||||
pMemFile->Pos = buffer +i +1 - (unsigned char *)pMemFile->pBuffer;
|
||||
return;
|
||||
default: /* an usual word */
|
||||
parsePos[parseCount]= buffer + i;
|
||||
if( bConvertToLowerCase )
|
||||
while( tbl[buffer[i]] == 1 )
|
||||
{
|
||||
if( buffer[i]>='A' && buffer[i]<='Z' )
|
||||
buffer[i] += 'a'-'A';
|
||||
i++;
|
||||
}
|
||||
else
|
||||
while( tbl[buffer[i]] == 1 ) i++;
|
||||
parseLen[parseCount] = buffer +i -parsePos[parseCount];
|
||||
parseCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LDT_tdeParseResult fn_e_ParseLine( int bSeek )
|
||||
{
|
||||
LDT_tdst_MemFile* pMemFile = g_FileDesc->_pInfoMemFile;
|
||||
unsigned char *buffer;
|
||||
|
||||
parseCount=0; /* no words */
|
||||
bConvertToLowerCase = 0; /* no lowercase conversion*/
|
||||
|
||||
if( g_FileDesc->iLastIndex!=-1 )
|
||||
{ /* sentinel - restores the previously requested word */
|
||||
*g_ulPos = g_FileDesc->chLastChar;
|
||||
g_FileDesc->iLastIndex=-1;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if(pMemFile->Pos >= pMemFile->Size) /* the end of file was reached*/
|
||||
return (g_FileDesc->iLevel? ParseResult_EOF: ParseResult_EndSection);
|
||||
|
||||
buffer=(unsigned char *)pMemFile->pBuffer+pMemFile->Pos; /* the line buffer */
|
||||
g_FileDesc->iLineNumber++; /* incrementing the line number */
|
||||
while( tbl[buffer[i]] == 0 ) i++; /* skipping the blank spaces */
|
||||
g_ulBeginLineMark=pMemFile->Pos + i; /* the beginning of the line */
|
||||
|
||||
|
||||
switch( tbl[buffer[i]] )
|
||||
{
|
||||
case 1: /* an entry */
|
||||
GetWords(pMemFile, buffer +i, bSeek);
|
||||
return ParseResult_Entry;
|
||||
case 5: /* directive */
|
||||
bConvertToLowerCase = 1; /* to lowercase */
|
||||
GetWords(pMemFile, buffer +i +1, bSeek);
|
||||
bConvertToLowerCase = 0;
|
||||
|
||||
if(!parseCount) break;
|
||||
switch(*((long*)LDT_szGetParam( 0 )))
|
||||
{
|
||||
case 'crof': g_FileDesc->uwFlags|=LDT_uw_Anl_ForceAnalyse; break; /* "ForceAnalyse" */
|
||||
case 'fdne': g_FileDesc->uwFlags&=~LDT_uw_Anl_ForceAnalyse; break; /* "EndForceAnalyse" */
|
||||
case 'ston': g_FileDesc->uwFlags|=LDT_uw_Anl_NotSaveSection; break; /* "NotSaveSection" */
|
||||
case 'ndne': g_FileDesc->uwFlags&=~LDT_uw_Anl_NotSaveSection; break;/* "EndNotSaveSection"*/
|
||||
case 'ctes': /* "SetCurrentFileLong" || "SetCurrentFileDouble" */
|
||||
if( parseCount != 3 ) break; // TODO : Signal ERROR
|
||||
i = atoi( LDT_szGetParam( 1 ) );
|
||||
if( i<0 || i>7 ) break;
|
||||
if( strcmp( LDT_szGetParam( 0 ), "setcurrentfiledouble" ) )
|
||||
g_FileDesc->ulValues[i]=(unsigned long)atol( LDT_szGetParam( 2 ) );
|
||||
else
|
||||
g_FileDesc->dValues[i]=(double)atof( LDT_szGetParam( 2 ) );
|
||||
break;
|
||||
case 'mmoc': /* "Comments" */
|
||||
for(g_FileDesc->uwFlags|=LDT_uw_Anl_Comments;;) /* parse the file until the "EndComments" directive is found or EOF is reached */
|
||||
{
|
||||
i = 0;
|
||||
if(pMemFile->Pos >= pMemFile->Size) /* the end of file was reached*/
|
||||
return (g_FileDesc->iLevel? ParseResult_EOF: ParseResult_EndSection);
|
||||
|
||||
buffer=(unsigned char *)pMemFile->pBuffer+pMemFile->Pos; /* the line buffer */
|
||||
g_FileDesc->iLineNumber++; /* incrementing the line number */
|
||||
while( tbl[buffer[i]] == 0 ) i++; /* skipping the blank spaces */
|
||||
g_ulBeginLineMark=pMemFile->Pos + i; /* the beginning of the line */
|
||||
|
||||
if(tbl[buffer[i]] == 5)
|
||||
{
|
||||
bConvertToLowerCase = 1;
|
||||
GetWords(pMemFile, buffer +i +1, bSeek);
|
||||
bConvertToLowerCase = 0;
|
||||
if(parseCount && (!strcmp( LDT_szGetParam( 0 ), "endcomments" )))
|
||||
g_FileDesc->uwFlags&=~LDT_uw_Anl_Comments;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
while( tbl[buffer[i]] != 9 ) i++; /* skip the line */
|
||||
pMemFile->Pos = buffer +i +1 - (unsigned char*)pMemFile->pBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6: /* begin of section */
|
||||
bConvertToLowerCase = 1; /* to lowercase */
|
||||
GetWords(pMemFile, buffer +i +1, 0);
|
||||
BeginSection();
|
||||
return ParseResult_BeginSection;
|
||||
case 7: /* end of section */
|
||||
GetWords( pMemFile, buffer +i +1, bSeek);
|
||||
EndSection();
|
||||
return ParseResult_EndSection;
|
||||
case 8: /* a comment */
|
||||
while( tbl[buffer[i]] != 9 ) i++; /* skip the line */
|
||||
case 9: /* an empty line */
|
||||
pMemFile->Pos = buffer +i +1 - (unsigned char*)pMemFile->pBuffer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : get next entry in section ( or begin/end section )
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
LDT_tdeParseResult LDT_GetNextEntry( void )
|
||||
{
|
||||
return fn_e_ParseLine(0);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : various access functions for callbacks
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
char *LDT_szGetSectionName()
|
||||
{
|
||||
return g_szId;
|
||||
}
|
||||
|
||||
char *LDT_szGetSectionType()
|
||||
{
|
||||
return g_szType;
|
||||
}
|
||||
|
||||
char *LDT_szGetEntryName()
|
||||
{
|
||||
return LDT_szGetParam(0);
|
||||
}
|
||||
|
||||
int LDT_iGetNbParams()
|
||||
{
|
||||
return parseCount;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : various access functions for file values
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
unsigned long LDT_GetFileLong( int i )
|
||||
{
|
||||
if( !g_FileDesc )
|
||||
return 0;
|
||||
return g_FileDesc->ulValues[i];
|
||||
}
|
||||
|
||||
double LDT_GetFileDouble( int i )
|
||||
{
|
||||
if( !g_FileDesc )
|
||||
return (double)0.0;
|
||||
return g_FileDesc->dValues[i];
|
||||
}
|
||||
|
||||
void LDT_SetFileLong( int i, unsigned long ul )
|
||||
{
|
||||
if( !g_FileDesc )
|
||||
return;
|
||||
g_FileDesc->ulValues[i]=ul;
|
||||
}
|
||||
|
||||
void LDT_SetFileDouble( int i, double d )
|
||||
{
|
||||
if( !g_FileDesc )
|
||||
return;
|
||||
g_FileDesc->dValues[i]=d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : opens a file and fills in the FileDesc
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
MODIFIED: Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int OpenFileDesc( char* szFile, LDT_tdst_MemFile* pFile )
|
||||
{
|
||||
int i;
|
||||
if( !pFile )
|
||||
return -1;
|
||||
|
||||
TheFileDesc.szFile=szFile;
|
||||
TheFileDesc._pInfoMemFile = pFile;
|
||||
|
||||
/* CC : contents initialization -> start */
|
||||
DSAr_Init( &TheFileDesc.arContents );
|
||||
DSAr_SetSortMethod( &TheFileDesc.arContents, LDT_Compare_Positions );
|
||||
DSAr_SetGranularity( &TheFileDesc.arContents, 50 );
|
||||
/* CC : contents initialization -> end */
|
||||
|
||||
TheFileDesc.iLevel=0;
|
||||
TheFileDesc.iLineNumber=0;
|
||||
|
||||
TheFileDesc.iLastIndex=-1;
|
||||
TheFileDesc.chLastChar=0;
|
||||
|
||||
TheFileDesc.uwFlags=0;
|
||||
TheFileDesc.uwLoadType=0; /* CC : Loading Type */
|
||||
|
||||
for( i=0; i<256; i++ )
|
||||
TheFileDesc.ulValues[i]=0;
|
||||
for( i=0; i<8; i++ )
|
||||
TheFileDesc.dValues[i]=0.0;
|
||||
|
||||
g_FileDesc=&TheFileDesc;
|
||||
|
||||
g_szName[0]=0;
|
||||
g_szParent[0]=0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : closes a file and fills in the FileDesc
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void CloseFileDesc( void )
|
||||
{
|
||||
int idx;
|
||||
LDT_M_File_Close( TheFileDesc._pInfoMemFile );
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
ReleaseSemaphore( GReadLimit, 1, NULL); /* signal that the file was closed */
|
||||
#endif
|
||||
|
||||
/* CC : contents clean-up -> start */
|
||||
for(idx = DSAr_GetUpperBound( &TheFileDesc.arContents); idx>=0; idx--)
|
||||
free( TheFileDesc.arContents.pData[idx] );
|
||||
DSAr_RemoveAll( &TheFileDesc.arContents );
|
||||
/* CC : contents clean-up -> end */
|
||||
|
||||
g_FileDesc=NULL;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : positions a file and fills in the FileDesc
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void PositionFile( LDT_tdst_Position *pos )
|
||||
{
|
||||
LDT_M_File_Seek( TheFileDesc._pInfoMemFile, pos->dwPos, SEEK_SET );
|
||||
g_ulBeginLineMark=pos->dwPos;
|
||||
|
||||
TheFileDesc.iLineNumber=pos->nLine;
|
||||
TheFileDesc.iLevel=pos->iLevel;
|
||||
TheFileDesc.uwFlags=pos->uwFlags;
|
||||
|
||||
TheFileDesc.iLastIndex=-1;
|
||||
TheFileDesc.chLastChar=0;
|
||||
|
||||
fn_e_ParseLine( 0 ); /* read the begin section line */
|
||||
}
|
||||
|
||||
LDT_tdst_Link *pParent[100];
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : default create - does nothing
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int LDT_Default_NULL_Create(LDT_tdst_Link *link)
|
||||
{
|
||||
link->pObject = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : skipping a section
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void SkipSection( )
|
||||
{
|
||||
LDT_tdeParseResult result;
|
||||
int iLevel=g_FileDesc->iLevel;
|
||||
|
||||
do{
|
||||
result=fn_e_ParseLine( 0 );
|
||||
}while ((g_FileDesc->iLevel>=iLevel)&&(result !=ParseResult_EOF) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : default loading
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int LDT_Default_Load( LDT_tdst_Link *_Link )
|
||||
{
|
||||
LDT_tdeParseResult result;
|
||||
_Link=_Link;
|
||||
|
||||
do{
|
||||
result=LDT_GetNextEntry();
|
||||
if( result== ParseResult_BeginSection )
|
||||
LDT_LoadSection( NULL );
|
||||
}while ( result!=ParseResult_EndSection );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : load the whole file
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int LoadAllFile( LDT_tdst_Link *link )
|
||||
{
|
||||
int ERRoR = 0;
|
||||
TheFileDesc.uwLoadType=1; /* CC : load-all-file flag */
|
||||
g_CrtSection=pParent[0]= link;
|
||||
if(( link->dwFlags&LDT_LF_LOADED ) == 0)
|
||||
{
|
||||
/* CC ...allowing file closure ->start*/
|
||||
if(( link->dwFlags&LDT_LF_ALLOCATED ) == 0)
|
||||
{
|
||||
ERRoR=link->Type->Create( link ); /* the Type is always !NULL */
|
||||
link->dwFlags |= LDT_LF_ALLOCATED; /* the link was allocated */
|
||||
}
|
||||
if(!ERRoR)
|
||||
{
|
||||
ERRoR = link->Type->Load( link );
|
||||
link->dwFlags |= LDT_LF_LOADED; /* the link was loaded */
|
||||
}
|
||||
/* CC ...allowing file closure ->end*/
|
||||
}
|
||||
return ERRoR;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : loads a list of delayed references ( corresponding to a file )
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
MODIFIED: Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int Solve( LDT_tdst_Refs *refs )
|
||||
{
|
||||
|
||||
LDT_tdst_MemFile* pFile;
|
||||
char bAllFile=0;
|
||||
LDT_tdst_Link *link = NULL, *link1, TmpLink;
|
||||
LDT_tdeParseResult result;
|
||||
LDT_tdst_CallbackEntry *Type;
|
||||
int ERRoR = 0;
|
||||
|
||||
if( DSAr_GetSize( &refs->Links )==1 )
|
||||
{
|
||||
link=(LDT_tdst_Link*)DSAr_GetAt( &refs->Links, 0 );
|
||||
if( link->dwFlags& LDT_LF_FILE )
|
||||
bAllFile=1;
|
||||
}
|
||||
pParent[0]=NULL;
|
||||
|
||||
#ifdef LDT_MULTITHREADED
|
||||
pFile = refs->pFile;
|
||||
#else
|
||||
LDT_M_File_OpenRead(pFile, refs->szFile);
|
||||
#endif
|
||||
|
||||
if( OpenFileDesc( refs->szFile, pFile )) /* open the file */
|
||||
return -1;
|
||||
|
||||
if( bAllFile ) ERRoR = LoadAllFile( link ); /* load all file */
|
||||
else /* load a list of sections */
|
||||
{
|
||||
do{
|
||||
result=fn_e_ParseLine( 1 );
|
||||
switch( result )
|
||||
{
|
||||
case ParseResult_BeginSection:
|
||||
{
|
||||
int index;
|
||||
|
||||
Type = GetType( g_szType, LDT_REG_SECTION );
|
||||
|
||||
TmpLink.szFile = refs->szFile;
|
||||
TmpLink.szParent = g_szParent;
|
||||
TmpLink.szName = g_szId;
|
||||
TmpLink.Type = Type;
|
||||
|
||||
index=DSAr_Index( &refs->Links, &TmpLink, NULL );
|
||||
|
||||
if( index!=-1 )
|
||||
{
|
||||
link1=(LDT_tdst_Link *)DSAr_GetAt( &refs->Links, index );
|
||||
DSAr_RemoveAt( &refs->Links, index );
|
||||
pParent[ g_FileDesc->iLevel ]=link1;
|
||||
g_CrtSection=link1;
|
||||
ERRoR=Type->Load( link1 );
|
||||
if(!ERRoR)
|
||||
link1->dwFlags |= LDT_LF_LOADED; /* the link was loaded */
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}while ( (result !=ParseResult_EOF)&&(DSAr_GetSize(&refs->Links)>0) );
|
||||
|
||||
if(DSAr_GetSize(&refs->Links)>0)
|
||||
DSAr_QSort( &g_FileDesc->arContents );
|
||||
|
||||
while( DSAr_GetSize(&refs->Links)>0 )
|
||||
{
|
||||
LDT_tdst_Position pos, *p;
|
||||
int index=DSAr_GetUpperBound( &refs->Links );
|
||||
link1=(LDT_tdst_Link *)DSAr_GetAt( &refs->Links, index );
|
||||
if( link1->dwFlags&LDT_LF_FILE ) /* all file requested */
|
||||
{
|
||||
int i;
|
||||
/* reset the file */
|
||||
if( g_FileDesc->iLastIndex!=-1 )
|
||||
{ /* sentinel - restores the previously requested word */
|
||||
*g_ulPos = g_FileDesc->chLastChar;
|
||||
g_FileDesc->iLastIndex=-1;
|
||||
}
|
||||
|
||||
LDT_M_File_Seek( TheFileDesc._pInfoMemFile, 0, SEEK_SET );
|
||||
|
||||
TheFileDesc.iLevel=0;
|
||||
TheFileDesc.iLineNumber=0;
|
||||
|
||||
TheFileDesc.iLastIndex=-1;
|
||||
TheFileDesc.chLastChar=0;
|
||||
|
||||
TheFileDesc.uwFlags=0;
|
||||
|
||||
for( i=0; i<8; i++ )
|
||||
{
|
||||
TheFileDesc.ulValues[i]=0;
|
||||
TheFileDesc.dValues[i]=0.0;
|
||||
}
|
||||
|
||||
ERRoR = LoadAllFile( link1 ); /* load all file */
|
||||
|
||||
CloseFileDesc(); /* close the file */
|
||||
return ERRoR;
|
||||
}
|
||||
DSAr_RemoveAt( &refs->Links, index );
|
||||
pos.szName=link1->szName;
|
||||
pos.szParent=link1->szParent;
|
||||
pos.Type=link1->Type;
|
||||
index=DSAr_Index( &g_FileDesc->arContents, (void *)&pos, NULL );
|
||||
if( index<0 )
|
||||
{
|
||||
ERRoR = -1;
|
||||
break;
|
||||
}
|
||||
p=(LDT_tdst_Position *)DSAr_GetAt( &g_FileDesc->arContents, index );
|
||||
PositionFile( p );
|
||||
g_CrtSection=link1;
|
||||
pParent[g_FileDesc->iLevel]=link1;
|
||||
if( (index=link1->Type->Load( link1 )) <0 ) return index;
|
||||
}
|
||||
}
|
||||
|
||||
CloseFileDesc(); /* close the file */
|
||||
return ERRoR;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : loads a subsection
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int GetSubSection( LDT_tdst_Link *link )
|
||||
{
|
||||
g_CrtSection=link;
|
||||
pParent[g_FileDesc->iLevel]=link;
|
||||
return link->Type->Load( link );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : breaks a reference name in file, parent, type, id
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void LDT_SplitSectionName( char *szSection, char *szFile, char *szParent, char *szType, char *szId )
|
||||
{
|
||||
char *szP, *szI, *szT;
|
||||
|
||||
strcpy( szFile, szSection );
|
||||
|
||||
szT=strrchr( szFile, '^' );
|
||||
*szT=0;
|
||||
szT++;
|
||||
|
||||
szI=strrchr( szT, ':' );
|
||||
if( szI )
|
||||
{
|
||||
*szI=0;
|
||||
szI++;
|
||||
strcpy( szId, szI );
|
||||
}
|
||||
else szId[0]=0;
|
||||
|
||||
strcpy( szType, szT );
|
||||
|
||||
szP=strchr( szFile, '^' );
|
||||
if( szP )
|
||||
{
|
||||
*szP=0;
|
||||
szP++;
|
||||
strcpy( szParent, szP );
|
||||
}
|
||||
else szParent[0]=0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : computes name of current section and returns length of file name
|
||||
CREATED : 98/05/17
|
||||
AUTHOR : Mircea Petrescu
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
int LDT_ComputeSectionName( char *buffer )
|
||||
{
|
||||
LDT_tdst_Link* link=g_CrtSection;
|
||||
|
||||
int i=strlen( link->szFile );
|
||||
strcpy( buffer, link->szFile);
|
||||
if( link->szParent[0] )
|
||||
{
|
||||
strcat( buffer, "^" );
|
||||
strcat( buffer, link->szParent );
|
||||
}
|
||||
strcat( buffer, "^" );
|
||||
strcat( buffer, link->Type->szType );
|
||||
if( link->szName[0] )
|
||||
{
|
||||
strcat( buffer, ":" );
|
||||
strcat( buffer, link->szName );
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
1091
Rayman_X/cpa/tempgrp/ldt/Src/PARSER.C
Normal file
1091
Rayman_X/cpa/tempgrp/ldt/Src/PARSER.C
Normal file
File diff suppressed because it is too large
Load Diff
381
Rayman_X/cpa/tempgrp/ldt/Src/Register.c
Normal file
381
Rayman_X/cpa/tempgrp/ldt/Src/Register.c
Normal file
@@ -0,0 +1,381 @@
|
||||
/*------------------------------------------------------------------------------
|
||||
FILE : Register.c
|
||||
CREATED : 98/05/19
|
||||
AUTHOR : Catalin Cocos
|
||||
CONTENTS: callback registering structures & functions
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "Register.h"
|
||||
#include "Interface.h"
|
||||
#include "Error.h"
|
||||
#include "Refs.h"
|
||||
|
||||
/* Globals
|
||||
-------------*/
|
||||
extern int g_nInitialized;
|
||||
|
||||
LDT_tdst_DSArray g_ArSectionCallbacks; /* the section callbacks */
|
||||
LDT_tdst_DSArray g_ArFileCallbacks; /* the file callbacks */
|
||||
LDT_tdst_DSArray g_ArPaths; /* the paths */
|
||||
LDT_tdst_DSArray g_ArPathStrings; /* the path strings */
|
||||
LDT_tdst_DSArray g_ArBaseDirectories; /* the base paths */
|
||||
|
||||
LDT_tdst_CallbackEntry Default_Type = { ".*", LDT_Default_NULL_Create, LDT_Default_Load};
|
||||
|
||||
/* Functions
|
||||
-------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : compares two callback registration entries
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_Compare_CallbackEntries(const void** _pA, const void** _pB)
|
||||
{
|
||||
int Result = stricmp(((LDT_tdst_CallbackEntry*) *_pA)->szType,
|
||||
((LDT_tdst_CallbackEntry*) *_pB)->szType );
|
||||
if(Result < 0) return -1;
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : registers a type
|
||||
INPUT : the type;
|
||||
the pointer to the create callback;
|
||||
pointer to the load callback;
|
||||
Registering mode:
|
||||
LDT_REG_SECTION - registers section callbacks
|
||||
LDT_REG_FILE - registers file callbacks
|
||||
OUTPUT : non-zero if successful, 0 if the type is already registered or
|
||||
if the paramters are invalid
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_RegisterType(char* szType, int (*_Create) ( LDT_tdst_Link* ),
|
||||
int (*_Load) ( LDT_tdst_Link* ),
|
||||
int Mode)
|
||||
{
|
||||
// char *sz;
|
||||
LDT_tdst_DSArray* pAr;
|
||||
LDT_tdst_CallbackEntry* pNewEntry, *pOldEntry;
|
||||
int position;
|
||||
|
||||
if( !g_nInitialized ) return 0; /* table not initialized */
|
||||
if( !szType || !_Create || !_Load ) return 0; /* invalid parameters */
|
||||
pAr = (Mode == LDT_REG_SECTION)? &g_ArSectionCallbacks: &g_ArFileCallbacks; /* select the array*/
|
||||
|
||||
/* convert to lower case */
|
||||
// sz=szType;
|
||||
// for( ; *sz; sz++ )
|
||||
// if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
// *sz+='a'-'A';
|
||||
|
||||
/* create the new entry */
|
||||
pNewEntry = malloc( sizeof(LDT_tdst_CallbackEntry));
|
||||
pNewEntry->szType = szType;
|
||||
pNewEntry->Create = _Create;
|
||||
pNewEntry->Load = _Load;
|
||||
|
||||
if( LDT_DSAr_SAdd( pAr, pNewEntry, 0, &position) < 0 )
|
||||
{
|
||||
/* insertion failed */
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
pOldEntry = LDT_DSAr_GetAt( pAr, position );
|
||||
if( (pOldEntry->Create != _Create) || (pOldEntry->Load != _Load) )
|
||||
ERRoR(0, NULL, 0, "Type already registered. Registration failed.");
|
||||
#endif
|
||||
free( pNewEntry );
|
||||
return 0;
|
||||
}
|
||||
strcpy( pNewEntry->szType = malloc( strlen(szType) + 1 ), szType ); /* copy the type string*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : returns a pointer to the type or NULL if the type is not registered;
|
||||
the parameters have the same signification as in the above function
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_CallbackEntry* LDT_IsTypeRegistered( char* szType, int Mode)
|
||||
{
|
||||
LDT_tdst_DSArray* pAr;
|
||||
|
||||
/* convert to lower case */
|
||||
// char *sz;
|
||||
// sz=szType;
|
||||
// for( ; *sz; sz++ )
|
||||
// if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
// *sz+='a'-'A';
|
||||
|
||||
if( !g_nInitialized ) return NULL; /* table not initialized */
|
||||
if( !szType) return NULL; /* invalid parameter */
|
||||
pAr = (Mode == LDT_REG_SECTION)? &g_ArSectionCallbacks: &g_ArFileCallbacks;
|
||||
return LDT_DSAr_GetAt(pAr, LDT_DSAr_Index( pAr, (LDT_tdst_CallbackEntry*)&szType, NULL ));
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : returns a pointer to the type or the default type if the type is not registered;
|
||||
the parameters have the same signification as in the above function
|
||||
CREATED : 98/05/12
|
||||
NOTE : the input string MUST BE LOWERCASE
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
LDT_tdst_CallbackEntry* GetType( char* szType, int Mode)
|
||||
{
|
||||
LDT_tdst_DSArray* pAr;
|
||||
LDT_tdst_CallbackEntry* pType;
|
||||
|
||||
if(!g_nInitialized || !szType)
|
||||
return &Default_Type;
|
||||
pAr = (Mode == LDT_REG_SECTION)? &g_ArSectionCallbacks: &g_ArFileCallbacks;
|
||||
pType = LDT_DSAr_GetAt(pAr, LDT_DSAr_Index( pAr, (LDT_tdst_CallbackEntry*)&szType, NULL ));
|
||||
if( !pType )
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT) && ( LDT_WARNING_LEVEL >= 3 || LDT_ERROR_LEVEL >= 3)
|
||||
char buffer [300];
|
||||
sprintf(buffer, "The type \"%s\" (%s) is not registered. The default callback will be used.", szType, (Mode == LDT_REG_SECTION)?"SECTION":"FILE");
|
||||
ERRoR((Mode == LDT_REG_SECTION)?3:4, NULL, 0, buffer );
|
||||
#endif
|
||||
return &Default_Type;
|
||||
}
|
||||
return pType;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : unregisters an existing type
|
||||
OUTPUT : non-zero if successful, 0 on error
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_UnregisterType( char* szType, int Mode)
|
||||
{
|
||||
// char *sz;
|
||||
int idx;
|
||||
LDT_tdst_DSArray* pAr;
|
||||
LDT_tdst_CallbackEntry TestEntry, *pDelEntry;
|
||||
|
||||
if( !g_nInitialized || !szType ) return 1; /* no opened session or invalid type */
|
||||
|
||||
/* convert to lower case */
|
||||
// sz=szType;
|
||||
// for( ; *sz; sz++ )
|
||||
// if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
// *sz+='a'-'A';
|
||||
|
||||
TestEntry.szType = szType;
|
||||
pAr = (Mode == LDT_REG_SECTION)? &g_ArSectionCallbacks: &g_ArFileCallbacks; /* select the array*/
|
||||
idx = LDT_DSAr_Index( pAr, &TestEntry, NULL );
|
||||
if( idx < 0) return 1; /* not found */
|
||||
|
||||
/* solve all references before proceeding */
|
||||
if(!LDT_Flush()) return 0; /* if the flush failed, return */
|
||||
|
||||
/* remove & delete the entry */
|
||||
pDelEntry = LDT_DSAr_RemoveAt( pAr, idx );
|
||||
free( pDelEntry->szType );
|
||||
free( pDelEntry );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : registers a Base Directory - if present the base directories will
|
||||
always prefix the paths
|
||||
INPUT : the base directory
|
||||
OUTPUT : 0 if successful, !0 on error
|
||||
CREATED : 98/09/24
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_AddBaseDirectory( char* szPath )
|
||||
{
|
||||
// char *sz;
|
||||
char path[_MAX_PATH];
|
||||
int i;
|
||||
|
||||
if( !g_nInitialized || !szPath ) return 1; /* no opened session or invalid parameters */
|
||||
|
||||
/* Get the path */
|
||||
while (*szPath == ' ') szPath ++;
|
||||
strcpy( path, szPath );
|
||||
for( i = strlen(path)-1; i>=0 && path[i] == ' '; i--) path[i] = 0;
|
||||
if(path[strlen(path)-1] != '\\') strcat( path, "\\");
|
||||
|
||||
/* convert file path string to lower case */
|
||||
// sz=path;
|
||||
// for( ; *sz; sz++ )
|
||||
// if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
// *sz+='a'-'A';
|
||||
|
||||
/* add the file path to the base directories list */
|
||||
LDT_DSAr_Add( &g_ArBaseDirectories, strcpy( malloc( strlen(path) +1 ), path));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
DESC. : registers a Path
|
||||
INPUT : the path, the file types extensions(without the leading'.'), separated by spaces
|
||||
OUTPUT : 0 if successful, !0 on error
|
||||
CREATED : 98/05/12
|
||||
AUTHOR : Catalin Cocos
|
||||
------------------------------------------------------------------------------*/
|
||||
int LDT_RegisterPath( char* szPath, char* szFileTypes )
|
||||
{
|
||||
char *sz, * szNewPath;
|
||||
char buffer[_MAX_EXT];
|
||||
char path[_MAX_PATH];
|
||||
int i, idx, iidx;
|
||||
LDT_tdst_TypePaths Dummy;
|
||||
Dummy.szExtension = buffer;
|
||||
|
||||
if( !g_nInitialized || !szPath || !szFileTypes ) return 1; /* no opened session or invalid parameters */
|
||||
|
||||
|
||||
/* Get the path */
|
||||
while (*szPath == ' ') szPath ++;
|
||||
strcpy( path, szPath );
|
||||
for( i = strlen(path)-1; i>=0 && path[i] == ' '; i--) path[i] = 0;
|
||||
if(path[strlen(path)-1] != '\\') strcat( path, "\\");
|
||||
|
||||
/* convert file path string to lower case */
|
||||
// sz=path;
|
||||
// for( ; *sz; sz++ )
|
||||
// if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
// *sz+='a'-'A';
|
||||
/* add the file path to the path collection */
|
||||
|
||||
idx = LDT_DSAr_Index( &g_ArPathStrings, path, &iidx);
|
||||
if( idx<0 )
|
||||
/* insert the new path */
|
||||
LDT_DSAr_InsertAt(&g_ArPathStrings, iidx, strcpy( szNewPath = malloc( strlen(path) +1), path));
|
||||
else
|
||||
/* we already have it */
|
||||
szNewPath = g_ArPathStrings.pData[idx];
|
||||
|
||||
|
||||
/* convert file type string to lower case */
|
||||
// sz=szFileTypes;
|
||||
// for( ; *sz; sz++ )
|
||||
// if( ( *sz>='A') && ( *sz<='Z' ) )
|
||||
// *sz+='a'-'A';
|
||||
|
||||
sz=szFileTypes;
|
||||
while ( *sz )
|
||||
{
|
||||
int cnt = 0;
|
||||
while (*sz == ' ') sz++;
|
||||
for(; *sz!=' ' && *sz ; sz++, cnt++ )
|
||||
buffer[cnt] = *sz;
|
||||
buffer[cnt] = 0;
|
||||
if(*buffer)
|
||||
{
|
||||
/* we have a valid file type */
|
||||
int idx,iidx;
|
||||
idx = LDT_DSAr_Index( &g_ArPaths, &Dummy, &iidx );
|
||||
if(idx<0)
|
||||
{
|
||||
/* type not registered before */
|
||||
LDT_tdst_TypePaths* pPath = malloc( sizeof(LDT_tdst_TypePaths));
|
||||
strcpy( pPath->szExtension = malloc( strlen(buffer) + 1 ), buffer);
|
||||
LDT_DSAr_Init(&pPath->arPaths);
|
||||
LDT_DSAr_SetGranularity(&pPath->arPaths, 10);
|
||||
LDT_DSAr_Add(&pPath->arPaths, szNewPath);
|
||||
LDT_DSAr_InsertAt( &g_ArPaths, iidx, pPath );
|
||||
}
|
||||
else
|
||||
/* type already present */
|
||||
LDT_DSAr_Add(&((LDT_tdst_TypePaths*)g_ArPaths.pData[idx])->arPaths, szNewPath);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LDT_LOG_STATISTICS
|
||||
/* Log/stat stuff
|
||||
-------------------*/
|
||||
unsigned TimerStartCount = 0;
|
||||
unsigned TimerStopCount = 0;
|
||||
|
||||
LONGLONG Frequency;
|
||||
LONGLONG TimingOverhead = 0;
|
||||
LONGLONG StartOverhead = 0;
|
||||
LONGLONG StopOverhead = 0;
|
||||
|
||||
void InitializeTimingEnvironment()
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
LONGLONG tmpli;
|
||||
int i;
|
||||
TimerStruct time, dummy;
|
||||
QueryPerformanceFrequency( &li );
|
||||
Frequency = li.QuadPart; /* the clock frequency */
|
||||
|
||||
InitTimer( &time );
|
||||
for( i = 0; i<32768; i++) /* 2^15 */
|
||||
{
|
||||
StartTimer( &time );
|
||||
StopTimer( &time );
|
||||
}
|
||||
TimingOverhead = Int64ShraMod32(time.TimeCounter, 15); /* the timing overhead */
|
||||
|
||||
InitTimer( &time );
|
||||
for( i = 0; i<32768; i++) /* 2^15 */
|
||||
{
|
||||
StartTimer( &time );
|
||||
StartTimer( &dummy );
|
||||
StopTimer( &time );
|
||||
}
|
||||
tmpli = time.TimeCounter;
|
||||
|
||||
InitTimer( &time );
|
||||
InitTimer( &dummy );
|
||||
for( i = 0; i<32768; i++) /* 2^15 */
|
||||
{
|
||||
StartTimer( &time );
|
||||
StartTimer( &dummy );
|
||||
StopTimer( &dummy );
|
||||
StopTimer( &time );
|
||||
}
|
||||
StartOverhead = Int64ShraMod32(tmpli , 15); /* the stoptiming overhead */
|
||||
StopOverhead = Int64ShraMod32(time.TimeCounter - tmpli , 15); /* the stoptiming overhead */
|
||||
|
||||
InitTimer( &time );
|
||||
InitTimer( &dummy );
|
||||
StartTimer( &time );
|
||||
StartTimer( &dummy );
|
||||
StopTimer( &dummy );
|
||||
StopTimer( &time );
|
||||
}
|
||||
|
||||
void InitTimer(TimerStruct* time)
|
||||
{
|
||||
time->TimeCounter = 0;
|
||||
}
|
||||
|
||||
void StartTimer(TimerStruct* time)
|
||||
{
|
||||
time->LastStartCount = ++TimerStartCount;
|
||||
time->LastStopCount = TimerStopCount;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&time->LastValue);
|
||||
}
|
||||
|
||||
void StopTimer(TimerStruct* time)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
QueryPerformanceCounter(&li);
|
||||
time->TimeCounter += li.QuadPart
|
||||
- time->LastValue
|
||||
- TimingOverhead
|
||||
- (TimerStartCount-time->LastStartCount)*StartOverhead
|
||||
- (TimerStopCount-time->LastStopCount)*StopOverhead;
|
||||
TimerStopCount++;
|
||||
}
|
||||
|
||||
double ReadTimer(TimerStruct* time)
|
||||
{
|
||||
return ((double)time->TimeCounter)/Frequency;
|
||||
}
|
||||
|
||||
#endif
|
160
Rayman_X/cpa/tempgrp/ldt/Src/refs.c
Normal file
160
Rayman_X/cpa/tempgrp/ldt/Src/refs.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <stdinc.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "LDT.h"
|
||||
#include "refs.h"
|
||||
#include "DynArray.h"
|
||||
#include "Error.h"
|
||||
|
||||
extern LDT_tdst_Link *g_pGetFrom;
|
||||
extern int g_nInitialized;
|
||||
|
||||
LDT_tdst_DSArray g_ArSolvers;
|
||||
|
||||
int SortRefs( const void **A, const void **B )
|
||||
{
|
||||
tdst_Ref *pA, *pB;
|
||||
pA=(tdst_Ref *)*A;
|
||||
pB=(tdst_Ref *)*B;
|
||||
|
||||
if( pA->iType<pB->iType)
|
||||
return 1;
|
||||
else if( pA->iType>pB->iType)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SortSolvers( const void **A, const void **B )
|
||||
{
|
||||
tdst_Solver *pA, *pB;
|
||||
pA=(tdst_Solver *)*A;
|
||||
pB=(tdst_Solver *)*B;
|
||||
|
||||
if( pA->iPriority<pB->iPriority)
|
||||
return -1;
|
||||
else if( pA->iPriority>pB->iPriority)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
HREF LDT_CreateRefsTable( )
|
||||
{
|
||||
LDT_tdst_DSArray* pRef=LDT_DSAr_new();
|
||||
LDT_DSAr_SetGranularity( pRef, 50 );
|
||||
|
||||
LDT_DSAr_SetSortMethod( pRef, SortRefs );
|
||||
return (HREF)pRef;
|
||||
}
|
||||
|
||||
void LDT_AddToRefsTable( HREF hRef, LDT_tdst_Link* pObj, int iType, short xCount, ... )
|
||||
{
|
||||
LDT_tdst_DSArray* pRef=(LDT_tdst_DSArray *)hRef;
|
||||
tdst_Ref *pSt=(tdst_Ref *)malloc( sizeof(tdst_Ref) );
|
||||
|
||||
pSt->pObject=pObj;
|
||||
pSt->pGetFrom=g_pGetFrom;
|
||||
pSt->iType=iType;
|
||||
|
||||
pSt->xCount=xCount;
|
||||
if( xCount )
|
||||
{
|
||||
int i;
|
||||
va_list vaList;
|
||||
|
||||
pSt->pVal=(long *)malloc( xCount*sizeof( long ) );
|
||||
|
||||
va_start( vaList, xCount );
|
||||
for( i=0; i<xCount; i++ )
|
||||
pSt->pVal[i]=va_arg( vaList, long );
|
||||
|
||||
va_end( vaList );
|
||||
}
|
||||
else pSt->pVal=NULL;
|
||||
|
||||
pObj->wUnsolvedRefs++;
|
||||
|
||||
LDT_DSAr_SAdd( pRef, (void *)pSt, 1, NULL );
|
||||
}
|
||||
|
||||
long pValues[128];
|
||||
|
||||
int LDT_GetRefFromTable( HREF hRef, LDT_tdst_Link **pObj, LDT_tdst_Link **pGetFrom, int *iType, short *xCount, long **pVal )
|
||||
{
|
||||
LDT_tdst_DSArray* pRef=(LDT_tdst_DSArray *)hRef;
|
||||
int i=LDT_DSAr_GetUpperBound( pRef ), ii;
|
||||
tdst_Ref *pSt;
|
||||
|
||||
if( i==-1 )
|
||||
return -1;
|
||||
|
||||
for( ii=i; (ii>=0) && (pSt=(tdst_Ref *)LDT_DSAr_GetAt( pRef, ii ))->pGetFrom && pSt->pGetFrom->wUnsolvedRefs; ii--);
|
||||
|
||||
if( ii<0 ) /* circular refs - problem ! */
|
||||
return -2;
|
||||
|
||||
if( ii!=i ) /* swap */
|
||||
{
|
||||
void *pTemp=LDT_DSAr_GetAt( pRef, i );
|
||||
LDT_DSAr_SetAt( pRef, ii, pTemp );
|
||||
}
|
||||
|
||||
LDT_DSAr_SetSize( pRef, i );
|
||||
|
||||
*pObj=pSt->pObject;
|
||||
if( pSt->pGetFrom )
|
||||
*pGetFrom=pSt->pGetFrom;
|
||||
else *pGetFrom=NULL;
|
||||
*iType=pSt->iType;
|
||||
*xCount=pSt->xCount;
|
||||
if(pSt->xCount)
|
||||
{
|
||||
memcpy(pValues, pSt->pVal, pSt->xCount*sizeof(long));
|
||||
*pVal=pValues;
|
||||
free(pSt->pVal);
|
||||
}
|
||||
else
|
||||
*pVal = NULL;
|
||||
|
||||
pSt->pObject->wUnsolvedRefs--;
|
||||
|
||||
free( pSt );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma warning( disable:4100 )
|
||||
void LDT_FreeRefValues( long *p )
|
||||
{
|
||||
// free( p ); the function is here only for backwards compatibility
|
||||
}
|
||||
#pragma warning( default:4100 )
|
||||
|
||||
HREF LDT_RegisterSolver( void(* Solve)(HREF), int iPri )
|
||||
{
|
||||
tdst_Solver *pSolver;
|
||||
|
||||
if(!g_nInitialized )
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, NULL, 0, "Call LDT_Initialize prior to solver registration !");
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSolver=(tdst_Solver *)malloc( sizeof(tdst_Solver) );
|
||||
|
||||
pSolver->Solve=Solve;
|
||||
pSolver->iPriority=iPri;
|
||||
|
||||
if( LDT_DSAr_SAdd( &g_ArSolvers, (void *)pSolver, 0, NULL ) <0 )
|
||||
{
|
||||
#if defined(LDT_ERROR_TREATMENT)
|
||||
ERRoR(0, NULL, 0, "Solver registration failed. The priority slot is in use. Please choose a different priority number.");
|
||||
#endif
|
||||
free (pSolver);
|
||||
return NULL;
|
||||
}
|
||||
pSolver->hRef=LDT_CreateRefsTable();
|
||||
|
||||
return pSolver->hRef;
|
||||
}
|
||||
|
5
Rayman_X/cpa/tempgrp/ldt/mssccprj.scc
Normal file
5
Rayman_X/cpa/tempgrp/ldt/mssccprj.scc
Normal file
@@ -0,0 +1,5 @@
|
||||
SCC = This is a Source Code Control file
|
||||
|
||||
[Ldt.dsp]
|
||||
SCC_Aux_Path = "\\srvprojets-ma\Rayman4_DS\Versions\Rayman4DS\Tools"
|
||||
SCC_Project_Name = "$/CPA/tempgrp/ldt", WYMAAAAA
|
Reference in New Issue
Block a user