Annotation of libelwix/example/test_array.c, revision 1.3
1.1 misho 1: #include <stdio.h>
2: #include <string.h>
3: #include <elwix.h>
4:
5: int
6: main(int argc, char **argv)
7: {
8: array_t *a = NULL;
1.2 misho 9: void *s, *d = "MEOWeoeoeoeoe!!!";
1.1 misho 10:
11: a = array_Init(0);
12: if (!a) {
13: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
14: return 1;
15: }
1.2 misho 16: array_Pop(a, NULL, 0);
17: array_Pop(a, NULL, 0);
18: array_Pop(a, NULL, 0);
19: printf("si=%d l=%d\n", array_Size(a), array_Last(a));
20: array_Push(a, d, 0);
1.3 ! misho 21: printf("push>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) array_Get(a, 0));
1.2 misho 22: array_Pop(a, &s, 42);
1.3 ! misho 23: printf("pop>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) s);
1.2 misho 24: array_Push(a, d, 0);
1.3 ! misho 25: printf("push>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) array_Get(a, 0));
1.1 misho 26: array_Elem(a, 5, d);
1.2 misho 27: printf("si=%d l=%d\n", array_Size(a), array_Last(a));
28: array_Pop(a, &s, 42);
1.3 ! misho 29: printf("pop>si=%d l=%d %s\n", array_Size(a), array_Last(a), (char*) s);
1.2 misho 30: array_Pop(a, NULL, 0);
31: array_Pop(a, NULL, 0);
1.3 ! misho 32: printf("pops>si=%d l=%d get=%s\n", array_Size(a), array_Last(a), (char*) array_Get(a, 5));
1.2 misho 33: array_Push(a, d, 0);
34: printf("push>si=%d l=%d\n", array_Size(a), array_Last(a));
1.1 misho 35: array_Destroy(&a);
36:
37: a = array_Init(10);
38: if (!a) {
39: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
40: return 1;
41: }
42:
43: switch (argc) {
44: case 4:
45: array_Set(a, 5, argv[3]);
46: case 3:
47: array_Set(a, 4, argv[2]);
48: case 2:
49: array_Set(a, 1, argv[1]);
50: }
51:
52: printf("d=%p push=%d\n", d, array_Push(a, &d, 0));
53: printf("d=%p pop=%d\n", d, array_Pop(a, &d, 0));
54: printf("last=%d ", array_Last(a));
55: printf("d=%p pop=%d\n", d, array_Pop(a, &d, 1));
56: printf("last=%d ", array_Last(a));
57:
58: printf(">>> a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
59: array(a, 0, char*), array(a, 1, char*),
60: array(a, 2, char*), array(a, 3, char*),
61: array(a, 4, char*), array(a, 5, char*));
62: printf(">>> array really len=%d array size=%d\n", array_Len(a), array_Size(a));
63:
64: array_Vacuum(a, VACUUM_BETWEEN);
65: printf("vacuum:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
66: array(a, 0, char*), array(a, 1, char*),
67: array(a, 2, char*), array(a, 3, char*),
68: array(a, 4, char*), array(a, 5, char*));
69:
70: printf("vacuum:: array really len=%d array size=%d\n", array_Len(a), array_Size(a));
71:
72: array_Grow(a, array_Len(a) + 4, 0);
73: printf("grow:: array really len=%d array size=%d\n", array_Len(a), array_Size(a));
74: printf("grow:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
75: array(a, 0, char*), array(a, 1, char*),
1.3 ! misho 76: array(a, 2, char*), /*array(a, 3, char*), */ (char*) NULL,
! 77: /*array(a, 4, char*), array(a, 5, char*)*/ (char*) NULL, (char*) NULL);
1.1 misho 78:
79: array_Grow(a, 1, 0);
80: array_Grow(a, 2, 0);
81: printf("shrink:: array really len=%d array size=%d\n", array_Len(a), array_Size(a));
82: printf("shrink:: a[0]=%s a[1]=%s\n", array(a, 0, char*), array(a, 1, char*));
83:
84: array_Destroy(&a);
85: return 0;
86: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>