public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE3 - config dump: beautify output
@ 2009-09-04  7:08 Fabio M. Di Nitto
  0 siblings, 0 replies; only message in thread
From: Fabio M. Di Nitto @ 2009-09-04  7:08 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=b230e89a309c61806b1a21ae8bde672f8d8d9e6b
Commit:        b230e89a309c61806b1a21ae8bde672f8d8d9e6b
Parent:        015f6e441998848d4c32a95d99ba273497c02c37
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Fri Sep 4 09:07:46 2009 +0200
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Fri Sep 4 09:07:46 2009 +0200

config dump: beautify output

make config dump output human readable

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
 config/tools/xml/ccs_config_dump.c |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/config/tools/xml/ccs_config_dump.c b/config/tools/xml/ccs_config_dump.c
index 7723c40..a5ddf50 100644
--- a/config/tools/xml/ccs_config_dump.c
+++ b/config/tools/xml/ccs_config_dump.c
@@ -6,11 +6,13 @@
 static confdb_callbacks_t callbacks = {};
 
 static int dump_objdb_buff(confdb_handle_t dump_handle, hdb_handle_t cluster_handle,
-			   hdb_handle_t parent_object_handle)
+			   hdb_handle_t parent_object_handle, int level)
 {
 	hdb_handle_t object_handle;
 	char object_name[PATH_MAX], key_name[PATH_MAX], key_value[PATH_MAX];
 	size_t key_value_len = 0, key_name_len = 0, object_name_len = 0;
+	int current_level = level+1;
+	int has_childs = 0;
 
 	if (confdb_key_iter_start(dump_handle, parent_object_handle) != CS_OK)
 		return -1;
@@ -23,9 +25,6 @@ static int dump_objdb_buff(confdb_handle_t dump_handle, hdb_handle_t cluster_han
 		printf(" %s=\"%s\"", key_name, key_value);
 	}
 
-	if (parent_object_handle > 0)
-		printf(">\n");
-
 	if (confdb_object_iter_start(dump_handle, parent_object_handle) != CS_OK)
 		return -1;
 
@@ -33,22 +32,39 @@ static int dump_objdb_buff(confdb_handle_t dump_handle, hdb_handle_t cluster_han
 				   &object_handle, object_name,
 				   &object_name_len) == CS_OK) {
 		hdb_handle_t parent;
+		int i;
+		int found_childs;
+
+		if ((!has_childs) && (parent_object_handle > 0))
+			printf(">\n");
+
+		has_childs = 1;
 
 		if (confdb_object_parent_get(dump_handle, object_handle, &parent) != CS_OK)
 			return -1;
 
 		object_name[object_name_len] = '\0';
+		for (i=0; i<current_level; i++) {
+			printf("\t");
+		}
 		printf("<%s", object_name);
 
-		if(dump_objdb_buff(dump_handle, cluster_handle, object_handle))
+		found_childs = dump_objdb_buff(dump_handle, cluster_handle, object_handle, current_level);
+		if (found_childs < 0)
 			return -1;
 
-		if (object_handle != parent_object_handle)
+		if ((object_handle != parent_object_handle) && (found_childs)) {
+			for (i=0; i<current_level; i++) {
+				printf("\t");
+			}
 			printf("</%s>\n", object_name);
-		else
-			printf(">\n");
+		}
 	}
-	return 0;
+
+	if(!has_childs)
+		printf("/>\n");
+
+	return has_childs;
 }
 
 int main(void) {
@@ -66,7 +82,7 @@ int main(void) {
 
 	printf("<?xml version=\"1.0\"?>\n<cluster");
 
-	if (dump_objdb_buff(handle, cluster_handle, cluster_handle))
+	if (dump_objdb_buff(handle, cluster_handle, cluster_handle, 0) < 0)
 		return -1;
 
 	printf("</cluster>\n");


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-09-04  7:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04  7:08 cluster: STABLE3 - config dump: beautify output Fabio M. Di Nitto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).