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 | */ |
… | |
… | |
206 | } |
200 | } |
207 | |
201 | |
208 | /* decay and destroy persihable items in a map */ |
202 | /* decay and destroy persihable items in a map */ |
209 | |
203 | |
210 | void |
204 | void |
211 | decay_objects (mapstruct *m) |
205 | decay_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 | |
552 | void * |
548 | ///////////////////////////////////////////////////////////////////////////// |
553 | zero_initialised::operator new (size_t s, void *p) |
549 | |
|
|
550 | #if 0 |
|
|
551 | refcounted *refcounted::rc_first; |
|
|
552 | |
|
|
553 | refcounted::refcounted () |
554 | { |
554 | { |
555 | memset (p, 0, s); |
555 | refcnt = 0; |
|
|
556 | rc_next = rc_first; |
|
|
557 | rc_first = this; |
|
|
558 | } |
|
|
559 | |
|
|
560 | refcounted::~refcounted () |
|
|
561 | { |
|
|
562 | assert (!rc_next); |
|
|
563 | assert (!refcnt); |
|
|
564 | } |
|
|
565 | #endif |
|
|
566 | |
|
|
567 | void *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 | |
556 | return p; |
574 | return p; |
557 | } |
575 | } |
558 | |
576 | |
559 | void * |
577 | void assign (char *dst, const char *src, int maxlen) |
560 | zero_initialised::operator new (size_t s) |
|
|
561 | { |
578 | { |
562 | //return calloc (1, s); |
579 | if (!src) |
563 | return g_slice_alloc0 (s); |
580 | src = ""; |
564 | } |
|
|
565 | |
581 | |
566 | void * |
582 | 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 | |
583 | |
573 | void |
584 | if (len >= maxlen - 1) |
574 | zero_initialised::operator delete (void *p, size_t s) |
585 | { |
575 | { |
586 | if (maxlen <= 4) |
576 | //free (p); return; |
587 | { |
577 | g_slice_free1 (s, p); |
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); |
578 | } |
599 | } |
579 | |
600 | |
580 | void |
601 | |
581 | zero_initialised::operator delete[] (void *p, size_t s) |
|
|
582 | { |
|
|
583 | //free (p); return; |
|
|
584 | g_slice_free1 (s, p); |
|
|
585 | } |
|
|