[CRIU] [PATCH 3/5] protobuf: added nested messages outup shift for vertical output

Kinsbursky Stanislav skinsbursky at openvz.org
Tue Jul 24 09:59:19 EDT 2012


Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 protobuf.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/protobuf.c b/protobuf.c
index a0a48b5..a056440 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -23,6 +23,7 @@
 struct pb_pr_ctrl_s {
 	void *arg;
 	int single_entry;
+	int depth;
 };
 
 typedef struct pb_pr_ctrl_s pb_pr_ctl_t;
@@ -48,9 +49,22 @@ static void pb_msg_unk(void *obj, pb_pr_ctl_t *ctl)
 	pr_msg("unknown object %p\n", obj);
 }
 
-static void print_nested_message_braces(pb_pr_ctl_t *ctl, int side)
+static inline void print_tabs(pb_pr_ctl_t *ctl)
 {
-	pr_msg("%s%s", (side) ? "]" : "[", (ctl->single_entry) ? "\n" : " ");
+	int counter = ctl->depth;
+
+	if (!ctl->single_entry)
+		return;
+
+	while (counter--)
+		pr_msg("\t");
+}
+
+static void print_nested_message_braces(pb_pr_ctl_t *ctl, int right_brace)
+{
+	if (right_brace)
+		print_tabs(ctl);
+	pr_msg("%s%s", (right_brace) ? "]" : "[", (ctl->single_entry) ? "\n" : " ");
 }
 
 static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl);
@@ -58,7 +72,9 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl);
 static void show_nested_message(void *msg, pb_pr_ctl_t *ctl)
 {
 	print_nested_message_braces(ctl, 0);
+	ctl->depth++;
 	pb_show_msg(msg, ctl);
+	ctl->depth--;
 	print_nested_message_braces(ctl, 1);
 }
 
@@ -88,6 +104,8 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where,
 	unsigned long counter;
 	size_t fsize;
 
+	print_tabs(ctl);
+
 	pr_msg("%s: ", fd->name);
 
 	switch (fd->type) {
@@ -175,7 +193,7 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
 void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
 		pb_unpack_t unpack, pb_free_t free, int single_entry)
 {
-	pb_pr_ctl_t ctl = {NULL, single_entry};
+	pb_pr_ctl_t ctl = {NULL, single_entry, 0};
 
 	while (1) {
 		void *obj;



More information about the CRIU mailing list