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

610987 views
1
/****************************************************************************
2
**
3
*W utils.c XGAP Source Frank Celler
4
**
5
**
6
*Y Copyright 1995-1997, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany
7
*Y Copyright 1997, Frank Celler, Huerth, Germany
8
**
9
** This file contains the utility functions and macros used in XGAP,
10
** basically the list functions ('ELM', 'LEN', 'AddList', and 'List') and
11
** the debug macro ('DEBUG'). This file also includes all the necessary
12
** system and X11 include files and defines the following data types:
13
**
14
** Boolean "True" or "False" (defined by X11)
15
** Char a "Char" will be able to hold one character
16
** Int a 32-bit signed integer
17
** Long an integer able to hold a pointer
18
** Pointer a generic pointer
19
** Short a 16-bit signed integer
20
** String an array of chars
21
** UChar unsigned version of "Char"
22
** UInt a 32-bit unsigned integer
23
** ULong unsigned version of "Long"
24
** UShort a 16-bit unsigned integer
25
**
26
** List( <len> )
27
** -------------
28
** 'List' creates a new list able to hold <len> pointers of type 'Pointer'.
29
**
30
** AddList( <lst>, <elm> )
31
** -----------------------
32
** 'AddList' appends the new element <elm> of type 'Pointer' to <lst>,
33
** enlarging the list if necessary.
34
**
35
** ELM( <lst>, <i> )
36
** -----------------
37
** 'ELM' returns the <i>.th element of <lst>.
38
**
39
** LEN( <lst> )
40
** ------------
41
** 'LEN' returns the length of <lst>.
42
**
43
** DEBUG( <type>, ( <debug-text>, ... ) )
44
** --------------------------------------
45
** 'DEBUG' uses 'printf' to print the <debug-text> in case that 'Debug' &&
46
** <type> is true. The text is preceded by the line number and the source
47
** file name. The following types are available: D_LIST, D_XCMD, D_COMM.
48
*/
49
#include "utils.h"
50
51
52
/****************************************************************************
53
**
54
55
*V Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . debug on/off
56
*/
57
Int Debug = 0;
58
59
60
/****************************************************************************
61
**
62
*F List( <len> ) . . . . . . . . . . . . . . . . . . . create a new list
63
*/
64
#ifdef DEBUG_ON
65
TypeList LIST ( file, line, len )
66
String file;
67
Int line;
68
UInt len;
69
#else
70
TypeList List ( len )
71
UInt len;
72
#endif
73
{
74
TypeList list;
75
76
/* get memory for new list */
77
list = (TypeList) XtMalloc( sizeof( struct _list ) );
78
list->len = len;
79
list->size = len+10;
80
list->ptr = (Pointer) XtMalloc( list->size * sizeof(Pointer) );
81
82
/* give some debug information */
83
#ifdef DEBUG_ON
84
if ( Debug & D_LIST )
85
printf( "%04d:%s: List(%d)=%p\n", line, file, len, (void*)list );
86
#endif
87
88
/* return the new list */
89
return list;
90
}
91
92
93
/****************************************************************************
94
**
95
*F AddList( <lst>, <elm> ) . . . . . . . . add list element <elm> to <list>
96
*/
97
#ifdef DEBUG_ON
98
void ADD_LIST ( file, line, lst, elm )
99
String file;
100
Int line;
101
TypeList lst;
102
Pointer elm;
103
#else
104
void AddList ( lst, elm )
105
TypeList lst;
106
Pointer elm;
107
#endif
108
{
109
/* give some debug information */
110
#ifdef DEBUG_ON
111
if ( Debug & D_LIST )
112
printf( "%04d:%s: AddList( %p, %p )\n", line, file, (void*)lst,
113
(void*)elm );
114
#endif
115
116
/* resize <lst> if necessary */
117
if ( lst->len == lst->size )
118
{
119
lst->size = lst->size*4/3 + 5;
120
lst->ptr = (Pointer) XtRealloc( (char*) lst->ptr,
121
lst->size * sizeof(Pointer) );
122
}
123
124
/* and add list element */
125
lst->ptr[lst->len++] = elm;
126
}
127
128
129
/****************************************************************************
130
**
131
132
*E utils.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
133
*/
134
135