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