annotate dmd2/root/array.c @ 1452:638d16625da2

LDC 2 compiles again.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 30 May 2009 17:23:32 +0100
parents
children f0423003caa6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1452
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
1
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
2 // Copyright (c) 1999-2009 by Digital Mars
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
3 // All Rights Reserved
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
4 // written by Walter Bright
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
5 // www.digitalmars.com
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
6 // License for redistribution is by either the Artistic License
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
8 // See the included readme.txt for details.
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
9
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
10 #include <stdio.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
11 #include <stdlib.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
12 #include <stdarg.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
13 #include <string.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
14 #include <assert.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
15
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
16 #if (defined (__SVR4) && defined (__sun))
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
17 #include <alloca.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
18 #endif
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
19
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
20 #if _MSC_VER || __MINGW32__
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
21 #include <malloc.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
22 #endif
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
23
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
24 #if IN_GCC
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
25 #include "gdc_alloca.h"
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
26 #endif
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
27
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
28 #if _WIN32
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
29 #include <windows.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
30 #endif
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
31
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
32 #ifndef _WIN32
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
33 #include <sys/types.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
34 #include <sys/stat.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
35 #include <fcntl.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
36 #include <errno.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
37 #include <unistd.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
38 #include <utime.h>
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
39 #endif
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
40
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
41 #include "port.h"
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
42 #include "root.h"
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
43 #include "dchar.h"
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
44 #include "rmem.h"
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
45
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
46
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
47 /********************************* Array ****************************/
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
48
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
49 Array::Array()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
50 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
51 data = NULL;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
52 dim = 0;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
53 allocdim = 0;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
54 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
55
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
56 Array::~Array()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
57 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
58 mem.free(data);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
59 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
60
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
61 void Array::mark()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
62 { unsigned u;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
63
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
64 mem.mark(data);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
65 for (u = 0; u < dim; u++)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
66 mem.mark(data[u]); // BUG: what if arrays of Object's?
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
67 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
68
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
69 void Array::reserve(unsigned nentries)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
70 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
71 //printf("Array::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
72 if (allocdim - dim < nentries)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
73 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
74 allocdim = dim + nentries;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
75 data = (void **)mem.realloc(data, allocdim * sizeof(*data));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
76 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
77 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
78
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
79 void Array::setDim(unsigned newdim)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
80 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
81 if (dim < newdim)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
82 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
83 reserve(newdim - dim);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
84 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
85 dim = newdim;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
86 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
87
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
88 void Array::fixDim()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
89 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
90 if (dim != allocdim)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
91 { data = (void **)mem.realloc(data, dim * sizeof(*data));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
92 allocdim = dim;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
93 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
94 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
95
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
96 void Array::push(void *ptr)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
97 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
98 reserve(1);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
99 data[dim++] = ptr;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
100 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
101
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
102 void *Array::pop()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
103 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
104 return data[--dim];
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
105 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
106
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
107 void Array::shift(void *ptr)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
108 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
109 reserve(1);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
110 memmove(data + 1, data, dim * sizeof(*data));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
111 data[0] = ptr;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
112 dim++;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
113 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
114
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
115 void Array::insert(unsigned index, void *ptr)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
116 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
117 reserve(1);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
118 memmove(data + index + 1, data + index, (dim - index) * sizeof(*data));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
119 data[index] = ptr;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
120 dim++;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
121 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
122
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
123
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
124 void Array::insert(unsigned index, Array *a)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
125 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
126 if (a)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
127 { unsigned d;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
128
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
129 d = a->dim;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
130 reserve(d);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
131 if (dim != index)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
132 memmove(data + index + d, data + index, (dim - index) * sizeof(*data));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
133 memcpy(data + index, a->data, d * sizeof(*data));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
134 dim += d;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
135 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
136 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
137
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
138
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
139 /***********************************
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
140 * Append array a to this array.
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
141 */
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
142
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
143 void Array::append(Array *a)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
144 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
145 insert(dim, a);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
146 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
147
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
148 void Array::remove(unsigned i)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
149 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
150 memmove(data + i, data + i + 1, (dim - i) * sizeof(data[0]));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
151 dim--;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
152 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
153
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
154 char *Array::toChars()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
155 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
156 unsigned len;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
157 unsigned u;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
158 char **buf;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
159 char *str;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
160 char *p;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
161
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
162 buf = (char **)alloca(dim * sizeof(char *));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
163 len = 2;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
164 for (u = 0; u < dim; u++)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
165 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
166 buf[u] = ((Object *)data[u])->toChars();
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
167 len += strlen(buf[u]) + 1;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
168 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
169 str = (char *)mem.malloc(len);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
170
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
171 str[0] = '[';
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
172 p = str + 1;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
173 for (u = 0; u < dim; u++)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
174 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
175 if (u)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
176 *p++ = ',';
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
177 len = strlen(buf[u]);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
178 memcpy(p,buf[u],len);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
179 p += len;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
180 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
181 *p++ = ']';
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
182 *p = 0;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
183 return str;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
184 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
185
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
186 void Array::zero()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
187 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
188 memset(data,0,dim * sizeof(data[0]));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
189 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
190
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
191 void *Array::tos()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
192 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
193 return dim ? data[dim - 1] : NULL;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
194 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
195
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
196 int
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
197 #if _WIN32
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
198 __cdecl
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
199 #endif
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
200 Array_sort_compare(const void *x, const void *y)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
201 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
202 Object *ox = *(Object **)x;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
203 Object *oy = *(Object **)y;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
204
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
205 return ox->compare(oy);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
206 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
207
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
208 void Array::sort()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
209 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
210 if (dim)
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
211 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
212 qsort(data, dim, sizeof(Object *), Array_sort_compare);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
213 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
214 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
215
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
216 Array *Array::copy()
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
217 {
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
218 Array *a = new Array();
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
219
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
220 a->setDim(dim);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
221 memcpy(a->data, data, dim * sizeof(void *));
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
222 return a;
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
223 }
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents:
diff changeset
224