| 1 |
/* |
| 2 |
* Copyright © 2012 Intel Corporation |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
* |
| 5 |
* Author: Daniel Stone <[email protected]> |
| 6 |
*/ |
| 7 |
#pragma once |
| 8 |
|
| 9 |
#include "config.h" |
| 10 |
|
| 11 |
#include <stdbool.h> |
| 12 |
#include <stddef.h> |
| 13 |
|
| 14 |
#include "xkbcommon/xkbcommon.h" |
| 15 |
#include "atom.h" |
| 16 |
#include "darray.h" |
| 17 |
#include "messages-codes.h" |
| 18 |
#include "rmlvo.h" |
| 19 |
#include "utils.h" |
| 20 |
|
| 21 |
struct xkb_context { |
| 22 |
int refcnt; |
| 23 |
|
| 24 |
ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx, |
| 25 |
enum xkb_log_level level, |
| 26 |
const char *fmt, va_list args); |
| 27 |
enum xkb_log_level log_level; |
| 28 |
int log_verbosity; |
| 29 |
void *user_data; |
| 30 |
|
| 31 |
struct xkb_rule_names names_dflt; |
| 32 |
|
| 33 |
darray(char *) includes; |
| 34 |
darray(char *) failed_includes; |
| 35 |
|
| 36 |
struct atom_table *atom_table; |
| 37 |
|
| 38 |
/* Used and allocated by xkbcommon-x11, free()d with the context. */ |
| 39 |
void *x11_atom_cache; |
| 40 |
|
| 41 |
/* Buffer for the *Text() functions. */ |
| 42 |
char text_buffer[2048]; |
| 43 |
size_t text_next; |
| 44 |
|
| 45 |
bool use_environment_names : 1; |
| 46 |
bool use_secure_getenv : 1; |
| 47 |
bool pending_default_includes : 1; |
| 48 |
}; |
| 49 |
|
| 50 |
char * |
| 51 |
xkb_context_getenv(struct xkb_context *ctx, const char *name); |
| 52 |
|
| 53 |
darray_size_t |
| 54 |
xkb_context_num_failed_include_paths(struct xkb_context *ctx); |
| 55 |
|
| 56 |
bool |
| 57 |
xkb_context_init_includes(struct xkb_context *ctx); |
| 58 |
|
| 59 |
const char * |
| 60 |
xkb_context_failed_include_path_get(struct xkb_context *ctx, |
| 61 |
darray_size_t idx); |
| 62 |
|
| 63 |
const char * |
| 64 |
xkb_context_include_path_get_extra_path(struct xkb_context *ctx); |
| 65 |
|
| 66 |
const char * |
| 67 |
xkb_context_include_path_get_unversioned_extensions_path(struct xkb_context *ctx); |
| 68 |
|
| 69 |
const char * |
| 70 |
xkb_context_include_path_get_versioned_extensions_path(struct xkb_context *ctx); |
| 71 |
|
| 72 |
const char * |
| 73 |
xkb_context_include_path_get_system_path(struct xkb_context *ctx); |
| 74 |
|
| 75 |
XKB_EXPORT_PRIVATE darray_size_t |
| 76 |
xkb_atom_table_size(struct xkb_context *ctx); |
| 77 |
|
| 78 |
/* |
| 79 |
* Returns XKB_ATOM_NONE if @string was not previously interned, |
| 80 |
* otherwise returns the atom. |
| 81 |
*/ |
| 82 |
xkb_atom_t |
| 83 |
xkb_atom_lookup(struct xkb_context *ctx, const char *string); |
| 84 |
|
| 85 |
XKB_EXPORT_PRIVATE xkb_atom_t |
| 86 |
xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len); |
| 87 |
|
| 88 |
#define xkb_atom_intern_literal(ctx, literal) \ |
| 89 |
xkb_atom_intern((ctx), (literal), sizeof(literal) - 1) |
| 90 |
|
| 91 |
/** |
| 92 |
* If @string is dynamically allocated, NUL-terminated, free'd immediately |
| 93 |
* after being interned, and not used afterwards, use this function |
| 94 |
* instead of xkb_atom_intern to avoid some unnecessary allocations. |
| 95 |
* The caller should not use or free the passed in string afterwards. |
| 96 |
*/ |
| 97 |
xkb_atom_t |
| 98 |
xkb_atom_steal(struct xkb_context *ctx, char *string); |
| 99 |
|
| 100 |
XKB_EXPORT_PRIVATE const char * |
| 101 |
xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom); |
| 102 |
|
| 103 |
char * |
| 104 |
xkb_context_get_buffer(struct xkb_context *ctx, size_t size); |
| 105 |
|
| 106 |
XKB_EXPORT_PRIVATE ATTR_PRINTF(4, 5) void |
| 107 |
xkb_log(struct xkb_context *ctx, enum xkb_log_level level, int verbosity, |
| 108 |
const char *fmt, ...); |
| 109 |
|
| 110 |
enum RMLVO |
| 111 |
xkb_context_sanitize_rule_names(struct xkb_context *ctx, |
| 112 |
struct xkb_rule_names *rmlvo); |
| 113 |
|
| 114 |
/* |
| 115 |
* The format is not part of the argument list in order to avoid the |
| 116 |
* "ISO C99 requires rest arguments to be used" warning when only the |
| 117 |
* format is supplied without arguments. Not supplying it would still |
| 118 |
* result in an error, though. |
| 119 |
*/ |
| 120 |
#define xkb_log_with_code(ctx, level, verbosity, msg_id, fmt, ...) \ |
| 121 |
xkb_log(ctx, level, verbosity, PREPEND_MESSAGE_ID(msg_id, fmt), ##__VA_ARGS__) |
| 122 |
#define log_dbg(ctx, id, ...) \ |
| 123 |
xkb_log_with_code((ctx), XKB_LOG_LEVEL_DEBUG, XKB_LOG_VERBOSITY_MINIMAL, id, __VA_ARGS__) |
| 124 |
#define log_info(ctx, id, ...) \ |
| 125 |
xkb_log_with_code((ctx), XKB_LOG_LEVEL_INFO, XKB_LOG_VERBOSITY_MINIMAL, id, __VA_ARGS__) |
| 126 |
#define log_warn(ctx, id, ...) \ |
| 127 |
xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, XKB_LOG_VERBOSITY_MINIMAL, id, __VA_ARGS__) |
| 128 |
#define log_vrb(ctx, vrb, id, ...) \ |
| 129 |
xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, (vrb), id, __VA_ARGS__) |
| 130 |
#define log_err(ctx, id, ...) \ |
| 131 |
xkb_log_with_code((ctx), XKB_LOG_LEVEL_ERROR, XKB_LOG_VERBOSITY_MINIMAL, id, __VA_ARGS__) |
| 132 |
#define log_wsgo(ctx, id, ...) \ |
| 133 |
xkb_log_with_code((ctx), XKB_LOG_LEVEL_CRITICAL, XKB_LOG_VERBOSITY_MINIMAL, id, __VA_ARGS__) |
| 134 |
|
| 135 |
/* |
| 136 |
* Variants which are prefixed by the name of the function they're |
| 137 |
* called from. |
| 138 |
* Here we must have the silly 1 variant. |
| 139 |
*/ |
| 140 |
#define log_err_func(ctx, id, fmt, ...) \ |
| 141 |
log_err(ctx, id, "%s: " fmt, __func__, __VA_ARGS__) |
| 142 |
#define log_err_func1(ctx, id, fmt) \ |
| 143 |
log_err(ctx, id, "%s: " fmt, __func__) |