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