tree3_console.c (1422B)
1 #include <stdlib.h> 2 #include <stdio.h> 3 4 #include "../tree.h" 5 #include "../tree_dump.h" 6 7 typedef struct teststructure { 8 lash_tree_key_t val; 9 char *nothing; 10 } teststructure; 11 12 int main(int argc, char **argv) { 13 int run = 1; 14 int dump = 1; 15 char buf[1024]; 16 int pushes = 0; 17 18 lash_tree_t *tree = NULL; 19 tree = lash_treeInit(tree, 100); 20 if (tree == NULL) 21 return 1; 22 23 teststructure *ts = (teststructure*)malloc(sizeof(teststructure)*1000); 24 if (ts == NULL) 25 return 1; 26 27 teststructure *result; 28 29 lash_treeDumpInit(1); 30 lash_treeDumpAdd(tree, "tree"); 31 32 while (run) { 33 char cmd; 34 long int val1 = -1; 35 unsigned int pos = 0; 36 printf(">> "); 37 fflush(stdout); 38 fgets(buf, 1024, stdin); 39 sscanf(buf, "%c", &cmd); 40 41 switch(cmd) { 42 case 'p': 43 printf("value: "); 44 fflush(stdout); 45 fgets(buf, 1024, stdin); 46 sscanf(buf, "%li", &val1); 47 if (val1 != -1) { 48 (ts+pushes)->val = val1; 49 pos = lash_treePush(tree, (ts+pushes), NULL); 50 printf("pos: %u\n", pos); 51 pushes++; 52 } 53 break; 54 case 's': 55 if (tree->count == 0) { 56 printf("Nothing to shift\n"); 57 } else { 58 lash_treeShift(tree, (void**)&result); 59 printf("val1: %li, val2: %p\n", result->val, result); 60 } 61 break; 62 case 'd': 63 dump ^= 1; 64 printf(dump ? "(Dump on)\n" : "(Dump off)\n"); 65 break; 66 case 'q': 67 run = 0; 68 break; 69 } 70 71 if (dump) 72 lash_treeDump(tree, NULL); 73 } 74 return 0; 75 }