Index: uspace/app/bithenge/Makefile.linux
===================================================================
--- uspace/app/bithenge/Makefile.linux	(revision e8e31d9e852422d266d715e52dcd401c4d66a48b)
+++ uspace/app/bithenge/Makefile.linux	(revision 842ed1463f51ccdba3bacb329247f4a11eed8ee0)
@@ -51,2 +51,3 @@
 clean:
 	find . -name '*.o' -follow -exec rm \{\} \;
+	rm -f $(BINARY)
Index: uspace/app/bithenge/print.c
===================================================================
--- uspace/app/bithenge/print.c	(revision e8e31d9e852422d266d715e52dcd401c4d66a48b)
+++ uspace/app/bithenge/print.c	(revision 842ed1463f51ccdba3bacb329247f4a11eed8ee0)
@@ -33,4 +33,6 @@
  * @file
  * Write a tree as JSON or other text formats.
+ * @todo Allow more control over the printing style, and handle printing in
+ * limited space.
  */
 
@@ -44,18 +46,40 @@
 	bithenge_print_type_t type;
 	bool first;
-} print_internal_data_t;
-
-static int print_internal_func(bithenge_node_t *key, bithenge_node_t *value, void *data_)
-{
-	print_internal_data_t *data = (print_internal_data_t *)data_;
+	int depth;
+} state_t;
+
+static int print_node(state_t *, bithenge_node_t *);
+
+static void newline(state_t *state)
+{
+	printf("\n");
+	for (int i = 0; i < state->depth; i++) {
+		printf("    ");
+	}
+}
+
+static void increase_depth(state_t *state)
+{
+	state->depth++;
+}
+
+static void decrease_depth(state_t *state)
+{
+	state->depth--;
+}
+
+static int print_internal_func(bithenge_node_t *key, bithenge_node_t *value, void *data)
+{
+	state_t *state = (state_t *)data;
 	int rc = EOK;
-	if (!data->first)
-		printf(", ");
-	data->first = false;
-	bool add_quotes = data->type == BITHENGE_PRINT_JSON
+	if (!state->first)
+		printf(",");
+	newline(state);
+	state->first = false;
+	bool add_quotes = state->type == BITHENGE_PRINT_JSON
 	    && bithenge_node_type(key) != BITHENGE_NODE_STRING;
 	if (add_quotes)
 		printf("\"");
-	rc = bithenge_print_node(data->type, key);
+	rc = print_node(state, key);
 	if (rc != EOK)
 		goto end;
@@ -63,5 +87,5 @@
 		printf("\"");
 	printf(": ");
-	rc = bithenge_print_node(data->type, value);
+	rc = print_node(state, value);
 	if (rc != EOK)
 		goto end;
@@ -72,20 +96,25 @@
 }
 
-static int print_internal(bithenge_print_type_t type, bithenge_node_t *node)
+static int print_internal(state_t *state, bithenge_node_t *node)
 {
 	int rc;
-	print_internal_data_t data = { type, true };
 	printf("{");
-	rc = bithenge_node_for_each(node, print_internal_func, &data);
+	increase_depth(state);
+	state->first = true;
+	rc = bithenge_node_for_each(node, print_internal_func, state);
 	if (rc != EOK)
 		return rc;
+	decrease_depth(state);
+	if (!state->first)
+		newline(state);
+	state->first = false;
 	printf("}");
 	return EOK;
 }
 
-static int print_boolean(bithenge_print_type_t type, bithenge_node_t *node)
+static int print_boolean(state_t *state, bithenge_node_t *node)
 {
 	bool value = bithenge_boolean_node_value(node);
-	switch (type) {
+	switch (state->type) {
 	case BITHENGE_PRINT_PYTHON:
 		printf(value ? "True" : "False");
@@ -98,5 +127,5 @@
 }
 
-static int print_integer(bithenge_print_type_t type, bithenge_node_t *node)
+static int print_integer(state_t *state, bithenge_node_t *node)
 {
 	bithenge_int_t value = bithenge_integer_node_value(node);
@@ -105,5 +134,5 @@
 }
 
-static int print_string(bithenge_print_type_t type, bithenge_node_t *node)
+static int print_string(state_t *state, bithenge_node_t *node)
 {
 	const char *value = bithenge_string_node_value(node);
@@ -126,5 +155,5 @@
 }
 
-static int print_blob(bithenge_print_type_t type, bithenge_node_t *node)
+static int print_blob(state_t *state, bithenge_node_t *node)
 {
 	bithenge_blob_t *blob = bithenge_node_as_blob(node);
@@ -133,5 +162,5 @@
 	aoff64_t size = sizeof(buffer);
 	int rc;
-	printf(type == BITHENGE_PRINT_PYTHON ? "b\"" : "\"");
+	printf(state->type == BITHENGE_PRINT_PYTHON ? "b\"" : "\"");
 	do {
 		rc = bithenge_blob_read(blob, pos, buffer, &size);
@@ -146,4 +175,21 @@
 }
 
+static int print_node(state_t *state, bithenge_node_t *tree)
+{
+	switch (bithenge_node_type(tree)) {
+	case BITHENGE_NODE_INTERNAL:
+		return print_internal(state, tree);
+	case BITHENGE_NODE_BOOLEAN:
+		return print_boolean(state, tree);
+	case BITHENGE_NODE_INTEGER:
+		return print_integer(state, tree);
+	case BITHENGE_NODE_STRING:
+		return print_string(state, tree);
+	case BITHENGE_NODE_BLOB:
+		return print_blob(state, tree);
+	}
+	return ENOTSUP;
+}
+
 /** Print a tree as text.
  * @param type The format to use.
@@ -152,17 +198,6 @@
 int bithenge_print_node(bithenge_print_type_t type, bithenge_node_t *tree)
 {
-	switch (bithenge_node_type(tree)) {
-	case BITHENGE_NODE_INTERNAL:
-		return print_internal(type, tree);
-	case BITHENGE_NODE_BOOLEAN:
-		return print_boolean(type, tree);
-	case BITHENGE_NODE_INTEGER:
-		return print_integer(type, tree);
-	case BITHENGE_NODE_STRING:
-		return print_string(type, tree);
-	case BITHENGE_NODE_BLOB:
-		return print_blob(type, tree);
-	}
-	return ENOTSUP;
+	state_t state = {type, true, 0};
+	return print_node(&state, tree);
 }
 
