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.16 by root, Sat Sep 16 22:24:12 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 * 550void *alloc (int s) throw (std::bad_alloc)
561 zero_initialised::operator
562new[] (size_t s)
563{ 551{
564 //return calloc (1, s); 552 void *p = g_slice_alloc (s);
565 return g_slice_alloc0 (s);
566}
567 553
568void 554 if (!p)
569 zero_initialised::operator 555 throw std::bad_alloc ();
570delete (void *p, size_t s)
571{
572 //free (p); return;
573 g_slice_free1 (s, p);
574}
575 556
576void 557 return p;
577 zero_initialised::operator
578delete[] (void *p, size_t s)
579{
580 //free (p); return;
581 g_slice_free1 (s, p);
582} 558}
559
560void assign (char *dst, const char *src, int maxlen)
561{
562 if (!src)
563 src = "";
564
565 int len = strlen (src);
566
567 if (len >= maxlen - 1)
568 {
569 if (maxlen <= 4)
570 {
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);
582}
583

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines