Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "Huffman.H"
#include "Compress.H"
#include "Decompress.H"
#include <iostream>
#include <algorithm>
#include <sstream>
#include <signal.h>
using namespace std;
void printIntroduction(){
cout << "Huffman base Data Compression (Lossless)\n"
<< "Written By: Tony Pham\n"
<< "Version: 1.0.0.0.0..........\n";
}
void printInstruction(){
cout << "[Usage] ./huffman <-d/-c> <input Filename> <output Filename>\n"
<< " - If an output filename is not given:\n"
<< "\t - Compressing (-c): the output will be the input name appended with 'compressed_'\n"
<< "\t - Decompressing (-d): the output will be the input name appended with 'decompressed_'\n"
<< " - To check program version use the tag --v\n";
}
void parseInput(vector<string> input){
if(input.size() < 2){ // Not enough given args
cout << "Not enough arguments" << endl;
return;
}
if (!(input.at(0).compare("-c"))){
Compress comp = Compress(input.at(1));
if (input.size() < 3) comp.compressFile("compressed_"+input.at(1));
else comp.compressFile(input.at(2));
}
else if (!(input.at(0).compare("-d"))){
Decompress decomp = Decompress(input.at(1));
if(input.size() < 3){
string str = input.at(1);
size_t found = str.find("_");
string check = string(str.begin(),str.begin()+found+1);
if (!check.compare("compressed_")) decomp.decompressFile("de"+input.at(1));
else decomp.decompressFile("decompressed_"+input.at(1));
}
else { decomp.decompressFile(input.at(2));}
}
else{
cout << input.at(0) + " is not a recognized command\n";
}
}
int main(int argc, char *argv[]){
using namespace std;
if (argc < 2){
cout << "[Usage] ./huffman <-d/-c> <input Filename> <output Filename>\n \t For more information run the progam with -h\n";
exit(0);
}
if (!strcmp(argv[1],"--v")){
printIntroduction();
exit(0);
}
if (!strcmp(argv[1],"-h")){
printInstruction();
exit(0);
}
if (argc > 2){
vector<string> input = vector<string>();
input.push_back(string(argv[1]));
input.push_back(string(argv[2]));
if (argc > 3) input.push_back(argv[3]);
try{
parseInput(input);
}
catch(string &e){cout << e << endl;}
}
else{
cout << "Unknown Command: " + string(argv[1]) + "\n";
}
return 0;
}