/*-----------------------------------------------------------------------*/
/*   FS-MTS  1.0  Ver.                                                   */
/*   Copyright (C) 2000 FIRST SAIL                                       */
/*   All Rights Reserved                                                 */
/*   Warning:                                                            */
/*       This program author is GuoHeng,this system is protected         */
/*   by copyright law and international Treaties . Unauthorized          */
/*   reproduction of  distribution of this  system, or any portion       */
/*   of it , may result in severe civil and criminal penalties ,         */
/*   and will be prosecuted to the maximum extern possible under         */
/*   the law.                                                            */
/*                                                                       */
/*   Update Date:2002-06-25                                              */
/*   Update Time:22:35:00                                                */
/*-----------------------------------------------------------------------*/

#ifndef _REGISTER_H_
#define _REGISTER_H_

#define REGISTER_SEGMENT_COUNT     40
#define REGISTER_COMMENT_CHARACTER ';'

#define REGISTER_MAX_BUFFER        20

#define REGISTER_SEGMENT_WIDTH     28
#define REGISTER_KEY_WIDTH         28
#define REGISTER_VALUE_WIDTH       100

#define REGSITER_KEY_ATTRIB_STRING 0
#define REGSITER_KEY_ATTRIB_LONG   1

#define TMPNAM_STRING  tmpnam


#include <Symbol.h>
#include <Listing.h>

struct REGISTERBUFFER
{
	char  ssSegment[REGISTER_SEGMENT_WIDTH];
	char  ssKey[REGISTER_KEY_WIDTH];
	char  ssKeyValue[REGISTER_VALUE_WIDTH];
	DWORD dwStyle;
};

struct USER_REGISTER_SEGMENT
{
	char    strSegment[REGISTER_SEGMENT_WIDTH];
	long    lSegmentLocation;
};

class CRegister
{
private:
	BOOL    m_bWrite;
	FILE*	m_pFile;


	CListManager m_ListManager;
	//char    m_ssSegment[REGISTER_SEGMENT_COUNT][REGISTER_SEGMENT_WIDTH];
	//long	m_lSegmentLocation[REGISTER_SEGMENT_COUNT];
private:
	REGISTERBUFFER m_ssRegisterBuffer[REGISTER_MAX_BUFFER];
private:
//	static char   m_strLinBuffer[];
	char   m_strFileName[128];
    BOOL   m_bOnlyRead;
public:
	static char*  GetBuffer();//{return(m_strLinBuffer);}
	CListManager* GetListManager(){return(&m_ListManager);}
public:
	//获得文件指针
	FILE*  GetFile(){return(m_pFile);};
	//获得只读属性
    BOOL   GetOnlyRead(){return(m_bOnlyRead);}
	//char*  GetSegmentBuffer(int nIndex){return(m_ssSegment[nIndex]);};
	//long   GetSegmentSegtion(int nIndex){return(m_lSegmentLocation[nIndex]);}
public:
	//将16进制串转成10进制串
	static int      Atoi(char *pStr);
	//归一化尾串数字0值
	static char*    TrimZero(char *pStr);
	//计算串中出现指定“字符”的个数
	static int      GetCount(char *pStr,char nCh);
	//分离由指定字符分隔的子字符串
	static char*	GetString(int nIndex,char nCh,char *pStrSource);
	//将字符串中的注释剪栽掉
	static char*	TrimComment(char *pStr);
	//获得字符串中的注释内容
	static char*    GetComment(char *pStr);
	//修剪字符串前导空格
	static char*    TrimLeft(char  *pStr);
	//修剪字符串后导空格
	static char*	TrimRight(char *pStr);
	//判断指定的字符串是否是“布尔”真值
	static BOOL     IsProfileBoolen(char *pStr);
public:
	//装入配置文件
	BOOL	LoadFile(char  *pStr, BOOL bOnlyRead = FALSE);
	//判断字符串是否是“段”描述
	BOOL	IsSegment(char *pStr);
	//获得离符串中的“段”值
	char*	GetSegment(char *pStr);
	//判断字符串是否是“键”描述
	BOOL    IsKey(char *pStrSource);
	//获得键索引
	BOOL    GetKeyIndex(char *strSegment,char *strKey);
	//判断键是否在“写”缓冲区中
	BOOL    IsExistKeyBuffer(char *strSegment,char *strKey);
	//获得键名
	char    *GetKeyName(char *pStrSource);
	//比较键名
	BOOL	IsSameKey(char *pStrSource,char *pStrCompile);
	//获得键值
	char*	GetKeyValue(char *pStrSource,char *pStrTarget);	
	//写键值
	BOOL	WriteKey(int nIndex,FILE *pFile,char *strComment=NULL);
public:
	//读串类型值
	char*	GetProfileString(char *pStrSegment,char *pStrKey,char *pStrDefault="");
	//读长整型类型值
	long 	GetProfileLong(char *pStrSegment,char *pStrKey,long lDefault=0L);
	//读无符号短整型值
	WORD    GetProfileWord(char *pStrSegment,char *pStrKey,WORD wDefault);
	//读有符号整型值
	int     GetProfileInt(char *pStrSegment,char *pStrKey, int  nDefault);
	//读单精度浮点值
	float   GetProfileFloat(char *pStrSegment,char *pStrKey,float fDefault);
	//读双精度浮点值
	double  GetProfileDouble(char *pStrSegment,char *pStrKey,double dbDefault);

	//写串类型值
	BOOL	WriteProfileString(char *pStrSegment,char *pStrKey,char *pStrDefault);
	//写长整型类型值
	BOOL 	WriteProfileLong(char *pStrSegment,char *pStrKey,long lDefault);
	//写无符号短整型值
	BOOL    WriteProfileWord(char *pStrSegment,char *pStrKey,WORD wDefault);
	//写有符号整型值
	BOOL    WriteProfileInt(char *pStrSegment,char *pStrKey, int  nDefault);
	//写单精度浮点值
	BOOL    WriteProfileFloat(char *pStrSegment,char *pStrKey,float fDefault);
	//写双精度浮点值
	BOOL    WriteProfileDouble(char *pStrSegment,char *pStrKey,double dbDefault);

public:
	//判断是否曾经写入内容
	BOOL    IsWrite(){return(m_bWrite);};
	//清文件“脏”标志
	void    ClearWrite(){m_bWrite=FALSE;}
	//刷新磁盘缓冲区
	BOOL    FlushRegister();
	//将“写”缓冲区内容更新到磁盘文件中
	BOOL	WriteBuffer(FILE *pFile);

public:
	//构造函数调用
	BOOL	CoRegister();
	//构造函数
	CRegister();
	//构造函数
	CRegister(char *pStr);
	//构造函数
	CRegister(char *pStr, BOOL bOnlyRead);
	//析构函数
	~CRegister();
};

void GetSegmentUser(LISTING* pNode,USER_REGISTER_SEGMENT* pUser);
void DeleteSegmentNode(void* pUser);
int CompareSegmentNode(void* pSourceUser , void* pDestUser);

#endif