24 #pragma warning( disable: 4251 )
42 #include <unicode/utypes.h>
43 #include <unicode/ucnv.h>
44 #include <unicode/ustring.h>
45 #include <unicode/uchar.h>
46 #include <unicode/unistr.h>
47 #include <unicode/translit.h>
48 #include <unicode/locid.h>
51 #ifndef NO_SWORD_NAMESPACE
52 using namespace sword;
66 fprintf(stderr,
"imp2gbs 1.0 General Book module creation tool for the SWORD Project\n\n");
67 fprintf(stderr,
"usage: %s <inFile> [OPTIONS]\n", app);
68 fprintf(stderr,
"\t-o <outPath>\n\t\tSpecify an output Path other than inFile location.\n");
69 fprintf(stderr,
"\t-a\n\t\tAugment Module [default: create new]\n");
70 fprintf(stderr,
"\t-O\n\t\tOverwrite entries of same key [default: append to]\n");
71 fprintf(stderr,
"\t-U\n\t\tKey filter: Convert toUpper\n");
72 fprintf(stderr,
"\t-g\n\t\tKey filter: Strip Greek diacritics\n");
73 fprintf(stderr,
"\t-l <levels>\n\t\tKey filter: Pseudo-Lexicon n-level generation using first character\n");
74 fprintf(stderr,
"\t\te.g. -l 2 \"Abbey\" -> \"A/AB/Abbey\"\n");
75 fprintf(stderr,
"\n");
88 for (
int i = 2; i < argc; i++) {
89 if (!strcmp(argv[i],
"-o")) {
90 if ((i+1 < argc) && (argv[i+1][0] !=
'-')) {
96 else if (!strcmp(argv[i],
"-U")) {
101 fprintf(stderr,
"Error: %s. Cannot reliably toUpper without UTF8 support\n\t(recompile with ICU enabled)\n\n", *argv);
105 else if (!strcmp(argv[i],
"-g")) {
108 else if (!strcmp(argv[i],
"-O")) {
111 else if (!strcmp(argv[i],
"-a")) {
114 else if (!strcmp(argv[i],
"-l")) {
131 void writeEntry(SWModule *book, SWBuf keyBuffer, SWBuf entBuffer) {
139 unsigned size = (keyBuffer.size()+5)*3;
140 keyBuffer.setFillByte(0);
141 keyBuffer.resize(size);
149 if (
lexLevels && !keyBuffer.startsWith(
"/Intro")) {
151 keyBuffer.setFillByte(0);
152 keyBuffer.resize(size);
154 UErrorCode err = U_ZERO_ERROR;
156 int max = (size+5)*3;
157 UChar *ubuffer =
new UChar[max+10];
160 u_strFromUTF8(ubuffer, max+9, &len, keyBuffer.c_str(), -1, &err);
161 if (err == U_ZERO_ERROR) {
162 UChar *upper =
new UChar[(
lexLevels+1)*3];
163 memcpy(upper, ubuffer,
lexLevels*
sizeof(UChar));
165 len = u_strToUpper(upper, (
lexLevels+1)*3, upper, -1, 0, &err);
166 memmove(ubuffer+len+1, ubuffer, (max-len)*
sizeof(UChar));
167 memcpy(ubuffer, upper, len*
sizeof(UChar));
173 int shift = (i < len)? i : len;
174 memmove(ubuffer+(shift+1), ubuffer, (max-shift)*
sizeof(UChar));
175 ubuffer[shift] =
'/';
176 totalShift += (shift+1);
178 u_strToUTF8(keyBuffer.getRawData(), max, 0, ubuffer, -1, &err);
206 std::cout << keyBuffer << std::endl;
208 book->setKey(keyBuffer.c_str());
213 key.setFormatted(
"%s {%d}", keyBuffer.c_str(), i);
214 std::cout <<
"dup key, trying: " << key << std::endl;
215 book->setKey(key.c_str());
218 book->setEntry(entBuffer);
222 int main(
int argc,
char **argv) {
228 if (fd->
getFd() < 0) {
229 fprintf(stderr,
"error: %s: couldn't open input file: %s \n", argv[0],
inFile.c_str());
239 book =
new RawGenBook(
outPath);
248 if (lineBuffer.startsWith(
"$$$")) {
249 if ((keyBuffer.size()) && (entBuffer.size())) {
252 keyBuffer = lineBuffer;
258 if (keyBuffer.size()) {
259 entBuffer += lineBuffer;
264 if ((keyBuffer.size()) && (entBuffer.size())) {
static unsigned int RDONLY
static char createModule(const char *ipath)
static bool hasUTF8Support()
static StringMgr * getSystemStringMgr()
virtual char * upperUTF8(char *text, unsigned int max=0) const
void writeEntry(SWModule *book, SWBuf keyBuffer, SWBuf entBuffer)
#define KEYERR_OUTOFBOUNDS
void usage(const char *app)
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
virtual void setOptionValue(const char *ival)
void parseParams(int argc, char **argv)
static char getLine(FileDesc *fDesc, SWBuf &line)
UTF8GreekAccents greekAccentsFilter
static FileMgr * getSystemFileMgr()