Annotation of libaitio/example/test_array.c, revision 1.5.4.2
1.2 misho 1: #include <stdio.h>
2: #include <string.h>
3: #include <aitio.h>
4:
5: int
6: main(int argc, char **argv)
7: {
8: array_t *a = NULL;
9: void *d = "MEOWeoeoeoeoe!!!";
10:
1.5 misho 11: a = io_arrayInit(0);
12: if (!a) {
13: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
14: return 1;
15: }
16: io_arrayElem(a, 5, d);
17: printf("si=%d\n", io_arraySize(a));
18: io_arrayDestroy(&a);
19:
1.2 misho 20: a = io_arrayInit(10);
21: if (!a) {
22: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
23: return 1;
24: }
25:
26: switch (argc) {
27: case 4:
28: io_arraySet(a, 5, argv[3]);
29: case 3:
30: io_arraySet(a, 4, argv[2]);
31: case 2:
32: io_arraySet(a, 1, argv[1]);
33: }
34:
1.5.4.1 misho 35: printf("d=%p push=%d\n", d, io_arrayPush(a, &d, 0));
1.2 misho 36: printf("d=%p pop=%d\n", d, io_arrayPop(a, &d, 0));
1.5.4.2 ! misho 37: printf("before last=%d ", io_arrayLast(a));
! 38: io_arraySyncLast(a);
! 39: printf("after last=%d\n", io_arrayLast(a));
1.2 misho 40: printf("d=%p pop=%d\n", d, io_arrayPop(a, &d, 1));
1.5.4.2 ! misho 41: printf("before last=%d ", io_arrayLast(a));
! 42: io_arraySyncLast(a);
! 43: printf("after last=%d\n", io_arrayLast(a));
1.2 misho 44:
45: printf(">>> a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
1.3 misho 46: io_array(a, 0, char*), io_array(a, 1, char*),
47: io_array(a, 2, char*), io_array(a, 3, char*),
48: io_array(a, 4, char*), io_array(a, 5, char*));
49: printf(">>> array really len=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
1.2 misho 50:
51: io_arrayVacuum(a, VACUUM_BETWEEN);
52: printf("vacuum:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
1.3 misho 53: io_array(a, 0, char*), io_array(a, 1, char*),
54: io_array(a, 2, char*), io_array(a, 3, char*),
55: io_array(a, 4, char*), io_array(a, 5, char*));
1.2 misho 56:
1.3 misho 57: printf("vacuum:: array really len=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
1.2 misho 58:
1.5.4.1 misho 59: io_arrayGrow(a, io_arrayLen(a) + 4, 0);
1.3 misho 60: printf("grow:: array really len=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
1.2 misho 61: printf("grow:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
1.3 misho 62: io_array(a, 0, char*), io_array(a, 1, char*),
1.5 misho 63: io_array(a, 2, char*), /*io_array(a, 3, char*), */ NULL,
64: /*io_array(a, 4, char*), io_array(a, 5, char*)*/ NULL, NULL);
1.2 misho 65:
1.4 misho 66: io_arrayGrow(a, 1, 0);
67: io_arrayGrow(a, 2, 0);
1.3 misho 68: printf("shrink:: array really len=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
69: printf("shrink:: a[0]=%s a[1]=%s\n", io_array(a, 0, char*), io_array(a, 1, char*));
1.2 misho 70:
71: io_arrayDestroy(&a);
72: return 0;
73: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>