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

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

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

  1 /**@(#)Vector (1 dimension array) handling for Tstructs
  2  * @(#)Allocate and free displaced vectors & arrays.
  3  * @(#)Elements (of general size) are initialised to zero.
  4  */
  5 
  6 #include <math.h>
  7 #include <stdio.h>
  8 #include <tina/sys.h>
  9 #include <tina/sysfuncs.h>
 10 #include <tina/dynamic.h>
 11 
 12 /* Allocate and tag multiple Tina structures */
 13 void   *ts_nralloc_fn(int n, size_t size, Ts_id ts_id)
 14 {
 15     char   *structure = (char *) ralloc(n * size);
 16 
 17     while (n--)
 18     {
 19         *(Ts_id *) (structure + n * size) = ts_id;
 20     }
 21 
 22     return (void *) structure;
 23 }
 24 
 25 /* Generic tagged structure create function */
 26 void   *ts_ralloc_fn(size_t size, Ts_id ts_id)
 27 {
 28     void   *structure = (void *) ralloc(size);
 29 
 30     *(Ts_id *) structure = ts_id;
 31     return structure;
 32 }
 33 
 34 /* Displaced array of Tstruct's whose type is coded by ts_id.
 35  * vector[i]: n1 <= i < n2 */
 36 void   *ts_nvector_alloc_fn(int n1, int n2, size_t size, Ts_id ts_id)
 37 {
 38     char *nvector;
 39     if (n1 >= n2) return(NULL);
 40 
 41     nvector = ts_nralloc_fn((n2 - n1), size, ts_id);
 42 /* store offset vector for checking later NAT 1999 see also dynamic.c */
 43     nvector_test((void *)nvector,n1,size,true);
 44     nvector -= n1 * size;
 45     return((void *)nvector); 
 46 }
 47 
 48 /* Displaced array of Tstruct's whose type is coded by ts_id.
 49  * array[i][j]: m1 <= i < m2, n1 <= j < n2 */
 50 void  **ts_narray_alloc_fn(int m1, int n1, int m2, int n2, size_t size, Ts_id ts_id)
 51 {
 52     int     i;
 53     void  **array = NULL;
 54 
 55     if (m1 < m2 && n1 < n2)
 56     {
 57         array = (void **) nvector_alloc(m1, m2, sizeof(void *));
 58         for (i = m1; i < m2; ++i)
 59         {
 60             array[i] = ts_nvector_alloc_fn(n1, n2, size, ts_id);
 61         }
 62     }
 63     return array;
 64 }
 65 
 66 /* Displaced lower triangle of Tstruct's whose type is coded by ts_id.
 67  * Element size s a[i][j]: n1 <=i < n2, i <= j < n2. */
 68 void  **ts_nlower_alloc_fn(int n1, int n2, size_t size, Ts_id ts_id)
 69 {
 70     char  **a;
 71     int     n = n2 - n1;
 72     int     i;
 73 
 74     if (n < 1)
 75         return (NULL);
 76     a = (char **) nvector_alloc(n1, n2, sizeof(char *));
 77     for (i = n1; i < n2; ++i)
 78         a[i] = (char *) ts_nvector_alloc_fn(n1, i + 1, size, ts_id);
 79     return ((void **) a);
 80 }
 81 
 82 /* Displaced upper triangle of Tstruct's whose type is coded by ts_id.
 83  * Element size s a[i][j]: n1 <=i < n2, i <= j < n2. */
 84 void  **ts_nupper_alloc_fn(int n1, int n2, size_t size, Ts_id ts_id)
 85 {
 86     char  **a;
 87     int     n = n2 - n1;
 88     int     i;
 89 
 90     if (n < 1)
 91         return (NULL);
 92     a = (char **) nvector_alloc(n1, n2, sizeof(char *));
 93     for (i = n1; i < n2; ++i)
 94         a[i] = (char *) ts_nvector_alloc_fn(i, n2, size, ts_id);
 95     return ((void **) a);
 96 }
 97 

~ [ 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.