ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/player.C
(Generate patch)

Comparing deliantra/server/common/player.C (file contents):
Revision 1.42 by root, Mon Sep 8 11:30:53 2008 UTC vs.
Revision 1.47 by root, Mon Sep 29 10:32:50 2008 UTC

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 " >>>"
295static const char * 296static const char *
296expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end) 297expand_cfpod (const player *pl, dynbuf_text &buf, const char *cfpod, int end = 0)
297{ 298{
298 static dynbuf_text nest(128, 128); 299 static dynbuf_text nest(128, 128);
299 300
300 for (;;) 301 for (;;)
301 switch (char ch = *cfpod++) 302 switch (char ch = *cfpod++)
302 { 303 {
303 case 0: 304 case 0:
304 return cfpod - 1; 305 return cfpod - 1;
305 306
306 case ' ': 307 case ' ':
308 // verbatim block?
309 if (!buf.size () && !end)
310 {
311 --cfpod;
312 goto verbatim;
313 }
314
307 if (end <= 0) 315 if (end < 1)
308 goto passthrough; 316 goto passthrough;
309 317
310 for (int i = 0; i < end; ++i) 318 for (int i = 0; i < end; ++i)
311 if (cfpod [i] != '>') 319 if (cfpod [i] != '>')
312 goto passthrough; 320 goto passthrough;
313 321
314 return cfpod + end; 322 return cfpod + end;
315 323
316 case '>': 324 case '>':
317 if (end) 325 if (end != -1)
318 { 326 {
319 buf << "&gt;"; 327 buf << "&gt;";
320 break; 328 break;
321 } 329 }
322 330
333 case '\r': 341 case '\r':
334 buf << '\n'; 342 buf << '\n';
335 break; 343 break;
336 344
337 case '\n': 345 case '\n':
346 if (end == -2)
347 return cfpod;
348
349 // \n\ => newline, tt
350 // \n\n => \n\n
351 // \n => single space
352
353 // two or more newlines will be copied verbatim, one is replaced by space
338 if (*cfpod == ' ') 354 if (*cfpod == '\n')
339 goto passthrough;
340 else if (*cfpod == '\n')
341 { 355 {
342 --cfpod; 356 --cfpod;
343 do 357 do
344 buf << *cfpod++; 358 buf << *cfpod++;
345 while (*cfpod == '\n'); 359 while (*cfpod == '\n');
346 } 360 }
347 else 361 else if (*cfpod != ' ')
348 buf << ' '; 362 buf << ' ';
363
364 // verbatim block?
365 if (*cfpod == ' ')
366 goto verbatim;
349 367
350 break; 368 break;
351 369
352 case 'B': case 'C': case 'E': case 'G': 370 case 'B': case 'C': case 'E': case 'G':
353 case 'H': case 'I': case 'T': case 'U': 371 case 'H': case 'I': case 'T': case 'U':
354 case 'Z': 372 case 'Z':
355 { 373 {
356 int len = 0; 374 int end = 0;
357 375
358 while (cfpod [len] == '<') 376 while (cfpod [end] == '<')
359 ++len; 377 ++end;
360 378
361 if (!len) 379 if (!end)
362 goto passthrough; 380 goto passthrough;
363 381
364 if (len == 1 || cfpod [len] != ' ') 382 if (end == 1 || cfpod [end] != ' ')
365 { 383 {
366 len = 0; 384 end = -1;
367 ++cfpod; 385 ++cfpod;
368 } 386 }
369 else 387 else
370 cfpod += len + 1; 388 cfpod += end + 1;
371 389
372 const char *pfx, *sfx; 390 const char *pfx, *sfx;
373 391
374 switch (ch) 392 switch (ch)
375 { 393 {
382 400
383 case 'H': // hint 401 case 'H': // hint
384 { 402 {
385 if (pl->hintmode) 403 if (pl->hintmode)
386 { 404 {
387 cfpod = expand_cfpod (pl, nest, cfpod, len); 405 cfpod = expand_cfpod (pl, nest, cfpod, end);
388 nest.clear (); 406 nest.clear ();
389 407
390 if (pl->hintmode == 1) 408 if (pl->hintmode == 1)
391 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 409 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
392 else 410 else
403 } 421 }
404 break; 422 break;
405 423
406 case 'G': // gender 424 case 'G': // gender
407 { 425 {
408 expand_cfpod (pl, nest, cfpod, len); 426 cfpod = expand_cfpod (pl, nest, cfpod, end);
409 nest << '\0'; // zero-terminate 427 nest << '\0'; // zero-terminate
410 428
411 const char *str = nest.linearise (); 429 const char *str = nest.linearise ();
412 const char *sep = strchr (str, '|'); 430 const char *sep = strchr (str, '|');
413 431
414 if (sep) 432 if (sep)
415 { 433 {
416 if (pl->gender || 1) 434 if (pl->gender)
417 buf.add (sep + 1, nest.size () - (sep - str) - 2); 435 buf.add (sep + 1, nest.size () - (sep - str) - 2);
418 else 436 else
419 buf.add (str, sep - str); 437 buf.add (str, sep - str);
420 } 438 }
421 439
424 goto skip; 442 goto skip;
425 } 443 }
426 } 444 }
427 445
428 buf << pfx; 446 buf << pfx;
429 cfpod = expand_cfpod (pl, buf, cfpod, len); 447 cfpod = expand_cfpod (pl, buf, cfpod, end);
430 buf << sfx; 448 buf << sfx;
431 } 449 }
432 450
433 break; 451 break;
434 452
435 default: 453 default:
436 passthrough: 454 passthrough:
437 buf << ch; 455 buf << ch;
438 skip: 456 skip:
439 break; 457 break;
458
459 verbatim:
460 // elements cannot currently span multiple lines
461 do
462 {
463 buf << "<tt>";
464 cfpod = expand_cfpod (pl, buf, cfpod, -2);
465 buf << "</tt>\n";
466 }
467 while (*cfpod == ' ');
468
469 while (*cfpod == '\n')
470 buf << *cfpod++;
471
472 break;
440 } 473 }
441} 474}
442 475
443dynbuf_text * 476dynbuf_text *
444player::expand_cfpod (const char *cfpod) const 477player::expand_cfpod (const char *cfpod) const
445{ 478{
446 static dynbuf_text buf(1024, 1024); 479 static dynbuf_text buf(1024, 1024);
447 buf.clear (); 480 buf.clear ();
448 481
449 ::expand_cfpod (this, buf, cfpod, -1); 482 ::expand_cfpod (this, buf, cfpod);
450 483
451 return &buf; 484 return &buf;
452} 485}
453 486

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines