Remove underscore prefix from field names (pretty-print)
[babeltrace.git] / formats / ctf-text / types / enum.c
1 /*
2 * Common Trace Format
3 *
4 * Enumeration mapping strings (quarks) from/to integers.
5 *
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 */
20
21 #include <babeltrace/ctf-text/types.h>
22 #include <stdio.h>
23 #include <stdint.h>
24
25 int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
26 {
27 struct definition_enum *enum_definition =
28 container_of(definition, struct definition_enum, p);
29 struct definition_integer *integer_definition =
30 enum_definition->integer;
31 struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
32 GArray *qs;
33 int i, ret;
34 int field_nr_saved;
35
36 if (!print_field(definition))
37 return 0;
38
39 if (pos->dummy)
40 return 0;
41
42 if (pos->field_nr++ != 0)
43 fprintf(pos->fp, ",");
44 fprintf(pos->fp, " ");
45 if (pos->print_names)
46 fprintf(pos->fp, "%s = ",
47 rem_(g_quark_to_string(definition->name)));
48
49 field_nr_saved = pos->field_nr;
50 pos->field_nr = 0;
51 fprintf(pos->fp, "(");
52 pos->depth++;
53 qs = enum_definition->value;
54
55 if (qs) {
56 for (i = 0; i < qs->len; i++) {
57 GQuark q = g_array_index(qs, GQuark, i);
58 const char *str = g_quark_to_string(q);
59
60 assert(str);
61 if (pos->field_nr++ != 0)
62 fprintf(pos->fp, ",");
63 fprintf(pos->fp, " ");
64 fprintf(pos->fp, "%s", str);
65 }
66 } else {
67 fprintf(pos->fp, " <unknown>");
68 }
69
70 pos->field_nr = 0;
71 fprintf(pos->fp, " :");
72 ret = generic_rw(ppos, &integer_definition->p);
73
74 pos->depth--;
75 fprintf(pos->fp, " )");
76 pos->field_nr = field_nr_saved;
77 return ret;
78 }
This page took 0.031906 seconds and 5 git commands to generate.