payredu

Cross-platform ledger GUI written in c99
git clone git@getsh.org:payredu.git
Log | Files | Refs | README

account_tree.c (790B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include <account.h>
      5 
      6 /* TEST_INPUT
      7 this:is:a:account
      8 virtualaccount:
      9 virtualaccount
     10 this:is:
     11 TEST_INPUT */
     12 
     13 void account_walk (map_tree_t* rootp)
     14 {
     15 	static int tab_acc;
     16 	if (rootp == NULL) return;
     17 	for(int i = 0; i < tab_acc; i++) {
     18 		printf("  ");
     19 	}
     20 	vstr_t *val = rootp->value;
     21 	if (val != NULL) {
     22 		printf("%.*s\n", val->len, val->str);
     23 		tab_acc++;
     24 	}
     25 	for (int i = 0; i < rootp->children_len; i++) {
     26 		account_walk(rootp->children + i);
     27 	}
     28 	tab_acc--;
     29 }
     30 
     31 
     32 int main(int argc, char* argv[]) {
     33 	map_tree_t* account_tree = NULL;
     34 	for(int i = 1; i < argc; i++) {
     35 		account_add(&account_tree, argv[i], strlen(argv[i]));
     36 	}
     37 	account_walk(account_tree);
     38 }
     39 
     40 /* TEST_OUTPUT
     41 this:
     42   is:
     43     a:
     44       account
     45 virtualaccount:
     46 virtualaccount
     47 TEST_OUTPUT */