Annotation of libaitio/example/test_vars.c, revision 1.1.2.2
1.1.2.1 misho 1: /*
2: *
3: * Sorting example: ./test_vars 9 sdf 2 aaa 6 gghfh 7 piuk 6 uaaa 3 abc 1 000 11 mda 0 cccc 0 fiup 23 blah
4: *
5: */
6: #include <stdio.h>
7: #include <string.h>
8: #include <aitio.h>
9:
10:
11: static int
12: cmpfunc(const void *a, const void *b)
13: {
14: return strcmp(AIT_GET_STR(*(ait_val_t**) a), AIT_GET_STR(*(ait_val_t**) b));
15: }
16:
17: int
18: main(int argc, char **argv)
19: {
20: array_t *arr;
21: ait_val_t *v;
22: register int i;
23:
24: arr = io_allocVars((argc - 1 ) / 2);
25: if (!arr) {
26: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
27: return 1;
28: }
29:
30: for (i = 0; i < io_arraySize(arr); i++) {
31: v = io_arrayGet(arr, i);
32: AIT_KEY(v) = atoi(argv[i * 2 + 1]);
33: AIT_SET_STR(v, argv[i * 2 + 2]);
34: }
35:
1.1.2.2 ! misho 36: v = io_findKeyVars(arr, 7);
! 37: printf("v=%p\n", v);
! 38: fflush(stdout);
! 39: printf("search for key=7 %s\n", AIT_GET_LIKE(v, char*));
! 40: printf("search for key=23 %s\n", AIT_GET_LIKE(io_findKeyVars(arr, 23), char*));
! 41: printf("search for key=0 %s\n", AIT_GET_LIKE(io_findKeyVars(arr, 0), char*));
! 42: printf("search for key=99 %s\n", AIT_GET_LIKE(io_findKeyVars(arr, 99), char*));
! 43:
1.1.2.1 misho 44: printf("Before sorting::\n");
45: for (i = 0; i < io_arraySize(arr); i++)
46: printf("%d) KEY=%d %s\n", i, AIT_KEY(io_array(arr, i, ait_val_t*)),
47: AIT_GET_STR(io_array(arr, i, ait_val_t*)));
48:
49: io_sortVars(arr, 0, NULL);
50: printf("After KEY ascend sorting::\n");
51: for (i = 0; i < io_arraySize(arr); i++)
52: printf("%d) KEY=%d %s\n", i, AIT_KEY(io_array(arr, i, ait_val_t*)),
53: AIT_GET_STR(io_array(arr, i, ait_val_t*)));
54:
55: io_sortVars(arr, 42, NULL);
56: printf("After KEY descend sorting::\n");
57: for (i = 0; i < io_arraySize(arr); i++)
58: printf("%d) KEY=%d %s\n", i, AIT_KEY(io_array(arr, i, ait_val_t*)),
59: AIT_GET_STR(io_array(arr, i, ait_val_t*)));
60:
61: io_sortVars(arr, 0, cmpfunc);
62: printf("After string sorting::\n");
63: for (i = 0; i < io_arraySize(arr); i++)
64: printf("%d) KEY=%d %s\n", i, AIT_KEY(io_array(arr, i, ait_val_t*)),
65: AIT_GET_STR(io_array(arr, i, ait_val_t*)));
66:
67: io_freeVars(&arr);
68: return 0;
69: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>