Esempio n. 1
0
void array_alloc_string_array(string_array_t* dest, int n,
                              string_array_t first,...)
{
    int i,j,c;
    va_list ap;

    string_array_t *elts = (string_array_t*)malloc(sizeof(string_array_t) * n);
    assert(elts);
    /* collect all array ptrs to simplify traversal.*/
    va_start(ap,first);
    elts[0] = first;
    for(i = 1; i < n; ++i) {
        elts[i] = va_arg(ap, string_array_t);
    }
    va_end(ap);

    check_base_array_dim_sizes(elts, n);

    if(first.ndims == 1) {
        alloc_string_array(dest, 2, n, first.dim_size[0]);
    } else if(first.ndims == 2) {
        alloc_string_array(dest, 3, n, first.dim_size[0], first.dim_size[1]);
    } else if(first.ndims == 3) {
        alloc_string_array(dest, 4, n, first.dim_size[0], first.dim_size[1], first.dim_size[2]);
    } else if(first.ndims == 4) {
        alloc_string_array(dest, 5, n, first.dim_size[0], first.dim_size[1], first.dim_size[2], first.dim_size[3]);
    } else {
        assert(0 && "Dimension size > 4 not impl. yet");
    }

    for(i = 0, c = 0; i < n; ++i) {
        int m = base_array_nr_of_elements(elts[i]);
        for(j = 0; j < m; ++j) {
            string_set(dest, c, string_get(elts[i], j));
            c++;
        }
    }
    free(elts);
}
Esempio n. 2
0
void test_alloc_string_array() {
	String *str_arr = alloc_string_array(1);
	assert(str_arr != NULL);
}