summaryrefslogtreecommitdiff
path: root/graphics/clanlib/patches/patch-ac
blob: 2144fbb6a211fe3e2e4001ad4578f0bf9e764910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$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 <cctype>
+#include <stdio.h>
+#include <sys/param.h>
 #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;