GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"1#include "tools.h"2/**************************************************************************\3@---------------------------------------------------------------------------4@---------------------------------------------------------------------------5@ FILE: malloc2dim.c6@---------------------------------------------------------------------------7@---------------------------------------------------------------------------8@9\**************************************************************************/1011/*12|13| tools/malloc2dim.c -- malloc & co fuer 2-dim. Arrays14| exportiert die Funktionen15|16| calloc2dim17| malloc2dim18| memcpy2dim19| memset2dim20| free2dim21|22*/2324/*{{{}}}*/25/*{{{ calloc2dim*/26/*27@28@-------------------------------------------------------------------------29@ char **calloc2dim ( r, c, size )30@ int r,c,size;31|-- allokiert ein 2-dimesionales array32@33@ allocates a 2-dimensional array with 'r' rows and 'c' columns34@ the size of the entries in bytes is given by the argument 'size'.35| int r, int c: ZeilenxSpalten des Arrays36| int size: Groesse eines Eintrags in bytes37@38*/39char **calloc2dim(r,c,size)40int r,c,size;41{42char **new;43int i, j;4445if( r == 0 || c == 0 || size == 0 )46new= NULL;47else48{49new= (char **)malloc( r*sizeof(char *));50if ( new != NULL )51{52i= 0;53do54{55new[i]= (char *)calloc( c, size );56} while ( new[i++] && i < r );57if ( i != r )58{59for ( j=0; j < i;j++) free ( (int *)new[i] );60free ( (int *)new );61new= NULL;62}63}64}65return new;66}6768/*}}} */69/*{{{ malloc2dim*/70/*71@-------------------------------------------------------------------------72@ char **malloc2dim ( r, c, size )73@ int r,c,size;74| -- allokiert ein 2-dimesionales array75@76| int r, int c: ZeilenxSpalten des Arrays77| int size: Groesse eines Eintrags in bytes78@ allocates a 2-dimensional array with 'r' rows and 'c' columns79@ the size of the entries in bytes is given by the argument 'size'.80@81@-------------------------------------------------------------------------82*/83char **malloc2dim(r,c,size)84int r,c,size;85{86char **new;87int i, j;8889if( r == 0 || c == 0 || size == 0 )90new= NULL;91else92{93new= (char **)malloc( r*sizeof(char *));94if ( new != NULL )95{96i= 0;97do98{99new[i]= (char *)malloc( c*size);100} while ( new[i++] && i < r );101if ( i != r )102{103for ( j=0; j < i;j++) free ( (int *)new[i] );104free ( (int *)new );105new= NULL;106}107}108}109return new;110}111112/*}}} */113/*{{{ memcpy2dim*/114/*115@-------------------------------------------------------------------------116@ void memcpy2dim ( dest, src, r, c, size )117@ copies a 2-dimesional array118@119@ char **dest: destination120@ char **src: source121@ int r, int c: rows x columns of the arrays122@ int size: size of an entry in bytes123@124@-------------------------------------------------------------------------125*/126void memcpy2dim(dest, src, r,c,size)127char **dest, **src;128int r,c,size;129{130int i, j;131132if( !( r == 0 || c == 0 || size == 0 || dest == NULL || src == NULL ) )133{134for ( i=0; i < r; i ++ ) memcpy(dest[i],src[i],c*size);135}136}137138/*}}} */139/*{{{ memset2dim*/140/*141@-------------------------------------------------------------------------142@ void memset2dim ( dest, r, c, size, value )143@ initializes a 2-dimensional array144@145@ char **dest: destination146@ int r, int c: rows x columns of the arrays147@ int size: size of an entry in bytes148| char *value: Pointer auf den Eintrag, mit dem das Feld initialisiert149| werden soll150@ char *value: pointer to the entry, the array shall be initialized with151@152@-------------------------------------------------------------------------153*/154void memset2dim(dest, r, c, size, value)155char **dest;156int r,c,size;157char *value;158{159int i, j;160161if( !( r == 0 || c == 0 || size == 0 || dest == NULL || value == NULL) )162{163for ( j=0; j < c; j++ ) {164memcpy( &dest[0][j*size], value, size );165}166for ( i=1; i < r; i ++ ) {167memcpy( dest[i], dest[0], size*c );168}169}170}171172/*}}} */173/*{{{ free2dim*/174/*175@-------------------------------------------------------------------------176@ void free2dim ( old, rows )177| -- gibt ein 2-dimesionales array frei178@ frees a 2-dimensional array179@180@ char **old: pointer to the array181| int rows: Anzahl der Zeilen (obere Grenze des ersten Arrayindexes)182@ int rows: number of rows (upper bound for the first index of the array)183@184@-------------------------------------------------------------------------185*/186void free2dim(old, rows)187char **old;188int rows;189{190int i;191192for (i=0; i < rows;i++)193{194free( (int *)old[i] );195}196free( (int *)old );197}198199/*}}} */200201202203