/***************************************************************************
**
**    $Header:   D:/ECB2S/SRC/LOG/MAKETAB/MAKECOM.CPP   1.2.1.5   17 Apr 1997 16:30:06   ZJRD  $
**
**    $Log:   D:/ECB2S/SRC/LOG/MAKETAB/MAKECOM.CPP  $
** 
**    Rev 1.2.1.5   17 Apr 1997 16:30:06   ZJRD
** No change.
** 
**    Rev 1.2.1.4   16 Apr 1997 11:08:52   ZJRD
** No change.
** 
**    Rev 1.2.1.3   10 Apr 1997 15:55:38   ZJRD
** 2.09F
** 
**    Rev 1.2.1.1   03 Apr 1997 15:32:42   ZJRD
** No change.
** 
**    Rev 1.2.1.0   28 Mar 1997 10:37:08   ZJRD
** easy pack sld 2.09d
** 
**    Rev 1.1   19 Mar 1997 11:46:38   ZJRD
** No change.
** 
**    Rev 1.0   12 Mar 1997 15:00:48   ZJRD
** Initial revision.
** 
**    Rev 1.5.1.0.1.2   09 Dec 1996 10:24:34   ZJRD
** EasyPack/SLD Version 2.0P
** 
**    Rev 1.5.1.0.1.0   11 Nov 1996 13:04:36   ZJRD
** EasyPack/SLD Version 2.01
** 
**    Rev 1.5.1.4   09 Sep 1996 13:48:52   ZJRD
** No change.
** 
**    Rev 1.5.1.3   05 Sep 1996 11:39:38   ZJRD
** No change.
** 
**    Rev 1.5.1.2   02 Sep 1996 10:04:14   ZJRD
** No change.
** 
**    Rev 1.5.1.1   28 Aug 1996 15:57:42   ZJRD
** No change.
** 
**    Rev 1.5.1.0   12 Aug 1996 11:05:34   ZJRD
** No change.
** 
**    Rev 1.5   11 Jun 1996 10:33:12   ZJRD
** EasyPack/SLD Version 1.97
** 
**    Rev 1.3   05 Jun 1996 15:00:42   ZJRD
** No change.
** 
**    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---------------------------*/
    