44 lines
837 B
C++
44 lines
837 B
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <eyd.hh>
|
|
#include <exception>
|
|
|
|
void usage(){
|
|
printf("usage : bitcopy <int> <file>\n");
|
|
}
|
|
|
|
int main(int argc, char ** argv){
|
|
if (argc<2){ usage(); exit(-1); }
|
|
int size = atoi(argv[1]);
|
|
std::string original = argv[2];
|
|
std::string copy = original + ".copy";
|
|
|
|
EydLib::BitReader bitread(size, 256);
|
|
bitread.open(original);
|
|
|
|
EydLib::BitWriter bitwrite(size,256);
|
|
bitwrite.open(copy);
|
|
|
|
printf("File opened\n");
|
|
|
|
bool done=false;
|
|
EydLib::BitGroup bg;
|
|
while(!done){
|
|
try{
|
|
bg = bitread.read();
|
|
printf("read = %s \n",bg.toString().c_str());
|
|
bitwrite.write(bg);
|
|
} catch (EydLib::eBitReaderEndOfFile& e) {
|
|
done = true;
|
|
} catch (std::exception& e){
|
|
printf("ERROR\n");
|
|
}
|
|
}
|
|
printf("copy done\n");
|
|
|
|
bitread.close();
|
|
bitwrite.close();
|
|
|
|
printf("file closed\n");
|
|
}
|