2 * SPDX-License-Identifier: MIT
4 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Babeltrace CTF writer - Utilities
9 #define BT_LOG_TAG "CTF-WRITER/UTILS"
15 #include <babeltrace2-ctf-writer/utils.h>
16 #include <babeltrace2-ctf-writer/object.h>
18 #include "common/assert.h"
20 #include "clock-class.h"
21 #include "field-types.h"
24 const char * const reserved_keywords_str
[] = {"align", "callsite",
25 "const", "char", "clock", "double", "enum", "env", "event",
26 "floating_point", "float", "integer", "int", "long", "short", "signed",
27 "stream", "string", "struct", "trace", "typealias", "typedef",
28 "unsigned", "variant", "void", "_Bool", "_Complex", "_Imaginary"};
30 static GHashTable
*reserved_keywords_set
;
34 void try_init_reserved_keywords(void)
37 const size_t reserved_keywords_count
=
38 sizeof(reserved_keywords_str
) / sizeof(char *);
40 if (reserved_keywords_set
) {
44 reserved_keywords_set
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
45 BT_ASSERT_DBG(reserved_keywords_set
);
47 for (i
= 0; i
< reserved_keywords_count
; i
++) {
48 gpointer quark
= GINT_TO_POINTER(g_quark_from_string(
49 reserved_keywords_str
[i
]));
51 g_hash_table_insert(reserved_keywords_set
, quark
, quark
);
57 static __attribute__((destructor
))
58 void trace_finalize(void)
60 if (reserved_keywords_set
) {
61 g_hash_table_destroy(reserved_keywords_set
);
65 bt_ctf_bool
bt_ctf_identifier_is_valid(const char *identifier
)
67 bt_ctf_bool is_valid
= BT_CTF_TRUE
;
69 char *save_ptr
, *token
;
72 BT_LOGT_STR("Invalid parameter: input string is NULL.");
73 is_valid
= BT_CTF_FALSE
;
77 try_init_reserved_keywords();
79 if (identifier
[0] == '\0') {
80 is_valid
= BT_CTF_FALSE
;
84 string
= strdup(identifier
);
86 BT_LOGE("strdup() failed.");
87 is_valid
= BT_CTF_FALSE
;
91 token
= strtok_r(string
, " ", &save_ptr
);
93 if (g_hash_table_lookup_extended(reserved_keywords_set
,
94 GINT_TO_POINTER(g_quark_from_string(token
)),
96 is_valid
= BT_CTF_FALSE
;
100 token
= strtok_r(NULL
, " ", &save_ptr
);
This page took 0.032629 seconds and 4 git commands to generate.