
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include <egb.h>
#include <mos.h>
#include <guidbg.h>
#include <mtl.h>
#include <eintm.h>
#include <mtlein.h>
#include "eindd.h"

int		EINDD_analysis( POOLDATA *ptr , char *fname , int *mosPos )
{
	char	mosFlag , selectFile , selectMos ;
	int		ret , retPol ;
	size_t	size , len ;
	uchar	*rec , *work ;
	ushort	tag ;

	ret = NOTEXISTEIN ;		// EIN(TM) プールデータがない場合

	// マウス座標取得をするかどうか
	mosFlag = 0 ;
	if ( mosPos != NULL )	mosFlag = 1 ;

	if ( ptr->Kind & POOL_REAL )
	{
		// テキストブロックの先頭アドレスを探す
		retPol = POL_cbSearchBlock( ( uchar *)ptr->dPtr , PCBF_TEXT , 1 ,
					&rec , &size ) ;
		if ( retPol > 0 )
		{
			work = POL_cbGetRecSize( rec , &len ) ;

			selectFile = selectMos = 0 ;
			do
			{
				tag = *(ushort *)work ;
				work = POL_cbGetRecSize( work , &len ) ;

				// テキストファイル名
				if ( ( tag & 0xff ) == PCBF_EINTEXTFILE )
				{
					if ( selectFile )
					{
						ret = NOERR ;
					}
					else
					{
						strcpy( fname , (char *)work ) ;
						ret = NOERR ;
						selectFile = 1 ;
					}
				}
				// マウス位置データ
				else if ( ( ( tag & 0xff ) == PCBF_EINMOSPOSDATA ) && mosFlag )
				{
					if ( selectMos )
					{
						ret = NOERR ;
					}
					else
					{
						memcpy( mosPos , work , 4 ) ;
						ret = NOERR ;
						selectMos = 1 ;
					}
				}
				work += len ;
			} while( ( tag & 0xff ) != 0x1f ) ;		// データレコード終了
		}
	}

	return ret ;
}

