Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563580 views
1
#include "typedef.h"
2
#include "tools.h"
3
/**************************************************************************\
4
@---------------------------------------------------------------------------
5
@---------------------------------------------------------------------------
6
@ FILE: malloc2dim.c
7
@---------------------------------------------------------------------------
8
@---------------------------------------------------------------------------
9
@
10
\**************************************************************************/
11
12
/*
13
|
14
| tools/malloc2dim.c -- malloc & co fuer 2-dim. Arrays
15
| exportiert die Funktionen
16
|
17
| calloc2dim
18
| malloc2dim
19
| memcpy2dim
20
| memset2dim
21
| free2dim
22
|
23
*/
24
25
/*{{{}}}*/
26
/*{{{ calloc2dim*/
27
/*
28
@
29
@-------------------------------------------------------------------------
30
@ char **calloc2dim ( r, c, size )
31
@ int r,c,size;
32
|-- allokiert ein 2-dimesionales array
33
@
34
@ allocates a 2-dimensional array with 'r' rows and 'c' columns
35
@ the size of the entries in bytes is given by the argument 'size'.
36
| int r, int c: ZeilenxSpalten des Arrays
37
| int size: Groesse eines Eintrags in bytes
38
@
39
*/
40
char **calloc2dim(r,c,size)
41
int r,c,size;
42
{
43
char **new;
44
int i, j;
45
46
if( r == 0 || c == 0 || size == 0 )
47
new= NULL;
48
else
49
{
50
new= (char **)malloc( r*sizeof(char *));
51
if ( new != NULL )
52
{
53
i= 0;
54
do
55
{
56
new[i]= (char *)calloc( c, size );
57
} while ( new[i++] && i < r );
58
if ( i != r )
59
{
60
for ( j=0; j < i;j++) free ( (int *)new[i] );
61
free ( (int *)new );
62
new= NULL;
63
}
64
}
65
}
66
return new;
67
}
68
69
/*}}} */
70
/*{{{ malloc2dim*/
71
/*
72
@-------------------------------------------------------------------------
73
@ char **malloc2dim ( r, c, size )
74
@ int r,c,size;
75
| -- allokiert ein 2-dimesionales array
76
@
77
| int r, int c: ZeilenxSpalten des Arrays
78
| int size: Groesse eines Eintrags in bytes
79
@ allocates a 2-dimensional array with 'r' rows and 'c' columns
80
@ the size of the entries in bytes is given by the argument 'size'.
81
@
82
@-------------------------------------------------------------------------
83
*/
84
char **malloc2dim(r,c,size)
85
int r,c,size;
86
{
87
char **new;
88
int i, j;
89
90
if( r == 0 || c == 0 || size == 0 )
91
new= NULL;
92
else
93
{
94
new= (char **)malloc( r*sizeof(char *));
95
if ( new != NULL )
96
{
97
i= 0;
98
do
99
{
100
new[i]= (char *)malloc( c*size);
101
} while ( new[i++] && i < r );
102
if ( i != r )
103
{
104
for ( j=0; j < i;j++) free ( (int *)new[i] );
105
free ( (int *)new );
106
new= NULL;
107
}
108
}
109
}
110
return new;
111
}
112
113
/*}}} */
114
/*{{{ memcpy2dim*/
115
/*
116
@-------------------------------------------------------------------------
117
@ void memcpy2dim ( dest, src, r, c, size )
118
@ copies a 2-dimesional array
119
@
120
@ char **dest: destination
121
@ char **src: source
122
@ int r, int c: rows x columns of the arrays
123
@ int size: size of an entry in bytes
124
@
125
@-------------------------------------------------------------------------
126
*/
127
void memcpy2dim(dest, src, r,c,size)
128
char **dest, **src;
129
int r,c,size;
130
{
131
int i, j;
132
133
if( !( r == 0 || c == 0 || size == 0 || dest == NULL || src == NULL ) )
134
{
135
for ( i=0; i < r; i ++ ) memcpy(dest[i],src[i],c*size);
136
}
137
}
138
139
/*}}} */
140
/*{{{ memset2dim*/
141
/*
142
@-------------------------------------------------------------------------
143
@ void memset2dim ( dest, r, c, size, value )
144
@ initializes a 2-dimensional array
145
@
146
@ char **dest: destination
147
@ int r, int c: rows x columns of the arrays
148
@ int size: size of an entry in bytes
149
| char *value: Pointer auf den Eintrag, mit dem das Feld initialisiert
150
| werden soll
151
@ char *value: pointer to the entry, the array shall be initialized with
152
@
153
@-------------------------------------------------------------------------
154
*/
155
void memset2dim(dest, r, c, size, value)
156
char **dest;
157
int r,c,size;
158
char *value;
159
{
160
int i, j;
161
162
if( !( r == 0 || c == 0 || size == 0 || dest == NULL || value == NULL) )
163
{
164
for ( j=0; j < c; j++ ) {
165
memcpy( &dest[0][j*size], value, size );
166
}
167
for ( i=1; i < r; i ++ ) {
168
memcpy( dest[i], dest[0], size*c );
169
}
170
}
171
}
172
173
/*}}} */
174
/*{{{ free2dim*/
175
/*
176
@-------------------------------------------------------------------------
177
@ void free2dim ( old, rows )
178
| -- gibt ein 2-dimesionales array frei
179
@ frees a 2-dimensional array
180
@
181
@ char **old: pointer to the array
182
| int rows: Anzahl der Zeilen (obere Grenze des ersten Arrayindexes)
183
@ int rows: number of rows (upper bound for the first index of the array)
184
@
185
@-------------------------------------------------------------------------
186
*/
187
void free2dim(old, rows)
188
char **old;
189
int rows;
190
{
191
int i;
192
193
for (i=0; i < rows;i++)
194
{
195
free( (int *)old[i] );
196
}
197
free( (int *)old );
198
}
199
200
/*}}} */
201
202
203