24 #pragma warning( disable: 4251 )
49 #ifndef NO_SWORD_NAMESPACE
50 using namespace sword;
55 void writeEntry(SWModule *
module,
const SWBuf &key,
const SWBuf &entry,
bool replace);
57 void usage(
const char *progName,
const char *error = 0) {
58 if (error) fprintf(stderr,
"\n%s: %s\n", progName, error);
59 fprintf(stderr,
"\n=== imp2vs (Revision $Rev: 3741 $) SWORD Bible/Commentary importer.\n");
60 fprintf(stderr,
"\nusage: %s <imp_file> [options]\n", progName);
61 fprintf(stderr,
" -a\t\t\t augment module if exists (default is to create new)\n");
62 fprintf(stderr,
" -r\t\t\t replace existing entries (default is to append)\n");
63 fprintf(stderr,
" -z <l|z|b|x>\t\t use compression (default: none):\n");
64 fprintf(stderr,
"\t\t\t\t l - LZSS; z - ZIP; b - bzip2; x - xz\n");
65 fprintf(stderr,
" -o <output_path>\t where to write data files.\n");
66 fprintf(stderr,
" -4\t\t\t use 4 byte size entries (default is 2).\n");
67 fprintf(stderr,
" -b <2|3|4>\t\t compression block size (default 4):\n");
68 fprintf(stderr,
"\t\t\t\t 2 - verse; 3 - chapter; 4 - book\n");
69 fprintf(stderr,
" -v <v11n>\t\t specify a versification scheme to use (default is KJV)\n");
70 fprintf(stderr,
"\t\t\t\t Note: The following are valid values for v11n:\n");
73 for (StringList::iterator loop = av11n.begin(); loop != av11n.end(); loop++) {
74 fprintf(stderr,
"\t\t\t\t\t%s\n", (*loop).c_str());
76 fprintf(stderr,
" -l <locale>\t\t specify a locale scheme to use (default is en)\n");
77 fprintf(stderr,
" -c <cipher_key>\t encipher module using supplied key\n");
78 fprintf(stderr,
"\t\t\t\t (default no enciphering)\n");
79 fprintf(stderr,
"\n");
80 fprintf(stderr,
"'imp' format is a simple standard for importing data into SWORD modules.\n"
81 "Required is a plain text file containing $$$key lines followed by content.\n\n"
83 "In the beginning God created\n"
84 "the heavens and the earth\n"
86 "and the earth...\n\n"
87 "Key lines can contain ranges, for example, a commentary entry which discusses\n"
88 "John 1:1-4 might have a key, $$$Jn.1.1-4. Special keys for intro entries use\n"
89 "standard SWORD notation, e.g. $$$Rom.4.0 for intro of Romans chapter 4,\n"
90 "$$$Rev.0.0 for intro of the Book of Revelation of John. $$$[ Module Heading ]\n"
91 "for entire module intro. $$$[ Testament 2 Heading ] for NT intro.\n\n");
96 int main(
int argc,
char **argv) {
100 if (argc < 2)
usage(*argv);
102 const char *progName = argv[0];
103 const char *inFileName = argv[1];
108 bool fourByteSize =
false;
110 bool replace =
false;
112 SWBuf cipherKey =
"";
116 for (
int i = 2; i < argc; i++) {
117 if (!strcmp(argv[i],
"-a")) {
120 else if (!strcmp(argv[i],
"-r")) {
123 else if (!strcmp(argv[i],
"-z")) {
124 if (fourByteSize)
usage(*argv,
"Cannot specify both -z and -4");
126 if (i+1 < argc && argv[i+1][0] !=
'-') {
127 switch (argv[++i][0]) {
128 case 'l': compType =
"LZSS";
break;
129 case 'z': compType =
"ZIP";
break;
130 case 'b': compType =
"BZIP2";
break;
131 case 'x': compType =
"XZ";
break;
135 else if (!strcmp(argv[i],
"-Z")) {
136 if (compType.size())
usage(*argv,
"Cannot specify both -z and -Z");
137 if (fourByteSize)
usage(*argv,
"Cannot specify both -Z and -4");
140 else if (!strcmp(argv[i],
"-4")) {
143 else if (!strcmp(argv[i],
"-b")) {
145 iType = atoi(argv[++i]);
146 if ((iType >= 2) && (iType <= 4))
continue;
148 usage(*argv,
"-b requires one of <2|3|4>");
150 else if (!strcmp(argv[i],
"-o")) {
151 if (i+1 < argc) outPath = argv[++i];
152 else usage(progName,
"-o requires <output_path>");
154 else if (!strcmp(argv[i],
"-v")) {
155 if (i+1 < argc) v11n = argv[++i];
156 else usage(progName,
"-v requires <v11n>");
158 else if (!strcmp(argv[i],
"-l")) {
159 if (i+1 < argc) locale = argv[++i];
160 else usage(progName,
"-l requires <locale>");
162 else if (!strcmp(argv[i],
"-c")) {
163 if (i+1 < argc) cipherKey = argv[++i];
164 else usage(*argv,
"-c requires <cipher_key>");
166 else usage(progName, (((SWBuf)
"Unknown argument: ")+ argv[i]).c_str());
170 if (!v) std::cout <<
"Warning: Versification " << v11n <<
" not found. Using KJV versification...\n";
172 if (compType ==
"LZSS") {
175 else if (compType ==
"ZIP") {
177 compressor =
new ZipCompress();
179 usage(*argv,
"ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libz is available when compiling SWORD library");
182 else if (compType ==
"BZIP2") {
186 usage(*argv,
"ERROR: SWORD library not compiled with bzip2 compression support.\n\tBe sure libbz2 is available when compiling SWORD library");
189 else if (compType ==
"XZ") {
193 usage(*argv,
"ERROR: SWORD library not compiled with xz compression support.\n\tBe sure liblzma is available when compiling SWORD library");
202 fprintf(stderr,
"ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str());
232 module = (!fourByteSize)
239 if (cipherKey.length()) {
240 fprintf(stderr,
"Adding cipher filter with phrase: %s\n", cipherKey.c_str() );
242 module->addRawFilter(cipherFilter);
253 VerseKey *vkey = (VerseKey *)module->createKey();
254 vkey->setIntros(
true);
255 vkey->setAutoNormalize(
false);
256 vkey->setPersist(
true);
257 module->setKey(*vkey);
271 if (lineBuffer.startsWith(
"$$$")) {
272 if ((keyBuffer.size()) && (entBuffer.size())) {
273 writeEntry(module, keyBuffer, entBuffer, replace);
275 keyBuffer = lineBuffer;
281 if (keyBuffer.size()) {
282 entBuffer += lineBuffer;
287 if ((keyBuffer.size()) && (entBuffer.size())) {
288 writeEntry(module, keyBuffer, entBuffer, replace);
308 if (key.size() && entry.size()) {
309 std::cout <<
"from file: " << key << std::endl;
310 VerseKey *vkey = (VerseKey *)module->getKey();
311 VerseKey *linkMaster = (VerseKey *)module->createKey();
313 ListKey listKey = vkey->parseVerseList(key.c_str(),
"Gen1:1",
true);
316 for (listKey =
TOP; !listKey.popError(); listKey++) {
320 SWBuf text = (replace) ?
"" : module->getRawEntry();
321 if (text.length()) text +=
" ";
355 std::cout <<
"adding entry: " << *vkey <<
" length " << entry.size() <<
"/" << (
unsigned short)text.size() << std::endl;
356 module->setEntry(text);
360 std::cout <<
"linking entry: " << *vkey <<
" to " << *linkMaster << std::endl;
361 module->linkEntry(linkMaster);
virtual void setDefaultLocaleName(const char *name)
static unsigned int RDONLY
static char createModule(const char *path, const char *v11n="KJV")
std::list< SWBuf > StringList
static LocaleMgr * getSystemLocaleMgr()
void writeEntry(SWModule *book, SWBuf keyBuffer, SWBuf entBuffer)
static char createModule(const char *path, const char *v11n="KJV")
const StringList getVersificationSystems() const
static char createModule(const char *path, int blockBound, const char *v11n="KJV")
void usage(const char *app)
static char getLine(FileDesc *fDesc, SWBuf &line)
static VersificationMgr * getSystemVersificationMgr()
const System * getVersificationSystem(const char *name) const
static FileMgr * getSystemFileMgr()