1 /*-----------------------------------------------------------------------
2
3 File : clb_fixdarrays.c
4
5 Author: Stephan Schulz
6
7 Contents
8
9 Functions for handling fixed size arrays.
10
11 Copyright 1998-2011 by the author.
12 This code is released under the GNU General Public Licence and
13 the GNU Lesser General Public License.
14 See the file COPYING in the main E directory for details..
15 Run "eprover -h" for contact information.
16
17 Changes
18
19 <1> Wed Jul 9 23:40:23 CEST 2003
20 New
21
22 -----------------------------------------------------------------------*/
23
24 #include "clb_fixdarrays.h"
25
26
27
28 /*---------------------------------------------------------------------*/
29 /* Global Variables */
30 /*---------------------------------------------------------------------*/
31
32
33 /*---------------------------------------------------------------------*/
34 /* Forward Declarations */
35 /*---------------------------------------------------------------------*/
36
37
38 /*---------------------------------------------------------------------*/
39 /* Internal Functions */
40 /*---------------------------------------------------------------------*/
41
42
43
44 /*---------------------------------------------------------------------*/
45 /* Exported Functions */
46 /*---------------------------------------------------------------------*/
47
48 /*-----------------------------------------------------------------------
49 //
50 // Function: FixedDArrayAlloc()
51 //
52 // Allocate an array of known size.
53 //
54 // Global Variables: -
55 //
56 // Side Effects : Memory operations.
57 //
58 /----------------------------------------------------------------------*/
59
FixedDArrayAlloc(long size)60 FixedDArray_p FixedDArrayAlloc(long size)
61 {
62 FixedDArray_p handle = FixedDArrayCellAlloc();
63
64 handle->size = size;
65 handle->array = SizeMalloc(sizeof(long)*size);
66
67 return handle;
68 }
69
70
71 /*-----------------------------------------------------------------------
72 //
73 // Function: FixedDArrayFree()
74 //
75 // Free an array. Handles NULL silently.
76 //
77 // Global Variables: -
78 //
79 // Side Effects : Memory operations.
80 //
81 /----------------------------------------------------------------------*/
82
FixedDArrayFree(FixedDArray_p junk)83 void FixedDArrayFree(FixedDArray_p junk)
84 {
85 if(junk)
86 {
87 SizeFree(junk->array, sizeof(long)*junk->size);
88 FixedDArrayCellFree(junk);
89 }
90 }
91
92
93 /*-----------------------------------------------------------------------
94 //
95 // Function: FixedDArrayCopy()
96 //
97 // Copy an array, return pointer to new copy.
98 //
99 // Global Variables: -
100 //
101 // Side Effects : Memory operations
102 //
103 /----------------------------------------------------------------------*/
104
FixedDArrayCopy(FixedDArray_p array)105 FixedDArray_p FixedDArrayCopy(FixedDArray_p array)
106 {
107 if(!array)
108 {
109 return NULL;
110 }
111 else
112 {
113 FixedDArray_p handle = FixedDArrayAlloc(array->size);
114 long i;
115
116 for(i=0; i<array->size; i++)
117 {
118 handle->array[i] = array->array[i];
119 }
120 return handle;
121 }
122 }
123
124
125 /*-----------------------------------------------------------------------
126 //
127 // Function: FixedDArrayPrint()
128 //
129 // Print an array (useful for debugging, I suspect).
130 //
131 // Global Variables: -
132 //
133 // Side Effects : Output
134 //
135 /----------------------------------------------------------------------*/
136
FixedDArrayPrint(FILE * out,FixedDArray_p array)137 void FixedDArrayPrint(FILE* out, FixedDArray_p array)
138 {
139 long i;
140
141 fprintf(out, "# Size %ld:", array->size);
142 for(i=0; i<array->size; i++)
143 {
144 fprintf(out, " %4ld", array->array[i]);
145 }
146 fputc('\n', out);
147 }
148
149
150 /*---------------------------------------------------------------------*/
151 /* End of File */
152 /*---------------------------------------------------------------------*/
153
154
155