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.10 by root, Mon Sep 11 01:16:20 2006 UTC vs.
Revision 1.15 by root, Thu Sep 14 22:34:00 2006 UTC

1
2/*
3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.10 2006/09/11 01:16:20 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30/* 24/*
31 * General convenience functions for crossfire. 25 * General convenience functions for crossfire.
32 */ 26 */
531 525
532 strncpy (tmp, input, MAX_BUF - 5); 526 strncpy (tmp, input, MAX_BUF - 5);
533 /*trim all trailing commas, spaces etc. */ 527 /*trim all trailing commas, spaces etc. */
534 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--) 528 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--)
535 tmp[i] = '\0'; 529 tmp[i] = '\0';
530
536 strcat (tmp, "."); 531 strcat (tmp, ".");
537 532
538 p = strrchr (tmp, ','); 533 p = strrchr (tmp, ',');
539 if (p) 534 if (p)
540 { 535 {
544 strcat (input, " and"); 539 strcat (input, " and");
545 strcat (input, p); 540 strcat (input, p);
546 } 541 }
547 else 542 else
548 strcpy (input, tmp); 543 strcpy (input, tmp);
544
549 return; 545 return;
550} 546}
551 547
552void * 548/////////////////////////////////////////////////////////////////////////////
553zero_initialised::operator new (size_t s, void *p) 549
550void *alloc (int s) throw (std::bad_alloc)
554{ 551{
555 memset (p, 0, s); 552 void *p = g_slice_alloc (s);
553
554 if (!p)
555 throw std::bad_alloc ();
556
556 return p; 557 return p;
557} 558}
558 559
559void * 560void assign (char *dst, const char *src, int maxlen)
560zero_initialised::operator new (size_t s)
561{ 561{
562 //return calloc (1, s); 562 if (!src)
563 return g_slice_alloc0 (s); 563 src = "";
564}
565 564
566void * 565 int len = strlen (src);
567 zero_initialised::operator new[] (size_t s)
568{
569 //return calloc (1, s);
570 return g_slice_alloc0 (s);
571}
572 566
573void 567 if (len >= maxlen - 1)
574zero_initialised::operator delete (void *p, size_t s) 568 {
575{ 569 if (maxlen <= 4)
576 //free (p); return; 570 {
577 g_slice_free1 (s, p); 571 memset (dst, '.', maxlen - 1);
572 dst [maxlen - 1] = 0;
573 }
574 else
575 {
576 memcpy (dst, src, maxlen - 4);
577 memcpy (dst + maxlen - 4, "...", 4);
578 }
579 }
580 else
581 memcpy (dst, src, len + 1);
578} 582}
579 583
580void
581zero_initialised::operator delete[] (void *p, size_t s)
582{
583 //free (p); return;
584 g_slice_free1 (s, p);
585}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines