/* LzmaUtil.c -- Test application for LZMA compression
2008-11-23 : Igor Pavlov : Public domain */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>

/* #include "../Alloc.h"
#include "../7zFile.h"
#include "../7zVersion.h"
#include "../LzmaDec.h"
#include "../LzmaEnc.h"
#include "../LzmaLib.h" */

#include "Lzma.h"

int PrintError(char *buffer, const char *message)
{
  strcat(buffer, "\nError: ");
  strcat(buffer, message);
  strcat(buffer, "\n");
  return 1;
}

void printPrefix(Byte *s, int num)
{
  for( ; (num > 0) && (*s != '\0'); num--,s++)
    printf("%c",*s);
}


// In millisecs
double getTime(void)
{

  double usertime, systime;
  struct rusage usage;

  getrusage(RUSAGE_SELF, &usage);

  usertime = (double) usage.ru_utime.tv_sec * 1000 +
    (double) usage.ru_utime.tv_usec / 1000.0;
  systime = (double) usage.ru_stime.tv_sec * 1000 +
    (double) usage.ru_stime.tv_usec / 1000.0;
  return (usertime + systime);

}

void ProvaPaolo(void)
{

  SRes res;
  Byte *inBuf, *outBuf, *outBuf1;
  size_t  inSize, outSize, outSize1;
  FILE *fp;
  unsigned char outProps[LZMA_PROPS_SIZE]; 
  size_t outPropsSize = LZMA_PROPS_SIZE;
  
  inBuf = (Byte *)malloc(100000);
  outBuf = (Byte *)malloc(100000);
  outBuf1 = (Byte *)malloc(100000);

  // Load the input
  fp = fopen("_aa_","r");
  if (!fp){
    printf("No input file\n");
    exit(0);
  }
  inSize = fread(inBuf,1,500,fp);
  fclose(fp);


  // Description of the parameters in ../LzmaLib.h
  // Dict size = 32Mb, compression level = 9, other params = default  
  outSize = (size_t)100000;
  res = LzmaCompress(outBuf, &outSize, inBuf, inSize, outProps, &outPropsSize, 9, (1<<24), 3, 0, 2, 32, 2);
  if (res != SZ_OK)
  { fprintf(stderr, "Error in MYCompress: %d\n",res); exit(1); }

  // Decompression
  // ATTENTION: outSize1 must be the final uncompressed output length
  //            so it must be passed someway.
  outSize1 = (size_t)500;  
  res = LzmaUncompress(outBuf1, &outSize1, outBuf, &outSize, outProps, outPropsSize);
  if (res != SZ_OK)
  { fprintf(stderr, "Error in MYCompress: %d\n",res); exit(1); }


}



int main(int numArgs, const char *args[])
{

  ProvaPaolo();
  return 0;
}

