#include "PalmType.h"
#include "PalmChip.h"
#include "p_util.h"

static XSHORT _iLineLen;
static PXCHAR _pLine;
static XSHORT _iLineLenBackup;
static PXCHAR _pLineBackup;

void p_line_start(PXCHAR pDst)
{
	_iLineLen = 0;
	_pLine = pDst;
}

void p_line_backup()
{
	_iLineLenBackup = _iLineLen;
	_pLineBackup = _pLine;
}

void p_line_restore()
{
	_iLineLen = _iLineLenBackup;
	_pLine = _pLineBackup;
}

USHORT p_line_get_len()
{
	return _iLineLen;
}

void p_line_set_len(USHORT iLen)
{
	_iLineLen = iLen;
}

void p_line_inc_len(USHORT iLen)
{
	_iLineLen += iLen;
}

PXCHAR p_line_get_buf()
{
	return (PXCHAR)(_pLine + _iLineLen);
}

void p_line_update_len()
{
	_iLineLen += p_strlen_x(p_line_get_buf());
}

/*
void p_line_add_c(PCCHAR pStr)
{
	p_strcpy_c2x(p_line_get_buf(), pStr);
	p_line_update_len();
}

void p_line_add_x(PXCHAR pStr)
{
	p_strcpy_x2x(p_line_get_buf(), pStr);
	p_line_update_len();
}

void p_line_add_p(USHORT iSdramIndex)
{
	SdramReadString(iSdramIndex);
	p_line_add_x((PXCHAR)Sdram_pDataCache);
}

void p_line_add_val(USHORT iVal)
{
	p_itoa(iVal, p_line_get_buf(), 10);
	p_line_update_len();
}

void p_line_add_long(ULONG lVal)
{
	p_ltoa(lVal, p_line_get_buf(), 10);
	p_line_update_len();
}

void p_line_add_ip(PXCHAR pIPAddr)
{
	p_IP2String(pIPAddr, p_line_get_buf());
	p_line_update_len();
}
*/

void p_line_add_char(UCHAR iChar)
{
	_pLine[_iLineLen] = iChar;
	_iLineLen ++;
	_pLine[_iLineLen] = 0;
}

/*
void p_line_add_newline()
{
	p_line_add_char('\r');
	p_line_add_char('\n');
}

void p_line_add_space()
{
	p_line_add_char(' ');
}

void p_line_add_comma()
{
	p_line_add_char(',');
	p_line_add_space();
}

void p_line_add_colon()
{
	p_line_add_char(':');
	p_line_add_space();
}
*/

