context: add xkb_context_sanitize_rule_names() We want all the default logic in a test, so encapsulate it in this function, and make all the get_default_* functions static. 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
diff --git a/src/context-priv.c b/src/context-priv.c
index 999ece9..c934201 100644
--- a/src/context-priv.c
+++ b/src/context-priv.c
@@ -112,7 +112,7 @@ xkb_context_get_buffer(struct xkb_context *ctx, size_t size)
#define DEFAULT_XKB_OPTIONS NULL
#endif
-const char *
+static const char *
xkb_context_get_default_rules(struct xkb_context *ctx)
{
const char *env = NULL;
@@ -123,7 +123,7 @@ xkb_context_get_default_rules(struct xkb_context *ctx)
return env ? env : DEFAULT_XKB_RULES;
}
-const char *
+static const char *
xkb_context_get_default_model(struct xkb_context *ctx)
{
const char *env = NULL;
@@ -134,7 +134,7 @@ xkb_context_get_default_model(struct xkb_context *ctx)
return env ? env : DEFAULT_XKB_MODEL;
}
-const char *
+static const char *
xkb_context_get_default_layout(struct xkb_context *ctx)
{
const char *env = NULL;
@@ -145,7 +145,7 @@ xkb_context_get_default_layout(struct xkb_context *ctx)
return env ? env : DEFAULT_XKB_LAYOUT;
}
-const char *
+static const char *
xkb_context_get_default_variant(struct xkb_context *ctx)
{
const char *env = NULL;
@@ -159,7 +159,7 @@ xkb_context_get_default_variant(struct xkb_context *ctx)
return env ? env : DEFAULT_XKB_VARIANT;
}
-const char *
+static const char *
xkb_context_get_default_options(struct xkb_context *ctx)
{
const char *env = NULL;
@@ -169,3 +169,22 @@ xkb_context_get_default_options(struct xkb_context *ctx)
return env ? env : DEFAULT_XKB_OPTIONS;
}
+
+void
+xkb_context_sanitize_rule_names(struct xkb_context *ctx,
+ struct xkb_rule_names *rmlvo)
+{
+ if (isempty(rmlvo->rules))
+ rmlvo->rules = xkb_context_get_default_rules(ctx);
+ if (isempty(rmlvo->model))
+ rmlvo->model = xkb_context_get_default_model(ctx);
+ /* Layout and variant are tied together, so don't try to use one from
+ * the caller and one from the environment. */
+ if (isempty(rmlvo->layout)) {
+ rmlvo->layout = xkb_context_get_default_layout(ctx);
+ rmlvo->variant = xkb_context_get_default_variant(ctx);
+ }
+ /* Options can be empty, so respect that if passed in. */
+ if (rmlvo->options == NULL)
+ rmlvo->options = xkb_context_get_default_options(ctx);
+}
diff --git a/src/context.h b/src/context.h
index 486f408..03e6d50 100644
--- a/src/context.h
+++ b/src/context.h
@@ -91,20 +91,9 @@ ATTR_PRINTF(4, 5) void
xkb_log(struct xkb_context *ctx, enum xkb_log_level level, int verbosity,
const char *fmt, ...);
-const char *
-xkb_context_get_default_rules(struct xkb_context *ctx);
-
-const char *
-xkb_context_get_default_model(struct xkb_context *ctx);
-
-const char *
-xkb_context_get_default_layout(struct xkb_context *ctx);
-
-const char *
-xkb_context_get_default_variant(struct xkb_context *ctx);
-
-const char *
-xkb_context_get_default_options(struct xkb_context *ctx);
+void
+xkb_context_sanitize_rule_names(struct xkb_context *ctx,
+ struct xkb_rule_names *rmlvo);
/*
* The format is not part of the argument list in order to avoid the
diff --git a/src/keymap.c b/src/keymap.c
index abf1387..892b7cf 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -137,28 +137,15 @@ xkb_keymap_new_from_names(struct xkb_context *ctx,
return NULL;
}
+ keymap = xkb_keymap_new(ctx, format, flags);
+ if (!keymap)
+ return NULL;
+
if (rmlvo_in)
rmlvo = *rmlvo_in;
else
memset(&rmlvo, 0, sizeof(rmlvo));
-
- if (isempty(rmlvo.rules))
- rmlvo.rules = xkb_context_get_default_rules(ctx);
- if (isempty(rmlvo.model))
- rmlvo.model = xkb_context_get_default_model(ctx);
- /* Layout and variant are tied together, so don't try to use one from
- * the caller and one from the environment. */
- if (isempty(rmlvo.layout)) {
- rmlvo.layout = xkb_context_get_default_layout(ctx);
- rmlvo.variant = xkb_context_get_default_variant(ctx);
- }
- /* Options can be empty, so respect that if passed in. */
- if (rmlvo.options == NULL)
- rmlvo.options = xkb_context_get_default_options(ctx);
-
- keymap = xkb_keymap_new(ctx, format, flags);
- if (!keymap)
- return NULL;
+ xkb_context_sanitize_rule_names(ctx, &rmlvo);
if (!ops->keymap_new_from_names(keymap, &rmlvo)) {
xkb_keymap_unref(keymap);