Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

rwprtf.cpp

00001 /******************************************************************************
00002  *
00003  * rwprtf -     SWFilter decendant to convert all GBF tags to RTF tags
00004  */
00005 
00006 
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include <rwprtf.h>
00010 
00011 
00012 RWPRTF::RWPRTF() {
00013 
00014 }
00015 
00016 
00017 char RWPRTF::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00018 {
00019         char *to, *from;
00020         bool ingreek = false;
00021         bool inverse = false;
00022         int len;
00023 
00024         len = strlen(text) + 1;                                         // shift string to right of buffer
00025         if (len < maxlen) {
00026                 memmove(&text[maxlen - len], text, len);
00027                 from = &text[maxlen - len];
00028         }
00029         else    from = text;                                                    // -------------------------------
00030         for (to = text; *from; from++) {
00031                 if (*from == '\\') {
00032                         if(!ingreek) {
00033                                 ingreek = true;
00034                                 *to++ = '[';
00035                                 *to++ = '{';
00036                                 *to++ = '\\';
00037                                 *to++ = 'f';
00038                                 *to++ = '8';
00039                                 *to++ = ' ';
00040                                 continue;
00041                         }
00042                         else {
00043                                 ingreek = false;
00044                                 *to++ = '}';
00045                                 *to++ = ']';
00046                                 continue;
00047                         }
00048                 }
00049 
00050                 if ((ingreek) && ((*from == 'h') || (*from == 'H')))
00051                         continue;               // 'h's are mostly useless in RWP translitterations.  The greek is more correct without them.
00052 
00053                 if (*from == '#') {     // verse markings (e.g. "#Mark 1:1|")
00054                         inverse = true;
00055                         *to++ = '{';
00056                         *to++ = '\\';
00057                         *to++ = 'c';
00058                         *to++ = 'f';
00059                         *to++ = '2';
00060                         *to++ = ' ';
00061                         *to++ = '#';
00062                         continue;
00063                 }
00064                 if ((*from == '|') && (inverse)) {
00065                         inverse = false;
00066                         *to++ = '|';
00067                         *to++ = '}';
00068                         continue;
00069                 }
00070                 
00071                 if (*from == '{') {
00072                         *to++ = '{';
00073                         *to++ = '\\';
00074                         *to++ = 'b';
00075                         *to++ = ' ';
00076                         if ((from - &text[maxlen - len]) > 10) {        // not the beginning of the entry
00077                                 *to++ = '\\';
00078                                 *to++ = 'p';
00079                                 *to++ = 'a';
00080                                 *to++ = 'r';
00081                                 *to++ = ' ';
00082                         }
00083                         continue;
00084                 }
00085 
00086                 if (*from == '}') {
00087                         // this is kinda neat... DO NOTHING
00088                 }
00089                 if ((*from == '\n') && (from[1] == '\n')) {
00090                         *to++ = '\\';
00091                         *to++ = 'p';
00092                         *to++ = 'a';
00093                         *to++ = 'r';
00094                         *to++ = '\\';
00095                         *to++ = 'p';
00096                         *to++ = 'a';
00097                         *to++ = 'r';
00098                         *to++ = ' ';
00099                         continue;
00100                 }
00101 
00102                 *to++ = *from;
00103         }
00104         *to++ = 0;
00105         *to = 0;
00106         return 0;
00107 }

Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by doxygen1.2.15