Revert "Remove leading underscores from identifiers directly in lexer"
[babeltrace.git] / formats / ctf-text / types / enum.c
CommitLineData
1ae19169
MD
1/*
2 * Common Trace Format
3 *
4 * Enumeration mapping strings (quarks) from/to integers.
5 *
64fa3fec
MD
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1ae19169
MD
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
c5e74408 25int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
1ae19169
MD
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;
c5e74408 33 int i, ret;
ccdb988e 34 int field_nr_saved;
1ae19169 35
d335f0f7
MD
36 if (!print_field(definition))
37 return 0;
38
1ae19169 39 if (pos->dummy)
c5e74408 40 return 0;
31262354 41
fd3382e8 42 if (pos->field_nr++ != 0)
31262354 43 fprintf(pos->fp, ",");
fd3382e8 44 fprintf(pos->fp, " ");
31262354
MD
45 if (pos->print_names)
46 fprintf(pos->fp, "%s = ",
6743f229 47 rem_(g_quark_to_string(definition->name)));
31262354 48
ccdb988e
MD
49 field_nr_saved = pos->field_nr;
50 pos->field_nr = 0;
1ae19169
MD
51 fprintf(pos->fp, "(");
52 pos->depth++;
1ae19169 53 qs = enum_definition->value;
1ae19169 54
07bc033e
MD
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);
31262354 59
07bc033e
MD
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>");
1ae19169 68 }
07bc033e
MD
69
70 pos->field_nr = 0;
71 fprintf(pos->fp, " :");
72 ret = generic_rw(ppos, &integer_definition->p);
73
1ae19169 74 pos->depth--;
31262354 75 fprintf(pos->fp, " )");
ccdb988e 76 pos->field_nr = field_nr_saved;
c5e74408 77 return ret;
1ae19169 78}
This page took 0.026278 seconds and 4 git commands to generate.