| 1 |
*** hdrs/ansi.h.orig Fri Oct 5 23:36:32 2007 |
|---|
| 2 |
--- hdrs/ansi.h Mon Jan 28 21:54:50 2008 |
|---|
| 3 |
*************** |
|---|
| 4 |
*** 185,188 **** |
|---|
| 5 |
--- 185,190 ---- |
|---|
| 6 |
int safe_tag_wrap(char const *a_tag, char const *params, |
|---|
| 7 |
char const *data, char *buf, char **bp, dbref player); |
|---|
| 8 |
|
|---|
| 9 |
+ |
|---|
| 10 |
+ char * decompose_to_html(char *what); |
|---|
| 11 |
#endif /* __ANSI_H */ |
|---|
| 12 |
*** src/function.c.orig Fri Oct 5 23:36:32 2007 |
|---|
| 13 |
--- src/function.c Mon Jan 28 21:01:39 2008 |
|---|
| 14 |
*************** |
|---|
| 15 |
*** 785,790 **** |
|---|
| 16 |
--- 785,791 ---- |
|---|
| 17 |
{"TAG", fun_tag, 1, INT_MAX, FN_REG}, |
|---|
| 18 |
{"ENDTAG", fun_endtag, 1, 1, FN_REG}, |
|---|
| 19 |
{"TAGWRAP", fun_tagwrap, 2, 3, FN_REG}, |
|---|
| 20 |
+ {"HTMLENCODE", fun_htmlencode, 1, -1, FN_REG}, |
|---|
| 21 |
{NULL, NULL, 0, 0, 0} |
|---|
| 22 |
}; |
|---|
| 23 |
|
|---|
| 24 |
*** src/funstr.c.orig Fri Oct 5 23:36:32 2007 |
|---|
| 25 |
--- src/funstr.c Mon Jan 28 21:55:47 2008 |
|---|
| 26 |
*************** |
|---|
| 27 |
*** 1469,1474 **** |
|---|
| 28 |
--- 1469,1488 ---- |
|---|
| 29 |
} |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
+ FUNCTION(fun_htmlencode) |
|---|
| 33 |
+ { |
|---|
| 34 |
+ /* |
|---|
| 35 |
+ int n; |
|---|
| 36 |
+ for (n = 0; n < arglens[0]; n++) { |
|---|
| 37 |
+ if(accent_table[(unsigned char) args[0][n]].base) |
|---|
| 38 |
+ safe_str(accent_table[(unsigned char) args[0][n]].entity, buff, bp); |
|---|
| 39 |
+ else |
|---|
| 40 |
+ safe_chr(args[0][n], buff, bp); |
|---|
| 41 |
+ } |
|---|
| 42 |
+ */ |
|---|
| 43 |
+ safe_str(decompose_to_html(args[0]), buff, bp); |
|---|
| 44 |
+ } |
|---|
| 45 |
+ |
|---|
| 46 |
/* ARGSUSED */ |
|---|
| 47 |
FUNCTION(fun_edit) |
|---|
| 48 |
{ |
|---|
| 49 |
*** src/markup.c.orig Fri Oct 5 23:36:32 2007 |
|---|
| 50 |
--- src/markup.c Mon Jan 28 22:30:59 2008 |
|---|
| 51 |
*************** |
|---|
| 52 |
*** 60,65 **** |
|---|
| 53 |
--- 60,67 ---- |
|---|
| 54 |
safe_markup_cancel(char const *a_tag, char *buf, char **bp, char type); |
|---|
| 55 |
static int compare_starts(const void *a, const void *b); |
|---|
| 56 |
static int escape_marked_str(char **str, char *buff, char **bp); |
|---|
| 57 |
+ static int escape_marked_str_to_html(char **str, char *buff, char **bp); |
|---|
| 58 |
+ static int real_decompose_to_html(char *orig, char *buff, char **bp); |
|---|
| 59 |
|
|---|
| 60 |
const char *is_allowed_tag(const char *s, unsigned int len); |
|---|
| 61 |
|
|---|
| 62 |
*************** |
|---|
| 63 |
*** 1897,1902 **** |
|---|
| 64 |
--- 1899,1960 ---- |
|---|
| 65 |
return retval; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
+ static int |
|---|
| 69 |
+ escape_marked_str_to_html(char **str, char *buff, char **bp) |
|---|
| 70 |
+ { |
|---|
| 71 |
+ unsigned char *in; |
|---|
| 72 |
+ int retval = 0; |
|---|
| 73 |
+ int dospace = 1; |
|---|
| 74 |
+ int spaces = 0; |
|---|
| 75 |
+ int i; |
|---|
| 76 |
+ |
|---|
| 77 |
+ if (!str || !*str || !**str) |
|---|
| 78 |
+ return 0; |
|---|
| 79 |
+ in = (unsigned char *) *str; |
|---|
| 80 |
+ for (; *in && *in != ESC_CHAR && *in != TAG_START; in++) { |
|---|
| 81 |
+ if (*in == ' ') { |
|---|
| 82 |
+ spaces++; |
|---|
| 83 |
+ } else { |
|---|
| 84 |
+ if (spaces) { |
|---|
| 85 |
+ if (dospace) { |
|---|
| 86 |
+ spaces--; |
|---|
| 87 |
+ retval += safe_str(" ", buff, bp); |
|---|
| 88 |
+ } |
|---|
| 89 |
+ while (spaces) { |
|---|
| 90 |
+ retval += safe_chr(' ', buff, bp); |
|---|
| 91 |
+ if (--spaces) { |
|---|
| 92 |
+ --spaces; |
|---|
| 93 |
+ retval += safe_str(" ", buff, bp); |
|---|
| 94 |
+ } |
|---|
| 95 |
+ } |
|---|
| 96 |
+ } |
|---|
| 97 |
+ spaces = 0; |
|---|
| 98 |
+ dospace = 0; |
|---|
| 99 |
+ if(accent_table[(unsigned char) *in].base) |
|---|
| 100 |
+ safe_str(accent_table[(unsigned char) *in].entity, buff, bp); |
|---|
| 101 |
+ else |
|---|
| 102 |
+ safe_chr(*in, buff, bp); |
|---|
| 103 |
+ } |
|---|
| 104 |
+ } |
|---|
| 105 |
+ if (spaces) { |
|---|
| 106 |
+ spaces--; /* This is for the final %b space */ |
|---|
| 107 |
+ if (spaces && dospace) { |
|---|
| 108 |
+ spaces--; |
|---|
| 109 |
+ retval += safe_str(" ", buff, bp); |
|---|
| 110 |
+ } |
|---|
| 111 |
+ while (spaces) { |
|---|
| 112 |
+ safe_chr(' ', buff, bp); |
|---|
| 113 |
+ if (--spaces) { |
|---|
| 114 |
+ --spaces; |
|---|
| 115 |
+ retval += safe_str(" ", buff, bp); |
|---|
| 116 |
+ } |
|---|
| 117 |
+ } |
|---|
| 118 |
+ retval += safe_str(" ", buff, bp); |
|---|
| 119 |
+ } |
|---|
| 120 |
+ *str = (char *) in; |
|---|
| 121 |
+ return retval; |
|---|
| 122 |
+ } |
|---|
| 123 |
+ |
|---|
| 124 |
/* Does the work of decompose_str, which is found in look.c. |
|---|
| 125 |
* Even handles ANSI and Pueblo, which is why it's so ugly. |
|---|
| 126 |
* Code based off of real_parse_ansi_string, not safe_ansi_string. |
|---|
| 127 |
*************** |
|---|
| 128 |
*** 2093,2098 **** |
|---|
| 129 |
--- 2151,2415 ---- |
|---|
| 130 |
return retval; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
+ char * |
|---|
| 134 |
+ decompose_to_html(char *what) |
|---|
| 135 |
+ { |
|---|
| 136 |
+ static char value[BUFFER_LEN]; |
|---|
| 137 |
+ char *vp = value; |
|---|
| 138 |
+ |
|---|
| 139 |
+ real_decompose_to_html(what, value, &vp); |
|---|
| 140 |
+ *vp = '\0'; |
|---|
| 141 |
+ |
|---|
| 142 |
+ return value; |
|---|
| 143 |
+ } |
|---|
| 144 |
+ |
|---|
| 145 |
+ static int |
|---|
| 146 |
+ real_decompose_to_html(char *orig, char *buff, char **bp) |
|---|
| 147 |
+ { |
|---|
| 148 |
+ int i; |
|---|
| 149 |
+ char *str = orig; |
|---|
| 150 |
+ char *tmp; |
|---|
| 151 |
+ char *pstr; |
|---|
| 152 |
+ char type; |
|---|
| 153 |
+ |
|---|
| 154 |
+ ansi_data ansistack[BUFFER_LEN]; |
|---|
| 155 |
+ ansistack[0] = ansi_null; |
|---|
| 156 |
+ ansi_data oldansi; |
|---|
| 157 |
+ ansi_data tmpansi; |
|---|
| 158 |
+ int ansitop = 0; |
|---|
| 159 |
+ int ansiheight = 0; |
|---|
| 160 |
+ int howmanyopen = 0; |
|---|
| 161 |
+ int oldcodes = 0; |
|---|
| 162 |
+ int underline = 0, bold = 0; |
|---|
| 163 |
+ |
|---|
| 164 |
+ char *pueblostack[BUFFER_LEN]; |
|---|
| 165 |
+ char tagbuff[BUFFER_LEN]; |
|---|
| 166 |
+ int pueblotop = -1; |
|---|
| 167 |
+ |
|---|
| 168 |
+ int retval = 0; |
|---|
| 169 |
+ |
|---|
| 170 |
+ if (!str || !*str) |
|---|
| 171 |
+ return 0; |
|---|
| 172 |
+ |
|---|
| 173 |
+ retval += escape_marked_str_to_html(&str, buff, bp); |
|---|
| 174 |
+ |
|---|
| 175 |
+ while (str && *str && *str != '\0') { |
|---|
| 176 |
+ oldansi = ansistack[ansitop]; |
|---|
| 177 |
+ ansiheight = ansitop; |
|---|
| 178 |
+ while (*str == TAG_START || *str == ESC_CHAR) { |
|---|
| 179 |
+ switch (*str) { |
|---|
| 180 |
+ case TAG_START: |
|---|
| 181 |
+ for (tmp = str; *tmp && *tmp != TAG_END; tmp++) ; |
|---|
| 182 |
+ if (*tmp) { |
|---|
| 183 |
+ *tmp = '\0'; |
|---|
| 184 |
+ } else { |
|---|
| 185 |
+ tmp--; |
|---|
| 186 |
+ } |
|---|
| 187 |
+ str++; |
|---|
| 188 |
+ type = *(str++); |
|---|
| 189 |
+ switch (type) { |
|---|
| 190 |
+ case MARKUP_COLOR: |
|---|
| 191 |
+ if (!*str) |
|---|
| 192 |
+ break; |
|---|
| 193 |
+ if (oldcodes == 1) { |
|---|
| 194 |
+ ansitop--; |
|---|
| 195 |
+ oldcodes = 0; |
|---|
| 196 |
+ } |
|---|
| 197 |
+ /* Start or end tag? */ |
|---|
| 198 |
+ if (*str != '/') { |
|---|
| 199 |
+ define_ansi_data(&tmpansi, str); |
|---|
| 200 |
+ nest_ansi_data(&(ansistack[ansitop]), &tmpansi); |
|---|
| 201 |
+ ansitop++; |
|---|
| 202 |
+ ansistack[ansitop] = tmpansi; |
|---|
| 203 |
+ } else { |
|---|
| 204 |
+ if (*(str + 1) == 'a') { |
|---|
| 205 |
+ ansitop = 0; |
|---|
| 206 |
+ } else { |
|---|
| 207 |
+ if (ansitop > 0) { |
|---|
| 208 |
+ ansitop--; |
|---|
| 209 |
+ } |
|---|
| 210 |
+ } |
|---|
| 211 |
+ } |
|---|
| 212 |
+ break; |
|---|
| 213 |
+ case MARKUP_HTML: |
|---|
| 214 |
+ if (!*str) |
|---|
| 215 |
+ break; |
|---|
| 216 |
+ if (*str != '/') { |
|---|
| 217 |
+ pueblotop++; |
|---|
| 218 |
+ snprintf(tagbuff, BUFFER_LEN, "%s", parse_tagname(str)); |
|---|
| 219 |
+ pueblostack[pueblotop] = mush_strdup(tagbuff, "markup_code"); |
|---|
| 220 |
+ |
|---|
| 221 |
+ retval += safe_chr('<', buff, bp); |
|---|
| 222 |
+ retval += safe_str(tagbuff, buff, bp); |
|---|
| 223 |
+ retval += safe_chr(' ', buff, bp); |
|---|
| 224 |
+ str += strlen(tagbuff); |
|---|
| 225 |
+ if (str && *str) { |
|---|
| 226 |
+ while (str && str != tmp) { |
|---|
| 227 |
+ str++; |
|---|
| 228 |
+ pstr = strchr(str, '='); |
|---|
| 229 |
+ if (pstr) { |
|---|
| 230 |
+ *pstr = '\0'; |
|---|
| 231 |
+ retval += safe_str(str, buff, bp); |
|---|
| 232 |
+ retval += safe_chr('=', buff, bp); |
|---|
| 233 |
+ str = pstr + 1; |
|---|
| 234 |
+ pstr = strchr(str, '\"'); |
|---|
| 235 |
+ |
|---|
| 236 |
+ retval += safe_chr('\"', buff, bp); |
|---|
| 237 |
+ if (str == pstr) { |
|---|
| 238 |
+ str++; |
|---|
| 239 |
+ pstr = strchr(str, '\"'); |
|---|
| 240 |
+ } else { |
|---|
| 241 |
+ pstr = strchr(str, ' '); |
|---|
| 242 |
+ } |
|---|
| 243 |
+ |
|---|
| 244 |
+ if (!pstr) |
|---|
| 245 |
+ pstr = tmp; |
|---|
| 246 |
+ |
|---|
| 247 |
+ *pstr = '\0'; |
|---|
| 248 |
+ retval += safe_str(str, buff, bp); |
|---|
| 249 |
+ retval += safe_chr('\"', buff, bp); |
|---|
| 250 |
+ str = pstr; |
|---|
| 251 |
+ } else { |
|---|
| 252 |
+ safe_str(str, buff, bp); |
|---|
| 253 |
+ break; |
|---|
| 254 |
+ } |
|---|
| 255 |
+ } |
|---|
| 256 |
+ } |
|---|
| 257 |
+ retval += safe_chr('>', buff, bp); |
|---|
| 258 |
+ |
|---|
| 259 |
+ } else { |
|---|
| 260 |
+ if (pueblotop > -1) { |
|---|
| 261 |
+ i = (*(str + 1) == 'a') ? 0 : pueblotop; |
|---|
| 262 |
+ for (i--; pueblotop > i; pueblotop--) { |
|---|
| 263 |
+ retval += safe_str("</", buff, bp); |
|---|
| 264 |
+ retval += safe_str(pueblostack[pueblotop], buff, bp); |
|---|
| 265 |
+ retval += safe_chr('>', buff, bp); |
|---|
| 266 |
+ mush_free(pueblostack[pueblotop], "markup_code"); |
|---|
| 267 |
+ } |
|---|
| 268 |
+ } |
|---|
| 269 |
+ } |
|---|
| 270 |
+ break; |
|---|
| 271 |
+ } |
|---|
| 272 |
+ tmp++; |
|---|
| 273 |
+ str = tmp; |
|---|
| 274 |
+ break; |
|---|
| 275 |
+ case ESC_CHAR: |
|---|
| 276 |
+ /* It SHOULD be impossible to get here... */ |
|---|
| 277 |
+ for (tmp = str; *tmp && *tmp != 'm'; tmp++) ; |
|---|
| 278 |
+ |
|---|
| 279 |
+ /* Store the "background" colors */ |
|---|
| 280 |
+ tmpansi = ansistack[ansitop]; |
|---|
| 281 |
+ if (oldcodes == 0) { |
|---|
| 282 |
+ oldcodes = 1; |
|---|
| 283 |
+ ansitop++; |
|---|
| 284 |
+ ansistack[ansitop] = tmpansi; |
|---|
| 285 |
+ ansistack[ansitop].offbits = 0; |
|---|
| 286 |
+ } |
|---|
| 287 |
+ |
|---|
| 288 |
+ read_raw_ansi_data(&tmpansi, str); |
|---|
| 289 |
+ ansistack[ansitop].bits |= tmpansi.bits; |
|---|
| 290 |
+ ansistack[ansitop].bits &= ~(tmpansi.offbits); /* ANSI_RAW_NORMAL */ |
|---|
| 291 |
+ if (tmpansi.fore) |
|---|
| 292 |
+ ansistack[ansitop].fore = tmpansi.fore; |
|---|
| 293 |
+ if (tmpansi.back) |
|---|
| 294 |
+ ansistack[ansitop].back = tmpansi.back; |
|---|
| 295 |
+ |
|---|
| 296 |
+ str = tmp; |
|---|
| 297 |
+ if (*tmp) |
|---|
| 298 |
+ str++; |
|---|
| 299 |
+ break; |
|---|
| 300 |
+ } |
|---|
| 301 |
+ } |
|---|
| 302 |
+ |
|---|
| 303 |
+ /* Handle ANSI/Text */ |
|---|
| 304 |
+ tmpansi = ansistack[ansitop]; |
|---|
| 305 |
+ if (ansitop > 0 || ansiheight > 0) { |
|---|
| 306 |
+ /* Close existing tags as necessary to cleanly open the next. */ |
|---|
| 307 |
+ /* oldansi = ansistack[ansiheight]; */ |
|---|
| 308 |
+ if (!ansi_equal(oldansi, tmpansi)) { |
|---|
| 309 |
+ while (ansiheight > 0) { |
|---|
| 310 |
+ if (howmanyopen > 0) { |
|---|
| 311 |
+ howmanyopen--; |
|---|
| 312 |
+ if (bold) { |
|---|
| 313 |
+ bold--; |
|---|
| 314 |
+ retval += safe_str("</b>", buff, bp); |
|---|
| 315 |
+ } |
|---|
| 316 |
+ if (underline) { |
|---|
| 317 |
+ underline--; |
|---|
| 318 |
+ retval += safe_str("</u>", buff, bp); |
|---|
| 319 |
+ } |
|---|
| 320 |
+ retval += safe_str("</font>", buff, bp); |
|---|
| 321 |
+ } |
|---|
| 322 |
+ ansiheight--; |
|---|
| 323 |
+ } |
|---|
| 324 |
+ } |
|---|
| 325 |
+ if (!ansi_isnull(tmpansi) && !ansi_equal(oldansi, tmpansi)) { |
|---|
| 326 |
+ if (tmpansi.fore == 'n' || tmpansi.fore == 'd') { |
|---|
| 327 |
+ } else { |
|---|
| 328 |
+ retval += safe_str("<font color=\"", buff, bp); |
|---|
| 329 |
+ switch (tmpansi.fore) { |
|---|
| 330 |
+ case 'r': |
|---|
| 331 |
+ retval += safe_str("red", buff, bp); |
|---|
| 332 |
+ break; |
|---|
| 333 |
+ case 'g': |
|---|
| 334 |
+ retval += safe_str("green", buff, bp); |
|---|
| 335 |
+ break; |
|---|
| 336 |
+ case 'b': |
|---|
| 337 |
+ retval += safe_str("blue", buff, bp); |
|---|
| 338 |
+ break; |
|---|
| 339 |
+ case 'c': |
|---|
| 340 |
+ retval += safe_str("cyan", buff, bp); |
|---|
| 341 |
+ break; |
|---|
| 342 |
+ case 'm': |
|---|
| 343 |
+ retval += safe_str("magenta", buff, bp); |
|---|
| 344 |
+ break; |
|---|
| 345 |
+ case 'y': |
|---|
| 346 |
+ retval += safe_str("yellow", buff, bp); |
|---|
| 347 |
+ break; |
|---|
| 348 |
+ case 'x': |
|---|
| 349 |
+ retval += safe_str("black", buff, bp); |
|---|
| 350 |
+ break; |
|---|
| 351 |
+ case 'w': |
|---|
| 352 |
+ retval += safe_str("white", buff, bp); |
|---|
| 353 |
+ break; |
|---|
| 354 |
+ default: |
|---|
| 355 |
+ break; |
|---|
| 356 |
+ } |
|---|
| 357 |
+ retval += safe_str("\">", buff, bp); |
|---|
| 358 |
+ howmanyopen++; |
|---|
| 359 |
+ } |
|---|
| 360 |
+ #define CBIT_SET(x,y) (x.bits & y) |
|---|
| 361 |
+ if (CBIT_SET(tmpansi, CBIT_HILITE)) { |
|---|
| 362 |
+ retval += safe_str("<b>", buff, bp); |
|---|
| 363 |
+ bold++; |
|---|
| 364 |
+ } |
|---|
| 365 |
+ if (CBIT_SET(tmpansi, CBIT_UNDERSCORE)) { |
|---|
| 366 |
+ retval += safe_str("<u>", buff, bp); |
|---|
| 367 |
+ underline++; |
|---|
| 368 |
+ } |
|---|
| 369 |
+ #undef CBIT_SET |
|---|
| 370 |
+ |
|---|
| 371 |
+ |
|---|
| 372 |
+ } |
|---|
| 373 |
+ } |
|---|
| 374 |
+ retval += escape_marked_str_to_html(&str, buff, bp); |
|---|
| 375 |
+ } |
|---|
| 376 |
+ |
|---|
| 377 |
+ for (; underline > 0; underline--) |
|---|
| 378 |
+ retval += safe_str("</u>", buff, bp); |
|---|
| 379 |
+ for (; bold > 0; bold--) |
|---|
| 380 |
+ retval += safe_str("</b>", buff, bp); |
|---|
| 381 |
+ for (; howmanyopen > 0; howmanyopen--) |
|---|
| 382 |
+ retval += safe_str("</font>", buff, bp); |
|---|
| 383 |
+ for (; pueblotop > -1; pueblotop--) { |
|---|
| 384 |
+ retval += safe_str("</", buff, bp); |
|---|
| 385 |
+ retval += safe_str(pueblostack[pueblotop], buff, bp); |
|---|
| 386 |
+ retval += safe_chr('>', buff, bp); |
|---|
| 387 |
+ } |
|---|
| 388 |
+ |
|---|
| 389 |
+ return retval; |
|---|
| 390 |
+ } |
|---|
| 391 |
+ |
|---|
| 392 |
/** Our version of pcre_copy_substring, with ansi-safeness. |
|---|
| 393 |
* \param as the ansi_string whose .text value was matched against. |
|---|
| 394 |
* \param ovector the offset vectors |
|---|