// **********************************************************************************
// * "l_chl_v6.c"																	*
// * Written by :	Sébastien Rubens												*
// * Tabulations :	4 char															*
// **********************************************************************************
#define	L_CHL_V6_C


// **********************************************************************************
//                                                                     Included files
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#include "SCR.h"

#include "specif\\a3x_pref.h"


#include "a3x_glob.h"
#include "makeanim.h"
#include "l_global_v6.h"
#include "l_chl_v6.h"



// **********************************************************************************
//                                                                   Global Variables
static	signed long		slWaitedChannelNamesTableEntry;
static	signed long		slWaitedMax;

// Max in channel name le to set ChannelNumber value !!!
signed long		slMaxInChannel;							



// ******************************************************* fn_eChannelNameCallBackV6i
//                   CHANNEL NAMES CALLBACK
//
// Sebastien Rubens
// **********************************************************************************
SCR_tde_Anl_ReturnValue	fn_eChannelNameCallBackV6i(	SCR_tdst_File_Description	*_p_stFile,
													char						*_p_szName,
													char						*_ap_SzParam[],
													SCR_tde_Anl_Action			_eAction )
{
	// Section already analysed
	if	(_eAction == SCR_EA_Anl_AlreadyAnalysed) {	
		fprintf( ErrorFile, "%s :  A3dChannelNames already analysed\n", AnimationName );
	}

	// Beginning of section
	if	(_eAction == SCR_EA_Anl_BeginSection) {
#ifdef ShowInfos
		fn_v_LogSectionBegin(D_BINSCR_LogNew,"A3dChannelNames",AnimationName);
#endif

		slWaitedMax = ReadUShort(0);
		slMaxInChannel = slWaitedMax;
		fn_v_AllocateOnStack(eStackBinChannelNames,slWaitedMax);

		slWaitedChannelNamesTableEntry = 0L;
	}

	// We are in the section
	else if	(_eAction == SCR_EA_Anl_Entry)
	{
		// AddChannelName
		if	( !strcmp(_p_szName, "AddChannelName") ) {
			strcpy( &ax_xChannelNames[M_GetStackAlloc(eStackBinChannelNames)+slWaitedChannelNamesTableEntry][0], _ap_SzParam[0] );
			slWaitedChannelNamesTableEntry++;
		}

		// Unknown field
		else {	
			fprintf( ErrorFile, "%s :  Unknown field in A3d file, A3dChannelNames (%s)\n", AnimationName, _p_szName );
		}
	}

	// End of section
	else if	(_eAction == SCR_EA_Anl_EndSection) {
		if	( slWaitedChannelNamesTableEntry != slWaitedMax )
			fprintf(	ErrorFile, "Not enough entries in ChannelNamesTable", AnimationName );

#ifdef	ShowInfos
		fn_v_LogSectionEnd();
#endif
	}

	return	SCR_ERV_Anl_NormalReturn;
}



// ****************************************************************** fn_v_InitCHLV6i
// Register Call back for the different sections
//
// Sebastien Rubens
// **********************************************************************************
void fn_v_InitCHLV6i( void ) {
	// Channel Names Section
	SCR_fn_v_RdL0_RegisterCallback("A3dChannelNames",fn_eChannelNameCallBackV6i,SCR_CRC_c_RdL0_ForSection );
}



// **********************************************************************************
#undef	L_CHL_V6_C
