File:
[ELWIX - Embedded LightWeight unIX -] /
libelwix /
example /
test_array.c
Revision
1.3:
download - view:
text,
annotated -
select for diffs -
revision graph
Mon Apr 15 10:42:26 2024 UTC (7 months, 1 week ago) by
misho
Branches:
MAIN
CVS tags:
elwix6_6,
elwix6_5,
elwix6_4,
elwix6_3,
elwix6_2,
elwix6_1,
elwix5_12,
HEAD,
ELWIX6_5,
ELWIX6_4,
ELWIX6_2,
ELWIX6_1,
ELWIX6_0,
ELWIX5_11
Version 5.11
#include <stdio.h>
#include <string.h>
#include <elwix.h>
int
main(int argc, char **argv)
{
array_t *a = NULL;
void *s, *d = "MEOWeoeoeoeoe!!!";
a = array_Init(0);
if (!a) {
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
return 1;
}
array_Pop(a, NULL, 0);
array_Pop(a, NULL, 0);
array_Pop(a, NULL, 0);
printf("si=%d l=%d\n", array_Size(a), array_Last(a));
array_Push(a, d, 0);
printf("push>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) array_Get(a, 0));
array_Pop(a, &s, 42);
printf("pop>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) s);
array_Push(a, d, 0);
printf("push>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) array_Get(a, 0));
array_Elem(a, 5, d);
printf("si=%d l=%d\n", array_Size(a), array_Last(a));
array_Pop(a, &s, 42);
printf("pop>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) s);
array_Pop(a, NULL, 0);
array_Pop(a, NULL, 0);
printf("pops>si=%d l=%d get=%s\n", array_Size(a), array_Last(a), (char*) array_Get(a, 5));
array_Push(a, d, 0);
printf("push>si=%d l=%d\n", array_Size(a), array_Last(a));
array_Destroy(&a);
a = array_Init(10);
if (!a) {
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
return 1;
}
switch (argc) {
case 4:
array_Set(a, 5, argv[3]);
case 3:
array_Set(a, 4, argv[2]);
case 2:
array_Set(a, 1, argv[1]);
}
printf("d=%p push=%d\n", d, array_Push(a, &d, 0));
printf("d=%p pop=%d\n", d, array_Pop(a, &d, 0));
printf("last=%d ", array_Last(a));
printf("d=%p pop=%d\n", d, array_Pop(a, &d, 1));
printf("last=%d ", array_Last(a));
printf(">>> a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
array(a, 0, char*), array(a, 1, char*),
array(a, 2, char*), array(a, 3, char*),
array(a, 4, char*), array(a, 5, char*));
printf(">>> array really len=%d array size=%d\n", array_Len(a), array_Size(a));
array_Vacuum(a, VACUUM_BETWEEN);
printf("vacuum:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
array(a, 0, char*), array(a, 1, char*),
array(a, 2, char*), array(a, 3, char*),
array(a, 4, char*), array(a, 5, char*));
printf("vacuum:: array really len=%d array size=%d\n", array_Len(a), array_Size(a));
array_Grow(a, array_Len(a) + 4, 0);
printf("grow:: array really len=%d array size=%d\n", array_Len(a), array_Size(a));
printf("grow:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
array(a, 0, char*), array(a, 1, char*),
array(a, 2, char*), /*array(a, 3, char*), */ (char*) NULL,
/*array(a, 4, char*), array(a, 5, char*)*/ (char*) NULL, (char*) NULL);
array_Grow(a, 1, 0);
array_Grow(a, 2, 0);
printf("shrink:: array really len=%d array size=%d\n", array_Len(a), array_Size(a));
printf("shrink:: a[0]=%s a[1]=%s\n", array(a, 0, char*), array(a, 1, char*));
array_Destroy(&a);
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>