288 lines
9.7 KiB
C
288 lines
9.7 KiB
C
/*
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
* SCR_Sect.c
|
|
* Managment of open sections.
|
|
*
|
|
* Scripts, Beaudet Christophe
|
|
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
*/
|
|
|
|
/*
|
|
*=================================================================================================
|
|
* Includes.
|
|
*=================================================================================================
|
|
*/
|
|
|
|
#include <memory.h>
|
|
#include "SCR.h"
|
|
|
|
/*
|
|
*=================================================================================================
|
|
* Global variables.
|
|
*=================================================================================================
|
|
*/
|
|
|
|
/*
|
|
* Array of all open sections.
|
|
* Hadh table for that array.
|
|
*/
|
|
SCR_tdst_DyAr_Description SCR_g_st_Sect_ArrayOpen;
|
|
SCR_tda_st_Hash_Table SCR_g_a_st_Sect_HashTableOpen;
|
|
|
|
/*
|
|
*=================================================================================================
|
|
* Functions.
|
|
*=================================================================================================
|
|
*/
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Init.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
void fn_v_Sect_InitModule(void)
|
|
{
|
|
fn_v_DyAr_InitArray(&SCR_g_st_Sect_ArrayOpen);
|
|
fn_v_Hash_InitTable(SCR_g_a_st_Sect_HashTableOpen);
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Close.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
void fn_v_Sect_CloseModule(void)
|
|
{
|
|
SCR_M_DyAr_DeleteAllElements(SCR_tdst_Sect_Open, &SCR_g_st_Sect_ArrayOpen, ;);
|
|
fn_v_Hash_CloseTable(SCR_g_a_st_Sect_HashTableOpen);
|
|
}
|
|
|
|
/*===============================================================================================*/
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* To add one open section. The section description must be in current context.
|
|
* _p_stContext : Current context.
|
|
* _xHashKey : Hash key code of section.
|
|
* Returns allocated structure.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
SCR_tdst_Sect_Open *fnp_st_Sect_AddOpen
|
|
(
|
|
SCR_tdst_Cxt_Description *_p_stContext,
|
|
SCR_tdx_Hash_Key _xHashKey
|
|
)
|
|
{
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
unsigned int uiSectionPos;
|
|
SCR_tdst_Sect_Open *p_stSection;
|
|
unsigned int uiIndexOfHashValue;
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
SCR_M_Dbg_AssertStruct_P(SCR_tdst_Cxt_Description, _p_stContext);
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*
|
|
* Add element in array.
|
|
* Add pointer in corresponding hash table.
|
|
*/
|
|
SCR_M_DyAr_AddElement(SCR_tdst_Sect_Open, uiSectionPos, p_stSection, SCR_g_st_Sect_ArrayOpen);
|
|
fnp_st_Hash_AddValue
|
|
(
|
|
_xHashKey,
|
|
SCR_g_a_st_Sect_HashTableOpen,
|
|
(unsigned long) p_stSection,
|
|
&uiIndexOfHashValue
|
|
);
|
|
|
|
/*
|
|
* Initialize structure.
|
|
*/
|
|
SCR_M_Cxt_CopyBuffers(&p_stSection->stBuffers, &_p_stContext->stBuffers);
|
|
memset(&p_stSection->stSectionValues, 0, sizeof(SCR_tdst_Cxt_Values));
|
|
p_stSection->uiLineInFile = _p_stContext->stPosition.uiLineInFile;
|
|
p_stSection->xHashKey = _xHashKey;
|
|
p_stSection->uiIndexOfHashValue = uiIndexOfHashValue;
|
|
|
|
/*
|
|
* Return structure.
|
|
*/
|
|
return p_stSection;
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* Search for _p_stSection in all open files to set to NULL the p_stOpenSection field of section
|
|
* description.
|
|
* _p_stSection : Section to delete.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
void fn_v_Sect_UpdateSectionDes(SCR_tdst_Sect_Open *_p_stSection)
|
|
{
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
unsigned int uiPos;
|
|
SCR_tdst_File_Open *p_stOpenFile = NULL;
|
|
SCR_tdst_Anl_SectionDes *p_stSectionDes = NULL;
|
|
unsigned int ui_Num = 0;
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*
|
|
* Parse all files to get section des.
|
|
*/
|
|
uiPos = 0;
|
|
SCR_M_DyAr_GetNextElement(SCR_tdst_File_Open, uiPos, p_stOpenFile, SCR_g_st_File_ArrayOpen);
|
|
while(p_stOpenFile)
|
|
{
|
|
p_stSectionDes = fnp_st_Anl_SearchSectionDes(p_stOpenFile, _p_stSection->stBuffers.a_szBufferCompleteName, 0,ui_Num);
|
|
while(p_stSectionDes)
|
|
{
|
|
p_stSectionDes->p_stOpenSection = NULL;
|
|
ui_Num++;
|
|
p_stSectionDes = fnp_st_Anl_SearchSectionDes(p_stOpenFile, _p_stSection->stBuffers.a_szBufferCompleteName, 0,ui_Num);
|
|
}
|
|
|
|
/* if(p_stSectionDes)
|
|
p_stSectionDes->p_stOpenSection = NULL;*/
|
|
|
|
uiPos++;
|
|
SCR_M_DyAr_GetNextElement(SCR_tdst_File_Open, uiPos, p_stOpenFile, SCR_g_st_File_ArrayOpen);
|
|
}
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* To delete an already open section.
|
|
* _p_stSection : Section to delete.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
void fn_v_Sect_DeleteOpen(SCR_tdst_Sect_Open *_p_stSection)
|
|
{
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
SCR_M_Dbg_AssertStruct_P(SCR_tdst_Sect_Open, _p_stSection);
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
fn_v_Sect_UpdateSectionDes(_p_stSection);
|
|
|
|
/*
|
|
* Delete element in hash table.
|
|
*/
|
|
SCR_M_DyAr_DeleteElement
|
|
(
|
|
SCR_tdst_Hash_Value,
|
|
_p_stSection->uiIndexOfHashValue,
|
|
&SCR_g_a_st_Sect_HashTableOpen[_p_stSection->xHashKey],
|
|
;
|
|
);
|
|
|
|
/*
|
|
* Delete structure.
|
|
*/
|
|
SCR_M_DyAr_DeleteElement
|
|
(
|
|
SCR_tdst_Sect_Open,
|
|
_p_stSection->stHeader.uiIndexInArray,
|
|
&SCR_g_st_Sect_ArrayOpen,
|
|
;
|
|
);
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* To search an open section.
|
|
* _p_szSectionName : Complete section name.
|
|
* _uiLineInFile : Line of section in file (0 to ignore).
|
|
* _xHashKey : Hash key code of section.
|
|
* Returns structure found, NULL if not.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
SCR_tdst_Sect_Open *fnp_st_Sect_SearchOpen
|
|
(
|
|
char *_p_szSectionName,
|
|
unsigned int _uiLineInFile,
|
|
SCR_tdx_Hash_Key _xHashKey
|
|
)
|
|
{
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
unsigned int uiValuePos;
|
|
SCR_tdst_Hash_Value *p_stValue = NULL;
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
SCR_M_Dbg_Assert_P(_p_szSectionName != NULL);
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
/*
|
|
* Search section.
|
|
*/
|
|
SCR_M_DyAr_SearchElement
|
|
(
|
|
SCR_tdst_Hash_Value,
|
|
uiValuePos,
|
|
p_stValue,
|
|
SCR_g_a_st_Sect_HashTableOpen[_xHashKey],
|
|
(
|
|
(!strcmpi
|
|
(
|
|
((SCR_tdst_Sect_Open *) (p_stValue->ulValue))->stBuffers.a_szBufferCompleteName,
|
|
_p_szSectionName
|
|
)
|
|
)
|
|
&& (
|
|
(_uiLineInFile == 0)
|
|
|| (((SCR_tdst_Sect_Open *) (p_stValue->ulValue))->uiLineInFile == _uiLineInFile)
|
|
)
|
|
)
|
|
);
|
|
|
|
/*
|
|
* Return address of structure.
|
|
*/
|
|
if(p_stValue)
|
|
return (SCR_tdst_Sect_Open *) p_stValue->ulValue;
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
**************************************************************************************************
|
|
**************************************************************************************************
|
|
**************************************************************************************************
|
|
**************************************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
* To reduce memory size.
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
void fn_v_Sect_ReduceMemory(void)
|
|
{
|
|
/* Pack array of open sections */
|
|
SCR_M_DyAr_PackArray(SCR_tdst_Sect_Open, SCR_g_st_Sect_ArrayOpen, ;);
|
|
|
|
/* Pack open section hash table */
|
|
SCR_M_Hash_PackArray(SCR_g_a_st_Sect_HashTableOpen, SCR_tdst_Sect_Open, SCR_g_st_Sect_ArrayOpen, xHashKey, uiIndexOfHashValue);
|
|
}
|
|
|
|
/*
|
|
*-------------------------------------------------------------------------------------------------
|
|
*-------------------------------------------------------------------------------------------------
|
|
*/
|
|
void fn_v_Sect_DeleteWithMemLevel(unsigned char _ucMin, unsigned char _ucMax)
|
|
{
|
|
SCR_M_DyAr_DeleteElementWithMemLevel
|
|
(
|
|
SCR_tdst_Sect_Open,
|
|
SCR_g_st_Sect_ArrayOpen,
|
|
{
|
|
fn_v_Sect_UpdateSectionDes(_p_stPointer_);
|
|
},
|
|
_ucMin,
|
|
_ucMax
|
|
);
|
|
SCR_M_Hash_DeleteWithMemLevel
|
|
(
|
|
SCR_g_a_st_Sect_HashTableOpen,
|
|
_ucMin,
|
|
_ucMax
|
|
);
|
|
}
|