~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/sys/dynamic/vdynamic.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Array handling. 2+ dimensions (1 dimension arrays are called vectors).
  2  * @(#)Allocation and freeing.
  3 **/
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 
  7 static void *rec_array_alloc(int i, int n, unsigned int s, int *m1, int *m2)
  8 {
  9     void  **vector;
 10     void   *nvector_alloc();
 11     int     j;
 12 
 13     if (i == n - 1)             /* use s to determine block size */
 14         return (nvector_alloc(m1[i], m2[i], s));
 15 
 16     vector = (void **) nvector_alloc(m1[i], m2[i], sizeof(void *));
 17 
 18     for (j = m1[i]; j < m2[i]; j++)
 19         vector[j] = rec_array_alloc(i + 1, n, s, m1, m2);
 20 
 21     return ((void *) vector);
 22 }
 23 
 24 void   *ndim_array_alloc(int n, unsigned int s, int *m1, int *m2)
 25 /* No of dimensions */
 26 /* element size */
 27 /* m1 and m2 for each of the dimensions   */
 28 {
 29     if (n == 0)
 30         return ((void *) 0);
 31     return (rec_array_alloc(0, n, s, m1, m2));
 32 }
 33 
 34 
 35 static void rec_array_free(void **vector, int i, int n, unsigned int s, int *m1, int *m2)
 36 {
 37     void    nvector_free();
 38     int     j;
 39 
 40     if (i == n - 1)
 41     {
 42         nvector_free((void *) vector, m1[i], s);
 43         return;
 44     }
 45     for (j = m1[i]; j < m2[i]; j++)
 46         rec_array_free((void **) vector[i], i + 1, n, s, m1, m2);
 47 
 48     nvector_free((void *) vector, m1[i], sizeof(void *));
 49 }
 50 
 51 void    ndim_array_free(void *array, int n, unsigned int s, int *m1, int *m2)
 52 /* previously created array */
 53 /* number of dimensions */
 54 /* element size */
 55 /* m1 and m2 for each of the dimensions */
 56 
 57 {
 58     if (n)
 59     {
 60         rec_array_free((void **) array, 0, n, s, m1, m2);
 61     }
 62 }
 63 
 64 #ifndef ANSIFYING
 65 #ifdef __STRICT_ANSI__
 66 
 67 
 68 /* Variable argument variable dimension array allocation. array =
 69  * vdim_array_alloc(n, s, a1, b1, c1, d1, ..., a2, b2, c2, d2, ...); */
 70 /* No of dimensions */
 71 /* element size */
 72 void   *vdim_array_alloc(int n, unsigned int s,...)
 73 {
 74     va_list ap;
 75     int    *m1, *m2;            /* m1 and m2 for each of the dimensions */
 76 
 77     void   *array;
 78     int     i;
 79 
 80     if (n == 0)
 81         return ((void *) 0);
 82 
 83     m1 = (int *) ralloc((unsigned) n * sizeof(int));
 84     m2 = (int *) ralloc((unsigned) n * sizeof(int));
 85     va_start(ap, s);
 86     for (i = 0; i != n; ++i)
 87         m1[i] = va_arg(ap, int);
 88     for (i = 0; i != n; ++i)
 89         m2[i] = va_arg(ap, int);
 90     va_end(ap);
 91 
 92     array = rec_array_alloc(0, n, s, m1, m2);
 93     rfree((void *) m1);
 94     rfree((void *) m2);
 95     return (array);
 96 }
 97 
 98 
 99 /* array previously created array */
100 /* n No of dimensions */
101 /* s element size */
102 void    vdim_array_free(void *array, int n, unsigned int s,...)
103 {
104     va_list ap;
105     int    *m1, *m2;            /* m1 and m2 for each of the dimensions */
106     int     i;
107 
108     if (n == 0)
109         return;
110 
111     m1 = (int *) ralloc((unsigned) n * sizeof(int));
112     m2 = (int *) ralloc((unsigned) n * sizeof(int));
113     va_start(ap, s);
114 
115     for (i = 0; i != n; ++i)
116         m1[i] = va_arg(ap, int);
117     for (i = 0; i != n; ++i)
118         m2[i] = va_arg(ap, int);
119     va_end(ap);
120 
121     rec_array_free((void **) array, 0, n, s, m1, m2);
122     rfree((void *) m1);
123     rfree((void *) m2);
124 }
125 
126 #else
127 
128 /* Variable argument variable dimension array allocation. array =
129  * vdim_array_alloc(n, s, a1, b1, c1, d1, ..., a2, b2, c2, d2, ...); */
130 void   *vdim_array_alloc(n, s, va_alist)
131 int     n;                      /* No of dimensions */
132 unsigned int s;                 /* element size */
133 
134 va_dcl                          /* m1 and m2 for each of the dimensions */
135 {
136     va_list ap;
137     int    *m1, *m2;
138     void   *array;
139     int     i;
140 
141     if (n == 0)
142         return ((void *) 0);
143 
144     m1 = (int *) ralloc((unsigned) n * sizeof(int));
145     m2 = (int *) ralloc((unsigned) n * sizeof(int));
146     va_start(ap);
147     for (i = 0; i != n; ++i)
148         m1[i] = va_arg(ap, int);
149     for (i = 0; i != n; ++i)
150         m2[i] = va_arg(ap, int);
151     va_end(ap);
152 
153     array = rec_array_alloc(0, n, s, m1, m2);
154     rfree((void *) m1);
155     rfree((void *) m2);
156     return (array);
157 }
158 
159 void    vdim_array_free(array, n, s, va_alist)
160 void   *array;                  /* previously created array */
161 int     n;                      /* No of dimensions */
162 unsigned int s;                 /* element size */
163 
164 va_dcl                          /* m1 and m2 for each of the dimensions */
165 {
166     va_list ap;
167     int    *m1, *m2;
168     int     i;
169 
170     if (n == 0)
171         return;
172 
173     m1 = (int *) ralloc((unsigned) n * sizeof(int));
174     m2 = (int *) ralloc((unsigned) n * sizeof(int));
175     va_start(ap);
176     for (i = 0; i != n; ++i)
177         m1[i] = va_arg(ap, int);
178     for (i = 0; i != n; ++i)
179         m2[i] = va_arg(ap, int);
180     va_end(ap);
181 
182     rec_array_free((void **) array, 0, n, s, m1, m2);
183     rfree((void *) m1);
184     rfree((void *) m2);
185 }
186 
187 #endif                          /* __STRICT_ANSI__ */
188 #endif                          /* ANSIFYING */
189 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.