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.9 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.12 by root, Tue Sep 12 20:55:40 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_utils_c = 3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.9 2006/09/10 16:00:23 root Exp $"; 4 * "$Id: utils.C,v 1.12 2006/09/12 20:55:40 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
531 531
532 strncpy (tmp, input, MAX_BUF - 5); 532 strncpy (tmp, input, MAX_BUF - 5);
533 /*trim all trailing commas, spaces etc. */ 533 /*trim all trailing commas, spaces etc. */
534 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--) 534 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--)
535 tmp[i] = '\0'; 535 tmp[i] = '\0';
536
536 strcat (tmp, "."); 537 strcat (tmp, ".");
537 538
538 p = strrchr (tmp, ','); 539 p = strrchr (tmp, ',');
539 if (p) 540 if (p)
540 { 541 {
544 strcat (input, " and"); 545 strcat (input, " and");
545 strcat (input, p); 546 strcat (input, p);
546 } 547 }
547 else 548 else
548 strcpy (input, tmp); 549 strcpy (input, tmp);
550
549 return; 551 return;
550} 552}
551 553
552void * 554void *alloc (int s) throw (std::bad_alloc)
553 zero_initialised::operator
554new (size_t s)
555{ 555{
556 //return calloc (1, s); 556 if (s)
557 return g_slice_alloc0 (s); 557 return g_slice_alloc (s);
558 else
559 return 0;
558} 560}
559 561
560void * 562void dealloc (void *p, int s) throw ()
561 zero_initialised::operator
562new[] (size_t s)
563{ 563{
564 //return calloc (1, s); 564 if (s)
565 return g_slice_alloc0 (s);
566}
567
568void
569 zero_initialised::operator
570delete (void *p, size_t s)
571{
572 //free (p); return;
573 g_slice_free1 (s, p); 565 g_slice_free1 (s, p);
574} 566}
575 567
576void 568void assign (char *dst, const char *src, int maxlen)
577 zero_initialised::operator
578delete[] (void *p, size_t s)
579{ 569{
580 //free (p); return; 570 if (!src)
581 g_slice_free1 (s, p); 571 src = "";
572
573 int len = strlen (src);
574
575 if (len >= maxlen - 1)
576 {
577 if (maxlen <= 4)
578 {
579 memset (dst, '.', maxlen - 1);
580 dst [maxlen - 1] = 0;
581 }
582 else
583 {
584 memcpy (dst, src, maxlen - 4);
585 memcpy (dst + maxlen - 4, "...", 4);
586 }
587 }
588 else
589 memcpy (dst, src, len + 1);
582} 590}
591

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines