24 #pragma warning( disable: 4251 )
48 #ifndef NO_SWORD_NAMESPACE
49 using namespace sword;
52 void usage(
const char *progName,
const char *error = 0) {
53 if (error) fprintf(stderr,
"\n%s: %s\n", progName, error);
54 fprintf(stderr,
"\n=== imp2ld (Revision $Rev: 3223 $) SWORD lexicon importer.\n");
55 fprintf(stderr,
"\nusage: %s <imp_file> [options]\n", progName);
56 fprintf(stderr,
" -a\t\t\t augment module if exists (default is to create new)\n");
57 fprintf(stderr,
" -z <l|z|b|x>\t\t use compression (default: none)\n");
58 fprintf(stderr,
"\t\t\t\t l - LZSS; z - ZIP; b - bzip2; x - xz\n");
59 fprintf(stderr,
" -o <output_path>\t\t where to write data files.\n");
60 fprintf(stderr,
" -4\t\t\t use 4 byte size entries (default: 2).\n");
61 fprintf(stderr,
" -b <entry_count>\t\t compression block size (default 30 entries)\n");
62 fprintf(stderr,
" -s\t\t\t case sensitive keys (default is not case sensitive)\n");
63 fprintf(stderr,
" -P\t\t\t disable key Strong's number padding (by default keys will be padded).");
64 fprintf(stderr,
"\n");
65 fprintf(stderr,
"'imp' format is a simple standard for importing data into SWORD modules.\n"
66 "Required is a plain text file containing $$$key lines followed by content.\n\n"
68 "Abraham was the father of Isaac...\n"
69 "He was called by God to leave his country and journey to the land of Canaan...\n"
71 "Isaac was the son of Abraham and Sarah...\n\n");
75 int main(
int argc,
char **argv) {
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)