public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
From: "Fabio M. Di Nitto" <fabbione@fedoraproject.org>
To: cluster-cvs-relay@redhat.com
Subject: cluster: STABLE3 - config dump: beautify output
Date: Fri, 04 Sep 2009 07:08:00 -0000	[thread overview]
Message-ID: <20090904070822.44034120338@lists.fedorahosted.org> (raw)

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");


                 reply	other threads:[~2009-09-04  7:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090904070822.44034120338@lists.fedorahosted.org \
    --to=fabbione@fedoraproject.org \
    --cc=cluster-cvs-relay@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).