Move _text() functions from keymap-dump to text.c And make them use context_get_buffer() instead of using a static char array. This was the last non-thread-safe piece we had, as far as I can tell. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 82a301f..357ba42 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -148,79 +148,6 @@ write_vmods(struct xkb_keymap *keymap, struct buf *buf)
return true;
}
-#define GET_TEXT_BUF_SIZE 512
-
-#define append_get_text(...) do { \
- int _size = snprintf(ret, GET_TEXT_BUF_SIZE, __VA_ARGS__); \
- if (_size >= GET_TEXT_BUF_SIZE) \
- return NULL; \
-} while (0)
-
-static char *
-get_indicator_state_text(enum xkb_state_component which)
-{
- unsigned int i;
- static char ret[GET_TEXT_BUF_SIZE];
-
- memset(ret, 0, GET_TEXT_BUF_SIZE);
-
- if (which == 0) {
- strcpy(ret, "0");
- return NULL;
- }
-
- for (i = 0; which != 0; i++) {
- const char *name;
-
- if (!(which & (1 << i)))
- continue;
-
- which &= ~(1 << i);
- name = LookupValue(modComponentMaskNames, (1 << i));
-
- if (ret[0] != '\0')
- append_get_text("%s+%s", ret, name);
- else
- append_get_text("%s", name);
- }
-
- return ret;
-}
-
-static char *
-get_control_mask_text(enum xkb_action_controls control_mask)
-{
- int i;
- static char ret[GET_TEXT_BUF_SIZE];
- const char *control_name;
-
- memset(ret, 0, GET_TEXT_BUF_SIZE);
-
- if (control_mask == 0) {
- strcpy(ret, "none");
- return ret;
- }
- else if (control_mask == CONTROL_ALL) {
- strcpy(ret, "all");
- return ret;
- }
-
- for (i = 0; control_mask; i++) {
- if (!(control_mask & (1 << i)))
- continue;
-
- control_mask &= ~(1 << i);
- control_name = LookupValue(ctrlMaskNames, (1 << i));
-
- if (ret[0] != '\0')
- append_get_text("%s+%s", ret, control_name);
- else
- append_get_text("%s", control_name);
- }
-
- return ret;
-}
-
static bool
write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
{
@@ -330,7 +257,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf,
if (led->which_groups) {
if (led->which_groups != XKB_STATE_EFFECTIVE) {
write_buf(buf, "\t\t\twhichGroupState= %s;\n",
- get_indicator_state_text(led->which_groups));
+ IndicatorStateText(keymap->ctx, led->which_groups));
}
write_buf(buf, "\t\t\tgroups= 0x%02x;\n",
led->groups);
@@ -339,7 +266,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf,
if (led->which_mods) {
if (led->which_mods != XKB_STATE_EFFECTIVE) {
write_buf(buf, "\t\t\twhichModState= %s;\n",
- get_indicator_state_text(led->which_mods));
+ IndicatorStateText(keymap->ctx, led->which_mods));
}
write_buf(buf, "\t\t\tmodifiers= %s;\n",
ModMaskText(keymap, led->mods.mods));
@@ -347,7 +274,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf,
if (led->ctrls) {
write_buf(buf, "\t\t\tcontrols= %s;\n",
- get_control_mask_text(led->ctrls));
+ ControlMaskText(keymap->ctx, led->ctrls));
}
write_buf(buf, "\t\t};\n");
@@ -473,7 +400,7 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
case ACTION_TYPE_CTRL_SET:
case ACTION_TYPE_CTRL_LOCK:
write_buf(buf, "%s%s(controls=%s)%s", prefix, type,
- get_control_mask_text(action->ctrls.ctrls), suffix);
+ ControlMaskText(keymap->ctx, action->ctrls.ctrls), suffix);
break;
case ACTION_TYPE_NONE:
diff --git a/src/text.c b/src/text.c
index 2d5cefb..cc9b0f3 100644
--- a/src/text.c
+++ b/src/text.c
@@ -308,3 +308,74 @@ SIMatchText(enum xkb_match_operation type)
{
return LookupValue(symInterpretMatchMaskNames, type);
}
+
+#define GET_TEXT_BUF_SIZE 512
+
+#define append_get_text(...) do { \
+ int _size = snprintf(ret, GET_TEXT_BUF_SIZE, __VA_ARGS__); \
+ if (_size >= GET_TEXT_BUF_SIZE) \
+ return NULL; \
+} while (0)
+
+const char *
+IndicatorStateText(struct xkb_context *ctx, enum xkb_state_component mask)
+{
+ unsigned int i;
+ char *ret;
+
+ if (mask == 0)
+ return "0";
+
+ ret = xkb_context_get_buffer(ctx, GET_TEXT_BUF_SIZE);
+ ret[0] = '\0';
+
+ for (i = 0; mask; i++) {
+ const char *name;
+
+ if (!(mask & (1 << i)))
+ continue;
+
+ mask &= ~(1 << i);
+ name = LookupValue(modComponentMaskNames, 1 << i);
+
+ if (ret[0] != '\0')
+ append_get_text("%s+%s", ret, name);
+ else
+ append_get_text("%s", name);
+ }
+
+ return ret;
+}
+
+const char *
+ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
+{
+ unsigned int i;
+ char *ret;
+
+ if (mask == 0)
+ return "none";
+
+ if (mask == CONTROL_ALL)
+ return "all";
+
+ ret = xkb_context_get_buffer(ctx, GET_TEXT_BUF_SIZE);
+ ret[0] = '\0';
+
+ for (i = 0; mask; i++) {
+ const char *name;
+
+ if (!(mask & (1 << i)))
+ continue;
+
+ mask &= ~(1 << i);
+ name = LookupValue(ctrlMaskNames, 1 << i);
+
+ if (ret[0] != '\0')
+ append_get_text("%s+%s", ret, name);
+ else
+ append_get_text("%s", name);
+ }
+
+ return ret;
+}
diff --git a/src/text.h b/src/text.h
index 1d7b929..74b6a96 100644
--- a/src/text.h
+++ b/src/text.h
@@ -69,4 +69,10 @@ KeyNameText(struct xkb_context *ctx, xkb_atom_t name);
const char *
SIMatchText(enum xkb_match_operation type);
+const char *
+IndicatorStateText(struct xkb_context *ctx, enum xkb_state_component mask);
+
+const char *
+ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask);
+
#endif /* TEXT_H */