77 std::vector<string> linkbuffer;
87 bool caseSensitive =
false;
90 bool fourByteSize =
false;
91 bool strongsPadding =
true;
93 if (argc < 2)
usage(*argv);
95 const char *progName = argv[0];
96 const char *inFileName = argv[1];
98 for (
int i = 2; i < argc; i++) {
99 if (!strcmp(argv[i],
"-a")) {
102 else if (!strcmp(argv[i],
"-z")) {
103 if (fourByteSize)
usage(*argv,
"Cannot specify both -z and -4");
105 if (i+1 < argc && argv[i+1][0] !=
'-') {
106 switch (argv[++i][0]) {
107 case 'l': compType =
"LZSS";
break;
108 case 'z': compType =
"ZIP";
break;
109 case 'b': compType =
"BZIP2";
break;
110 case 'x': compType =
"XZ";
break;
114 else if (!strcmp(argv[i],
"-Z")) {
115 if (compType.size())
usage(*argv,
"Cannot specify both -z and -Z");
116 if (fourByteSize)
usage(*argv,
"Cannot specify both -Z and -4");
119 else if (!strcmp(argv[i],
"-4")) {
122 else if (!strcmp(argv[i],
"-P")) {
123 strongsPadding =
false;
125 else if (!strcmp(argv[i],
"-b")) {
127 blockCount = atoi(argv[++i]);
128 if (blockCount > 0)
continue;
130 usage(*argv,
"-b requires in entry count integer > 0");
132 else if (!strcmp(argv[i],
"-o")) {
133 if (i+1 < argc) outPath = argv[++i];
134 else usage(progName,
"-o requires <output_path>");
136 else if (!strcmp(argv[i],
"-s")) {
137 caseSensitive =
true;
139 else usage(progName, (((SWBuf)
"Unknown argument: ")+ argv[i]).c_str());
144 if (outPath.size() < 1) {
145 for (i = 0; (i < 16) && (inFileName[i]) && (inFileName[i] !=
'.'); i++) {
146 outPath += inFileName[i];
150 std::ifstream infile(inFileName);
151 if (!infile.is_open()) {
152 fprintf(stderr,
"\nERROR: %s: could not open file for reading: %s\n\n", *argv, inFileName);
157 SWKey *key, *linkKey;
159 if (compType ==
"LZSS") {
162 else if (compType ==
"ZIP") {
164 compressor =
new ZipCompress();
166 usage(*argv,
"ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libz is available when compiling SWORD library");
169 else if (compType ==
"BZIP2") {
173 usage(*argv,
"ERROR: SWORD library not compiled with bzip2 compression support.\n\tBe sure libbz2 is available when compiling SWORD library");
176 else if (compType ==
"XZ") {
180 usage(*argv,
"ERROR: SWORD library not compiled with xz compression support.\n\tBe sure liblzma is available when compiling SWORD library");
189 fprintf(stderr,
"ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str());
203 mod =
new zLD(outPath, 0, 0, blockCount, compressor, 0,
ENC_UNKNOWN,
DIRECTION_LTR,
FMT_UNKNOWN, 0, caseSensitive, strongsPadding);
206 mod = (!fourByteSize)
214 key = mod->createKey();
215 linkKey = mod->createKey();
216 key->setPersist(
true);
219 while (!infile.eof()) {
220 std::getline(infile, linebuffer);
221 if (linebuffer.size() > 3 && linebuffer.substr(0,3) ==
"$$$") {
222 if (keybuffer.size() && entbuffer.size()) {
223 std::cout << keybuffer << std::endl;
224 *key = keybuffer.c_str();
226 mod->setEntry(entbuffer.c_str(), entbuffer.size());
227 for (i = 0; i < links; i++) {
228 std::cout <<
"Linking: " << linkbuffer[i] << std::endl;
229 *linkKey = linkbuffer[i].c_str();
230 mod->linkEntry(linkKey);
233 if (linebuffer.size() > 3)
234 keybuffer = linebuffer.substr(3,linebuffer.size());
240 else if (linebuffer.size() > 3 && linebuffer.substr(0,3) ==
"%%%") {
241 linkbuffer.push_back(linebuffer.substr(3,linebuffer.size()));
245 entbuffer += linebuffer;
250 if (keybuffer.size() && entbuffer.size()) {
251 std::cout << keybuffer << std::endl;
252 *key = keybuffer.c_str();
254 mod->setEntry(entbuffer.c_str(), entbuffer.size());
255 for (i = 0; i < links; i++) {
256 std::cout <<
"Linking: " << linkbuffer[i] << std::endl;
257 *linkKey = linkbuffer[i].c_str();
258 mod->linkEntry(linkKey);
static char createModule(const char *path)
static char createModule(const char *path)
void usage(const char *app)
static char createModule(const char *path)