$NetBSD: patch-ac,v 1.4 2001/05/11 14:12:10 dmcmahill Exp $ add an operator overload for CL_String << long so this can build on 64-bit systems. --- Sources/API/Core/System/clanstring.h.orig Tue May 9 17:09:32 2000 +++ Sources/API/Core/System/clanstring.h Thu May 10 17:57:14 2001 @@ -26,4 +26,6 @@ #ifndef WIN32 #include +#include +#include #endif @@ -69,4 +71,36 @@ } } + +void ltoa(long num, char *str, const int number_format) +{ + long num1 = num; + int num_chars = 0; + + while (num1>0) + { + num_chars++; + num1 /= number_format; + } + + if (num_chars == 0) num_chars = 1; + + str[num_chars] = 0; // Null-terminate the str + + for (int pos = num_chars-1; pos>=0; pos--) + { + int cur_char = num % number_format; + + if (cur_char < 10) // Insert number + { + str[pos] = cur_char + '0'; + } + else // Insert letter + { + str[pos] = cur_char-10 + 'A'; + } + + num /= number_format; + } +} #else #pragma warning( disable : 4244 ) @@ -97,4 +131,26 @@ return text; } + + char *long_to_string(const char *prefix, const long number) + { + char buf[20]; + ltoa(number, buf, 10); + + int len=0; + if (prefix!=NULL) len=strlen(prefix); + + char *text=new char[len+strlen(buf)+1]; + if (prefix!=NULL) + { + strcpy(text, prefix); + strcat(text, buf); + } + else + { + strcpy(text, buf); + } + + return text; + } char *float_to_string(const char *prefix, const float _float_number) @@ -102,7 +158,10 @@ char buf[25]; buf[0]=0; + int precision=4; +#if (defined(BSD) && BSD >= 199306) + snprintf(buf, sizeof buf, "%.*f", precision, (double)_float_number); +#else int decimal, sign; - int precision=4; char temp; @@ -135,4 +194,5 @@ copy_strings: +#endif int len=0; if (prefix!=NULL) len=strlen(prefix); @@ -434,4 +494,22 @@ { char *new_string=int_to_string(str, number); + if (str!=NULL) delete str; + str=new_string; + + return *this; + } + + CL_String &operator<< (const unsigned long number) + { + char *new_string=long_to_string(str, number); + if (str!=NULL) delete str; + str=new_string; + + return *this; + } + + CL_String &operator<< (const long number) + { + char *new_string=long_to_string(str, number); if (str!=NULL) delete str; str=new_string;