tree_console.c (1150B)
1 #include "../lash_tree.h" 2 #include "../lash_tree_dump.h" 3 #include <stdlib.h> 4 #include <stdio.h> 5 6 int main(int argc, char **argv) { 7 int run = 1; 8 int dump = 1; 9 char buf[1024]; 10 11 lash_tree_t *tree; 12 tree = lash_treeInit(tree, 100); 13 if (tree == NULL) 14 return 1; 15 lash_treeDumpInit(1); 16 lash_treeDumpAdd(tree, "tree"); 17 18 while (run) { 19 char cmd; 20 long int val1 = -1; 21 unsigned int val2 = 0; 22 unsigned int pos = 0; 23 printf(">> "); 24 fflush(stdout); 25 fgets(buf, 1024, stdin); 26 sscanf(buf, "%c", &cmd); 27 28 switch(cmd) { 29 case 'p': 30 printf("value: "); 31 fflush(stdout); 32 fgets(buf, 1024, stdin); 33 sscanf(buf, "%li", &val1); 34 if (val1 != -1) { 35 pos = lash_treePush(tree, val1, val2); 36 printf("pos: %u\n", pos); 37 } 38 break; 39 case 's': 40 if (tree->position == 0) { 41 printf("Nothing to shift\n"); 42 } else { 43 lash_treeShift(tree, &val1, &val2); 44 printf("val1: %li, val2: %u\n", val1, val2); 45 } 46 break; 47 case 'd': 48 dump ^= 1; 49 printf(dump ? "(Dump on)\n" : "(Dump off)\n"); 50 break; 51 case 'q': 52 run = 0; 53 break; 54 } 55 56 if (dump) 57 lash_treeDump(NULL, NULL); 58 } 59 return 0; 60 }