Annotation of libaitio/example/test_array.c, revision 1.1.2.2
1.1.2.1 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;
1.1.2.2 ! misho 9: void *d = "MEOWeoeoeoeoe!!!";
1.1.2.1 misho 10:
11: a = io_arrayInit(10);
12: if (!a) {
13: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
14: return 1;
15: }
16:
17: switch (argc) {
18: case 4:
19: io_arraySet(a, 5, argv[3]);
20: case 3:
21: io_arraySet(a, 4, argv[2]);
22: case 2:
23: io_arraySet(a, 1, argv[1]);
24: }
25:
1.1.2.2 ! misho 26: printf("d=%p push=%d\n", d, io_arrayPush(a, &d));
! 27: printf("d=%p pop=%d\n", d, io_arrayPop(a, &d, 0));
! 28: printf("d=%p pop=%d\n", d, io_arrayPop(a, &d, 1));
! 29:
1.1.2.1 misho 30: printf(">>> a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
31: io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*),
32: io_arrayGet(a, 2, char*), io_arrayGet(a, 3, char*),
33: io_arrayGet(a, 4, char*), io_arrayGet(a, 5, char*));
34: printf(">>> last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
35:
36: io_arrayVacuum(a, VACUUM_BETWEEN);
37: printf("vacuum:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
38: io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*),
39: io_arrayGet(a, 2, char*), io_arrayGet(a, 3, char*),
40: io_arrayGet(a, 4, char*), io_arrayGet(a, 5, char*));
41:
42: printf("vacuum:: last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
43:
44: io_arrayGrow(a, io_arrayLen(a) + 3);
45: printf("grow:: last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
46: printf("grow:: a[0]=%s a[1]=%s a[2]=%s a[3]=%s a[4]=%s a[5]=%s\n",
47: io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*),
48: io_arrayGet(a, 2, char*), io_arrayGet(a, 3, char*),
49: io_arrayGet(a, 4, char*), io_arrayGet(a, 5, char*));
50:
51: io_arrayGrow(a, 1);
52: io_arrayGrow(a, 2);
53: printf("shrink:: last used element=%d array size=%d\n", io_arrayLen(a), io_arraySize(a));
54: printf("shrink:: a[0]=%s a[1]=%s\n", io_arrayGet(a, 0, char*), io_arrayGet(a, 1, char*));
55:
56: io_arrayDestroy(&a);
57: return 0;
58: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>