… | |
… | |
284 | // end == -2, till '\n' |
284 | // end == -2, till '\n' |
285 | // end == -1, till '>' |
285 | // end == -1, till '>' |
286 | // end == 0, till eos |
286 | // end == 0, till eos |
287 | // end >= 1, levels of " >>>" |
287 | // end >= 1, levels of " >>>" |
288 | static const char * |
288 | static const char * |
289 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0) |
289 | expand_cfpod (int hintmode, int gender, dynbuf_text &buf, const char *cfpod, int end = 0) |
290 | { |
290 | { |
291 | static dynbuf_text nest(128, 128); |
291 | static dynbuf_text nest(128, 128); |
292 | |
292 | |
293 | for (;;) |
293 | for (;;) |
294 | switch (char ch = *cfpod++) |
294 | switch (char ch = *cfpod++) |
… | |
… | |
362 | if (*cfpod == ' ') |
362 | if (*cfpod == ' ') |
363 | goto verbatim; |
363 | goto verbatim; |
364 | |
364 | |
365 | break; |
365 | break; |
366 | |
366 | |
367 | case 'B': case 'C': case 'E': case 'G': |
367 | case 'B': case 'C': case 'E': case 'G': case 'H': |
368 | case 'H': case 'I': case 'T': case 'U': |
368 | case 'I': case 'L': case 'T': case 'U': case 'Z': |
369 | case 'Z': |
|
|
370 | { |
369 | { |
371 | int end = 0; |
370 | int end = 0; |
372 | |
371 | |
373 | while (cfpod [end] == '<') |
372 | while (cfpod [end] == '<') |
374 | ++end; |
373 | ++end; |
… | |
… | |
394 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
393 | case 'I': pfx = "<i>" ; sfx = "</i>" ; break; |
395 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
394 | case 'U': pfx = "<u>" ; sfx = "</u>" ; break; |
396 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
395 | case 'T': pfx = "<big><b>"; sfx = "</b></big>"; break; |
397 | case 'Z': pfx = "" ; sfx = "" ; break; |
396 | case 'Z': pfx = "" ; sfx = "" ; break; |
398 | |
397 | |
|
|
398 | case 'L': // link, not really supported - always use first (or only) component |
|
|
399 | { |
|
|
400 | cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end); |
|
|
401 | nest << '\0'; // zero-terminate |
|
|
402 | |
|
|
403 | const char *str = nest.linearise (); |
|
|
404 | const char *sep = strchr (str, '|'); |
|
|
405 | |
|
|
406 | buf.add (str, sep ? sep - str : nest.size ()); |
|
|
407 | |
|
|
408 | nest.clear (); |
|
|
409 | |
|
|
410 | goto skip; |
|
|
411 | } |
|
|
412 | |
399 | case 'H': // hint |
413 | case 'H': // hint |
400 | { |
414 | { |
401 | if (pl->hintmode) |
415 | if (hintmode) |
402 | { |
416 | { |
403 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
417 | cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end); |
404 | nest.clear (); |
418 | nest.clear (); |
405 | |
419 | |
406 | if (pl->hintmode == 1) |
420 | if (hintmode == 1) |
407 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
421 | buf << "<fg name=\"lightblue\">[Hint available]</fg>"; |
408 | else |
422 | else |
409 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
423 | while (*cfpod <= ' '&& *cfpod) // eat trailing whitespace |
410 | ++cfpod; |
424 | ++cfpod; |
411 | |
425 | |
… | |
… | |
419 | } |
433 | } |
420 | break; |
434 | break; |
421 | |
435 | |
422 | case 'G': // gender |
436 | case 'G': // gender |
423 | { |
437 | { |
424 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
438 | cfpod = expand_cfpod (hintmode, gender, nest, cfpod, end); |
425 | nest << '\0'; // zero-terminate |
439 | nest << '\0'; // zero-terminate |
426 | |
440 | |
427 | const char *str = nest.linearise (); |
441 | const char *str = nest.linearise (); |
428 | const char *sep = strchr (str, '|'); |
442 | const char *sep = strchr (str, '|'); |
429 | |
443 | |
430 | if (sep) |
444 | if (sep) |
431 | { |
445 | { |
432 | if (pl->gender) |
446 | if (gender) |
433 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
447 | buf.add (sep + 1, nest.size () - (sep - str) - 2); |
434 | else |
448 | else |
435 | buf.add (str, sep - str); |
449 | buf.add (str, sep - str); |
436 | } |
450 | } |
437 | |
451 | |
… | |
… | |
445 | sfx = "}"; |
459 | sfx = "}"; |
446 | break; |
460 | break; |
447 | } |
461 | } |
448 | |
462 | |
449 | buf << pfx; |
463 | buf << pfx; |
450 | cfpod = expand_cfpod (pl, buf, cfpod, end); |
464 | cfpod = expand_cfpod (hintmode, gender, buf, cfpod, end); |
451 | buf << sfx; |
465 | buf << sfx; |
452 | } |
466 | } |
453 | |
467 | |
454 | break; |
468 | break; |
455 | |
469 | |
… | |
… | |
462 | verbatim: |
476 | verbatim: |
463 | // elements cannot currently span multiple lines |
477 | // elements cannot currently span multiple lines |
464 | do |
478 | do |
465 | { |
479 | { |
466 | buf << "<tt>"; |
480 | buf << "<tt>"; |
467 | cfpod = expand_cfpod (pl, buf, cfpod, -2); |
481 | cfpod = expand_cfpod (hintmode, gender, buf, cfpod, -2); |
468 | buf << "</tt>\n"; |
482 | buf << "</tt>\n"; |
469 | |
483 | |
470 | while (*cfpod == '\n') |
484 | while (*cfpod == '\n') |
471 | buf << *cfpod++; |
485 | buf << *cfpod++; |
472 | } |
486 | } |
… | |
… | |
475 | break; |
489 | break; |
476 | } |
490 | } |
477 | } |
491 | } |
478 | |
492 | |
479 | dynbuf_text * |
493 | dynbuf_text * |
480 | player::expand_cfpod (const char *cfpod) const |
494 | player::expand_cfpod (int hintmode, int gender, const_utf8_string cfpod) |
481 | { |
495 | { |
482 | static dynbuf_text buf(1024, 1024); |
496 | static dynbuf_text buf(65536, 1024); |
483 | buf.clear (); |
497 | buf.clear (); |
484 | |
498 | |
485 | ::expand_cfpod (this, buf, cfpod); |
499 | ::expand_cfpod (hintmode, gender, buf, cfpod); |
486 | |
500 | |
487 | return &buf; |
501 | return &buf; |
488 | } |
502 | } |
489 | |
503 | |
|
|
504 | dynbuf_text * |
|
|
505 | player::expand_cfpod (const_utf8_string cfpod) const |
|
|
506 | { |
|
|
507 | return expand_cfpod (hintmode, gender, cfpod); |
|
|
508 | } |
|
|
509 | |