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.41 by root, Mon Sep 8 11:27:24 2008 UTC vs.
Revision 1.43 by root, Mon Sep 8 18:34:35 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)
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 << "&gt;"; 320 buf << "&gt;";
320 break; 321 break;
321 } 322 }
322 323
328 329
329 case '<': 330 case '<':
330 buf << "&lt;"; 331 buf << "&lt;";
331 break; 332 break;
332 333
334 case '\r':
335 buf << '\n';
336 break;
337
333 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
334 if (*cfpod == ' ') 347 if (*cfpod == '\n')
335 goto passthrough;
336 else if (*cfpod == '\n')
337 { 348 {
338 --cfpod; 349 --cfpod;
350 do
351 buf << *cfpod++;
352 while (*cfpod == '\n');
353 }
354 else if (*cfpod != ' ')
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
339 while (*cfpod == '\n') 369 while (*cfpod == '\n')
340 buf << *cfpod++; 370 buf << *cfpod++;
341
342 goto skip;
343 } 371 }
344 372
345 buf << ' ';
346 break; 373 break;
347 374
348 case 'B': case 'C': case 'E': case 'G': 375 case 'B': case 'C': case 'E': case 'G':
349 case 'H': case 'I': case 'T': case 'U': 376 case 'H': case 'I': case 'T': case 'U':
350 case 'Z': 377 case 'Z':
351 { 378 {
352 int len = 0; 379 int end = 0;
353 380
354 while (cfpod [len] == '<') 381 while (cfpod [end] == '<')
355 ++len; 382 ++end;
356 383
357 if (!len) 384 if (!end)
358 goto passthrough; 385 goto passthrough;
359 386
360 if (len == 1 || cfpod [len] != ' ') 387 if (end == 1 || cfpod [end] != ' ')
361 { 388 {
362 len = 0; 389 end = -1;
363 ++cfpod; 390 ++cfpod;
364 } 391 }
365 else 392 else
366 cfpod += len + 1; 393 cfpod += end + 1;
367 394
368 const char *pfx, *sfx; 395 const char *pfx, *sfx;
369 396
370 switch (ch) 397 switch (ch)
371 { 398 {
378 405
379 case 'H': // hint 406 case 'H': // hint
380 { 407 {
381 if (pl->hintmode) 408 if (pl->hintmode)
382 { 409 {
383 cfpod = expand_cfpod (pl, nest, cfpod, len); 410 cfpod = expand_cfpod (pl, nest, cfpod, end);
384 nest.clear (); 411 nest.clear ();
385 412
386 if (pl->hintmode == 1) 413 if (pl->hintmode == 1)
387 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>"; 414 buf << "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>";
388 else 415 else
399 } 426 }
400 break; 427 break;
401 428
402 case 'G': // gender 429 case 'G': // gender
403 { 430 {
404 expand_cfpod (pl, nest, cfpod, len); 431 expand_cfpod (pl, nest, cfpod, end);
405 nest << '\0'; // zero-terminate 432 nest << '\0'; // zero-terminate
406 433
407 const char *str = nest.linearise (); 434 const char *str = nest.linearise ();
408 const char *sep = strchr (str, '|'); 435 const char *sep = strchr (str, '|');
409 436
420 goto skip; 447 goto skip;
421 } 448 }
422 } 449 }
423 450
424 buf << pfx; 451 buf << pfx;
425 cfpod = expand_cfpod (pl, buf, cfpod, len); 452 cfpod = expand_cfpod (pl, buf, cfpod, end);
426 buf << sfx; 453 buf << sfx;
427 } 454 }
428 455
429 break; 456 break;
430 457
440player::expand_cfpod (const char *cfpod) const 467player::expand_cfpod (const char *cfpod) const
441{ 468{
442 static dynbuf_text buf(1024, 1024); 469 static dynbuf_text buf(1024, 1024);
443 buf.clear (); 470 buf.clear ();
444 471
445 ::expand_cfpod (this, buf, cfpod, -1); 472 ::expand_cfpod (this, buf, cfpod, 0);
446 473
447 return &buf; 474 return &buf;
448} 475}
449 476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines