Old stuff/ecole_etude_fac_de_pau/licence_3/projet_lzw/lzw.cpp
(Deskargatu)
/*
This file is part of projet_lzw_univ_pau.
projet_lzw_univ_pau is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
projet_lzw_univ_pau is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with projet_lzw_univ_pau; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "include/outputstream.h"
#include "include/inputstream.h"
#include <ostream>
#include <fstream>
#include <iostream>
int usage(char* argv)
{
std::cout << "usage: \033[1m" << argv << " <command> source_file result_file\033[0m\n";
std::cout << "<commands>\n";
std::cout << "\t-d\t\t compress file\n";
std::cout << "\t-i\t\t decompress file\n";
return 0;
}
int main(int argc,char** argv)
{
int action=0;
char* source= NULL;
char* result= NULL;
for(int i=1;i<argc;i++)
{
if (strcmp(argv[i],"-inflate") == 0 || strcmp(argv[i],"-i") == 0)
{
action = 2;
}
else if (strcmp(argv[i],"-deflate") == 0 || strcmp(argv[i],"-d") == 0)
{
action = 1;
}
else if(source==NULL)
{
source=argv[i];
}
else if(result==NULL)
{
result=argv[i];
}
else
{
usage(argv[0]);
return 0;
}
}
if (action==0 || source==NULL || result==NULL)
{
usage(argv[0]);
return 0;
}
std::cout << action << " avec " << source << " et " << result << "\n";
if(action==1)
{
std::ofstream fichier;
fichier.open (result,std::ofstream::binary);
DeflaterOutputStream str(fichier);
str.DeflateFromFile(source);
}
else
{
std::ofstream enre;
enre.open(result,std::ofstream::binary);
DeflaterInputStream str(enre);
str.DeflateFromFile(source);
}
std::cout << "Fin\n";
}