00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <ctype.h>
00021 #include <rwphtml.h>
00022
00023 RWPHTML::RWPHTML()
00024 {
00025 }
00026
00027
00028 char RWPHTML::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00029 {
00030 char *to, *from;
00031 signed char greek_str[500];
00032 bool inverse = false;
00033 bool first_letter = false;
00034 int len;
00035
00036 len = strlen(text) + 1;
00037 if (len < maxlen) {
00038 memmove(&text[maxlen - len], text, len);
00039 from = &text[maxlen - len];
00040 } else
00041 from = text;
00042 for (to = text; *from; from++) {
00043 if (*from == '\\') {
00044 ++from;
00045 int i=0;
00046 first_letter = true;
00047 greek_str[0] = '\0';
00048 while (*from != '\\') {
00049 greek_str[i++] = *from;
00050 greek_str[i + 1] = '\0';
00051 from++;
00052 }
00053 strcpy(to,"<I> </I><FONT FACE=\"symbol\">");
00054 to += strlen(to);
00055 for (int j = 0; j < i; j++) {
00056 if ((first_letter)
00057 && (greek_str[j] == 'h')) {
00058 if (greek_str[j + 1] == 'o') {
00059 *to++ = 'o';
00060 first_letter = false;
00061 ++j;
00062 continue;
00063 } else if (greek_str[j + 1] == 'a') {
00064 *to++ = 'a';
00065 first_letter = false;
00066 ++j;
00067 continue;
00068 } else if (greek_str[j + 1] == 'w') {
00069 *to++ = 'w';
00070 first_letter = false;
00071 ++j;
00072 continue;
00073 } else if (greek_str[j + 1] == 'u') {
00074 *to++ = 'u';
00075 first_letter = false;
00076 ++j;
00077 continue;
00078 } else if (greek_str[j + 1] ==
00079 -109) {
00080 *to++ = 'w';
00081 first_letter = false;
00082 ++j;
00083 continue;
00084 } else if (greek_str[j + 1] ==
00085 -120) {
00086 *to++ = 'h';
00087 first_letter = false;
00088 ++j;
00089 continue;
00090 } else if (greek_str[j + 1] == 'i') {
00091 *to++ = 'i';
00092 first_letter = false;
00093 ++j;
00094 continue;
00095 }else if (greek_str[j + 1] == 'e') {
00096 *to++ = 'e';
00097 first_letter = false;
00098 ++j;
00099 continue;
00100 }
00101 first_letter = false;
00102 }
00103 if ((greek_str[j] == 't')
00104 && (greek_str[j + 1] == 'h')) {
00105 *to++ = 'q';
00106 ++j;
00107 continue;
00108 }
00109 if ((greek_str[j] == 'c')
00110 && (greek_str[j + 1] == 'h')) {
00111 *to++ = 'c';
00112 ++j;
00113 continue;
00114 }
00115 if ((greek_str[j] == 'p')
00116 && (greek_str[j + 1] == 'h')) {
00117 ++j;
00118 *to++ = 'f';
00119 continue;
00120 }
00121 if (greek_str[j] == -120) {
00122 *to++ = 'h';
00123 continue;
00124 }
00125 if (greek_str[j] == -125) {
00126 *to++ = 'a';
00127 continue;
00128 }
00129 if (greek_str[j] == -109) {
00130 if(greek_str[j+1] == 'i') ++j;
00131 *to++ = 'w';
00132 continue;
00133 }
00134 if (greek_str[j] == ' ')
00135 first_letter = true;
00136 if (greek_str[j] == 's') {
00137 if(isalpha(greek_str[j + 1])) *to++ = 's';
00138 else if(!isprint(greek_str[j] )) *to++ = 's';
00139 else *to++ = 'V';
00140 continue;
00141 }
00142 if (greek_str[j] == '\'') {
00143 continue;
00144 }
00145 *to++ = greek_str[j];
00146 }
00147 strcpy(to,"</FONT><I> </I>");
00148 to += strlen(to);
00149 continue;
00150 }
00151 if (*from == '#') {
00152 inverse = true;
00153 strcpy(to,"<FONT COLOR=#0000FF>");
00154 to += strlen(to);
00155 continue;
00156 }
00157 if ((*from == '|') && (inverse)) {
00158 inverse = false;
00159 strcpy(to,"</FONT>");
00160 to += strlen(to);
00161 continue;
00162 }
00163 if (*from == '{') {
00164 strcpy(to,"<BR><STRONG>");
00165 to += strlen(to);
00166 if ((from - &text[maxlen - len]) > 10) {
00167 strcpy(to,"<P>");
00168 to += strlen(to);
00169 }
00170 continue;
00171 }
00172 if (*from == '}') {
00173 strcpy(to," </STRONG>");
00174 to += strlen(to);
00175 continue;
00176 }
00177 if ((*from == '\n') && (from[1] == '\n')) {
00178 strcpy(to,"<P>");
00179 to += strlen(to);
00180 continue;
00181 }
00182 *to++ = *from;
00183 }
00184 *to++ = 0;
00185 *to = 0;
00186 return 0;
00187 }