liblash

A bianry tree implementation used for game development from scratch
git clone git://holbrook.no/liblash.git
Log | Files | Refs | LICENSE

tree2_console.c (1148B)


      1 #include "../lash_tree2.h"
      2 #include "../lash_tree2_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 		
     16 	lash_treeDumpInit(1);
     17 	lash_treeDumpAdd(tree, "tree");
     18 	
     19 	while (run) {
     20 		char cmd;
     21 		long int val1 = -1;
     22 		char *val2 = NULL;
     23 		unsigned int pos = 0;
     24 		printf(">> ");
     25 		fflush(stdout);
     26 		fgets(buf, 1024, stdin);
     27 		sscanf(buf, "%c", &cmd);
     28 		
     29 		switch(cmd) {
     30 			case 'p':
     31 				printf("value: ");
     32 				fflush(stdout);
     33 				fgets(buf, 1024, stdin);
     34 				sscanf(buf, "%li", &val1);
     35 				if (val1 != -1) {
     36 					pos = lash_treePush(tree, val1, val2);
     37 					printf("pos: %u\n", pos);
     38 				}
     39 				break;
     40 			case 's':
     41 				if (tree->count == 0) {
     42 					printf("Nothing to shift\n");
     43 				} else {
     44 					lash_treeShift(tree, &val1, &val2);
     45 					printf("val1: %li, val2: %p\n", val1, val2);
     46 				}
     47 				break;
     48 			case 'd':
     49 				dump ^= 1;
     50 				printf(dump ? "(Dump on)\n" : "(Dump off)\n");
     51 				break;
     52 			case 'q':
     53 				run = 0;
     54 				break;
     55 		}
     56 		
     57 		if (dump)
     58 			lash_treeDump(tree, NULL);
     59 	}
     60 	return 0;
     61 }