1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcsid_utils_c = |
3 | * static char *rcsid_utils_c = |
4 | * "$Id: utils.C,v 1.9 2006/09/10 16:00:23 root Exp $"; |
4 | * "$Id: utils.C,v 1.11 2006/09/12 19:20:06 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
531 | |
531 | |
532 | strncpy (tmp, input, MAX_BUF - 5); |
532 | strncpy (tmp, input, MAX_BUF - 5); |
533 | /*trim all trailing commas, spaces etc. */ |
533 | /*trim all trailing commas, spaces etc. */ |
534 | for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--) |
534 | for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--) |
535 | tmp[i] = '\0'; |
535 | tmp[i] = '\0'; |
|
|
536 | |
536 | strcat (tmp, "."); |
537 | strcat (tmp, "."); |
537 | |
538 | |
538 | p = strrchr (tmp, ','); |
539 | p = strrchr (tmp, ','); |
539 | if (p) |
540 | if (p) |
540 | { |
541 | { |
… | |
… | |
544 | strcat (input, " and"); |
545 | strcat (input, " and"); |
545 | strcat (input, p); |
546 | strcat (input, p); |
546 | } |
547 | } |
547 | else |
548 | else |
548 | strcpy (input, tmp); |
549 | strcpy (input, tmp); |
|
|
550 | |
549 | return; |
551 | return; |
550 | } |
552 | } |
551 | |
553 | |
552 | void * |
554 | void * |
|
|
555 | zero_initialised::operator new (size_t s, void *p) |
|
|
556 | { |
|
|
557 | memset (p, 0, s); |
|
|
558 | return p; |
|
|
559 | } |
|
|
560 | |
|
|
561 | void * |
553 | zero_initialised::operator |
562 | zero_initialised::operator new (size_t s) |
554 | new (size_t s) |
|
|
555 | { |
563 | { |
556 | //return calloc (1, s); |
564 | //return calloc (1, s); |
557 | return g_slice_alloc0 (s); |
565 | return g_slice_alloc0 (s); |
558 | } |
566 | } |
559 | |
567 | |
560 | void * |
568 | void * |
561 | zero_initialised::operator |
569 | zero_initialised::operator new[] (size_t s) |
562 | new[] (size_t s) |
|
|
563 | { |
570 | { |
564 | //return calloc (1, s); |
571 | //return calloc (1, s); |
565 | return g_slice_alloc0 (s); |
572 | return g_slice_alloc0 (s); |
566 | } |
573 | } |
567 | |
574 | |
568 | void |
575 | void |
569 | zero_initialised::operator |
576 | zero_initialised::operator delete (void *p, size_t s) |
570 | delete (void *p, size_t s) |
|
|
571 | { |
577 | { |
572 | //free (p); return; |
578 | //free (p); return; |
573 | g_slice_free1 (s, p); |
579 | g_slice_free1 (s, p); |
574 | } |
580 | } |
575 | |
581 | |
576 | void |
582 | void |
577 | zero_initialised::operator |
583 | zero_initialised::operator delete[] (void *p, size_t s) |
578 | delete[] (void *p, size_t s) |
|
|
579 | { |
584 | { |
580 | //free (p); return; |
585 | //free (p); return; |
581 | g_slice_free1 (s, p); |
586 | g_slice_free1 (s, p); |
582 | } |
587 | } |
|
|
588 | |
|
|
589 | void assign (char *dst, const char *src, int maxlen) |
|
|
590 | { |
|
|
591 | if (!src) |
|
|
592 | src = ""; |
|
|
593 | |
|
|
594 | int len = strlen (src); |
|
|
595 | |
|
|
596 | if (len >= maxlen - 1) |
|
|
597 | { |
|
|
598 | if (maxlen <= 4) |
|
|
599 | { |
|
|
600 | memset (dst, '.', maxlen - 1); |
|
|
601 | dst [maxlen - 1] = 0; |
|
|
602 | } |
|
|
603 | else |
|
|
604 | { |
|
|
605 | memcpy (dst, src, maxlen - 4); |
|
|
606 | memcpy (dst + maxlen - 4, "...", 4); |
|
|
607 | } |
|
|
608 | } |
|
|
609 | else |
|
|
610 | memcpy (dst, src, len + 1); |
|
|
611 | } |
|
|
612 | |