/***************************************************************************
**
**    $Header:   D:/EPSLDV1/SRC/LOG/MAKETAB/MAKECOM.CPP   1.6   20 Jun 1996 09:34:10   ZJRD  $
**
**    $Log:   D:/EPSLDV1/SRC/LOG/MAKETAB/MAKECOM.CPP  $
** 
**    Rev 1.6   20 Jun 1996 09:34:10   ZJRD
** EasyPack/SLD Version 1.20a
** 
**    Rev 1.4   10 Jun 1996 10:28:36   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.2   29 May 1996 09:42:42   ZJRD
** 
** 
** EasyPack/SLD Versio 1.95
** 
**    Rev 1.1   16 May 1996 09:11:58   ZJRD
** No change.
** 
**    Rev 1.0   10 May 1996 09:24:08   ZJRD
** Initial revision.
** 
****************************************************************************/

#include "stdafx.h"
#include "stdafx.h"
#include "alias.h" 
#include "alias.dat"
    
CCommandArray *ComArray = NULL; 
CCommandArray *HiddenComArray = NULL;
//CCommandArray *AliasArray;                                          

char *szAppPath = "c:\\ep-sld\\maketab\\";  
void ShowLine(char*);
   
int MakeTable(void)
{                  

    int nMaxCom = sizeof(ComTable)/sizeof(ComTable[0]);
    CCommand *pNewCom;     
    CCommandRoot *pNewPara;
    int nParaNum = 0;         
    ComArray = new CCommandArray();  
    
    // add basic command to file
    for (int i=0; i<nMaxCom; i++)
    {
        pNewCom = new CCommand(ComTable[i].pszCommandName,
            ComTable[i].nMinKeyword,ComTable[i].pszHints);
    
        for (int j=0; j<ParaNum[i]; j++)
        {
            pNewPara = new CCommandRoot(
                ParaTable[nParaNum].pszCommandName,
                ParaTable[nParaNum].nMinKeyword);
            if(pNewCom->arrArgv.Add(pNewPara)>=0)    
                nParaNum++;
        }
        ComArray->Add(pNewCom);            
    }
         
    // add hiden command to file
    nMaxCom = sizeof(HiddenComTable)/sizeof(HiddenComTable[0]);
    nParaNum = 0;         
    HiddenComArray = new CCommandArray();
    for (i=0; i<nMaxCom; i++)
    {
        pNewCom = new CCommand(HiddenComTable[i].pszCommandName,
            HiddenComTable[i].nMinKeyword,HiddenComTable[i].pszHints);
    
        for (int j=0; j<HiddenParaNum[i]; j++)
        {
            pNewPara = new CCommandRoot(
                HiddenParaTable[nParaNum].pszCommandName,
                HiddenParaTable[nParaNum].nMinKeyword);
            if(pNewCom->arrArgv.Add(pNewPara)>=0)    
                nParaNum++;
        }
        HiddenComArray->Add(pNewCom);            
    }
         
        
    CString pFileName;
    pFileName = CString(szAppPath) + "command.dat";
    
    CFile f;
    char buf[512];
    if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite ) ) {
        #ifdef _DEBUG
          afxDump << "Unable to open file" << "\n";
        #endif                          
    	delete ComArray;          
    	delete HiddenComArray;
        return 2;
    }
    // store basic and hidden command to file.
    CArchive ar( &f, CArchive::store, 512, buf );
    ComArray->Serialize(ar);            
    HiddenComArray->Serialize(ar);
    
    delete ComArray;          
    delete HiddenComArray;
    
    return 1;
}   


int test_read()
{
    CString pFileName;
    pFileName = CString(szAppPath) + "command.dat";

    
    CFile f;
    char buf[512];
    if( !f.Open( pFileName, CFile::modeRead ) ) {
        #ifdef _DEBUG
          afxDump << "Unable to open file" << "\n";
        #endif   
        return -1;
    }
    CArchive ar( &f, CArchive::load, 512, buf );
    ComArray = new CCommandArray();
    HiddenComArray = new CCommandArray();   
    
    ComArray->Serialize(ar);
    HiddenComArray->Serialize(ar);          
    CCommand *pNewCom;     
    CCommandRoot *pNewPara;
    for(int i=0; i<ComArray->GetSize();i++)
    {
        pNewCom = (CCommand*)(*ComArray)[i];
        for(int j=0; j<pNewCom->arrArgv.GetSize();j++)
            pNewPara = (CCommandRoot*) pNewCom->arrArgv[j];
    }    
    
    for(i=0; i<HiddenComArray->GetSize();i++)
    {
        pNewCom = (CCommand*)(*HiddenComArray)[i];
        for(int j=0; j<pNewCom->arrArgv.GetSize();j++)
            pNewPara = (CCommandRoot*) pNewCom->arrArgv[j];
    }                               

    delete ComArray;            
    delete HiddenComArray;
    return 0;
} 

void ShowLine(char* pszMsg)
{
}
/*---------------------end of file---------------------------*/
    