/***************************************************************************
**
**    $Header:   D:/EPSLDV1/SRC/LOG/DLIB.CPP   1.4   20 Jun 1996 09:29:24   ZJRD  $
**
**    $Log:   D:/EPSLDV1/SRC/LOG/DLIB.CPP  $
** 
**    Rev 1.4   20 Jun 1996 09:29:24   ZJRD
** EasyPack/SLD Version 1.20a
** 
**    Rev 1.2   10 Jun 1996 10:24:02   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.0   29 May 1996 09:35:38   ZJRD
** Initial revision.
** 
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
// dc.cpp
//
// Michael Long
//                                                                           
// 5/14/96
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"

#include "toolopt.h"
#include "dlib.h"

/////////////////////////////////////////////////////////////////////////////
// diagnostic
#ifdef _DEBUG
void DLIBTool::Dump(CDumpContext &dc) const
{         
    CToolOption::Dump(dc);
    dc << "m_nSmall = " << m_nSmall << "\n";
    dc << "m_nCompact = " << m_nCompact << "\n";
    dc << "m_nLarge = " << m_nLarge << "\n";
    dc << "m_strMore = " << m_strMore << "\n";  
    dc << "m_strPath = " << m_strPath << "\n";
}
#endif

/////////////////////////////////////////////////////////////////////////////
// operations
void DLIBTool::SetDefault(void)
{
    m_nSmall = FALSE;     // 0-3
    m_nCompact = FALSE; // 0 - 2 = s,c,l
    m_nLarge = TRUE;    // 0 - 5
    m_strMore = " "; 
    m_strPath = "c:\\omf51 ";
}

BOOL DLIBTool::LoadOption(FILE * fp)
{
    ASSERT(fp);
    
    const int nCnt = 3;
    
    char dch[nCnt];
    
    if(fread(dch, 1, nCnt, fp) != nCnt)
        return FALSE;
        
    m_nSmall = dch[0];
    m_nCompact = dch[1];
    m_nLarge = dch[2];
    WORD wLen;
    if(fread(&wLen, 2, 1, fp) != 1)
        return FALSE;
    if(wLen > (WORD)32000)
        return FALSE;
        
    if(fread(m_strMore.GetBuffer(wLen), 1, wLen, fp) != wLen)
        return FALSE;

    m_strMore.ReleaseBuffer(wLen);  
    if(fread(&wLen, 2, 1, fp) != 1)
        return FALSE;
    if(wLen > (WORD)32000)
        return FALSE;
        
    if(fread(m_strPath.GetBuffer(wLen), 1, wLen, fp) != wLen)
        return FALSE;

    m_strPath.ReleaseBuffer(wLen);  
    
    return TRUE;
}                 

BOOL DLIBTool::SaveOption(FILE * fp)
{
    ASSERT(fp);
    
    const int nCnt = 3;

    char dch[nCnt];
    
    dch[0] = m_nSmall;
    dch[1] = m_nCompact;
    dch[2] = m_nLarge;
    
    if(fwrite(dch, 1, nCnt, fp) != nCnt)
        return FALSE;
             
    WORD wLen = m_strMore.GetLength();           
    if(fwrite(&wLen, 2, 1, fp) != 1)
        return FALSE;
        
    if(fwrite(m_strMore.GetBuffer(wLen), 1, wLen, fp) != wLen)
        return FALSE;

    m_strMore.ReleaseBuffer(wLen);  
    
    wLen = m_strPath.GetLength();           
    if(fwrite(&wLen, 2, 1, fp) != 1)
        return FALSE;
        
    if(fwrite(m_strMore.GetBuffer(wLen), 1, wLen, fp) != wLen)
        return FALSE;

    m_strPath.ReleaseBuffer(wLen);  
    
    return TRUE;
}   
                            
CString DLIBTool::GetOption(void) const
{
    CString str = " ";
    CString dlibstr;
    if(m_strPath[m_strPath.GetLength()-1]!='\\')
    dlibstr = m_strPath + "\\"; 
    str += dlibstr;
    
    if(m_nSmall)
        str += "C51FPS.LIB ";
        
    if(m_nCompact)
        str += "C51FPC.LIB ";
        
    if(m_nLarge)
        str += "C51FPL.LIB ";
    
        
    str += m_strMore;
    str += " ";
    
    return str;     
}

