// Change History:

#include "ddp/ddp_expdef.h"

// **************************************************************************
// DDP_ExportDef
// **************************************************************************

uint DDP_ExportDef::GetActionText(byte * buf, uint sz) const
{
    if(!buf || !sz)
        return 0;

    PORT_strncpy(buf, DART_ActionList[ActionType], sz);

return PORT_strlen(buf);
}
//--------------------------------------------------------------------------

uint DDP_ExportDef::GetSortText(byte * buf, uint sz) const
{
    if(!buf || !sz)
        return 0;

    if(SortVal == SORTVALUE_NOSORT)
        PORT_strncpy(buf, NOSORT, sz);
    else
        PORT_strncpy(buf, DART_SortList[SortVal], sz);

return PORT_strlen(buf);
}
//--------------------------------------------------------------------------

bool DDP_ExportDef::Dump(DDP_PrintFile * file, const byte * prefix) const
{
    const byte * uname = GetUserDefinedName();
    const byte * sp = prefix ? prefix : (const byte *)"";

    if(IsNull())
        {
        if(!file->Print(PORT_cbyte("LO_%s%sUserName = NULL\r\n"), sp, GetDefLabel() ))
            return false;
        if(!file->Print(PORT_cbyte("LO_%s%sAction = NULL\r\n"), sp, GetDefLabel() ))
            return false;
        if(!file->Print(PORT_cbyte("LO_%s%sSort = NULL\r\n"), sp, GetDefLabel() ))
            return false;
        if(!file->Print(PORT_cbyte("LO_%s%sUserData = NULL\r\n"), sp, GetDefLabel() ))
            return false;
        }
    else
        {
        byte bb[DDP_PrintFile::LINE_SIZE];

        if(!file->Print(PORT_cbyte("LO_%s%sUserName = %s\r\n"), sp, GetDefLabel(), uname ? uname : PORT_cbyte("NULL") ))
            return false;

        GetActionText(bb, sizeof(bb));
        if(!file->Print(PORT_cbyte("LO_%s%sAction = %s\r\n"), sp, GetDefLabel(), bb ))
            return false;

        GetSortText(bb, sizeof(bb));
        if(!file->Print(PORT_cbyte("LO_%s%sSort = %s\r\n"), sp, GetDefLabel(), bb ))
            return false;

        const byte * udata = GetUserData() ? GetUserData() : PORT_cbyte("NULL");
        
        if(!file->Print(PORT_cbyte("LO_%s%sUserData = %s\r\n"), sp, GetDefLabel(), udata ))
            return false;
        }

return true;
}

/****************************************************************************
 NOTES
 ****************************************************************************/


