/*=========================================================================
*
* Submaps.c	- Submap conversion
*
* Version			1.0
* Revision date
*
*=======================================================================*/
#include <time.h>

#include "Submaps.h"

#include "conventi.h"
#include "print.h"
#include "system.h"			
#include "vertex.h"

#include "Levels.h"

#include "SpoLoad.h"
#include "SpoSave.h"



//--- Global defines --------------------------------------------------------

MLT_tdxHandleToSuperObject	g_hRoot1 = NULL;
MLT_tdxHandleToSuperObject	g_hRoot2 = NULL;

BOOL						g_bSubmaps = FALSE;
int							g_iUnivSectors = 0;

//--- Global statics --------------------------------------------------------

MLT_tdxHandleToSuperObject	gs_hRoot3 = NULL;

static int					gs_iInd, gs_jInd;


//--------------------------------------------------------------------


/****************************************************************************
*		Description:	check the hierarchy for the submap architecture
*
*		Parameters:		hRoot		: root of the hierarchy
*						sGameLevel	: destination directory of the level
*						sRawLevel	: source directory of the level
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vCheckHierarchyForSubmaps (MLT_tdxHandleToSuperObject hRoot, char *sGameLevel, char *sRawLevel)
{
  xString						sDirectory;
  BOOL							bNoGood;
  int							i,j, k;

  // change directory
  GetCurrentDirectory(256, sDirectory);

  // init submap hierarchy
  g_hRoot1 = NULL;
  g_hRoot2 = NULL;
  gs_hRoot3 = NULL;
  g_bSubmaps = FALSE;

  // check if the hierarchy contains some submaps
  if (strstr(hRoot->d_hChild[0]->sName, "GS_"))
  { 
	// check all childs
	bNoGood=FALSE;
	for (i=1; i<hRoot->lNbChild; i++)
	{
	   if (!strstr(hRoot->d_hChild[i]->sName, "GS_"))
		  bNoGood=TRUE;
	}
	if (bNoGood) 
	{
	   MLT_vOutput( C_ComRes_cErrorLine, "\nError : The map contains both submaps and free sectors");
	   return;
	}
  
	// DISPLAY
	MLT_vOutput( C_ComRes_cNormalLine, "\n\tGenerate submaps...");

	// add submap translation to the matrix of the sectors
	for (i=0; i<hRoot->lNbChild; i++)
	{
		for (j=0; j<hRoot->d_hChild[i]->lNbChild; j++)
		{   
			MLT_M_AddVertex ( &hRoot->d_hChild[i]->d_hChild[j]->p_stMatrix->stTranslation , &hRoot->d_hChild[i]->p_stMatrix->stTranslation);
		}
	}
    
	// change directory
	SetCurrentDirectory(sGameLevel); 
	
	// generate sub file
	MLT_vInitSubMapsLoad();
    MLT_vSaveSubFile();
	SCR_fn_v_SvL1_UpdateAllNotify();
	
    // save subamp sections
	MLT_vSaveSubSectionsInFile();
	SCR_fn_v_SvL1_UpdateAllNotify();

	// change directory
	SetCurrentDirectory(sRawLevel); 

  	// init submap parameters
	g_iUnivSectors=hRoot->lNbChild;
	g_bSubmaps=TRUE;

	// create root 1 for normal hierarchy
	g_hRoot1=(MLT_tdxHandleToSuperObject)malloc(sizeof(MLT_tdstSprObj));
	// create root 2 for submap hierarchy
	g_hRoot2=(MLT_tdxHandleToSuperObject)malloc(sizeof(MLT_tdstSprObj));
	strcpy(g_hRoot2->sName,"");
	// create root 3 for saving hierarchy
	gs_hRoot3=(MLT_tdxHandleToSuperObject)malloc(sizeof(MLT_tdstSprObj));
	strcpy(gs_hRoot3->sName,"");
  
	// copy hierarchy into Root2 and Root3
	for (i=0; i<hRoot->lNbChild; i++)
	{	
		g_hRoot2->d_hChild[i] = hRoot->d_hChild[i]; 
		gs_hRoot3->d_hChild[i] = hRoot->d_hChild[i]; 
	}
	g_hRoot2->lNbChild=hRoot->lNbChild;
	gs_hRoot3->lNbChild=hRoot->lNbChild;
  
    // save submap hierarchy
	g_hRoot1=g_hRoot2;
	// clean hierarchy for position dummies
	for (i=0; i<hRoot->lNbChild; i++)
	{	
		k=0;
		for (j=0; j<hRoot->d_hChild[i]->lNbChild; j++)
		{
			if (!strstr( hRoot->d_hChild[i]->d_hChild[j]->sName, hRoot->d_hChild[i]->sName))
			{	
				g_hRoot1->d_hChild[i]->d_hChild[k] = hRoot->d_hChild[i]->d_hChild[j];
				k++;
			}
			else
			{
				if (hRoot->d_hChild[i]->d_hChild[j]->lNbChild)
				{   
					MLT_vOutput( C_ComRes_cErrorLine, "\nError : The SubMap_Position object should not contain any child.");
					return;
				}
			}
		}
		g_hRoot1->d_hChild[i]->lNbChild=k;
	}
  	// restore submap hierarchy
	g_hRoot2=g_hRoot1;

	// clean normal hierarchy for submap dummies
	k=0;
	for (i=0; i<hRoot->lNbChild; i++)
	{
	  for (j=0; j<hRoot->d_hChild[i]->lNbChild; j++)
	  { 
		g_hRoot1->d_hChild[k] = hRoot->d_hChild[i]->d_hChild[j]; 
		k++;
	  }
	}
	// restore normal hierarchy
	hRoot->lNbChild = k;

	for (i=0; i<hRoot->lNbChild; i++)
		hRoot->d_hChild[i] = g_hRoot1->d_hChild[i];

	// restore submap hierarchy
	g_hRoot2=gs_hRoot3;
  }	

  // restore directory
  SetCurrentDirectory(sDirectory);
}


/****************************************************************************
*		Description:	register callback for submaps
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vInitSubMapsLoad()
{    
  SCR_fn_v_RdL0_RegisterCallback(M_CreateSubMaps, MLT_xLoadAllSubMaps,SCR_CRC_c_RdL0_ForSection);  
}



/****************************************************************************
*		Description:	save SUB file of the level
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSaveSubFile (void)
{
  xString	sFile, sIdent, sSection;
  char		*p_Char;
  long		i;

  // get SUB file name
  sprintf(sFile, "%s.sub", g_sLevelFileIn);
  // if necessary, save existing sub file
  if (SCR_fn_c_RdL0_IsSectionExists(sFile))
  {	
	CopyFile(sFile, "temp.sub", FALSE);
    remove(sFile);
  }
  // notify SUB file
  SCR_fn_v_SvL1_RegisterNotify(sFile, MLT_vSaveNbSubMaps, NULL, SCR_EA_Ntfy_AddOrModifySection);

  // check each submap
  for (i=0; i<g_hRoot->lNbChild; i++)
  {
    // get submap name
	SCR_fn_v_RdL0_SplitSectionName(g_hRoot->d_hChild[i]->sName, sFile, sSection, sIdent);
    sprintf(sFile, "%s.sub", g_sLevelFileIn);
	p_Char= strstr(g_hRoot->d_hChild[i]->sName, "GS_");
	strcpy(sIdent, p_Char+3);
    // build corresponding section name
	SCR_fn_v_RdL0_ComputeSectionName(sSection, sFile, M_CreateSubMaps, sIdent);
    // notify section
	SCR_fn_v_SvL1_RegisterNotify(sSection, MLT_vSaveAllSubMapsSection, g_hRoot->d_hChild[i], SCR_EA_Ntfy_AddOrModifySection);	
  }
}


/****************************************************************************
*		Description:	save submap sections in SUB file 
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSaveSubSectionsInFile (void)
{
  xString	sFile, sIdent, sSection;
  char		*p_Char;
  long		i;

  for (i=0; i<g_hRoot->lNbChild; i++)
  {
    // get submap name
	SCR_fn_v_RdL0_SplitSectionName(g_hRoot->d_hChild[i]->sName, sFile, sSection, sIdent);
	sprintf(sFile, "%s.sub", g_sLevelFileIn);
	p_Char= strstr(g_hRoot->d_hChild[i]->sName, "GS_");
	strcpy(sIdent, p_Char+3);
    // build corresponding section name
	SCR_fn_v_RdL0_ComputeSectionName(sSection, sFile, M_CreateSubMaps, sIdent);
    // notify section
    SCR_fn_v_SvL1_RegisterNotify(sSection, MLT_vSaveSubMaps, g_hRoot->d_hChild[i], SCR_EA_Ntfy_AddOrModifySection);
  }
}


/****************************************************************************
*		Description:	save all submap sections
*
*		Parameters:		p_stFile	: script file pointer
*						sFileName	: file name
*						p_vPtr		: data pointer
*						xAction		: script action
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSaveAllSubMapsSection(SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
  MLT_tdxHandleToSuperObject	d_Child;
  xString						sFile, sIdent, sSection;
  char							*p_Char;
  int							l=0, k=0, i;

  // get the right position in file
  if (xAction == SCR_EA_Ntfy_AddSection) 
  {
    SCR_fn_v_SvL1_ToEndSection(p_stFile);
  }

  if ((xAction == SCR_EA_Ntfy_AddSection) ||
	  (xAction == SCR_EA_Ntfy_RebuildSection) ||
	  (xAction == SCR_EA_Ntfy_AddOrRebuildSection))
  {
	  // get submap name
	  d_Child = (MLT_tdxHandleToSuperObject)p_vPtr;
	  SCR_fn_v_RdL0_SplitSectionName(d_Child->sName, sFile, sSection, sIdent);
	  sprintf(sFile, "%s.sub", g_sLevelFileIn);
	  p_Char= strstr(d_Child->sName, "GS_");
	  strcpy(sIdent, p_Char+3);
	  // buold corresponding section name
	  SCR_fn_v_RdL0_ComputeSectionName(sSection, sFile, M_CreateSubMaps, sIdent);
	
	  // save submap section
	  SCR_M_SvL0_SaveBeginSection(p_stFile, MLT_p_cGetSectionName(sSection), SCR_CC_C_Cfg_NoChar);
	  // get the real childs (remove dummies)
	  for (i=0; i<d_Child->lNbChild; i++)
	  {
		  if (!strstr(d_Child->d_hChild[i]->sName, "GS_"))
			  k++;
	  }
	  // save number of children
	  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Scanf, 3, "%d,%d", k, l);
	  // save end section
	  SCR_M_SvL0_SaveEndSection(p_stFile, SCR_CC_C_Cfg_EOL);
  }
}

/****************************************************************************
*		Description:	save the content all submap sections
*
*		Parameters:		p_stFile	: script file pointer
*						sFileName	: file name
*						p_vPtr		: data pointer
*						xAction		: script action
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSaveSubMaps(SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
  MLT_tdxHandleToSuperObject d_Child;
  SCR_tdst_Cxt_Values		 *p_stVal;
  MLT_tdstSubMaps			 *p_stSubMaps;
  MTH_tdxReal				 RotMatrixComp[3][3];
  xString					 sFile, sIdent, sSection, sIdent1, sIdent2;
  xString					 sMatrixFile, sLevelName, sMatrixName, sFullName;
  BOOL						 bDelete=FALSE;
  long						 i, j, l;
  char						 *p_Char, *p_cExt;

  // make the identity matrix
  for (i=0; i<3; i++)
  {
	  for (j=0; j<3; j++)
	  {
		  if (i!=j) 
			  RotMatrixComp[i][j]=0;
		  else 
			  RotMatrixComp[i][j]=1;
	  }
  }

  // get submap
  d_Child = (MLT_tdxHandleToSuperObject)p_vPtr;
  // get submap name
  SCR_fn_v_RdL0_SplitSectionName(d_Child->sName, sFile, sSection, sIdent);
  sprintf(sFile, "%s.sub", g_sLevelFileIn);
  p_Char= strstr(d_Child->sName, "GS_");
  strcpy(sIdent, p_Char+3);
  // build corresponding section name
  SCR_fn_v_RdL0_ComputeSectionName(sSection, sFile, M_CreateSubMaps, sIdent);
  

  l=0;
  // check if the temporary SUB file exist
  SCR_fn_v_RdL0_ComputeSectionName(sSection, "temp.sub", M_CreateSubMaps, sIdent);
  if(SCR_fn_c_RdL0_IsSectionExists(sSection))
  {
	// load coresponding section
	p_stVal = SCR_fnp_st_RdL0_AnalyseSection(sSection, SCR_CDF_uw_Anl_Normal);
	p_stSubMaps = (MLT_tdstSubMaps*)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
	// get sound events
	if (strcmp(p_stSubMaps->sSoundEvent[0], "")) 
		bDelete=TRUE;
	// init parameters
	gs_iInd = 0; 
	gs_jInd = 0;
	g_bSubFile = FALSE;
  }
  SCR_fn_v_SvL1_ToEndSection(p_stFile);
  SCR_fn_v_SvL1_ToPrevLine(p_stFile);

  SCR_g_ui_SvL0_IndentationLevel = 1;
  
  // save Root section
  SCR_M_SvL0_SaveBeginSection(p_stFile, M_SuperObjectRoot, SCR_CC_C_Cfg_EOL);
  // get level name
  strcpy(sLevelName, sFileName);
  p_cExt = strchr(sLevelName, '.');
  if (p_cExt)
	  strcpy(p_cExt, "\0");

  // compute matrix name
  sprintf(sMatrixFile, "%s\\%s.spo", sLevelName, sLevelName);
  SCR_fn_v_RdL0_ComputeSectionName(sMatrixName, sMatrixFile, M_Matrix, "Root");
  // save matrix entry
  SCR_M_SvL0_SaveEntry(p_stFile, M_SPOActionPutMatrix , SCR_CC_C_Cfg_NoChar);
  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Normal, 1, sMatrixName);

  // save all children
  for (i=0; i<d_Child->lNbChild; i++)
  {
	if (!strstr(d_Child->d_hChild[i]->sName, "GS_"))
	{	SCR_M_SvL0_SaveEntry(p_stFile, M_SPOActionAddChild, SCR_CC_C_Cfg_NoChar);
		// build full name
		sprintf(sFullName, "%s\\%s", sLevelName, d_Child->d_hChild[i]->sName);
		// save parameter
		SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Normal, 1, sFullName);
	}
  }
  // save Univers sector for the submap
  SCR_M_SvL0_SaveEntry(p_stFile, M_SPOActionAddChild, SCR_CC_C_Cfg_NoChar);
  // build Univers name
  strcpy(sIdent, g_sLevelFileIn);
  strcat(sIdent, "\\");
  SCR_fn_v_RdL0_SplitSectionName(d_Child->sName, sFile, sSection, sIdent2);
  strcpy(sIdent1, "SPO_Univers_");
  strcat(sIdent1, sIdent2+7);
  SCR_fn_v_RdL0_ComputeSectionName(sIdent2, sFile, sSection, sIdent1);
  strcat(sIdent, sIdent2);
  // save corresponding entry
  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Normal, 1, sIdent);

  // save end root section
  SCR_M_SvL0_SaveEndSection(p_stFile, SCR_CC_C_Cfg_EOL);


  // check for position dummies
  for (i=0; i<d_Child->lNbChild; i++)
  {	
	if (strstr(d_Child->d_hChild[i]->sName, d_Child->sName))
	{   
		xString sStr;

	    // build matrix name
		strcpy(sStr, "Matrix:");
		strcat(sStr, d_Child->d_hChild[i]->sName+strlen(d_Child->sName)+1);
	    // save matrix section
		SCR_M_SvL0_SaveBeginSection(p_stFile, sStr, SCR_CC_C_Cfg_EOL);
		// save matrix translation
		SCR_M_SvL0_SaveEntry(p_stFile, M_MATActionTranslation, SCR_CC_C_Cfg_NoChar);
		SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Scanf, 4, "%.6f,%.6f,%.6f", d_Child->d_hChild[i]->p_stMatrix->stTranslation.xX, d_Child->d_hChild[i]->p_stMatrix->stTranslation.xY, d_Child->d_hChild[i]->p_stMatrix->stTranslation.xZ);
		// if necessary, save matrix rotation
		if (!MLT_vCompareMatrix(d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix, RotMatrixComp))
		{
		  SCR_M_SvL0_SaveEntry(p_stFile, M_MATActionRotation, SCR_CC_C_Cfg_NoChar);
		  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Scanf, 10, "%.6f,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f",
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[0][0],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[1][0],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[2][0],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[0][1],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[1][1],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[2][1],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[0][2],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[1][2],
			  d_Child->d_hChild[i]->p_stMatrix->a9_xRotMatrix[2][2]);
		}
		// save end matrix section
		SCR_M_SvL0_SaveEndSection(p_stFile, SCR_CC_C_Cfg_EOL);
	}
  }

  // if necessary, save sound events
  if (bDelete)
  {	
	j=0;
	while(strcmp(p_stSubMaps->sSoundEvent[j], ""))
	{
		SCR_M_SvL0_SaveEntry(p_stFile, M_BeginSubMapSoundEvent , SCR_CC_C_Cfg_NoChar);
		SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Normal, 1, p_stSubMaps->sSoundEvent[j]);
		j++; 
	}
  }
  
  // restore indentation level
  SCR_g_ui_SvL0_IndentationLevel = 0;

  bDelete=FALSE;

}

/****************************************************************************
*		Description:	save the global parameters of the SUB file
*
*		Parameters:		p_stFile	: script file pointer
*						sFileName	: file name
*						p_vPtr		: data pointer
*						xAction		: script action
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSaveNbSubMaps (SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
  char		sBuffer[MAX_PATH];
  xString	sComment, sDate, sTime;

  // save header
  SCR_M_SvL0_SaveScriptFileHeader(p_stFile);
  SCR_M_SvL0_SaveBlankLine(p_stFile);
  sprintf(sComment, "Generated by Max23Dos Moulinette");
  SCR_M_SvL0_SaveComment(p_stFile, sComment);
  SCR_M_SvL0_SaveBlankLine(p_stFile);
  // save date
  _strtime(sTime);
  _strdate(sDate);
  sprintf(sComment, "Created date : %s %s", sDate, sTime);
  SCR_M_SvL0_SaveComment(p_stFile, sComment);
  SCR_M_SvL0_SaveBlankLine(p_stFile);

  
  // save title
  SCR_M_SvL0_SaveComment(p_stFile, "*********************************************");
  sprintf(sBuffer, "SubDivisions de la Map %s Version N64", g_sLevelFileIn);
  SCR_M_SvL0_SaveComment(p_stFile, sBuffer);
  SCR_M_SvL0_SaveComment(p_stFile, "*********************************************");
  SCR_M_SvL0_SaveBlankLine(p_stFile);

  // save directive
  SCR_M_SvL0_SaveDirective(p_stFile, M_SetCurrentFileDouble,SCR_CC_C_Cfg_NoChar);
  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Scanf, 3, "%d,%.2f", 1, 1.0);
  SCR_M_SvL0_SaveBlankLine(p_stFile);

  // save number of submaps
  SCR_M_SvL0_SaveEntry(p_stFile, M_NumberOfSubMaps, SCR_CC_C_Cfg_NoChar);
  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Scanf, 2, "%d", g_hRoot->lNbChild);
  SCR_M_SvL0_SaveBlankLine(p_stFile);
}


/****************************************************************************
*		Description:	save the number of submaps in SUB file
*
*		Parameters:		p_stFile	: script file pointer
*						sFileName	: file name
*						p_vPtr		: data pointer
*						xAction		: script action
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSaveNumberOfSubMaps(SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
  MLT_tdxHandleToSuperObject hRoot;

  // get root pointer
  hRoot = (MLT_tdxHandleToSuperObject)p_vPtr;

  if(xAction == SCR_EA_Ntfy_AddSection) 
	SCR_fn_v_SvL1_ToEndSection(p_stFile);
  else
    SCR_fn_v_SvL1_DeleteSection(p_stFile);

  // save entry 
  SCR_M_SvL0_SaveEntry(p_stFile, M_NumberOfSubMaps, SCR_CC_C_Cfg_NoChar);
  SCR_fn_v_SvL0_SaveParameters_MP(p_stFile, SCR_EF_SvL0_Scanf, 2, "%d", hRoot->lNbChild);

  SCR_M_SvL0_SaveBlankLine(p_stFile);

}



/****************************************************************************
*		Description:	load all the submap sections
*
*		Parameters:		p_stFile	: script file pointer
*						szAction	: section or entry name
*						szParams	: parameters
*						cType		: action type
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
SCR_tde_Anl_ReturnValue MLT_xLoadAllSubMaps (SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
  MLT_tdstSubMaps *p_stSubMaps;
	
	switch (cType)
	{
		case SCR_EA_Anl_BeginSection:
			// create submap structure
			p_stSubMaps = (MLT_tdstSubMaps*)calloc(1,sizeof(MLT_tdstSubMaps));
      
			SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)p_stSubMaps);
			SCR_M_RdL0_SetContextLong(0,0,(unsigned long)p_stSubMaps);
			break;
	
		case SCR_EA_Anl_Entry:
			SCR_M_RdL0_GetContextLong(0,0,MLT_tdstSubMaps*,p_stSubMaps);
			// load sound event entry
			if (strcmp(szAction,M_BeginSubMapSoundEvent)==0)	
			{	
				strcpy(p_stSubMaps->sSoundEvent[gs_iInd], szParams[0]);
				gs_iInd++;
			}
			break;

		case SCR_EA_Anl_EndSection:
			break;
	}
  return  SCR_ERV_Anl_NormalReturn;
}


