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.10 by root, Mon Sep 11 01:16:20 2006 UTC vs.
Revision 1.11 by root, Tue Sep 12 19:20:06 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_utils_c = 3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.10 2006/09/11 01:16:20 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
552void * 554void *
553zero_initialised::operator new (size_t s, void *p) 555zero_initialised::operator new (size_t s, void *p)
581zero_initialised::operator delete[] (void *p, size_t s) 583zero_initialised::operator delete[] (void *p, size_t s)
582{ 584{
583 //free (p); return; 585 //free (p); return;
584 g_slice_free1 (s, p); 586 g_slice_free1 (s, p);
585} 587}
588
589void 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines