unsigned int print_it(t_tmp_arg *tmp, t_params *params, char c, unsigned int chars_to_save) { unsigned int wt; wt = 0; (c == 'd') ? (wt = print_int(tmp, params, 0, 0)) : (0); (c == 'i') ? (wt = print_int(tmp, params, 0, 0)) : (0); (c == 'u') ? (wt = print_uint(tmp, params, 0, 0)) : (0); (c == 'x') ? (wt = print_little_hexa(tmp, params, 0, 0)) : (0); (c == 'X') ? (wt = print_large_hexa(tmp, params, 0, 0)) : (0); (c == 'n') ? (wt = save_chars(tmp, chars_to_save)) : (0); (c == 'o') ? (wt = print_octal(tmp, params, 0, 0)) : (0); (c == 'c') ? (wt = print_char(tmp, params, 0, 0)) : (0); (c == 's') ? (wt = print_str(tmp, params, 0, 0)) : (0); (c == '%') ? (wt = print_percent()) : (0); (c == 'S') ? (wt = print_all_str(tmp, params, 0, 0)) : (0); (c == 'p') ? (wt = print_ptr(tmp, params, 0, 0)) : (0); (c == 'b') ? (wt = print_binary(tmp, params, 0, 0)) : (0); return (wt); }
int main(int argc, char * argv[]) { int x, x2, y, z, a; COMPS_RTree * tree, *clonned; //COMPS_HSList * values; (void)argc; (void)argv; tree = comps_rtree_create( NULL, &int_cloner, &free); //comps_rtree_init(tree); x = 10; x2 = 11; y = 20; z = 30; a = 1; void * data; /* Root */ comps_rtree_set(tree,"some key",int_cloner((void*)&x)); /* Root * ['some key']-->10 */ comps_rtree_set(tree,"some Cray",int_cloner((void*)&y)); /* Root * ['some']-->|-['Cray']-->20 * |-['key']-->10 */ comps_rtree_set(tree,"some",int_cloner((void*)&z)); /* Root * ['some']-->|-['Cray']-->20 * | |-['key']-->10 * V * 30 */ comps_rtree_set(tree,"anything",int_cloner((void*)&a)); /* Root * ['some']-->|-['Cray']-->20 * | |-['key']-->10 * V * 30 */ print_all(tree); //values = comps_rtree_values(tree); //print_intp_hslist(values); //comps_hslist_destroy(&values); data = comps_rtree_get(tree, "some key"); print_intp_data(data, "some key"); data = comps_rtree_get(tree, "some Cray"); print_intp_data(data, "some Cray"); data = comps_rtree_get(tree, "sAme Cray"); print_intp_data(data, "sAme Cray"); data = comps_rtree_get(tree, "some"); print_intp_data(data, "some"); data = comps_rtree_get(tree, "anything"); print_intp_data(data, "anything"); printf("------------\n"); printf("-data for clonned tree-\n"); clonned = comps_rtree_clone(tree); printf("end clonning\n"); data = comps_rtree_get(clonned, "some key"); print_intp_data(data, "some key"); data = comps_rtree_get(clonned, "some Cray"); print_intp_data(data, "some Cray"); data = comps_rtree_get(clonned, "sAme Cray"); print_intp_data(data, "sAme Cray"); data = comps_rtree_get(clonned, "some"); print_intp_data(data, "some"); data = comps_rtree_get(clonned, "anything"); print_intp_data(data, "anything"); comps_rtree_destroy(clonned); printf("------------\n"); comps_rtree_set(tree,"some key",int_cloner((void*)&x2)); /* Root * ['some']-->|-['Cray']-->20 * | |-['key']-->11 * V * 30 */ data = comps_rtree_get(tree, "some key"); print_intp_data(data, "some key (rewrited)"); printf("------------\n"); printf("removing 'some Cray'\n"); comps_rtree_unset(tree, "some Cray"); printf("------------\n"); /* Root * ['some']-->| * | |-['key']-->11 * V * 30 */ data = comps_rtree_get(tree, "some key"); print_intp_data(data, "some key"); data = comps_rtree_get(tree, "some Cray"); print_intp_data(data, "some cray"); data = comps_rtree_get(tree, "some"); print_intp_data(data, "some"); data = comps_rtree_get(tree, "anything"); print_intp_data(data, "anything"); printf("------------\n"); printf("removing 'some'\n"); comps_rtree_unset(tree, "some"); /* Root * ['some']-->| * |-['key']-->11 */ data = comps_rtree_get(tree, "some key"); print_intp_data(data, "some key"); data = comps_rtree_get(tree, "some"); print_intp_data(data, "some"); comps_rtree_destroy(tree); printf("------------\n"); printf("clonning empty rtree\n"); tree = comps_rtree_create(NULL, &int_cloner, &free); clonned = comps_rtree_clone(tree); comps_rtree_destroy(clonned); comps_rtree_destroy(tree); printf("------------\n"); printf("loading acronym dict\n"); tree = load_acrodict("dict-test.txt"); print_all_str(tree); comps_rtree_destroy(tree); return 0; }