#define D_CMP_Input_VariableDefine
 
#include "CMP_CPA.h"
#include "ErmCmp.h"
#include "CMP_File.h"
#include "CMP_Pub.h"
#include "CMP_DIFF.h"
#include "CMP_LZSS.h"
 
#define C_TemporaryFile "Temp.tmp"
 
/**************************************************************************/
void CMP_fn_vFirstInit()
{
 Erm_M_InitErrMsg(CMP);
}
/**************************************************************************/
void CMP_fn_vCompressFile(char *_szFileName,unsigned char _ucCompressMethod)
{
 rename(_szFileName,C_TemporaryFile);
 CMP_fn_vCompressFileIn(C_TemporaryFile,_szFileName,_ucCompressMethod);
 DeleteFile(C_TemporaryFile);
}
/**************************************************************************/
void CMP_fn_vCompressFileIn(char *_szInputFileName,char *_szOutputFileName,unsigned char _ucCompressMethod)
{
 #if defined(D_CMP_LZSS)
 if (_ucCompressMethod==D_CMP_LZSS)
 {
  FILE *p_stInputFile = NULL;
  tdstBitFile *p_stOutputBitFile = NULL;
 
  p_stInputFile  = M_p_stOpenInput(_szInputFileName);
  if (p_stInputFile!=NULL)
  {
   p_stOutputBitFile = CMP_fn_p_stOpenOutputBitFile(_szOutputFileName);
   if (p_stOutputBitFile!=NULL)
   {
    CMP_LZSS_fn_vCompressFile(p_stInputFile,p_stOutputBitFile);
    CMP_fn_vCloseOutputBitFile(p_stOutputBitFile);
   }
   M_vCloseInput(p_stInputFile);
  }
 }
 #endif /* D_CMP_LZSS */
 
 #if defined(D_CMP_DIFF)
 if (_ucCompressMethod==D_CMP_DIFF)
 {
  FILE *p_stInputFile = NULL;
  FILE *p_stOutputFile = NULL;
 
  p_stInputFile  = M_p_stOpenInput(_szInputFileName);
  if (p_stInputFile!=NULL)
  {
   p_stOutputFile = M_p_stOpenOutput(_szOutputFileName);
 
   if (p_stOutputFile!=NULL)
   {
    CMP_DIFF_fn_vCompressFile(p_stInputFile,p_stOutputFile);
    M_vCloseOutput(p_stOutputFile);
   }
   M_vCloseInput(p_stInputFile);
  }
 }
 #endif /* D_CMP_DIFF */
}
/**************************************************************************/
unsigned char CMP_fn_bExpandFile(char *_szFileName,unsigned char _ucCompressMethod)
{
 unsigned char ucReturn = TRUE;
 rename(_szFileName,C_TemporaryFile);
 ucReturn = CMP_fn_bExpandFileIn(C_TemporaryFile,_szFileName,_ucCompressMethod);
 DeleteFile(C_TemporaryFile);
 
 return(ucReturn);
}
/**************************************************************************/
unsigned char CMP_fn_bExpandFileIn(char *_szInputFileName,char *_szOutputFileName,unsigned char _ucCompressMethod)
{
 unsigned char ucReturn = FALSE;
 
 #if defined(D_CMP_LZSS)
 if (_ucCompressMethod==D_CMP_LZSS)
 {
  tdstBitFile *p_stInputBitFile = NULL;
  FILE *p_stOutputFile = NULL;
 
  p_stInputBitFile = CMP_fn_p_stOpenInputBitFile(_szInputFileName);
  if (p_stInputBitFile!=NULL)
  {
   p_stOutputFile = M_p_stOpenOutput(_szOutputFileName);
   if (p_stOutputFile!=NULL)
   {
    CMP_LZSS_fn_vExpandFile(p_stInputBitFile,p_stOutputFile);
    ucReturn = TRUE;
    M_vCloseOutput(p_stOutputFile);
   }
   CMP_fn_vCloseInputBitFile(p_stInputBitFile);
  } 
 }
 #endif /* D_CMP_LZSS */
 
 #if defined(D_CMP_DIFF)
 if (_ucCompressMethod==D_CMP_DIFF)
 {
  FILE *p_stInputFile = NULL;
  FILE *p_stOutputFile = NULL;
 
  p_stInputFile  = M_p_stOpenInput(_szInputFileName);
  if (p_stInputFile!=NULL)
  {
   p_stOutputFile = M_p_stOpenOutput(_szOutputFileName);
   if (p_stOutputFile!=NULL)
   {
    CMP_DIFF_fn_vExpandFile(p_stInputFile,p_stOutputFile);
    ucReturn = TRUE;
    M_vCloseOutput(p_stOutputFile);
   }
   M_vCloseInput(p_stInputFile);
  }
 }
 #endif /* D_CMP_DIFF */
 return(ucReturn);
}
/**************************************************************************/
