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

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.61 by root, Tue Jul 10 05:51:37 2007 UTC vs.
Revision 1.65 by root, Thu Aug 16 06:36:56 2007 UTC

36#include <funcpoint.h> 36#include <funcpoint.h>
37#include <material.h> 37#include <material.h>
38 38
39#include <glib.h> 39#include <glib.h>
40 40
41refcnt_base::refcnt_t refcnt_dummy;
42
41rand_gen rndm; 43rand_gen rndm;
42 44
43void 45void
44tausworthe_random_generator::seed (uint32_t seed) 46tausworthe_random_generator::seed (uint32_t seed)
45{ 47{
212{ 214{
213 for (materialtype_t *mt = materialt; mt && mt->next; mt = mt->next) 215 for (materialtype_t *mt = materialt; mt && mt->next; mt = mt->next)
214 if (name == mt->name) 216 if (name == mt->name)
215 return mt; 217 return mt;
216 218
217 return materialt; 219 return 0;
218} 220}
219 221
220/* when doing transmutation of objects, we have to recheck the resistances, 222/* when doing transmutation of objects, we have to recheck the resistances,
221 * as some that did not apply previously, may apply now. 223 * as some that did not apply previously, may apply now.
222 */ 224 */
223
224void 225void
225transmute_materialname (object *op, const object *change) 226transmute_materialname (object *op, const object *change)
226{ 227{
227 materialtype_t *mt; 228 materialtype_t *mt;
228 int j; 229 int j;
417 * a 'list' for the purposes here, is a string of items, seperated by commas, except 418 * a 'list' for the purposes here, is a string of items, seperated by commas, except
418 * for the last entry, which has an 'and' before it, and a full stop (period) after it. 419 * for the last entry, which has an 'and' before it, and a full stop (period) after it.
419 * This function will also strip all trailing non alphanumeric characters. 420 * This function will also strip all trailing non alphanumeric characters.
420 * It does not insert an oxford comma. 421 * It does not insert an oxford comma.
421 */ 422 */
422
423void 423void
424make_list_like (char *input) 424make_list_like (char *input)
425{ 425{
426 char *p, tmp[MAX_BUF]; 426 char *p, tmp[MAX_BUF];
427 int i; 427 int i;
517 } 517 }
518 else 518 else
519 memcpy (dst, src, len + 1); 519 memcpy (dst, src, len + 1);
520} 520}
521 521
522const std::string 522const char *
523format (const char *format, ...) 523format (const char *format, ...)
524{ 524{
525 int len; 525 static dynbuf_text buf;
526 526
527 { 527 buf.clear ();
528 char buf[128];
529 528
530 va_list ap; 529 va_list ap;
531 va_start (ap, format); 530 va_start (ap, format);
532 len = vsnprintf (buf, sizeof (buf), format, ap); 531 buf.vprintf (format, ap);
533 va_end (ap); 532 va_end (ap);
534 533
535 assert (len >= 0); // shield againstz broken vsnprintf's
536
537 // was our static buffer short enough?
538 if (len < sizeof (buf))
539 return std::string (buf, len);
540 }
541
542 {
543 // longer, try harder
544 char *buf = salloc<char> (len + 1);
545
546 va_list ap;
547 va_start (ap, format);
548 vsnprintf (buf, len + 1, format, ap);
549 va_end (ap);
550
551 const std::string s (buf, len);
552 sfree<char> (buf, len + 1);
553
554 return buf; 534 return buf;
555 }
556} 535}
557 536
558tstamp now () 537tstamp now ()
559{ 538{
560 struct timeval tv; 539 struct timeval tv;
628 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, 607 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
629 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, 608 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
630 0x2d02ef8dL 609 0x2d02ef8dL
631}; 610};
632 611
612#if 0
613void xyzzy (object_ptr &a, object_ptr &o)
614{
615 asm volatile ("int3");
616 a = o;
617 asm volatile ("int3");
618}
619#endif
633 620

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines