/*------------------------------------------------------------------------------
	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
