This commit is contained in:
parent
677add88f0
commit
c92bb5e352
4 changed files with 162 additions and 234 deletions
|
@ -1,102 +1,20 @@
|
|||
#include "eyd.hh"
|
||||
#include "eydrle.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
/*
|
||||
std::string *servermsgold, *usermsg, *userparam;
|
||||
int ret;
|
||||
char * tmp_c_string;
|
||||
ftp_cmd_t ftp_cmd;
|
||||
|
||||
ftp_connection_state_t cnx_state;
|
||||
FtpConfig * client_conf = NULL;
|
||||
|
||||
servermsgold = NULL;
|
||||
usermsg = NULL;
|
||||
userparam = NULL;
|
||||
cnx_state = FTP_STATE_DISCONNECTED;
|
||||
|
||||
client_conf = new FtpConfig();
|
||||
ret = miniftp_args(client_conf, argc, argv);
|
||||
if (ret < 0) { return EXIT_FAILURE; }
|
||||
|
||||
printf("Connecting to %s:%d\n... ",
|
||||
client_conf->server_conf->host->c_str(),
|
||||
client_conf->server_conf->port);
|
||||
fflush(stdout);
|
||||
|
||||
XionFS::XSock *cmdXSock; // *dataXSock;
|
||||
|
||||
cmdXSock = new XionFS::XSock(XionFS::CLIENT,XionFS::TCP);
|
||||
cmdXSock->port(client_conf->server_conf->port);
|
||||
cmdXSock->dns(client_conf->server_conf->host->c_str());
|
||||
|
||||
cmdXSock->launch();
|
||||
printf(" fait\n");
|
||||
client_conf->cmd_xsocket = cmdXSock;
|
||||
|
||||
// init sequence
|
||||
MiniFtp::ServerMsg * servermsg;
|
||||
// ("220 hophop");
|
||||
servermsg = ftp_cmd_recv(client_conf);
|
||||
|
||||
if ((servermsg->getStatus()/10) == 22){
|
||||
cnx_state = FTP_STATE_CONNECTED;
|
||||
} else {
|
||||
cout << "ERROR\n";
|
||||
return EXIT_FAILURE; // event system
|
||||
}
|
||||
delete(servermsg);
|
||||
// init
|
||||
|
||||
cout <<"Auth...\n";
|
||||
while(cnx_state == FTP_STATE_CONNECTED){
|
||||
|
||||
tmp_c_string = readline("Login...: ");
|
||||
usermsg = new std::string(tmp_c_string);
|
||||
ftp_cmd_send(client_conf, FTP_CMD_USER, (char*)usermsg->c_str());
|
||||
free(tmp_c_string);
|
||||
delete(usermsg);
|
||||
|
||||
servermsg = ftp_cmd_recv(client_conf);
|
||||
if (servermsg->getStatus() != 331){
|
||||
continue;
|
||||
}
|
||||
delete(servermsg);
|
||||
|
||||
tmp_c_string = readline("Password: ");
|
||||
usermsg = new std::string(tmp_c_string);
|
||||
ftp_cmd_send(client_conf, FTP_CMD_PASS, (char*)usermsg->c_str());
|
||||
delete(usermsg);
|
||||
|
||||
servermsg = ftp_cmd_recv(client_conf);
|
||||
if ((servermsg->getStatus() / 10) == 23){
|
||||
cnx_state = FTP_STATE_LOGGED_IN;
|
||||
}
|
||||
delete(usermsg);
|
||||
|
||||
}
|
||||
while(cnx_state == FTP_STATE_LOGGED_IN){
|
||||
tmp_c_string = readline("ftp> ");
|
||||
usermsg = new std::string(tmp_c_string);
|
||||
//userparam = (char *) malloc(sizeof(char) * CLIENTQUERY_MAX_LENGTH);
|
||||
ftp_cmd = ftp_cmd_parse(usermsg, &userparam);
|
||||
//Think to keep FTP filesystem tree somewhere
|
||||
ftp_cmd_send(client_conf, ftp_cmd, userparam);
|
||||
if (ftp_cmd == FTP_CMD_QUIT){
|
||||
printf("Disconnecting...\n");
|
||||
cnx_state = FTP_STATE_DISCONNECTED;
|
||||
}
|
||||
free(userparam);
|
||||
delete(usermsg);
|
||||
free(tmp_c_string);
|
||||
namespace EydTools {
|
||||
EydRle::EydRle(){
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
_input_file.clear();
|
||||
_output_file.clear();
|
||||
_cellsize = 8; // one octet each time (by default);
|
||||
}
|
||||
|
||||
void EydRle::run(){
|
||||
if (_mode_compress == EYDRLE_MODE_COMPRESS){
|
||||
this->compress();
|
||||
} else {
|
||||
this->uncompress();
|
||||
}
|
||||
}
|
||||
|
||||
// on le garde dans un coin au chaud en attendant
|
||||
// dataXSock->launch();
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <eyd.hh>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include "eydrle.hh"
|
||||
|
||||
void usage(){
|
||||
printf("usage : bitcopy <int> <file>\n");
|
||||
}
|
||||
namespace EydTools {
|
||||
void EydRle::compress(){
|
||||
EydLib::BitGroup data;
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
EydLib::BitGroup data;
|
||||
int cell_size;
|
||||
std::string original;
|
||||
std::string copy;
|
||||
EydLib::BitReader bitread(_cellsize, 256);
|
||||
bitread.open(_input_file);
|
||||
|
||||
if (argc<2){ usage(); exit(-1); }
|
||||
cell_size = atoi(argv[1]);
|
||||
original = argv[2];
|
||||
EydLib::BitWriter bitwrite(_cellsize,256);
|
||||
bitwrite.open(_output_file);
|
||||
unsigned char c = (unsigned char)_cellsize;
|
||||
bitwrite.writeDirect(&c, 1);
|
||||
|
||||
copy = original + ".rl1";
|
||||
EydLib::BitCompressor compressor(_cellsize);
|
||||
|
||||
EydLib::BitReader bitread(cell_size, 256);
|
||||
bitread.open(original);
|
||||
printf("File opened\n");
|
||||
|
||||
EydLib::BitWriter bitwrite(cell_size,256);
|
||||
bitwrite.open(copy);
|
||||
unsigned char c = (unsigned char)cell_size;
|
||||
bitwrite.writeDirect(&c, 1);
|
||||
bool done=false;
|
||||
std::vector<EydLib::BitGroup> record;
|
||||
while(!done){
|
||||
try{
|
||||
data = bitread.read();
|
||||
compressor.append(data);
|
||||
|
||||
EydLib::BitCompressor compressor(cell_size);
|
||||
|
||||
printf("File opened\n");
|
||||
|
||||
bool done=false;
|
||||
std::vector<EydLib::BitGroup> record;
|
||||
while(!done){
|
||||
try{
|
||||
data = bitread.read();
|
||||
compressor.append(data);
|
||||
|
||||
if (compressor.hasContent()){
|
||||
if (compressor.hasContent()){
|
||||
std::list<EydLib::BitGroup> compressedData = compressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator cmpDataIt;
|
||||
for(cmpDataIt = compressedData.begin();
|
||||
cmpDataIt != compressedData.end();
|
||||
cmpDataIt++){
|
||||
bitwrite.write((*cmpDataIt)); // cellule
|
||||
}
|
||||
}
|
||||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// on flushe le contenu de record
|
||||
compressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> compressedData = compressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator cmpDataIt;
|
||||
for(cmpDataIt = compressedData.begin();
|
||||
|
@ -47,26 +43,15 @@ int main(int argc, char ** argv){
|
|||
cmpDataIt++){
|
||||
bitwrite.write((*cmpDataIt)); // cellule
|
||||
}
|
||||
} catch (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// TODO: on flushe le contenu de record
|
||||
compressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> compressedData = compressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator cmpDataIt;
|
||||
for(cmpDataIt = compressedData.begin();
|
||||
cmpDataIt != compressedData.end();
|
||||
cmpDataIt++){
|
||||
bitwrite.write((*cmpDataIt)); // cellule
|
||||
}
|
||||
} catch (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
printf("compression done\n");
|
||||
|
||||
bitread.close();
|
||||
bitwrite.close();
|
||||
|
||||
printf("file closed\n");
|
||||
}
|
||||
printf("compression done\n");
|
||||
|
||||
bitread.close();
|
||||
bitwrite.close();
|
||||
|
||||
printf("file closed\n");
|
||||
}
|
||||
|
|
|
@ -1,34 +1,71 @@
|
|||
#include "eyd.hh"
|
||||
#include "eydrle.hh"
|
||||
|
||||
/*
|
||||
int miniftp_args(MiniFtp::FtpConfig * client_conf, int argc, char ** argv){ // GOOD
|
||||
int i;
|
||||
namespace EydTools {
|
||||
|
||||
for (i = 1; i + 1 < argc; i = i + 2){
|
||||
char * opt = argv[i]; //GOOD
|
||||
char * val = argv[i+1]; //GOOD
|
||||
if ( (strcmp(opt, "--port") == 0) || (strcmp(opt,"-p") == 0) ){
|
||||
client_conf->setServerPort(atoi(val));
|
||||
continue;
|
||||
}
|
||||
if ( (strcmp(opt, "--host") == 0) || (strcmp(opt,"-h") == 0) ){
|
||||
client_conf->setServerHost(std::string(val));
|
||||
continue;
|
||||
bool EydRle::init(int argc, char ** argv){
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
|
||||
int i;
|
||||
for (i = 1; i + 1 < argc; i = i + 2){
|
||||
char * opt = argv[i]; //GOOD
|
||||
char * val = argv[i+1]; //GOOD
|
||||
if ( (strcmp(opt, "--mode") == 0) || (strcmp(opt,"-m") == 0) ){
|
||||
switch(val[0]){
|
||||
case 'c':
|
||||
case 'C':
|
||||
_mode_compress = EYDRLE_MODE_COMPRESS;
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
_mode_compress = EYDRLE_MODE_UNCOMPRESS;
|
||||
break;
|
||||
default:
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( (strcmp(opt, "--input") == 0) || (strcmp(opt,"-i") == 0) ){
|
||||
_input_file = val;
|
||||
}
|
||||
|
||||
if ( (strcmp(opt, "--output") == 0) || (strcmp(opt,"-o") == 0) ){
|
||||
_output_file = val;
|
||||
}
|
||||
|
||||
if ( (strcmp(opt, "--cellsize") == 0) || (strcmp(opt,"-c") == 0) ){
|
||||
_cellsize = atoi(val);
|
||||
}
|
||||
|
||||
// printf("Option = %s, ",argv[i]);
|
||||
// printf("value = %s\n",argv[i+1]);
|
||||
}
|
||||
|
||||
// printf("Option = %s, ",argv[i]);
|
||||
// printf("value = %s\n",argv[i+1]);
|
||||
if ((_mode_compress == EYDRLE_MODE_UNDEF) ||
|
||||
(_input_file.length() == 0)) {
|
||||
printf("\nUsage: %s <options>\n", argv[0]);
|
||||
printf("\nWhere options could be:\n");
|
||||
printf("-m, --mode (c|u) Compress or uncompress\n");
|
||||
printf("-i, --input <file> File to compress | uncompress\n");
|
||||
printf("-o, --output <file> Destination file\n");
|
||||
printf("-c, --cellsize <file> Cell size (in bits)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_output_file.length() == 0){
|
||||
if (_mode_compress == EYDRLE_MODE_COMPRESS){
|
||||
_output_file = _input_file + ".rl1";
|
||||
} else {
|
||||
_output_file = _input_file + ".rl1_orig";
|
||||
}
|
||||
}
|
||||
|
||||
// setting rle
|
||||
EydLib::BitGroup rleFinal(_cellsize);
|
||||
_rle = rleFinal;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!client_conf->hasServerHost()
|
||||
|| !client_conf->hasServerPort()) {
|
||||
printf("\nUsage: %s <options>\n", argv[0]);
|
||||
printf("\nWhere options could be:\n");
|
||||
printf("-p, --port <integer> Port to connect on host\n");
|
||||
printf("-h, --host <string> DNS or IP address of the FTP host\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <eyd.hh>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include "eydrle.hh"
|
||||
|
||||
void usage(){
|
||||
printf("usage : bitcopy <int> <file>\n");
|
||||
}
|
||||
namespace EydTools {
|
||||
void EydRle::uncompress(){
|
||||
EydLib::BitGroup data;
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
EydLib::BitGroup data;
|
||||
int cell_size;
|
||||
std::string original;
|
||||
std::string copy;
|
||||
EydLib::BitReader bitread(_cellsize, 256);
|
||||
bitread.open(_input_file);
|
||||
|
||||
if (argc<2){ usage(); exit(-1); }
|
||||
cell_size = atoi(argv[1]);
|
||||
original = argv[2];
|
||||
unsigned char c;
|
||||
bitread.readDirect(&c, 1);
|
||||
//TODO: fixer cell_size en fonction de "c";
|
||||
|
||||
copy = original + ".rl2";
|
||||
if (c != _cellsize){
|
||||
printf("WARNING : File cellsize is %d, but uncompressing with %d\n",c, _cellsize);
|
||||
}
|
||||
|
||||
EydLib::BitReader bitread(cell_size, 256);
|
||||
bitread.open(original);
|
||||
EydLib::BitWriter bitwrite(_cellsize,256);
|
||||
bitwrite.open(_output_file);
|
||||
|
||||
unsigned char c;
|
||||
bitread.readDirect(&c, 1);
|
||||
//TODO: fixer cell_size en fonction de "c";
|
||||
EydLib::BitUncompressor uncompressor(_cellsize);
|
||||
|
||||
EydLib::BitWriter bitwrite(cell_size,256);
|
||||
bitwrite.open(copy);
|
||||
printf("File opened\n");
|
||||
|
||||
EydLib::BitUncompressor uncompressor(cell_size);
|
||||
bool done=false;
|
||||
std::vector<EydLib::BitGroup> record;
|
||||
while(!done){
|
||||
try{
|
||||
data = bitread.read();
|
||||
uncompressor.append(data);
|
||||
|
||||
printf("File opened\n");
|
||||
|
||||
bool done=false;
|
||||
std::vector<EydLib::BitGroup> record;
|
||||
while(!done){
|
||||
try{
|
||||
data = bitread.read();
|
||||
uncompressor.append(data);
|
||||
|
||||
if (uncompressor.hasContent()){
|
||||
if (uncompressor.hasContent()){
|
||||
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator uncmpDataIt;
|
||||
for(uncmpDataIt = uncompressedData.begin();
|
||||
uncmpDataIt != uncompressedData.end();
|
||||
uncmpDataIt++){
|
||||
bitwrite.write((*uncmpDataIt)); // cellule
|
||||
}
|
||||
}
|
||||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// on flushe le contenu de record
|
||||
// uncompressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator uncmpDataIt;
|
||||
for(uncmpDataIt = uncompressedData.begin();
|
||||
|
@ -49,27 +49,15 @@ int main(int argc, char ** argv){
|
|||
uncmpDataIt++){
|
||||
bitwrite.write((*uncmpDataIt)); // cellule
|
||||
}
|
||||
} catch (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// on flushe le contenu de record
|
||||
// FIXME: trouver un moyen de flusher la fin du fichier
|
||||
// uncompressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator uncmpDataIt;
|
||||
for(uncmpDataIt = uncompressedData.begin();
|
||||
uncmpDataIt != uncompressedData.end();
|
||||
uncmpDataIt++){
|
||||
bitwrite.write((*uncmpDataIt)); // cellule
|
||||
}
|
||||
} catch (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
printf("uncompression done\n");
|
||||
|
||||
bitread.close();
|
||||
bitwrite.close();
|
||||
|
||||
printf("file closed\n");
|
||||
}
|
||||
printf("uncompression done\n");
|
||||
|
||||
bitread.close();
|
||||
bitwrite.close();
|
||||
|
||||
printf("file closed\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue