/* *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * SCR_Vars.c * To manage global script variables. * * Scripts, Beaudet Christophe *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* *================================================================================================= * Includes. *================================================================================================= */ #include #include "SCR.h" /* *================================================================================================= * Global variables. *================================================================================================= */ /* * Array of all variables. */ SCR_tdst_DyAr_Description SCR_g_st_Vars_Array; /* *================================================================================================= * Functions. *================================================================================================= */ /* *------------------------------------------------------------------------------------------------- * Init. *------------------------------------------------------------------------------------------------- */ void fn_v_Vars_InitModule(void) { fn_v_DyAr_InitArray(&SCR_g_st_Vars_Array); } /* *------------------------------------------------------------------------------------------------- * Close. *------------------------------------------------------------------------------------------------- */ void fn_v_Vars_CloseModule(void) { SCR_M_DyAr_DeleteAllElements(SCR_tdst_Vars_Description, &SCR_g_st_Vars_Array, ;); } /*===============================================================================================*/ /* *------------------------------------------------------------------------------------------------- * To add one variable. * _p_szName : Name of variable to add. * _p_szValue : Value of variable to add. * Returns allocated structure. *------------------------------------------------------------------------------------------------- */ SCR_tdst_Vars_Description *fnp_st_Vars_Add ( char *_p_szName, char *_p_szValue ) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ unsigned int uiPos; SCR_tdst_Vars_Description *p_stPointer; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_M_Dbg_Assert_P(_p_szName != NULL); SCR_M_Dbg_Assert_P(_p_szValue != NULL); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* * Add element in array. */ SCR_M_DyAr_AddElement(SCR_tdst_Vars_Description, uiPos, p_stPointer, SCR_g_st_Vars_Array); /* * Initialize structure. */ p_stPointer->stHeader.uiIndexInArray = uiPos; strcpy(p_stPointer->a_szVarName, _p_szName); strcpy(p_stPointer->a_szVarValue, _p_szValue); /* * Return structure. */ return p_stPointer; } /* *------------------------------------------------------------------------------------------------- * To delete a variable. * _p_stVar : Variable to delete. *------------------------------------------------------------------------------------------------- */ void fn_v_Vars_Delete(SCR_tdst_Vars_Description *_p_stVar) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_M_Dbg_AssertStruct_P(SCR_tdst_Vars_Description, _p_stVar); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_M_DyAr_DeleteElement ( SCR_tdst_Vars_Description, _p_stVar->stHeader.uiIndexInArray, &SCR_g_st_Vars_Array, ;); } /* *------------------------------------------------------------------------------------------------- * To search a variable. * _p_szName : Name of variable to search. * Returns structure found, NULL if not. *------------------------------------------------------------------------------------------------- */ SCR_tdst_Vars_Description *fnp_st_Vars_Search(char *_p_szName) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ unsigned int uiPos; SCR_tdst_Vars_Description *p_stPointer = NULL; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_M_Dbg_Assert_P(_p_szName != NULL); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* * Search variable and return pointer. */ SCR_M_DyAr_SearchElement ( SCR_tdst_Vars_Description, uiPos, p_stPointer, SCR_g_st_Vars_Array, (!strcmpi(p_stPointer->a_szVarName, _p_szName)) ); return p_stPointer; } /* ************************************************************************************************** ************************************************************************************************** ************************************************************************************************** ************************************************************************************************** */ /* *------------------------------------------------------------------------------------------------- * To reduce memory size. *------------------------------------------------------------------------------------------------- */ void fn_v_Vars_ReduceMemory(void) { SCR_M_DyAr_PackArray(SCR_tdst_Vars_Description, SCR_g_st_Vars_Array, ;); } /* *------------------------------------------------------------------------------------------------- *------------------------------------------------------------------------------------------------- */ void fn_v_Vars_DeleteWithMemLevel(unsigned char _ucMin, unsigned char _ucMax) { SCR_M_DyAr_DeleteElementWithMemLevel ( SCR_tdst_Vars_Description, SCR_g_st_Vars_Array, ;, _ucMin, _ucMax ); }