Update pretty print output
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 18:14:41 +0000 (14:14 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 18:14:41 +0000 (14:14 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 files changed:
formats/ctf-text/ctf-text.c
formats/ctf-text/types/array.c
formats/ctf-text/types/enum.c
formats/ctf-text/types/float.c
formats/ctf-text/types/integer.c
formats/ctf-text/types/sequence.c
formats/ctf-text/types/string.c
formats/ctf-text/types/struct.c
formats/ctf-text/types/variant.c
include/babeltrace/ctf-text/types.h
include/babeltrace/types.h
types/struct.c

index 882e0620eed83159510f844d9c1d5ed4e34fccff..70e0e92ab6604a7535724b520808247b7dc43489 100644 (file)
@@ -60,11 +60,11 @@ int ctf_text_write_event(struct stream_pos *ppos,
        struct ctf_text_stream_pos *pos =
                container_of(ppos, struct ctf_text_stream_pos, parent);
        struct ctf_stream_class *stream_class = stream->stream_class;
        struct ctf_text_stream_pos *pos =
                container_of(ppos, struct ctf_text_stream_pos, parent);
        struct ctf_stream_class *stream_class = stream->stream_class;
+       int field_nr_saved;
        struct ctf_event *event_class;
        uint64_t id = 0;
        int len_index;
        int ret;
        struct ctf_event *event_class;
        uint64_t id = 0;
        int len_index;
        int ret;
-       int field_nr = 0;
 
        /* print event header */
        if (stream_class->event_header) {
 
        /* print event header */
        if (stream_class->event_header) {
@@ -109,54 +109,68 @@ int ctf_text_write_event(struct stream_pos *ppos,
                fprintf(pos->fp, "name = ");
        fprintf(pos->fp, "%s", g_quark_to_string(event_class->name));
        if (pos->print_names)
                fprintf(pos->fp, "name = ");
        fprintf(pos->fp, "%s", g_quark_to_string(event_class->name));
        if (pos->print_names)
-               field_nr++;
+               pos->field_nr++;
        else
        else
-               fprintf(pos->fp, ": ");
+               fprintf(pos->fp, ":");
 
        /* Only show the event header in verbose mode */
        if (babeltrace_verbose && stream_class->event_header) {
 
        /* Only show the event header in verbose mode */
        if (babeltrace_verbose && stream_class->event_header) {
-               if (field_nr++ != 0)
-                       fprintf(pos->fp, ", ");
+               if (pos->field_nr++ != 0)
+                       fprintf(pos->fp, ",");
                if (pos->print_names)
                if (pos->print_names)
-                       fprintf(pos->fp, "stream.event.header = ");
+                       fprintf(pos->fp, " stream.event.header =");
+               field_nr_saved = pos->field_nr;
+               pos->field_nr = 0;
                ret = generic_rw(ppos, &stream_class->event_header->p);
                if (ret)
                        goto error;
                ret = generic_rw(ppos, &stream_class->event_header->p);
                if (ret)
                        goto error;
+               pos->field_nr = field_nr_saved;
        }
 
        /* print stream-declared event context */
        if (stream_class->event_context) {
        }
 
        /* print stream-declared event context */
        if (stream_class->event_context) {
-               if (field_nr++ != 0)
-                       fprintf(pos->fp, ", ");
+               if (pos->field_nr++ != 0)
+                       fprintf(pos->fp, ",");
                if (pos->print_names)
                if (pos->print_names)
-                       fprintf(pos->fp, "stream.event.context = ");
+                       fprintf(pos->fp, " stream.event.context =");
+               field_nr_saved = pos->field_nr;
+               pos->field_nr = 0;
                ret = generic_rw(ppos, &stream_class->event_context->p);
                if (ret)
                        goto error;
                ret = generic_rw(ppos, &stream_class->event_context->p);
                if (ret)
                        goto error;
+               pos->field_nr = field_nr_saved;
        }
 
        /* print event-declared event context */
        if (event_class->context) {
        }
 
        /* print event-declared event context */
        if (event_class->context) {
-               if (field_nr++ != 0)
-                       fprintf(pos->fp, ", ");
+               if (pos->field_nr++ != 0)
+                       fprintf(pos->fp, ",");
                if (pos->print_names)
                if (pos->print_names)
-                       fprintf(pos->fp, "event.context = ");
+                       fprintf(pos->fp, " event.context =");
+               field_nr_saved = pos->field_nr;
+               pos->field_nr = 0;
                ret = generic_rw(ppos, &event_class->context->p);
                if (ret)
                        goto error;
                ret = generic_rw(ppos, &event_class->context->p);
                if (ret)
                        goto error;
+               pos->field_nr = field_nr_saved;
        }
 
        /* Read and print event payload */
        if (event_class->fields) {
        }
 
        /* Read and print event payload */
        if (event_class->fields) {
-               if (field_nr++ != 0)
-                       fprintf(pos->fp, ", ");
+               if (pos->field_nr++ != 0)
+                       fprintf(pos->fp, ",");
                if (pos->print_names)
                if (pos->print_names)
-                       fprintf(pos->fp, "event.fields = ");
+                       fprintf(pos->fp, " event.fields =");
+               field_nr_saved = pos->field_nr;
+               pos->field_nr = 0;
                ret = generic_rw(ppos, &event_class->fields->p);
                if (ret)
                        goto error;
                ret = generic_rw(ppos, &event_class->fields->p);
                if (ret)
                        goto error;
+               pos->field_nr = field_nr_saved;
        }
        }
+       /* newline */
        fprintf(pos->fp, "\n");
        fprintf(pos->fp, "\n");
+       pos->field_nr = 0;
 
        return 0;
 
 
        return 0;
 
index aa941b5e9a3dec8c6505d8bd1105b12ed1fac99e..9524ba166ea17b6f4d78497a2cbadcbf62f5a33c 100644 (file)
 int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
 int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+       int field_nr_saved;
        int ret;
 
        if (!pos->dummy) {
        int ret;
 
        if (!pos->dummy) {
-               if (definition->index != 0 && definition->index != INT_MAX)
+               if (pos->field_nr++ != 0)
                        fprintf(pos->fp, ",");
                        fprintf(pos->fp, ",");
-               if (definition->index != INT_MAX)
-                       fprintf(pos->fp, " ");
+               fprintf(pos->fp, " ");
                if (pos->print_names)
                        fprintf(pos->fp, "%s = ",
                                g_quark_to_string(definition->name));
                fprintf(pos->fp, "[");
                pos->depth++;
        }
                if (pos->print_names)
                        fprintf(pos->fp, "%s = ",
                                g_quark_to_string(definition->name));
                fprintf(pos->fp, "[");
                pos->depth++;
        }
+       field_nr_saved = pos->field_nr;
+       pos->field_nr = 0;
        ret = array_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                fprintf(pos->fp, " ]");
        }
        ret = array_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                fprintf(pos->fp, " ]");
        }
+       pos->field_nr = field_nr_saved;
        return ret;
 }
        return ret;
 }
index 0cb902180b3254597cc1237f9fc106e45a3ef287..381491a4dc81e68560ac6c1467c4b107b339d6af 100644 (file)
@@ -33,10 +33,9 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
        if (pos->dummy)
                return 0;
 
        if (pos->dummy)
                return 0;
 
-       if (definition->index != 0 && definition->index != INT_MAX)
+       if (pos->field_nr++ != 0)
                fprintf(pos->fp, ",");
                fprintf(pos->fp, ",");
-       if (definition->index != INT_MAX)
-               fprintf(pos->fp, " ");
+       fprintf(pos->fp, " ");
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
index 3569fd4e23ba92f0cd4f2f02ee6298b69af9838f..2ec7728eb1a907cc5ba6592ee7df4fda6c347292 100644 (file)
@@ -30,10 +30,9 @@ int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
        if (pos->dummy)
                return 0;
 
        if (pos->dummy)
                return 0;
 
-       if (definition->index != 0 && definition->index != INT_MAX)
+       if (pos->field_nr++ != 0)
                fprintf(pos->fp, ",");
                fprintf(pos->fp, ",");
-       if (definition->index != INT_MAX)
-               fprintf(pos->fp, " ");
+       fprintf(pos->fp, " ");
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
index 0032e642f58ea0a39104cbfb23765e2c68296014..8b2df2c005a2f2e65b826d75dd422c77dac98a2b 100644 (file)
@@ -32,10 +32,9 @@ int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definitio
        if (pos->dummy)
                return 0;
 
        if (pos->dummy)
                return 0;
 
-       if (definition->index != 0 && definition->index != INT_MAX)
+       if (pos->field_nr++ != 0)
                fprintf(pos->fp, ",");
                fprintf(pos->fp, ",");
-       if (definition->index != INT_MAX)
-               fprintf(pos->fp, " ");
+       fprintf(pos->fp, " ");
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
index 4e9048949fc3f54a3481b8ce2dc6b989c7a85246..7b5d3c946a7ff514d44c66acbb10de15317a49b1 100644 (file)
 int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
 int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+       int field_nr_saved;
        int ret;
 
        if (!pos->dummy) {
        int ret;
 
        if (!pos->dummy) {
-               if (definition->index != 0 && definition->index != INT_MAX)
+               if (pos->field_nr++ != 0)
                        fprintf(pos->fp, ",");
                        fprintf(pos->fp, ",");
-               if (definition->index != INT_MAX)
-                       fprintf(pos->fp, " ");
+               fprintf(pos->fp, " ");
                if (pos->print_names)
                        fprintf(pos->fp, "%s = ",
                                g_quark_to_string(definition->name));
                fprintf(pos->fp, "[");
                pos->depth++;
        }
                if (pos->print_names)
                        fprintf(pos->fp, "%s = ",
                                g_quark_to_string(definition->name));
                fprintf(pos->fp, "[");
                pos->depth++;
        }
+       field_nr_saved = pos->field_nr;
+       pos->field_nr = 0;
        ret = sequence_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                fprintf(pos->fp, " ]");
        }
        ret = sequence_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                fprintf(pos->fp, " ]");
        }
+       pos->field_nr = field_nr_saved;
        return ret;
 }
        return ret;
 }
index 3979e826407fb745d6fc0e9ac7acf856d7c9b3f0..eca5f91f9e3d7dc8b1dca38c2b7d06c2aa615b6e 100644 (file)
@@ -32,10 +32,9 @@ int ctf_text_string_write(struct stream_pos *ppos,
        if (pos->dummy)
                return 0;
 
        if (pos->dummy)
                return 0;
 
-       if (definition->index != 0 && definition->index != INT_MAX)
+       if (pos->field_nr++ != 0)
                fprintf(pos->fp, ",");
                fprintf(pos->fp, ",");
-       if (definition->index != INT_MAX)
-               fprintf(pos->fp, " ");
+       fprintf(pos->fp, " ");
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
        if (pos->print_names)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
index 9f63c7bd517543683d33efd4ac728c98b4c43f67..7dd17e04111db0ee6ccfbcf735746abce9209640 100644 (file)
 
 int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
 {
 
 int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
 {
+       struct declaration *declaration = definition->declaration;
+       struct declaration_struct *struct_declaration =
+               container_of(declaration, struct declaration_struct, p);
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+       uint64_t len = struct_declaration_len(struct_declaration);
+       int field_nr_saved;
        int ret;
 
        if (!pos->dummy) {
                if (pos->depth >= 0) {
        int ret;
 
        if (!pos->dummy) {
                if (pos->depth >= 0) {
-                       if (definition->index != 0 && definition->index != INT_MAX)
+                       if (pos->field_nr++ != 0)
                                fprintf(pos->fp, ",");
                                fprintf(pos->fp, ",");
-                       if (definition->index != INT_MAX)
-                               fprintf(pos->fp, " ");
+                       fprintf(pos->fp, " ");
                        if (pos->print_names && definition->name != 0)
                                fprintf(pos->fp, "%s = ",
                                        g_quark_to_string(definition->name));
                        if (pos->print_names && definition->name != 0)
                                fprintf(pos->fp, "%s = ",
                                        g_quark_to_string(definition->name));
-                       fprintf(pos->fp, "{");
+                       if (pos->print_names || len > 1)
+                               fprintf(pos->fp, "{");
                }
                pos->depth++;
        }
                }
                pos->depth++;
        }
+       field_nr_saved = pos->field_nr;
+       pos->field_nr = 0;
        ret = struct_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
        ret = struct_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
-               if (pos->depth >= 0) {
+               if (pos->depth >= 0 && (pos->print_names || len > 1)) {
                        fprintf(pos->fp, " }");
                }
        }
                        fprintf(pos->fp, " }");
                }
        }
+       pos->field_nr = field_nr_saved;
        return ret;
 }
        return ret;
 }
index 1787fb3e499d5c0921cc218e3dbccacf39d777e3..50d21903ce3dc83aa37dc42619e18737609e8e37 100644 (file)
 int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
 int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+       int field_nr_saved;
        int ret;
 
        if (!pos->dummy) {
                if (pos->depth >= 0) {
        int ret;
 
        if (!pos->dummy) {
                if (pos->depth >= 0) {
-                       if (definition->index != 0 && definition->index != INT_MAX)
+                       if (pos->field_nr++ != 0)
                                fprintf(pos->fp, ",");
                                fprintf(pos->fp, ",");
-                       if (definition->index != INT_MAX)
-                               fprintf(pos->fp, " ");
+                       fprintf(pos->fp, " ");
                        if (pos->print_names)
                                fprintf(pos->fp, "%s = ",
                                        g_quark_to_string(definition->name));
                        if (pos->print_names)
                                fprintf(pos->fp, "%s = ",
                                        g_quark_to_string(definition->name));
@@ -37,6 +37,8 @@ int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definitio
                }
                pos->depth++;
        }
                }
                pos->depth++;
        }
+       field_nr_saved = pos->field_nr;
+       pos->field_nr = 0;
        ret = variant_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
        ret = variant_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
@@ -44,5 +46,6 @@ int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definitio
                        fprintf(pos->fp, " }");
                }
        }
                        fprintf(pos->fp, " }");
                }
        }
+       pos->field_nr = field_nr_saved;
        return ret;
 }
        return ret;
 }
index bb837bcd5e671bbd5c4d30164cd5d22dd53fce41..0670b3d6dffdf182a09c4963f309a9e72213833b 100644 (file)
@@ -38,6 +38,7 @@ struct ctf_text_stream_pos {
        int depth;
        int dummy;              /* disable output */
        int print_names;        /* print field names */
        int depth;
        int dummy;              /* disable output */
        int print_names;        /* print field names */
+       int field_nr;
 };
 
 static inline
 };
 
 static inline
index b7e84da2ee22cf6bc488c27d76af2acf4ea76eab..2c7650e620779ae2e8c202c38b26f07d7f87b00b 100644 (file)
@@ -446,6 +446,7 @@ struct definition *
 struct_definition_get_field_from_index(struct definition_struct *struct_definition,
                                       int index);
 int struct_rw(struct stream_pos *pos, struct definition *definition);
 struct_definition_get_field_from_index(struct definition_struct *struct_definition,
                                       int index);
 int struct_rw(struct stream_pos *pos, struct definition *definition);
+uint64_t struct_declaration_len(struct declaration_struct *struct_declaration);
 
 /*
  * The tag enumeration is validated to ensure that it contains only mappings
 
 /*
  * The tag enumeration is validated to ensure that it contains only mappings
index 6012447bc2a678194aa4ba5dc8a278ea3e58073e..ba312111cd3d65c3f25a5bf8cc3ecc71af7dd14d 100644 (file)
@@ -216,3 +216,8 @@ struct_definition_get_field_from_index(struct definition_struct *_struct,
                return NULL;
        return g_ptr_array_index(_struct->fields, index);
 }
                return NULL;
        return g_ptr_array_index(_struct->fields, index);
 }
+
+uint64_t struct_declaration_len(struct declaration_struct *struct_declaration)
+{
+       return struct_declaration->fields->len;
+}
This page took 0.031505 seconds and 4 git commands to generate.