… | |
… | |
287 | |
287 | |
288 | return buf; |
288 | return buf; |
289 | } |
289 | } |
290 | |
290 | |
291 | // expand one level of cfpod |
291 | // expand one level of cfpod |
|
|
292 | // end == -2, till '\n' |
|
|
293 | // end == -1, till '>' |
292 | // end == -1, till eos |
294 | // end == 0, till eos |
293 | // end == 0, one level of '>' |
|
|
294 | // end >= 1, this many levels of " >>>" |
295 | // end >= 1, levels of " >>>" |
295 | static const char * |
296 | static const char * |
296 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) |
297 | expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) |
297 | { |
298 | { |
298 | static dynbuf_text nest(128, 128); |
299 | static dynbuf_text nest(128, 128); |
299 | |
300 | |
… | |
… | |
302 | { |
303 | { |
303 | case 0: |
304 | case 0: |
304 | return cfpod - 1; |
305 | return cfpod - 1; |
305 | |
306 | |
306 | case ' ': |
307 | case ' ': |
307 | if (end <= 0) |
308 | if (end < 1) |
308 | goto passthrough; |
309 | goto passthrough; |
309 | |
310 | |
310 | for (int i = 0; i < end; ++i) |
311 | for (int i = 0; i < end; ++i) |
311 | if (cfpod [i] != '>') |
312 | if (cfpod [i] != '>') |
312 | goto passthrough; |
313 | goto passthrough; |
313 | |
314 | |
314 | return cfpod + end; |
315 | return cfpod + end; |
315 | |
316 | |
316 | case '>': |
317 | case '>': |
317 | if (end) |
318 | if (end != -1) |
318 | { |
319 | { |
319 | buf << ">"; |
320 | buf << ">"; |
320 | break; |
321 | break; |
321 | } |
322 | } |
322 | |
323 | |
… | |
… | |
333 | case '\r': |
334 | case '\r': |
334 | buf << '\n'; |
335 | buf << '\n'; |
335 | break; |
336 | break; |
336 | |
337 | |
337 | case '\n': |
338 | case '\n': |
|
|
339 | if (end == -2) |
|
|
340 | return cfpod; |
|
|
341 | |
|
|
342 | // \n\ => newline, tt |
|
|
343 | // \n\n => \n\n |
|
|
344 | // \n => single space |
|
|
345 | |
|
|
346 | // two or more newlines will be copied verbatim, one is replaced by space |
338 | if (*cfpod == ' ') |
347 | if (*cfpod == '\n') |
339 | goto passthrough; |
|
|
340 | else if (*cfpod == '\n') |
|
|
341 | { |
348 | { |
342 | --cfpod; |
349 | --cfpod; |
343 | do |
350 | do |
344 | buf << *cfpod++; |
351 | buf << *cfpod++; |
345 | while (*cfpod == '\n'); |
352 | while (*cfpod == '\n'); |
346 | } |
353 | } |
347 | else |
354 | else if (*cfpod != ' ') |
348 | buf << ' '; |
355 | buf << ' '; |
|
|
356 | |
|
|
357 | // start verbatim block's? |
|
|
358 | if (*cfpod == ' ') |
|
|
359 | { |
|
|
360 | // elements cannot currently span multiple lines |
|
|
361 | do |
|
|
362 | { |
|
|
363 | buf << "<tt>"; |
|
|
364 | cfpod = expand_cfpod (pl, buf, cfpod, -2); |
|
|
365 | buf << "</tt>\n"; |
|
|
366 | } |
|
|
367 | while (*cfpod == ' '); |
|
|
368 | |
|
|
369 | while (*cfpod == '\n') |
|
|
370 | buf << *cfpod++; |
|
|
371 | } |
349 | |
372 | |
350 | break; |
373 | break; |
351 | |
374 | |
352 | case 'B': case 'C': case 'E': case 'G': |
375 | case 'B': case 'C': case 'E': case 'G': |
353 | case 'H': case 'I': case 'T': case 'U': |
376 | case 'H': case 'I': case 'T': case 'U': |
354 | case 'Z': |
377 | case 'Z': |
355 | { |
378 | { |
356 | int len = 0; |
379 | int end = 0; |
357 | |
380 | |
358 | while (cfpod [len] == '<') |
381 | while (cfpod [end] == '<') |
359 | ++len; |
382 | ++end; |
360 | |
383 | |
361 | if (!len) |
384 | if (!end) |
362 | goto passthrough; |
385 | goto passthrough; |
363 | |
386 | |
364 | if (len == 1 || cfpod [len] != ' ') |
387 | if (end == 1 || cfpod [end] != ' ') |
365 | { |
388 | { |
366 | len = 0; |
389 | end = -1; |
367 | ++cfpod; |
390 | ++cfpod; |
368 | } |
391 | } |
369 | else |
392 | else |
370 | cfpod += len + 1; |
393 | cfpod += end + 1; |
371 | |
394 | |
372 | const char *pfx, *sfx; |
395 | const char *pfx, *sfx; |
373 | |
396 | |
374 | switch (ch) |
397 | switch (ch) |
375 | { |
398 | { |
… | |
… | |
382 | |
405 | |
383 | case 'H': // hint |
406 | case 'H': // hint |
384 | { |
407 | { |
385 | if (pl->hintmode) |
408 | if (pl->hintmode) |
386 | { |
409 | { |
387 | cfpod = expand_cfpod (pl, nest, cfpod, len); |
410 | cfpod = expand_cfpod (pl, nest, cfpod, end); |
388 | nest.clear (); |
411 | nest.clear (); |
389 | |
412 | |
390 | if (pl->hintmode == 1) |
413 | if (pl->hintmode == 1) |
391 | buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; |
414 | buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; |
392 | else |
415 | else |
… | |
… | |
403 | } |
426 | } |
404 | break; |
427 | break; |
405 | |
428 | |
406 | case 'G': // gender |
429 | case 'G': // gender |
407 | { |
430 | { |
408 | expand_cfpod (pl, nest, cfpod, len); |
431 | expand_cfpod (pl, nest, cfpod, end); |
409 | nest << '\0'; // zero-terminate |
432 | nest << '\0'; // zero-terminate |
410 | |
433 | |
411 | const char *str = nest.linearise (); |
434 | const char *str = nest.linearise (); |
412 | const char *sep = strchr (str, '|'); |
435 | const char *sep = strchr (str, '|'); |
413 | |
436 | |
… | |
… | |
424 | goto skip; |
447 | goto skip; |
425 | } |
448 | } |
426 | } |
449 | } |
427 | |
450 | |
428 | buf << pfx; |
451 | buf << pfx; |
429 | cfpod = expand_cfpod (pl, buf, cfpod, len); |
452 | cfpod = expand_cfpod (pl, buf, cfpod, end); |
430 | buf << sfx; |
453 | buf << sfx; |
431 | } |
454 | } |
432 | |
455 | |
433 | break; |
456 | break; |
434 | |
457 | |
… | |
… | |
444 | player::expand_cfpod (const char *cfpod) const |
467 | player::expand_cfpod (const char *cfpod) const |
445 | { |
468 | { |
446 | static dynbuf_text buf(1024, 1024); |
469 | static dynbuf_text buf(1024, 1024); |
447 | buf.clear (); |
470 | buf.clear (); |
448 | |
471 | |
449 | ::expand_cfpod (this, buf, cfpod, -1); |
472 | ::expand_cfpod (this, buf, cfpod, 0); |
450 | |
473 | |
451 | return &buf; |
474 | return &buf; |
452 | } |
475 | } |
453 | |
476 | |