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.17 by root, Fri Nov 17 19:40:53 2006 UTC

1
2/*
3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.9 2006/09/10 16:00:23 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 */
206} 200}
207 201
208/* decay and destroy persihable items in a map */ 202/* decay and destroy persihable items in a map */
209 203
210void 204void
211decay_objects (mapstruct *m) 205decay_objects (maptile *m)
212{ 206{
213 int x, y, destroy; 207 int x, y, destroy;
214 object *op, *otmp; 208 object *op, *otmp;
215 209
216 if (m->unique) 210 if (m->unique)
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/////////////////////////////////////////////////////////////////////////////
553 zero_initialised::operator
554new (size_t s)
555{
556 //return calloc (1, s);
557 return g_slice_alloc0 (s);
558}
559 549
560void * 550#if 0
561 zero_initialised::operator 551refcounted *refcounted::rc_first;
562new[] (size_t s)
563{
564 //return calloc (1, s);
565 return g_slice_alloc0 (s);
566}
567 552
568void 553refcounted::refcounted ()
569 zero_initialised::operator
570delete (void *p, size_t s)
571{ 554{
572 //free (p); return; 555 refcnt = 0;
573 g_slice_free1 (s, p); 556 rc_next = rc_first;
557 rc_first = this;
574} 558}
575 559
576void 560refcounted::~refcounted ()
577 zero_initialised::operator
578delete[] (void *p, size_t s)
579{ 561{
580 //free (p); return; 562 assert (!rc_next);
581 g_slice_free1 (s, p); 563 assert (!refcnt);
582} 564}
565#endif
566
567void *alloc (int s) throw (std::bad_alloc)
568{
569 void *p = g_slice_alloc (s);
570
571 if (!p)
572 throw std::bad_alloc ();
573
574 return p;
575}
576
577void assign (char *dst, const char *src, int maxlen)
578{
579 if (!src)
580 src = "";
581
582 int len = strlen (src);
583
584 if (len >= maxlen - 1)
585 {
586 if (maxlen <= 4)
587 {
588 memset (dst, '.', maxlen - 1);
589 dst [maxlen - 1] = 0;
590 }
591 else
592 {
593 memcpy (dst, src, maxlen - 4);
594 memcpy (dst + maxlen - 4, "...", 4);
595 }
596 }
597 else
598 memcpy (dst, src, len + 1);
599}
600
601

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines