| 1 |
#include "Arguments.h" |
| 2 |
#include <iostream> |
| 3 |
#include <string> |
| 4 |
#include <strstream> |
| 5 |
#include <fstream> |
| 6 |
using namespace std; |
| 7 |
|
| 8 |
int main(int argc, const char** argv) |
| 9 |
{ |
| 10 |
Arguments A(argc, argv); |
| 11 |
|
| 12 |
string lfile, ofile; |
| 13 |
int maxchars, maxlinks; |
| 14 |
|
| 15 |
if ( (!A.get("--links", lfile, "")) || |
| 16 |
(!A.get("--out", ofile, "")) || |
| 17 |
(!A.get("--maxchars", maxchars, 17)) || |
| 18 |
(!A.get("--maxlinks", maxlinks, 5)) ) |
| 19 |
{ |
| 20 |
cerr << "Syntax: " << argv[0] << " --links=link.# --out=w-i.# --maxchars=x --maxlinks=x" << endl; |
| 21 |
exit(1); |
| 22 |
} |
| 23 |
|
| 24 |
ifstream in(lfile.c_str()); |
| 25 |
ofstream out(ofile.c_str()); |
| 26 |
|
| 27 |
char buf[64000]; |
| 28 |
|
| 29 |
while(in.getline(buf, 64000)) |
| 30 |
{ |
| 31 |
istrstream ss(buf); |
| 32 |
string word; |
| 33 |
ss >> word; |
| 34 |
|
| 35 |
if (word.size() > static_cast<unsigned int>(maxchars)) |
| 36 |
continue; |
| 37 |
|
| 38 |
out << word; |
| 39 |
for(unsigned i = 0;i < ( maxchars - word.size() );++i) |
| 40 |
{ |
| 41 |
out << static_cast<unsigned char>(0); |
| 42 |
} |
| 43 |
|
| 44 |
int i = 0, x; |
| 45 |
for(;(i < maxlinks) && (ss >> x);++i) |
| 46 |
{ |
| 47 |
unsigned char ochar1 = static_cast<unsigned char>(x >> 8); |
| 48 |
unsigned char ochar2 = static_cast<unsigned char>(x & 0xFF); |
| 49 |
out << ochar1 << ochar2; |
| 50 |
} |
| 51 |
|
| 52 |
for(;i < maxlinks;++i) |
| 53 |
{ |
| 54 |
out << static_cast<unsigned char>(0xFF) |
| 55 |
<< static_cast<unsigned char>(0xFF); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |